2026-05-08 15:31:52 +00:00
|
|
|
import type {
|
2026-07-13 13:11:46 +08:00
|
|
|
ApiServicePayload,
|
2026-06-13 20:08:18 +08:00
|
|
|
AutomationsPayload,
|
2026-06-14 18:24:59 +08:00
|
|
|
AutomationUpdatePayload,
|
2026-07-13 13:11:46 +08:00
|
|
|
ChannelConfigurePayload,
|
|
|
|
|
ChannelConnectPayload,
|
|
|
|
|
ChannelValidationPayload,
|
2026-05-08 15:31:52 +00:00
|
|
|
ChatSummary,
|
2026-05-22 22:25:12 +08:00
|
|
|
CliAppsPayload,
|
2026-06-06 19:49:33 +08:00
|
|
|
FilePreviewPayload,
|
2026-05-19 22:42:38 +08:00
|
|
|
ImageGenerationSettingsUpdate,
|
2026-05-24 13:38:37 +08:00
|
|
|
McpPresetsPayload,
|
2026-08-10 23:44:37 +08:00
|
|
|
McpOAuthFlowPayload,
|
2026-07-28 16:56:39 +08:00
|
|
|
MarketplaceProvider,
|
2026-07-03 18:17:52 +08:00
|
|
|
NanobotFeaturesPayload,
|
2026-05-24 13:38:37 +08:00
|
|
|
ModelConfigurationCreate,
|
2026-05-29 03:42:53 +08:00
|
|
|
ModelConfigurationUpdate,
|
|
|
|
|
NetworkSafetySettingsUpdate,
|
2026-07-13 13:11:46 +08:00
|
|
|
PairingPayload,
|
2026-07-24 00:55:06 +08:00
|
|
|
ProviderCreationUpdate,
|
2026-05-30 23:45:26 +08:00
|
|
|
ProviderModelsPayload,
|
2026-07-23 11:55:16 +08:00
|
|
|
ProviderOAuthCompletionResult,
|
|
|
|
|
ProviderOAuthLoginResult,
|
2026-05-08 15:31:52 +00:00
|
|
|
ProviderSettingsUpdate,
|
2026-08-22 19:33:22 +08:00
|
|
|
RecoveryState,
|
2026-06-11 19:11:37 +08:00
|
|
|
SessionDeleteResult,
|
2026-08-18 18:28:19 +08:00
|
|
|
SessionHandle,
|
2026-06-06 19:49:33 +08:00
|
|
|
SessionAutomationsPayload,
|
2026-05-08 15:31:52 +00:00
|
|
|
SettingsPayload,
|
2026-05-19 22:42:38 +08:00
|
|
|
SidebarStatePayload,
|
2026-06-06 19:49:33 +08:00
|
|
|
SkillDetail,
|
2026-07-27 21:19:42 +08:00
|
|
|
SkillActionPayload,
|
|
|
|
|
SkillInstallPayload,
|
2026-06-06 19:49:33 +08:00
|
|
|
SkillsPayload,
|
2026-07-27 21:19:42 +08:00
|
|
|
SkillsSearchPayload,
|
|
|
|
|
SkillsTrendsPayload,
|
|
|
|
|
SkillsTrendingPayload,
|
2026-05-08 15:31:52 +00:00
|
|
|
SlashCommand,
|
2026-07-07 14:01:07 +08:00
|
|
|
SlashCommandLifecycle,
|
2026-06-09 01:08:49 +08:00
|
|
|
TranscriptionSettingsUpdate,
|
2026-05-09 06:48:26 +00:00
|
|
|
WebSearchSettingsUpdate,
|
2026-05-29 03:42:53 +08:00
|
|
|
WorkspacesPayload,
|
2026-05-16 01:14:11 +08:00
|
|
|
WebuiThreadPersistedPayload,
|
2026-09-12 04:37:37 +08:00
|
|
|
WebuiThreadTraceDetailPayload,
|
2026-05-29 03:42:53 +08:00
|
|
|
WorkspaceScopePayload,
|
2026-05-08 15:31:52 +00:00
|
|
|
} from "./types";
|
2026-06-02 15:36:52 +08:00
|
|
|
import { fetchWithTimeout } from "./http";
|
|
|
|
|
|
|
|
|
|
const API_READ_TIMEOUT_MS = 20_000;
|
2026-08-10 15:43:54 +08:00
|
|
|
const API_MUTATION_TIMEOUT_MS = 20_000;
|
|
|
|
|
const PACKAGE_MUTATION_TIMEOUT_MS = 150_000;
|
2026-07-07 14:01:07 +08:00
|
|
|
const SLASH_COMMAND_LIFECYCLES = new Set<SlashCommandLifecycle>([
|
|
|
|
|
"side_channel",
|
|
|
|
|
"finalize_active_turn",
|
|
|
|
|
"stop_active_turn",
|
|
|
|
|
"agent_turn",
|
|
|
|
|
"agent_turn_with_args",
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
function isSlashCommandLifecycle(value: unknown): value is SlashCommandLifecycle {
|
|
|
|
|
return (
|
|
|
|
|
typeof value === "string"
|
|
|
|
|
&& SLASH_COMMAND_LIFECYCLES.has(value as SlashCommandLifecycle)
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-04-18 18:51:53 +00:00
|
|
|
export class ApiError extends Error {
|
|
|
|
|
status: number;
|
|
|
|
|
constructor(status: number, message: string) {
|
|
|
|
|
super(message);
|
|
|
|
|
this.status = status;
|
|
|
|
|
this.name = "ApiError";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-10 15:43:54 +08:00
|
|
|
export interface WebUIMutationTransport {
|
|
|
|
|
requestMutation<T>(
|
|
|
|
|
action: string,
|
|
|
|
|
payload?: Record<string, unknown>,
|
|
|
|
|
timeoutMs?: number,
|
|
|
|
|
): Promise<T>;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-18 18:51:53 +00:00
|
|
|
async function request<T>(
|
|
|
|
|
url: string,
|
|
|
|
|
token: string,
|
|
|
|
|
init?: RequestInit,
|
2026-06-02 15:36:52 +08:00
|
|
|
timeoutMs: number = 0,
|
2026-04-18 18:51:53 +00:00
|
|
|
): Promise<T> {
|
2026-06-02 15:36:52 +08:00
|
|
|
const res = await fetchWithTimeout(
|
|
|
|
|
url,
|
|
|
|
|
{
|
|
|
|
|
...(init ?? {}),
|
|
|
|
|
headers: {
|
|
|
|
|
...(init?.headers ?? {}),
|
|
|
|
|
Authorization: `Bearer ${token}`,
|
|
|
|
|
},
|
|
|
|
|
credentials: "same-origin",
|
2026-04-18 18:51:53 +00:00
|
|
|
},
|
2026-06-02 15:36:52 +08:00
|
|
|
timeoutMs,
|
|
|
|
|
);
|
2026-04-18 18:51:53 +00:00
|
|
|
if (!res.ok) {
|
2026-05-29 14:14:56 +08:00
|
|
|
const text = typeof res.text === "function" ? (await res.text()).trim() : "";
|
2026-08-10 23:44:37 +08:00
|
|
|
let message = text;
|
|
|
|
|
if (text.startsWith("{")) {
|
|
|
|
|
try {
|
|
|
|
|
const payload: unknown = JSON.parse(text);
|
|
|
|
|
if (payload && typeof payload === "object") {
|
|
|
|
|
const error = (payload as { error?: unknown }).error;
|
|
|
|
|
if (typeof error === "string" && error.trim()) message = error.trim();
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
// Preserve non-JSON error bodies exactly as returned by the gateway.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
throw new ApiError(res.status, message || `HTTP ${res.status}`);
|
2026-04-18 18:51:53 +00:00
|
|
|
}
|
2026-05-29 03:42:53 +08:00
|
|
|
const contentType = res.headers?.get?.("content-type") ?? "";
|
|
|
|
|
if (contentType && !contentType.toLowerCase().includes("application/json")) {
|
|
|
|
|
const text = typeof res.text === "function" ? await res.text() : "";
|
|
|
|
|
const isHtml = text.trimStart().toLowerCase().startsWith("<!doctype");
|
|
|
|
|
throw new ApiError(
|
|
|
|
|
res.status,
|
|
|
|
|
isHtml
|
|
|
|
|
? "Gateway returned WebUI HTML instead of JSON. Restart nanobot gateway and try again."
|
|
|
|
|
: "Gateway returned a non-JSON response.",
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-04-18 18:51:53 +00:00
|
|
|
return (await res.json()) as T;
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-10 15:43:54 +08:00
|
|
|
async function mutation<T>(
|
|
|
|
|
transport: WebUIMutationTransport,
|
|
|
|
|
action: string,
|
|
|
|
|
payload: Record<string, unknown> = {},
|
|
|
|
|
timeoutMs: number = API_MUTATION_TIMEOUT_MS,
|
|
|
|
|
): Promise<T> {
|
|
|
|
|
try {
|
|
|
|
|
return await transport.requestMutation<T>(action, payload, timeoutMs);
|
|
|
|
|
} catch (reason) {
|
|
|
|
|
const status = (
|
|
|
|
|
typeof reason === "object"
|
|
|
|
|
&& reason !== null
|
|
|
|
|
&& "status" in reason
|
|
|
|
|
&& typeof reason.status === "number"
|
|
|
|
|
) ? reason.status : 500;
|
|
|
|
|
const message = reason instanceof Error ? reason.message : "WebUI mutation failed";
|
|
|
|
|
throw new ApiError(status, message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function compactMcpValues(values: Record<string, unknown>): Record<string, unknown> {
|
2026-05-24 13:38:37 +08:00
|
|
|
const payload: Record<string, unknown> = {};
|
|
|
|
|
Object.entries(values).forEach(([key, value]) => {
|
|
|
|
|
if (value === null || value === undefined) return;
|
|
|
|
|
if (typeof value === "string") {
|
|
|
|
|
const trimmed = value.trim();
|
|
|
|
|
if (trimmed) payload[key] = trimmed;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
payload[key] = value;
|
|
|
|
|
});
|
2026-08-10 15:43:54 +08:00
|
|
|
return payload;
|
2026-06-15 15:14:24 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-18 18:51:53 +00:00
|
|
|
function splitKey(key: string): { channel: string; chatId: string } {
|
|
|
|
|
const idx = key.indexOf(":");
|
|
|
|
|
if (idx === -1) return { channel: "", chatId: key };
|
|
|
|
|
return { channel: key.slice(0, idx), chatId: key.slice(idx + 1) };
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-18 18:28:19 +08:00
|
|
|
function normalizeSessionHandle(value: unknown): SessionHandle | null {
|
2026-08-18 09:53:55 +08:00
|
|
|
if (!value || typeof value !== "object") return null;
|
2026-08-18 18:28:19 +08:00
|
|
|
const handle = value as Partial<SessionHandle>;
|
2026-08-18 09:53:55 +08:00
|
|
|
const id = typeof handle.id === "string" ? handle.id.trim() : "";
|
|
|
|
|
const name = typeof handle.name === "string" ? handle.name.trim() : "";
|
|
|
|
|
if (
|
|
|
|
|
!/^handle_[a-f0-9]{32}$/i.test(id)
|
|
|
|
|
|| !name
|
|
|
|
|
|| !/^[\p{L}\p{N}_-]+$/u.test(name)
|
|
|
|
|
) return null;
|
2026-08-18 18:28:19 +08:00
|
|
|
return { id, name };
|
2026-08-18 09:53:55 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-18 18:51:53 +00:00
|
|
|
export async function listSessions(
|
|
|
|
|
token: string,
|
|
|
|
|
base: string = "",
|
|
|
|
|
): Promise<ChatSummary[]> {
|
|
|
|
|
type Row = {
|
|
|
|
|
key: string;
|
|
|
|
|
created_at: string | null;
|
|
|
|
|
updated_at: string | null;
|
2026-05-06 14:15:36 +00:00
|
|
|
title?: string;
|
2026-04-18 18:51:53 +00:00
|
|
|
preview?: string;
|
2026-07-23 00:38:49 +08:00
|
|
|
model_preset?: string | null;
|
2026-05-19 22:42:38 +08:00
|
|
|
run_started_at?: number | null;
|
2026-08-22 19:33:22 +08:00
|
|
|
recovery_state?: RecoveryState | null;
|
2026-05-29 03:42:53 +08:00
|
|
|
workspace_scope?: WorkspaceScopePayload | null;
|
2026-08-18 18:28:19 +08:00
|
|
|
handle?: SessionHandle | null;
|
2026-04-18 18:51:53 +00:00
|
|
|
};
|
|
|
|
|
const body = await request<{ sessions: Row[] }>(
|
|
|
|
|
`${base}/api/sessions`,
|
|
|
|
|
token,
|
2026-06-02 15:36:52 +08:00
|
|
|
undefined,
|
|
|
|
|
API_READ_TIMEOUT_MS,
|
2026-04-18 18:51:53 +00:00
|
|
|
);
|
2026-08-18 09:53:55 +08:00
|
|
|
return body.sessions.map((s) => {
|
2026-08-18 18:28:19 +08:00
|
|
|
const handle = normalizeSessionHandle(s.handle);
|
2026-08-18 09:53:55 +08:00
|
|
|
return {
|
|
|
|
|
key: s.key,
|
|
|
|
|
...splitKey(s.key),
|
|
|
|
|
createdAt: s.created_at,
|
|
|
|
|
updatedAt: s.updated_at,
|
|
|
|
|
title: s.title ?? "",
|
|
|
|
|
preview: s.preview ?? "",
|
|
|
|
|
modelPreset: s.model_preset ?? null,
|
|
|
|
|
runStartedAt: s.run_started_at ?? null,
|
2026-08-22 19:33:22 +08:00
|
|
|
recoveryState: s.recovery_state ?? null,
|
2026-08-18 09:53:55 +08:00
|
|
|
workspaceScope: s.workspace_scope ?? null,
|
|
|
|
|
handle,
|
|
|
|
|
};
|
|
|
|
|
});
|
2026-04-18 18:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
2026-05-16 01:14:11 +08:00
|
|
|
/** Disk-backed WebUI display thread snapshot (separate from agent session). */
|
2026-06-10 18:02:27 +08:00
|
|
|
export interface FetchWebuiThreadOptions {
|
|
|
|
|
limit?: number;
|
|
|
|
|
direction?: "latest";
|
|
|
|
|
before?: string | null;
|
2026-07-30 10:25:22 +08:00
|
|
|
signal?: AbortSignal;
|
2026-09-12 04:37:37 +08:00
|
|
|
revision?: string;
|
|
|
|
|
cached?: WebuiThreadPersistedPayload;
|
2026-06-10 18:02:27 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-16 01:14:11 +08:00
|
|
|
export async function fetchWebuiThread(
|
2026-04-18 18:51:53 +00:00
|
|
|
token: string,
|
|
|
|
|
key: string,
|
2026-06-10 18:02:27 +08:00
|
|
|
optionsOrBase?: FetchWebuiThreadOptions | string,
|
2026-04-18 18:51:53 +00:00
|
|
|
base: string = "",
|
2026-05-16 01:14:11 +08:00
|
|
|
): Promise<WebuiThreadPersistedPayload | null> {
|
2026-06-10 18:02:27 +08:00
|
|
|
const options = typeof optionsOrBase === "string" ? undefined : optionsOrBase;
|
|
|
|
|
const resolvedBase = typeof optionsOrBase === "string" ? optionsOrBase : base;
|
|
|
|
|
const params = new URLSearchParams();
|
|
|
|
|
if (options?.limit !== undefined) params.set("limit", String(options.limit));
|
|
|
|
|
if (options?.direction) params.set("direction", options.direction);
|
|
|
|
|
if (options?.before) params.set("before", options.before);
|
|
|
|
|
const query = params.toString();
|
|
|
|
|
const suffix = query ? `?${query}` : "";
|
|
|
|
|
const url = `${resolvedBase}/api/sessions/${encodeURIComponent(key)}/webui-thread${suffix}`;
|
2026-09-12 04:37:37 +08:00
|
|
|
const headers: Record<string, string> = { Authorization: `Bearer ${token}` };
|
|
|
|
|
if (options?.revision) headers["If-None-Match"] = `"${options.revision}"`;
|
2026-06-02 15:36:52 +08:00
|
|
|
const res = await fetchWithTimeout(url, {
|
2026-09-12 04:37:37 +08:00
|
|
|
headers,
|
2026-05-16 01:14:11 +08:00
|
|
|
credentials: "same-origin",
|
2026-07-28 11:40:01 +08:00
|
|
|
cache: "no-store",
|
2026-07-30 10:25:22 +08:00
|
|
|
signal: options?.signal,
|
2026-05-16 01:14:11 +08:00
|
|
|
});
|
2026-09-12 04:37:37 +08:00
|
|
|
if (res.status === 304 && options?.cached) return options.cached;
|
2026-05-16 01:14:11 +08:00
|
|
|
if (res.status === 404) return null;
|
|
|
|
|
if (!res.ok) throw new ApiError(res.status, `HTTP ${res.status}`);
|
|
|
|
|
return (await res.json()) as WebuiThreadPersistedPayload;
|
2026-04-18 18:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
2026-09-12 04:37:37 +08:00
|
|
|
export async function fetchWebuiThreadTraceDetail(
|
|
|
|
|
token: string,
|
|
|
|
|
key: string,
|
|
|
|
|
ref: string,
|
|
|
|
|
base: string = "",
|
|
|
|
|
): Promise<WebuiThreadTraceDetailPayload> {
|
|
|
|
|
const query = new URLSearchParams({ ref });
|
|
|
|
|
const url = `${base}/api/sessions/${encodeURIComponent(key)}/webui-thread/trace-detail?${query}`;
|
|
|
|
|
const res = await fetchWithTimeout(url, {
|
|
|
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
|
|
|
credentials: "same-origin",
|
|
|
|
|
cache: "no-store",
|
|
|
|
|
});
|
|
|
|
|
if (!res.ok) throw new ApiError(res.status, `HTTP ${res.status}`);
|
|
|
|
|
return (await res.json()) as WebuiThreadTraceDetailPayload;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-06 19:49:33 +08:00
|
|
|
export async function fetchFilePreview(
|
|
|
|
|
token: string,
|
|
|
|
|
key: string,
|
|
|
|
|
path: string,
|
|
|
|
|
base: string = "",
|
|
|
|
|
): Promise<FilePreviewPayload> {
|
|
|
|
|
const query = new URLSearchParams();
|
|
|
|
|
query.set("path", path);
|
|
|
|
|
return request<FilePreviewPayload>(
|
|
|
|
|
`${base}/api/sessions/${encodeURIComponent(key)}/file-preview?${query}`,
|
|
|
|
|
token,
|
|
|
|
|
undefined,
|
|
|
|
|
API_READ_TIMEOUT_MS,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-15 10:45:40 +08:00
|
|
|
export async function fetchFilePreviewAvailability(
|
|
|
|
|
token: string,
|
|
|
|
|
key: string,
|
|
|
|
|
path: string,
|
|
|
|
|
base: string = "",
|
|
|
|
|
): Promise<boolean> {
|
|
|
|
|
const query = new URLSearchParams();
|
|
|
|
|
query.set("path", path);
|
|
|
|
|
query.set("probe", "1");
|
|
|
|
|
const payload = await request<{ available?: boolean }>(
|
|
|
|
|
`${base}/api/sessions/${encodeURIComponent(key)}/file-preview?${query}`,
|
|
|
|
|
token,
|
|
|
|
|
undefined,
|
|
|
|
|
API_READ_TIMEOUT_MS,
|
|
|
|
|
);
|
|
|
|
|
return payload.available !== false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-06 19:49:33 +08:00
|
|
|
export async function fetchSessionAutomations(
|
|
|
|
|
token: string,
|
|
|
|
|
key: string,
|
|
|
|
|
base: string = "",
|
|
|
|
|
): Promise<SessionAutomationsPayload> {
|
|
|
|
|
return request<SessionAutomationsPayload>(
|
|
|
|
|
`${base}/api/sessions/${encodeURIComponent(key)}/automations`,
|
|
|
|
|
token,
|
|
|
|
|
undefined,
|
|
|
|
|
API_READ_TIMEOUT_MS,
|
2026-06-13 20:08:18 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function fetchAutomations(
|
|
|
|
|
token: string,
|
|
|
|
|
base: string = "",
|
|
|
|
|
): Promise<AutomationsPayload> {
|
|
|
|
|
return request<AutomationsPayload>(
|
|
|
|
|
`${base}/api/webui/automations`,
|
|
|
|
|
token,
|
|
|
|
|
undefined,
|
|
|
|
|
API_READ_TIMEOUT_MS,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-13 05:04:38 +08:00
|
|
|
export async function fetchAutomationRunResult(
|
|
|
|
|
token: string,
|
|
|
|
|
id: string,
|
|
|
|
|
runAtMs: number,
|
|
|
|
|
kind: "cron" | "local_trigger",
|
|
|
|
|
signal?: AbortSignal,
|
|
|
|
|
): Promise<{ response: string | null }> {
|
|
|
|
|
const query = new URLSearchParams({ id, run_at_ms: String(runAtMs), kind });
|
|
|
|
|
return request<{ response: string | null }>(
|
|
|
|
|
`/api/webui/automations/result?${query}`, token, { signal }, API_READ_TIMEOUT_MS,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-13 20:08:18 +08:00
|
|
|
export async function runAutomationAction(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-06-13 20:08:18 +08:00
|
|
|
action: "enable" | "disable" | "delete" | "run",
|
|
|
|
|
id: string,
|
|
|
|
|
): Promise<AutomationsPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<AutomationsPayload>(transport, `automation.${action}`, { id });
|
2026-06-14 18:24:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function updateAutomation(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-06-14 18:24:59 +08:00
|
|
|
id: string,
|
|
|
|
|
values: AutomationUpdatePayload,
|
|
|
|
|
): Promise<AutomationsPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<AutomationsPayload>(transport, "automation.update", { id, values });
|
2026-06-06 19:49:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function fetchSkills(
|
|
|
|
|
token: string,
|
|
|
|
|
base: string = "",
|
|
|
|
|
): Promise<SkillsPayload> {
|
|
|
|
|
return request<SkillsPayload>(
|
|
|
|
|
`${base}/api/webui/skills`,
|
|
|
|
|
token,
|
|
|
|
|
undefined,
|
|
|
|
|
API_READ_TIMEOUT_MS,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function fetchSkillDetail(
|
|
|
|
|
token: string,
|
|
|
|
|
name: string,
|
|
|
|
|
base: string = "",
|
|
|
|
|
): Promise<SkillDetail> {
|
|
|
|
|
return request<SkillDetail>(
|
|
|
|
|
`${base}/api/webui/skills/${encodeURIComponent(name)}`,
|
|
|
|
|
token,
|
|
|
|
|
undefined,
|
|
|
|
|
API_READ_TIMEOUT_MS,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-27 21:19:42 +08:00
|
|
|
export async function updateSkillEnabled(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-07-27 21:19:42 +08:00
|
|
|
name: string,
|
|
|
|
|
enabled: boolean,
|
|
|
|
|
): Promise<SkillActionPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<SkillActionPayload>(transport, "skill.update", { name, enabled });
|
2026-07-27 21:19:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function deleteSkill(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-07-27 21:19:42 +08:00
|
|
|
name: string,
|
|
|
|
|
): Promise<SkillActionPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<SkillActionPayload>(transport, "skill.delete", { name });
|
2026-07-27 21:19:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function searchMarketplaceSkills(
|
|
|
|
|
token: string,
|
|
|
|
|
query: string,
|
2026-07-28 16:56:39 +08:00
|
|
|
provider: MarketplaceProvider = "all",
|
2026-07-27 21:19:42 +08:00
|
|
|
base: string = "",
|
|
|
|
|
): Promise<SkillsSearchPayload> {
|
2026-07-28 16:56:39 +08:00
|
|
|
const params = new URLSearchParams({ q: query, provider });
|
2026-07-27 21:19:42 +08:00
|
|
|
return request<SkillsSearchPayload>(
|
|
|
|
|
`${base}/api/webui/skills/search?${params}`,
|
|
|
|
|
token,
|
|
|
|
|
undefined,
|
|
|
|
|
API_READ_TIMEOUT_MS,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function fetchTrendingMarketplaceSkills(
|
|
|
|
|
token: string,
|
2026-07-28 16:56:39 +08:00
|
|
|
provider: MarketplaceProvider = "all",
|
2026-07-27 21:19:42 +08:00
|
|
|
base: string = "",
|
|
|
|
|
): Promise<SkillsTrendingPayload> {
|
2026-07-28 16:56:39 +08:00
|
|
|
const params = new URLSearchParams({ provider });
|
2026-07-27 21:19:42 +08:00
|
|
|
return request<SkillsTrendingPayload>(
|
2026-07-28 16:56:39 +08:00
|
|
|
`${base}/api/webui/skills/trending?${params}`,
|
2026-07-27 21:19:42 +08:00
|
|
|
token,
|
|
|
|
|
undefined,
|
|
|
|
|
API_READ_TIMEOUT_MS,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function fetchMarketplaceSkillTrends(
|
|
|
|
|
token: string,
|
|
|
|
|
skillIds: string[],
|
|
|
|
|
base: string = "",
|
|
|
|
|
): Promise<SkillsTrendsPayload> {
|
|
|
|
|
const params = new URLSearchParams();
|
|
|
|
|
skillIds.forEach((id) => params.append("id", id));
|
|
|
|
|
return request<SkillsTrendsPayload>(
|
|
|
|
|
`${base}/api/webui/skills/trends?${params}`,
|
|
|
|
|
token,
|
|
|
|
|
undefined,
|
|
|
|
|
API_READ_TIMEOUT_MS,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function installMarketplaceSkill(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-07-28 16:56:39 +08:00
|
|
|
provider: Exclude<MarketplaceProvider, "all">,
|
2026-07-27 21:19:42 +08:00
|
|
|
source: string,
|
|
|
|
|
skill: string,
|
2026-07-28 16:56:39 +08:00
|
|
|
version: string = "",
|
2026-07-27 21:19:42 +08:00
|
|
|
): Promise<SkillInstallPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<SkillInstallPayload>(
|
|
|
|
|
transport,
|
|
|
|
|
"skill.install",
|
|
|
|
|
{ provider, source, skill, ...(version ? { version } : {}) },
|
|
|
|
|
PACKAGE_MUTATION_TIMEOUT_MS,
|
2026-07-27 21:19:42 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-18 18:51:53 +00:00
|
|
|
export async function deleteSession(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-04-18 18:51:53 +00:00
|
|
|
key: string,
|
2026-06-11 19:11:37 +08:00
|
|
|
optionsOrBase?: { deleteAutomations?: boolean } | string,
|
|
|
|
|
): Promise<SessionDeleteResult> {
|
|
|
|
|
const options = typeof optionsOrBase === "string" ? undefined : optionsOrBase;
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<SessionDeleteResult>(
|
|
|
|
|
transport,
|
|
|
|
|
"session.delete",
|
|
|
|
|
{
|
|
|
|
|
key,
|
|
|
|
|
...(options?.deleteAutomations ? { delete_automations: true } : {}),
|
|
|
|
|
},
|
2026-04-18 18:51:53 +00:00
|
|
|
);
|
|
|
|
|
}
|
2026-04-25 18:05:06 +00:00
|
|
|
|
|
|
|
|
export async function fetchSettings(
|
|
|
|
|
token: string,
|
|
|
|
|
base: string = "",
|
|
|
|
|
): Promise<SettingsPayload> {
|
2026-06-02 15:36:52 +08:00
|
|
|
return request<SettingsPayload>(
|
|
|
|
|
`${base}/api/settings`,
|
|
|
|
|
token,
|
|
|
|
|
undefined,
|
|
|
|
|
API_READ_TIMEOUT_MS,
|
|
|
|
|
);
|
2026-04-25 18:05:06 +00:00
|
|
|
}
|
|
|
|
|
|
2026-06-06 19:49:33 +08:00
|
|
|
export async function fetchSettingsUsage(
|
|
|
|
|
token: string,
|
|
|
|
|
base: string = "",
|
|
|
|
|
): Promise<NonNullable<SettingsPayload["usage"]>> {
|
|
|
|
|
return request<NonNullable<SettingsPayload["usage"]>>(
|
|
|
|
|
`${base}/api/settings/usage`,
|
|
|
|
|
token,
|
|
|
|
|
undefined,
|
|
|
|
|
API_READ_TIMEOUT_MS,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-09 22:31:14 +08:00
|
|
|
export interface VersionCheckResult {
|
|
|
|
|
updateAvailable: {
|
|
|
|
|
currentVersion: string;
|
|
|
|
|
latestVersion: string;
|
|
|
|
|
pypiUrl?: string;
|
|
|
|
|
} | null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function checkVersion(
|
|
|
|
|
token: string,
|
|
|
|
|
base: string = "",
|
|
|
|
|
): Promise<VersionCheckResult> {
|
|
|
|
|
return request<VersionCheckResult>(
|
|
|
|
|
`${base}/api/settings/version-check`,
|
|
|
|
|
token,
|
|
|
|
|
undefined,
|
|
|
|
|
10_000,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-29 03:42:53 +08:00
|
|
|
export async function fetchWorkspaces(
|
|
|
|
|
token: string,
|
|
|
|
|
base: string = "",
|
|
|
|
|
): Promise<WorkspacesPayload> {
|
2026-06-02 15:36:52 +08:00
|
|
|
return request<WorkspacesPayload>(
|
|
|
|
|
`${base}/api/workspaces`,
|
|
|
|
|
token,
|
|
|
|
|
undefined,
|
|
|
|
|
API_READ_TIMEOUT_MS,
|
|
|
|
|
);
|
2026-05-29 03:42:53 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-22 22:25:12 +08:00
|
|
|
export async function fetchCliApps(
|
|
|
|
|
token: string,
|
|
|
|
|
base: string = "",
|
|
|
|
|
): Promise<CliAppsPayload> {
|
2026-06-02 15:36:52 +08:00
|
|
|
return request<CliAppsPayload>(
|
|
|
|
|
`${base}/api/settings/cli-apps`,
|
|
|
|
|
token,
|
|
|
|
|
undefined,
|
|
|
|
|
API_READ_TIMEOUT_MS,
|
|
|
|
|
);
|
2026-05-22 22:25:12 +08:00
|
|
|
}
|
|
|
|
|
|
2026-06-13 13:26:49 +08:00
|
|
|
export async function fetchInstalledCliApps(
|
|
|
|
|
token: string,
|
|
|
|
|
base: string = "",
|
|
|
|
|
): Promise<CliAppsPayload> {
|
|
|
|
|
return request<CliAppsPayload>(
|
|
|
|
|
`${base}/api/settings/cli-apps?installed_only=1`,
|
|
|
|
|
token,
|
|
|
|
|
undefined,
|
|
|
|
|
API_READ_TIMEOUT_MS,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-03 18:17:52 +08:00
|
|
|
export async function fetchNanobotFeatures(
|
|
|
|
|
token: string,
|
|
|
|
|
base: string = "",
|
|
|
|
|
): Promise<NanobotFeaturesPayload> {
|
|
|
|
|
return request<NanobotFeaturesPayload>(
|
|
|
|
|
`${base}/api/settings/nanobot-features`,
|
|
|
|
|
token,
|
|
|
|
|
undefined,
|
|
|
|
|
API_READ_TIMEOUT_MS,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-13 13:11:46 +08:00
|
|
|
export async function fetchApiService(token: string, base: string = ""): Promise<ApiServicePayload> {
|
|
|
|
|
return request<ApiServicePayload>(`${base}/api/settings/api-service`, token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function startApiService(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-07-13 13:11:46 +08:00
|
|
|
values: { host: string; port: number; timeout: number; apiKey?: string },
|
|
|
|
|
): Promise<ApiServicePayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<ApiServicePayload>(
|
|
|
|
|
transport,
|
|
|
|
|
"settings.api_service.start",
|
|
|
|
|
{
|
|
|
|
|
host: values.host,
|
|
|
|
|
port: values.port,
|
|
|
|
|
timeout: values.timeout,
|
|
|
|
|
...(values.apiKey !== undefined ? { api_key: values.apiKey } : {}),
|
|
|
|
|
},
|
|
|
|
|
PACKAGE_MUTATION_TIMEOUT_MS,
|
2026-07-13 13:11:46 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-10 15:43:54 +08:00
|
|
|
export async function stopApiService(
|
|
|
|
|
transport: WebUIMutationTransport,
|
|
|
|
|
): Promise<ApiServicePayload> {
|
|
|
|
|
return mutation<ApiServicePayload>(transport, "settings.api_service.stop");
|
2026-07-13 13:11:46 +08:00
|
|
|
}
|
|
|
|
|
|
2026-07-03 18:17:52 +08:00
|
|
|
export async function enableNanobotFeature(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-07-03 18:17:52 +08:00
|
|
|
name: string,
|
2026-09-11 15:22:14 +08:00
|
|
|
options: { instanceId?: string; installOnly?: boolean } = {},
|
2026-07-03 18:17:52 +08:00
|
|
|
): Promise<NanobotFeaturesPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<NanobotFeaturesPayload>(
|
|
|
|
|
transport,
|
|
|
|
|
"settings.feature.enable",
|
2026-09-11 15:22:14 +08:00
|
|
|
{
|
|
|
|
|
name,
|
|
|
|
|
...(options.instanceId ? { instance_id: options.instanceId } : {}),
|
|
|
|
|
...(options.installOnly ? { install_only: true } : {}),
|
|
|
|
|
},
|
2026-08-10 15:43:54 +08:00
|
|
|
PACKAGE_MUTATION_TIMEOUT_MS,
|
2026-07-03 18:17:52 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function disableNanobotFeature(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-07-03 18:17:52 +08:00
|
|
|
name: string,
|
2026-07-13 13:11:46 +08:00
|
|
|
options: { instanceId?: string } = {},
|
2026-07-03 18:17:52 +08:00
|
|
|
): Promise<NanobotFeaturesPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<NanobotFeaturesPayload>(
|
|
|
|
|
transport,
|
|
|
|
|
"settings.feature.disable",
|
|
|
|
|
{ name, ...(options.instanceId ? { instance_id: options.instanceId } : {}) },
|
2026-07-03 18:17:52 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-13 13:11:46 +08:00
|
|
|
export async function fetchPairingRequests(
|
|
|
|
|
token: string,
|
|
|
|
|
base: string = "",
|
|
|
|
|
): Promise<PairingPayload> {
|
|
|
|
|
return request<PairingPayload>(
|
|
|
|
|
`${base}/api/settings/pairing`,
|
|
|
|
|
token,
|
|
|
|
|
undefined,
|
|
|
|
|
API_READ_TIMEOUT_MS,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function runPairingAction(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-07-13 13:11:46 +08:00
|
|
|
action: "approve" | "deny",
|
|
|
|
|
code: string,
|
|
|
|
|
): Promise<PairingPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<PairingPayload>(transport, `settings.pairing.${action}`, { code });
|
2026-07-13 13:11:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function startChannelConnect(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-07-19 23:30:49 +08:00
|
|
|
channel: string,
|
2026-09-11 15:22:14 +08:00
|
|
|
params: Readonly<Record<string, string | boolean>> = {},
|
2026-07-13 13:11:46 +08:00
|
|
|
): Promise<ChannelConnectPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<ChannelConnectPayload>(
|
|
|
|
|
transport,
|
|
|
|
|
"settings.channel.connect.start",
|
|
|
|
|
{
|
2026-09-11 15:22:14 +08:00
|
|
|
...params,
|
2026-08-10 15:43:54 +08:00
|
|
|
channel,
|
|
|
|
|
},
|
|
|
|
|
PACKAGE_MUTATION_TIMEOUT_MS,
|
2026-07-13 13:11:46 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function pollChannelConnect(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-07-19 23:30:49 +08:00
|
|
|
channel: string,
|
2026-07-13 13:11:46 +08:00
|
|
|
sessionId: string,
|
2026-08-07 16:53:31 +08:00
|
|
|
params: Readonly<Record<string, string>> = {},
|
2026-07-13 13:11:46 +08:00
|
|
|
): Promise<ChannelConnectPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
const values = Object.fromEntries(
|
|
|
|
|
Object.entries(params).filter(([key]) => key !== "session_id"),
|
|
|
|
|
);
|
|
|
|
|
return mutation<ChannelConnectPayload>(
|
|
|
|
|
transport,
|
|
|
|
|
"settings.channel.connect.poll",
|
|
|
|
|
{ channel, session_id: sessionId, ...values },
|
|
|
|
|
PACKAGE_MUTATION_TIMEOUT_MS,
|
2026-07-13 13:11:46 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function cancelChannelConnect(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-07-19 23:30:49 +08:00
|
|
|
channel: string,
|
2026-07-13 13:11:46 +08:00
|
|
|
sessionId: string,
|
|
|
|
|
): Promise<ChannelConnectPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<ChannelConnectPayload>(
|
|
|
|
|
transport,
|
|
|
|
|
"settings.channel.connect.cancel",
|
|
|
|
|
{ channel, session_id: sessionId },
|
2026-07-13 13:11:46 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function configureChannel(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-07-13 13:11:46 +08:00
|
|
|
name: string,
|
2026-09-11 15:22:14 +08:00
|
|
|
values: Record<string, string | null>,
|
2026-07-13 13:11:46 +08:00
|
|
|
options: { enable?: boolean; instanceId?: string } = {},
|
|
|
|
|
): Promise<ChannelConfigurePayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<ChannelConfigurePayload>(
|
|
|
|
|
transport,
|
|
|
|
|
"settings.channel.configure",
|
2026-07-13 13:11:46 +08:00
|
|
|
{
|
2026-08-10 15:43:54 +08:00
|
|
|
name,
|
|
|
|
|
values,
|
|
|
|
|
...(options.enable !== undefined ? { enable: options.enable } : {}),
|
|
|
|
|
...(options.instanceId ? { instance_id: options.instanceId } : {}),
|
2026-07-13 13:11:46 +08:00
|
|
|
},
|
2026-08-10 15:43:54 +08:00
|
|
|
PACKAGE_MUTATION_TIMEOUT_MS,
|
2026-07-13 13:11:46 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function validateChannel(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-07-13 13:11:46 +08:00
|
|
|
name: string,
|
2026-09-11 15:22:14 +08:00
|
|
|
values: Record<string, string | null> = {},
|
2026-07-13 13:11:46 +08:00
|
|
|
options: { instanceId?: string } = {},
|
|
|
|
|
): Promise<ChannelValidationPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<ChannelValidationPayload>(
|
|
|
|
|
transport,
|
|
|
|
|
"settings.channel.validate",
|
|
|
|
|
{ name, values, ...(options.instanceId ? { instance_id: options.instanceId } : {}) },
|
2026-07-13 13:11:46 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-22 22:25:12 +08:00
|
|
|
export async function runCliAppAction(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-05-22 22:25:12 +08:00
|
|
|
action: "install" | "update" | "uninstall" | "test",
|
|
|
|
|
name: string,
|
|
|
|
|
): Promise<CliAppsPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<CliAppsPayload>(
|
|
|
|
|
transport,
|
|
|
|
|
`settings.cli_app.${action}`,
|
|
|
|
|
{ name },
|
|
|
|
|
action === "install" || action === "update"
|
|
|
|
|
? PACKAGE_MUTATION_TIMEOUT_MS
|
|
|
|
|
: API_MUTATION_TIMEOUT_MS,
|
|
|
|
|
);
|
2026-05-22 22:25:12 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-24 13:38:37 +08:00
|
|
|
export async function fetchMcpPresets(
|
|
|
|
|
token: string,
|
|
|
|
|
base: string = "",
|
|
|
|
|
): Promise<McpPresetsPayload> {
|
2026-06-02 15:36:52 +08:00
|
|
|
return request<McpPresetsPayload>(
|
|
|
|
|
`${base}/api/settings/mcp-presets`,
|
|
|
|
|
token,
|
|
|
|
|
undefined,
|
|
|
|
|
API_READ_TIMEOUT_MS,
|
|
|
|
|
);
|
2026-05-24 13:38:37 +08:00
|
|
|
}
|
|
|
|
|
|
2026-08-10 23:44:37 +08:00
|
|
|
export async function startMcpOAuth(
|
|
|
|
|
transport: WebUIMutationTransport,
|
|
|
|
|
name: string,
|
|
|
|
|
reset: boolean = false,
|
|
|
|
|
): Promise<McpOAuthFlowPayload> {
|
|
|
|
|
return mutation<McpOAuthFlowPayload>(
|
|
|
|
|
transport,
|
|
|
|
|
"settings.mcp.oauth_start",
|
|
|
|
|
{ name, ...(reset ? { reset: true } : {}) },
|
|
|
|
|
30_000,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function fetchMcpOAuthStatus(
|
|
|
|
|
token: string,
|
|
|
|
|
flowId: string,
|
|
|
|
|
base: string = "",
|
|
|
|
|
): Promise<McpOAuthFlowPayload> {
|
|
|
|
|
const query = new URLSearchParams({ flow_id: flowId });
|
|
|
|
|
return request<McpOAuthFlowPayload>(
|
|
|
|
|
`${base}/api/settings/mcp-oauth/status?${query}`,
|
|
|
|
|
token,
|
|
|
|
|
undefined,
|
|
|
|
|
API_READ_TIMEOUT_MS,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function completeMcpOAuth(
|
|
|
|
|
transport: WebUIMutationTransport,
|
|
|
|
|
flowId: string,
|
|
|
|
|
callbackUrl: string,
|
|
|
|
|
): Promise<McpOAuthFlowPayload> {
|
|
|
|
|
return mutation<McpOAuthFlowPayload>(
|
|
|
|
|
transport,
|
|
|
|
|
"settings.mcp.oauth_complete",
|
|
|
|
|
{ flow_id: flowId, callback_url: callbackUrl },
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function cancelMcpOAuth(
|
|
|
|
|
transport: WebUIMutationTransport,
|
|
|
|
|
flowId: string,
|
|
|
|
|
): Promise<McpOAuthFlowPayload> {
|
|
|
|
|
return mutation<McpOAuthFlowPayload>(
|
|
|
|
|
transport,
|
|
|
|
|
"settings.mcp.oauth_cancel",
|
|
|
|
|
{ flow_id: flowId },
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-30 23:45:26 +08:00
|
|
|
export async function fetchProviderModels(
|
|
|
|
|
token: string,
|
|
|
|
|
provider: string,
|
|
|
|
|
base: string = "",
|
|
|
|
|
): Promise<ProviderModelsPayload> {
|
|
|
|
|
const query = new URLSearchParams();
|
|
|
|
|
query.set("provider", provider);
|
|
|
|
|
return request<ProviderModelsPayload>(
|
|
|
|
|
`${base}/api/settings/provider-models?${query}`,
|
|
|
|
|
token,
|
2026-06-02 15:36:52 +08:00
|
|
|
undefined,
|
|
|
|
|
API_READ_TIMEOUT_MS,
|
2026-05-30 23:45:26 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-24 13:38:37 +08:00
|
|
|
export async function runMcpPresetAction(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-08-11 23:52:02 +08:00
|
|
|
action: "enable" | "disable" | "remove" | "test" | "reconnect",
|
2026-05-24 13:38:37 +08:00
|
|
|
name: string,
|
|
|
|
|
values: Record<string, string> = {},
|
|
|
|
|
): Promise<McpPresetsPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<McpPresetsPayload>(
|
|
|
|
|
transport,
|
|
|
|
|
`settings.mcp.${action}`,
|
|
|
|
|
{ name, ...compactMcpValues(values) },
|
2026-05-24 13:38:37 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function saveCustomMcpServer(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-05-24 13:38:37 +08:00
|
|
|
values: Record<string, string>,
|
|
|
|
|
): Promise<McpPresetsPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<McpPresetsPayload>(
|
|
|
|
|
transport,
|
|
|
|
|
"settings.mcp.custom",
|
|
|
|
|
compactMcpValues(values),
|
2026-05-24 13:38:37 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function importMcpConfig(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-05-24 13:38:37 +08:00
|
|
|
config: string,
|
|
|
|
|
): Promise<McpPresetsPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<McpPresetsPayload>(transport, "settings.mcp.import", { config });
|
2026-05-24 13:38:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function updateMcpServerTools(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-05-24 13:38:37 +08:00
|
|
|
name: string,
|
|
|
|
|
enabledTools: string[],
|
|
|
|
|
): Promise<McpPresetsPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<McpPresetsPayload>(
|
|
|
|
|
transport,
|
|
|
|
|
"settings.mcp.tools",
|
|
|
|
|
{ name, enabled_tools: enabledTools },
|
2026-05-24 13:38:37 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-06 15:54:15 +00:00
|
|
|
export async function listSlashCommands(
|
|
|
|
|
token: string,
|
|
|
|
|
base: string = "",
|
|
|
|
|
): Promise<SlashCommand[]> {
|
|
|
|
|
type Row = {
|
|
|
|
|
command: string;
|
|
|
|
|
title: string;
|
|
|
|
|
description: string;
|
|
|
|
|
icon: string;
|
|
|
|
|
arg_hint?: string;
|
2026-07-07 14:01:07 +08:00
|
|
|
lifecycle?: unknown;
|
|
|
|
|
accepts_args?: unknown;
|
2026-05-06 15:54:15 +00:00
|
|
|
};
|
2026-06-02 15:36:52 +08:00
|
|
|
const body = await request<{ commands: Row[] }>(
|
|
|
|
|
`${base}/api/commands`,
|
|
|
|
|
token,
|
|
|
|
|
undefined,
|
|
|
|
|
API_READ_TIMEOUT_MS,
|
|
|
|
|
);
|
2026-05-08 09:40:15 +00:00
|
|
|
return body.commands
|
2026-07-07 14:01:07 +08:00
|
|
|
.flatMap((command) => {
|
|
|
|
|
if (!isSlashCommandLifecycle(command.lifecycle)) return [];
|
|
|
|
|
return [{
|
|
|
|
|
command: command.command,
|
|
|
|
|
title: command.title,
|
|
|
|
|
description: command.description,
|
|
|
|
|
icon: command.icon,
|
|
|
|
|
argHint: command.arg_hint ?? "",
|
|
|
|
|
lifecycle: command.lifecycle,
|
|
|
|
|
acceptsArgs: command.accepts_args === true,
|
|
|
|
|
}];
|
|
|
|
|
});
|
2026-05-06 15:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
2026-05-19 22:42:38 +08:00
|
|
|
export async function fetchSidebarState(
|
|
|
|
|
token: string,
|
|
|
|
|
base: string = "",
|
|
|
|
|
): Promise<SidebarStatePayload> {
|
2026-06-02 15:36:52 +08:00
|
|
|
return request<SidebarStatePayload>(
|
|
|
|
|
`${base}/api/webui/sidebar-state`,
|
|
|
|
|
token,
|
|
|
|
|
undefined,
|
|
|
|
|
API_READ_TIMEOUT_MS,
|
|
|
|
|
);
|
2026-05-19 22:42:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function updateSidebarState(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-05-19 22:42:38 +08:00
|
|
|
state: SidebarStatePayload,
|
|
|
|
|
): Promise<SidebarStatePayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<SidebarStatePayload>(transport, "sidebar.update", { state });
|
2026-05-19 22:42:38 +08:00
|
|
|
}
|
|
|
|
|
|
2026-08-10 15:43:54 +08:00
|
|
|
function modelGenerationSettingsPayload(
|
2026-07-24 00:55:06 +08:00
|
|
|
configuration: Pick<
|
|
|
|
|
ModelConfigurationCreate,
|
|
|
|
|
"maxTokens" | "contextWindowTokens" | "temperature" | "reasoningEffort"
|
|
|
|
|
>,
|
2026-08-10 15:43:54 +08:00
|
|
|
): Record<string, unknown> {
|
|
|
|
|
const payload: Record<string, unknown> = {};
|
2026-07-24 00:55:06 +08:00
|
|
|
if (configuration.maxTokens !== undefined) {
|
2026-08-10 15:43:54 +08:00
|
|
|
payload.max_tokens = configuration.maxTokens;
|
2026-07-24 00:55:06 +08:00
|
|
|
}
|
|
|
|
|
if (configuration.contextWindowTokens !== undefined) {
|
2026-08-10 15:43:54 +08:00
|
|
|
payload.context_window_tokens = configuration.contextWindowTokens;
|
2026-07-24 00:55:06 +08:00
|
|
|
}
|
|
|
|
|
if (configuration.temperature !== undefined) {
|
2026-08-10 15:43:54 +08:00
|
|
|
payload.temperature = configuration.temperature;
|
2026-07-24 00:55:06 +08:00
|
|
|
}
|
|
|
|
|
if (configuration.reasoningEffort !== undefined) {
|
2026-08-10 15:43:54 +08:00
|
|
|
payload.reasoning_effort = configuration.reasoningEffort ?? "";
|
2026-07-24 00:55:06 +08:00
|
|
|
}
|
2026-08-10 15:43:54 +08:00
|
|
|
return payload;
|
2026-07-24 00:55:06 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-24 13:38:37 +08:00
|
|
|
export async function createModelConfiguration(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-05-24 13:38:37 +08:00
|
|
|
configuration: ModelConfigurationCreate,
|
|
|
|
|
): Promise<SettingsPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<SettingsPayload>(
|
|
|
|
|
transport,
|
|
|
|
|
"settings.model_configuration.create",
|
|
|
|
|
{
|
2026-08-16 00:20:39 +08:00
|
|
|
name: configuration.name,
|
2026-08-10 15:43:54 +08:00
|
|
|
provider: configuration.provider,
|
|
|
|
|
model: configuration.model,
|
|
|
|
|
...modelGenerationSettingsPayload(configuration),
|
|
|
|
|
},
|
2026-05-24 13:38:37 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-29 03:42:53 +08:00
|
|
|
export async function updateModelConfiguration(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-05-29 03:42:53 +08:00
|
|
|
configuration: ModelConfigurationUpdate,
|
|
|
|
|
): Promise<SettingsPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<SettingsPayload>(
|
|
|
|
|
transport,
|
|
|
|
|
"settings.model_configuration.update",
|
|
|
|
|
{
|
|
|
|
|
name: configuration.name,
|
2026-08-16 01:09:06 +08:00
|
|
|
...(configuration.newName !== undefined ? { new_name: configuration.newName } : {}),
|
2026-08-10 15:43:54 +08:00
|
|
|
...(configuration.provider !== undefined ? { provider: configuration.provider } : {}),
|
|
|
|
|
...(configuration.model !== undefined ? { model: configuration.model } : {}),
|
|
|
|
|
...modelGenerationSettingsPayload(configuration),
|
|
|
|
|
},
|
2026-05-29 03:42:53 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-24 00:55:06 +08:00
|
|
|
export async function deleteModelConfiguration(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-07-24 00:55:06 +08:00
|
|
|
name: string,
|
|
|
|
|
): Promise<SettingsPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<SettingsPayload>(
|
|
|
|
|
transport,
|
|
|
|
|
"settings.model_configuration.delete",
|
|
|
|
|
{ name },
|
2026-07-24 00:55:06 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function migrateModelConfigurations(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-07-24 00:55:06 +08:00
|
|
|
): Promise<SettingsPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<SettingsPayload>(transport, "settings.model_configuration.migrate");
|
2026-07-24 00:55:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function updateModelCallOrder(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-07-24 00:55:06 +08:00
|
|
|
order: string[],
|
|
|
|
|
): Promise<SettingsPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<SettingsPayload>(transport, "settings.model_call_order.update", { order });
|
2026-07-24 00:55:06 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-08 15:31:52 +00:00
|
|
|
export async function updateProviderSettings(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-05-08 15:31:52 +00:00
|
|
|
update: ProviderSettingsUpdate,
|
|
|
|
|
): Promise<SettingsPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<SettingsPayload>(transport, "settings.provider.update", { ...update });
|
2026-07-24 00:55:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function createProviderSettings(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-07-24 00:55:06 +08:00
|
|
|
update: ProviderCreationUpdate,
|
|
|
|
|
): Promise<SettingsPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<SettingsPayload>(transport, "settings.provider.create", { ...update });
|
2026-05-08 15:31:52 +00:00
|
|
|
}
|
2026-05-09 06:48:26 +00:00
|
|
|
|
2026-05-29 03:42:53 +08:00
|
|
|
export async function loginProviderOAuth(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-05-29 03:42:53 +08:00
|
|
|
provider: string,
|
2026-07-30 15:06:34 +08:00
|
|
|
remoteBrowserAccess: boolean = false,
|
2026-07-23 11:55:16 +08:00
|
|
|
): Promise<ProviderOAuthLoginResult> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<ProviderOAuthLoginResult>(
|
|
|
|
|
transport,
|
|
|
|
|
"settings.provider.oauth_login",
|
|
|
|
|
{ provider, ...(remoteBrowserAccess ? { remote_browser: true } : {}) },
|
2026-07-23 11:55:16 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function completeProviderOAuth(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-07-23 11:55:16 +08:00
|
|
|
provider: string,
|
|
|
|
|
flowId: string,
|
2026-07-30 15:06:34 +08:00
|
|
|
authorizationResponse?: string,
|
2026-07-23 11:55:16 +08:00
|
|
|
): Promise<ProviderOAuthCompletionResult> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<ProviderOAuthCompletionResult>(
|
|
|
|
|
transport,
|
|
|
|
|
"settings.provider.oauth_complete",
|
|
|
|
|
{
|
|
|
|
|
provider,
|
|
|
|
|
flow_id: flowId,
|
|
|
|
|
...(authorizationResponse ? { authorization_response: authorizationResponse } : {}),
|
|
|
|
|
},
|
2026-05-29 03:42:53 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function logoutProviderOAuth(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-05-29 03:42:53 +08:00
|
|
|
provider: string,
|
|
|
|
|
): Promise<SettingsPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<SettingsPayload>(transport, "settings.provider.oauth_logout", { provider });
|
2026-05-29 03:42:53 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-09 06:48:26 +00:00
|
|
|
export async function updateWebSearchSettings(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-05-09 06:48:26 +00:00
|
|
|
update: WebSearchSettingsUpdate,
|
|
|
|
|
): Promise<SettingsPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<SettingsPayload>(
|
|
|
|
|
transport,
|
|
|
|
|
"settings.web_search.update",
|
|
|
|
|
{
|
|
|
|
|
provider: update.provider,
|
|
|
|
|
...(update.apiKey !== undefined ? { api_key: update.apiKey } : {}),
|
|
|
|
|
...(update.baseUrl !== undefined ? { base_url: update.baseUrl } : {}),
|
|
|
|
|
...(update.maxResults !== undefined ? { max_results: update.maxResults } : {}),
|
|
|
|
|
...(update.timeout !== undefined ? { timeout: update.timeout } : {}),
|
|
|
|
|
...(update.useJinaReader !== undefined
|
|
|
|
|
? { use_jina_reader: update.useJinaReader }
|
|
|
|
|
: {}),
|
|
|
|
|
},
|
2026-05-09 06:48:26 +00:00
|
|
|
);
|
|
|
|
|
}
|
2026-05-19 22:42:38 +08:00
|
|
|
|
2026-05-29 03:42:53 +08:00
|
|
|
export async function updateNetworkSafetySettings(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-05-29 03:42:53 +08:00
|
|
|
update: NetworkSafetySettingsUpdate,
|
|
|
|
|
): Promise<SettingsPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<SettingsPayload>(
|
|
|
|
|
transport,
|
|
|
|
|
"settings.network_safety.update",
|
|
|
|
|
{
|
|
|
|
|
webui_allow_local_service_access: update.webuiAllowLocalServiceAccess,
|
|
|
|
|
webui_default_access_mode: update.webuiDefaultAccessMode,
|
|
|
|
|
},
|
2026-05-29 03:42:53 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-19 22:42:38 +08:00
|
|
|
export async function updateImageGenerationSettings(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-05-19 22:42:38 +08:00
|
|
|
update: ImageGenerationSettingsUpdate,
|
|
|
|
|
): Promise<SettingsPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<SettingsPayload>(
|
|
|
|
|
transport,
|
|
|
|
|
"settings.image_generation.update",
|
|
|
|
|
{
|
|
|
|
|
enabled: update.enabled,
|
|
|
|
|
provider: update.provider,
|
|
|
|
|
model: update.model,
|
|
|
|
|
default_aspect_ratio: update.defaultAspectRatio,
|
|
|
|
|
default_image_size: update.defaultImageSize,
|
|
|
|
|
max_images_per_turn: update.maxImagesPerTurn,
|
|
|
|
|
},
|
2026-05-19 22:42:38 +08:00
|
|
|
);
|
|
|
|
|
}
|
2026-06-09 01:08:49 +08:00
|
|
|
|
|
|
|
|
export async function updateTranscriptionSettings(
|
2026-08-10 15:43:54 +08:00
|
|
|
transport: WebUIMutationTransport,
|
2026-06-09 01:08:49 +08:00
|
|
|
update: TranscriptionSettingsUpdate,
|
|
|
|
|
): Promise<SettingsPayload> {
|
2026-08-10 15:43:54 +08:00
|
|
|
return mutation<SettingsPayload>(
|
|
|
|
|
transport,
|
|
|
|
|
"settings.transcription.update",
|
|
|
|
|
{
|
|
|
|
|
enabled: update.enabled,
|
|
|
|
|
provider: update.provider,
|
|
|
|
|
model: update.model,
|
|
|
|
|
language: update.language,
|
|
|
|
|
max_duration_sec: update.maxDurationSec,
|
|
|
|
|
max_upload_mb: update.maxUploadMb,
|
|
|
|
|
},
|
2026-06-09 01:08:49 +08:00
|
|
|
);
|
|
|
|
|
}
|
2026-09-10 11:10:51 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
export async function updateRuntimeConfigSettings(
|
|
|
|
|
transport: WebUIMutationTransport,
|
|
|
|
|
values: Record<string, import("@/lib/types").RuntimeConfigValue>,
|
|
|
|
|
): Promise<SettingsPayload> {
|
|
|
|
|
return mutation<SettingsPayload>(transport, "settings.runtime_config.update", { values });
|
|
|
|
|
}
|