Merge branch 'main' into claude/moltbot-evaluation-DpGYf
This commit is contained in:
commit
34617996dc
@ -1,3 +1,4 @@
|
|||||||
|
import fs from "node:fs";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
|
|
||||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||||
@ -8,6 +9,24 @@ import { buildDockerExecArgs } from "./bash-tools.shared.js";
|
|||||||
import { sanitizeBinaryOutput } from "./shell-utils.js";
|
import { sanitizeBinaryOutput } from "./shell-utils.js";
|
||||||
|
|
||||||
const isWin = process.platform === "win32";
|
const isWin = process.platform === "win32";
|
||||||
|
const resolveShellFromPath = (name: string) => {
|
||||||
|
const envPath = process.env.PATH ?? "";
|
||||||
|
if (!envPath) return undefined;
|
||||||
|
const entries = envPath.split(path.delimiter).filter(Boolean);
|
||||||
|
for (const entry of entries) {
|
||||||
|
const candidate = path.join(entry, name);
|
||||||
|
try {
|
||||||
|
fs.accessSync(candidate, fs.constants.X_OK);
|
||||||
|
return candidate;
|
||||||
|
} catch {
|
||||||
|
// ignore missing or non-executable entries
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
const defaultShell = isWin
|
||||||
|
? undefined
|
||||||
|
: process.env.CLAWDBOT_TEST_SHELL || resolveShellFromPath("bash") || process.env.SHELL || "sh";
|
||||||
// PowerShell: Start-Sleep for delays, ; for command separation, $null for null device
|
// PowerShell: Start-Sleep for delays, ; for command separation, $null for null device
|
||||||
const shortDelayCmd = isWin ? "Start-Sleep -Milliseconds 50" : "sleep 0.05";
|
const shortDelayCmd = isWin ? "Start-Sleep -Milliseconds 50" : "sleep 0.05";
|
||||||
const yieldDelayCmd = isWin ? "Start-Sleep -Milliseconds 200" : "sleep 0.2";
|
const yieldDelayCmd = isWin ? "Start-Sleep -Milliseconds 200" : "sleep 0.2";
|
||||||
@ -52,7 +71,7 @@ describe("exec tool backgrounding", () => {
|
|||||||
const originalShell = process.env.SHELL;
|
const originalShell = process.env.SHELL;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
if (!isWin) process.env.SHELL = "/bin/bash";
|
if (!isWin && defaultShell) process.env.SHELL = defaultShell;
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@ -282,7 +301,7 @@ describe("exec PATH handling", () => {
|
|||||||
const originalShell = process.env.SHELL;
|
const originalShell = process.env.SHELL;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
if (!isWin) process.env.SHELL = "/bin/bash";
|
if (!isWin && defaultShell) process.env.SHELL = defaultShell;
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
|||||||
@ -35,8 +35,8 @@ function isAlive(pid: number): boolean {
|
|||||||
function releaseAllLocksSync(): void {
|
function releaseAllLocksSync(): void {
|
||||||
for (const [sessionFile, held] of HELD_LOCKS) {
|
for (const [sessionFile, held] of HELD_LOCKS) {
|
||||||
try {
|
try {
|
||||||
if (typeof held.handle.fd === "number") {
|
if (typeof held.handle.close === "function") {
|
||||||
fsSync.closeSync(held.handle.fd);
|
void held.handle.close().catch(() => {});
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// Ignore errors during cleanup - best effort
|
// Ignore errors during cleanup - best effort
|
||||||
|
|||||||
@ -1,10 +1,9 @@
|
|||||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
|
import * as ssrf from "../../infra/net/ssrf.js";
|
||||||
|
|
||||||
const lookupMock = vi.fn();
|
const lookupMock = vi.fn();
|
||||||
|
const resolvePinnedHostname = ssrf.resolvePinnedHostname;
|
||||||
vi.mock("node:dns/promises", () => ({
|
|
||||||
lookup: lookupMock,
|
|
||||||
}));
|
|
||||||
|
|
||||||
function makeHeaders(map: Record<string, string>): { get: (key: string) => string | null } {
|
function makeHeaders(map: Record<string, string>): { get: (key: string) => string | null } {
|
||||||
return {
|
return {
|
||||||
@ -33,6 +32,12 @@ function textResponse(body: string): Response {
|
|||||||
describe("web_fetch SSRF protection", () => {
|
describe("web_fetch SSRF protection", () => {
|
||||||
const priorFetch = global.fetch;
|
const priorFetch = global.fetch;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.spyOn(ssrf, "resolvePinnedHostname").mockImplementation((hostname) =>
|
||||||
|
resolvePinnedHostname(hostname, lookupMock),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
// @ts-expect-error restore
|
// @ts-expect-error restore
|
||||||
global.fetch = priorFetch;
|
global.fetch = priorFetch;
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
|
import * as ssrf from "../../infra/net/ssrf.js";
|
||||||
import { createWebFetchTool } from "./web-tools.js";
|
import { createWebFetchTool } from "./web-tools.js";
|
||||||
|
|
||||||
type MockResponse = {
|
type MockResponse = {
|
||||||
@ -73,6 +74,18 @@ function requestUrl(input: RequestInfo): string {
|
|||||||
describe("web_fetch extraction fallbacks", () => {
|
describe("web_fetch extraction fallbacks", () => {
|
||||||
const priorFetch = global.fetch;
|
const priorFetch = global.fetch;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.spyOn(ssrf, "resolvePinnedHostname").mockImplementation(async (hostname) => {
|
||||||
|
const normalized = hostname.trim().toLowerCase().replace(/\.$/, "");
|
||||||
|
const addresses = ["93.184.216.34", "93.184.216.35"];
|
||||||
|
return {
|
||||||
|
hostname: normalized,
|
||||||
|
addresses,
|
||||||
|
lookup: ssrf.createPinnedLookup({ hostname: normalized, addresses }),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
// @ts-expect-error restore
|
// @ts-expect-error restore
|
||||||
global.fetch = priorFetch;
|
global.fetch = priorFetch;
|
||||||
|
|||||||
@ -202,6 +202,16 @@ describe("canvas host", () => {
|
|||||||
|
|
||||||
it("serves the gateway-hosted A2UI scaffold", async () => {
|
it("serves the gateway-hosted A2UI scaffold", async () => {
|
||||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "moltbot-canvas-"));
|
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "moltbot-canvas-"));
|
||||||
|
const a2uiRoot = path.resolve(process.cwd(), "src/canvas-host/a2ui");
|
||||||
|
const bundlePath = path.join(a2uiRoot, "a2ui.bundle.js");
|
||||||
|
let createdBundle = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await fs.stat(bundlePath);
|
||||||
|
} catch {
|
||||||
|
await fs.writeFile(bundlePath, "window.moltbotA2UI = {};", "utf8");
|
||||||
|
createdBundle = true;
|
||||||
|
}
|
||||||
|
|
||||||
const server = await startCanvasHost({
|
const server = await startCanvasHost({
|
||||||
runtime: defaultRuntime,
|
runtime: defaultRuntime,
|
||||||
@ -226,6 +236,9 @@ describe("canvas host", () => {
|
|||||||
expect(js).toContain("moltbotA2UI");
|
expect(js).toContain("moltbotA2UI");
|
||||||
} finally {
|
} finally {
|
||||||
await server.close();
|
await server.close();
|
||||||
|
if (createdBundle) {
|
||||||
|
await fs.rm(bundlePath, { force: true });
|
||||||
|
}
|
||||||
await fs.rm(dir, { recursive: true, force: true });
|
await fs.rm(dir, { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -21,6 +21,7 @@ type ChatHost = {
|
|||||||
basePath: string;
|
basePath: string;
|
||||||
hello: GatewayHelloOk | null;
|
hello: GatewayHelloOk | null;
|
||||||
chatAvatarUrl: string | null;
|
chatAvatarUrl: string | null;
|
||||||
|
refreshSessionsAfterChat: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function isChatBusy(host: ChatHost) {
|
export function isChatBusy(host: ChatHost) {
|
||||||
@ -41,6 +42,14 @@ export function isChatStopCommand(text: string) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isChatResetCommand(text: string) {
|
||||||
|
const trimmed = text.trim();
|
||||||
|
if (!trimmed) return false;
|
||||||
|
const normalized = trimmed.toLowerCase();
|
||||||
|
if (normalized === "/new" || normalized === "/reset") return true;
|
||||||
|
return normalized.startsWith("/new ") || normalized.startsWith("/reset ");
|
||||||
|
}
|
||||||
|
|
||||||
export async function handleAbortChat(host: ChatHost) {
|
export async function handleAbortChat(host: ChatHost) {
|
||||||
if (!host.connected) return;
|
if (!host.connected) return;
|
||||||
host.chatMessage = "";
|
host.chatMessage = "";
|
||||||
@ -71,6 +80,7 @@ async function sendChatMessageNow(
|
|||||||
attachments?: ChatAttachment[];
|
attachments?: ChatAttachment[];
|
||||||
previousAttachments?: ChatAttachment[];
|
previousAttachments?: ChatAttachment[];
|
||||||
restoreAttachments?: boolean;
|
restoreAttachments?: boolean;
|
||||||
|
refreshSessions?: boolean;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
resetToolStream(host as unknown as Parameters<typeof resetToolStream>[0]);
|
resetToolStream(host as unknown as Parameters<typeof resetToolStream>[0]);
|
||||||
@ -94,6 +104,9 @@ async function sendChatMessageNow(
|
|||||||
if (ok && !host.chatRunId) {
|
if (ok && !host.chatRunId) {
|
||||||
void flushChatQueue(host);
|
void flushChatQueue(host);
|
||||||
}
|
}
|
||||||
|
if (ok && opts?.refreshSessions) {
|
||||||
|
host.refreshSessionsAfterChat = true;
|
||||||
|
}
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,6 +145,7 @@ export async function handleSendChat(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const refreshSessions = isChatResetCommand(message);
|
||||||
if (messageOverride == null) {
|
if (messageOverride == null) {
|
||||||
host.chatMessage = "";
|
host.chatMessage = "";
|
||||||
// Clear attachments when sending
|
// Clear attachments when sending
|
||||||
@ -149,13 +163,14 @@ export async function handleSendChat(
|
|||||||
attachments: hasAttachments ? attachmentsToSend : undefined,
|
attachments: hasAttachments ? attachmentsToSend : undefined,
|
||||||
previousAttachments: messageOverride == null ? attachments : undefined,
|
previousAttachments: messageOverride == null ? attachments : undefined,
|
||||||
restoreAttachments: Boolean(messageOverride && opts?.restoreDraft),
|
restoreAttachments: Boolean(messageOverride && opts?.restoreDraft),
|
||||||
|
refreshSessions,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function refreshChat(host: ChatHost) {
|
export async function refreshChat(host: ChatHost) {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
loadChatHistory(host as unknown as MoltbotApp),
|
loadChatHistory(host as unknown as MoltbotApp),
|
||||||
loadSessions(host as unknown as MoltbotApp),
|
loadSessions(host as unknown as MoltbotApp, { activeMinutes: 0 }),
|
||||||
refreshChatAvatar(host),
|
refreshChatAvatar(host),
|
||||||
]);
|
]);
|
||||||
scheduleChatScroll(host as unknown as Parameters<typeof scheduleChatScroll>[0], true);
|
scheduleChatScroll(host as unknown as Parameters<typeof scheduleChatScroll>[0], true);
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import {
|
|||||||
import type { MoltbotApp } from "./app";
|
import type { MoltbotApp } from "./app";
|
||||||
import type { ExecApprovalRequest } from "./controllers/exec-approval";
|
import type { ExecApprovalRequest } from "./controllers/exec-approval";
|
||||||
import { loadAssistantIdentity } from "./controllers/assistant-identity";
|
import { loadAssistantIdentity } from "./controllers/assistant-identity";
|
||||||
|
import { loadSessions } from "./controllers/sessions";
|
||||||
|
|
||||||
type GatewayHost = {
|
type GatewayHost = {
|
||||||
settings: UiSettings;
|
settings: UiSettings;
|
||||||
@ -50,6 +51,7 @@ type GatewayHost = {
|
|||||||
assistantAgentId: string | null;
|
assistantAgentId: string | null;
|
||||||
sessionKey: string;
|
sessionKey: string;
|
||||||
chatRunId: string | null;
|
chatRunId: string | null;
|
||||||
|
refreshSessionsAfterChat: boolean;
|
||||||
execApprovalQueue: ExecApprovalRequest[];
|
execApprovalQueue: ExecApprovalRequest[];
|
||||||
execApprovalError: string | null;
|
execApprovalError: string | null;
|
||||||
};
|
};
|
||||||
@ -194,6 +196,12 @@ function handleGatewayEventUnsafe(host: GatewayHost, evt: GatewayEventFrame) {
|
|||||||
void flushChatQueueForEvent(
|
void flushChatQueueForEvent(
|
||||||
host as unknown as Parameters<typeof flushChatQueueForEvent>[0],
|
host as unknown as Parameters<typeof flushChatQueueForEvent>[0],
|
||||||
);
|
);
|
||||||
|
if (host.refreshSessionsAfterChat) {
|
||||||
|
host.refreshSessionsAfterChat = false;
|
||||||
|
if (state === "final") {
|
||||||
|
void loadSessions(host as unknown as MoltbotApp, { activeMinutes: 0 });
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (state === "final") void loadChatHistory(host as unknown as MoltbotApp);
|
if (state === "final") void loadChatHistory(host as unknown as MoltbotApp);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -35,6 +35,9 @@ type LifecycleHost = {
|
|||||||
|
|
||||||
export function handleConnected(host: LifecycleHost) {
|
export function handleConnected(host: LifecycleHost) {
|
||||||
host.basePath = inferBasePath();
|
host.basePath = inferBasePath();
|
||||||
|
applySettingsFromUrl(
|
||||||
|
host as unknown as Parameters<typeof applySettingsFromUrl>[0],
|
||||||
|
);
|
||||||
syncTabWithLocation(
|
syncTabWithLocation(
|
||||||
host as unknown as Parameters<typeof syncTabWithLocation>[0],
|
host as unknown as Parameters<typeof syncTabWithLocation>[0],
|
||||||
true,
|
true,
|
||||||
@ -46,9 +49,6 @@ export function handleConnected(host: LifecycleHost) {
|
|||||||
host as unknown as Parameters<typeof attachThemeListener>[0],
|
host as unknown as Parameters<typeof attachThemeListener>[0],
|
||||||
);
|
);
|
||||||
window.addEventListener("popstate", host.popStateHandler);
|
window.addEventListener("popstate", host.popStateHandler);
|
||||||
applySettingsFromUrl(
|
|
||||||
host as unknown as Parameters<typeof applySettingsFromUrl>[0],
|
|
||||||
);
|
|
||||||
connectGateway(host as unknown as Parameters<typeof connectGateway>[0]);
|
connectGateway(host as unknown as Parameters<typeof connectGateway>[0]);
|
||||||
startNodesPolling(host as unknown as Parameters<typeof startNodesPolling>[0]);
|
startNodesPolling(host as unknown as Parameters<typeof startNodesPolling>[0]);
|
||||||
if (host.tab === "logs") {
|
if (host.tab === "logs") {
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import type { AppViewState } from "./app-view-state";
|
|||||||
import { iconForTab, pathForTab, titleForTab, type Tab } from "./navigation";
|
import { iconForTab, pathForTab, titleForTab, type Tab } from "./navigation";
|
||||||
import { icons } from "./icons";
|
import { icons } from "./icons";
|
||||||
import { loadChatHistory } from "./controllers/chat";
|
import { loadChatHistory } from "./controllers/chat";
|
||||||
|
import { refreshChat } from "./app-chat";
|
||||||
import { syncUrlWithSessionKey } from "./app-settings";
|
import { syncUrlWithSessionKey } from "./app-settings";
|
||||||
import type { SessionsListResult } from "./types";
|
import type { SessionsListResult } from "./types";
|
||||||
import type { ThemeMode } from "./theme";
|
import type { ThemeMode } from "./theme";
|
||||||
@ -39,7 +40,12 @@ export function renderTab(state: AppViewState, tab: Tab) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function renderChatControls(state: AppViewState) {
|
export function renderChatControls(state: AppViewState) {
|
||||||
const sessionOptions = resolveSessionOptions(state.sessionKey, state.sessionsResult);
|
const mainSessionKey = resolveMainSessionKey(state.hello, state.sessionsResult);
|
||||||
|
const sessionOptions = resolveSessionOptions(
|
||||||
|
state.sessionKey,
|
||||||
|
state.sessionsResult,
|
||||||
|
mainSessionKey,
|
||||||
|
);
|
||||||
const disableThinkingToggle = state.onboarding;
|
const disableThinkingToggle = state.onboarding;
|
||||||
const disableFocusToggle = state.onboarding;
|
const disableFocusToggle = state.onboarding;
|
||||||
const showThinking = state.onboarding ? false : state.settings.chatShowThinking;
|
const showThinking = state.onboarding ? false : state.settings.chatShowThinking;
|
||||||
@ -87,9 +93,9 @@ export function renderChatControls(state: AppViewState) {
|
|||||||
?disabled=${state.chatLoading || !state.connected}
|
?disabled=${state.chatLoading || !state.connected}
|
||||||
@click=${() => {
|
@click=${() => {
|
||||||
state.resetToolStream();
|
state.resetToolStream();
|
||||||
void loadChatHistory(state);
|
void refreshChat(state as unknown as Parameters<typeof refreshChat>[0]);
|
||||||
}}
|
}}
|
||||||
title="Refresh chat history"
|
title="Refresh chat data"
|
||||||
>
|
>
|
||||||
${refreshIcon}
|
${refreshIcon}
|
||||||
</button>
|
</button>
|
||||||
@ -132,15 +138,47 @@ export function renderChatControls(state: AppViewState) {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveSessionOptions(sessionKey: string, sessions: SessionsListResult | null) {
|
type SessionDefaultsSnapshot = {
|
||||||
|
mainSessionKey?: string;
|
||||||
|
mainKey?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
function resolveMainSessionKey(
|
||||||
|
hello: AppViewState["hello"],
|
||||||
|
sessions: SessionsListResult | null,
|
||||||
|
): string | null {
|
||||||
|
const snapshot = hello?.snapshot as { sessionDefaults?: SessionDefaultsSnapshot } | undefined;
|
||||||
|
const mainSessionKey = snapshot?.sessionDefaults?.mainSessionKey?.trim();
|
||||||
|
if (mainSessionKey) return mainSessionKey;
|
||||||
|
const mainKey = snapshot?.sessionDefaults?.mainKey?.trim();
|
||||||
|
if (mainKey) return mainKey;
|
||||||
|
if (sessions?.sessions?.some((row) => row.key === "main")) return "main";
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveSessionOptions(
|
||||||
|
sessionKey: string,
|
||||||
|
sessions: SessionsListResult | null,
|
||||||
|
mainSessionKey?: string | null,
|
||||||
|
) {
|
||||||
const seen = new Set<string>();
|
const seen = new Set<string>();
|
||||||
const options: Array<{ key: string; displayName?: string }> = [];
|
const options: Array<{ key: string; displayName?: string }> = [];
|
||||||
|
|
||||||
|
const resolvedMain =
|
||||||
|
mainSessionKey && sessions?.sessions?.find((s) => s.key === mainSessionKey);
|
||||||
const resolvedCurrent = sessions?.sessions?.find((s) => s.key === sessionKey);
|
const resolvedCurrent = sessions?.sessions?.find((s) => s.key === sessionKey);
|
||||||
|
|
||||||
// Add current session key first
|
// Add main session key first
|
||||||
seen.add(sessionKey);
|
if (mainSessionKey) {
|
||||||
options.push({ key: sessionKey, displayName: resolvedCurrent?.displayName });
|
seen.add(mainSessionKey);
|
||||||
|
options.push({ key: mainSessionKey, displayName: resolvedMain?.displayName });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add current session key next
|
||||||
|
if (!seen.has(sessionKey)) {
|
||||||
|
seen.add(sessionKey);
|
||||||
|
options.push({ key: sessionKey, displayName: resolvedCurrent?.displayName });
|
||||||
|
}
|
||||||
|
|
||||||
// Add sessions from the result
|
// Add sessions from the result
|
||||||
if (sessions?.sessions) {
|
if (sessions?.sessions) {
|
||||||
|
|||||||
@ -258,6 +258,7 @@ export class MoltbotApp extends LitElement {
|
|||||||
private logsScrollFrame: number | null = null;
|
private logsScrollFrame: number | null = null;
|
||||||
private toolStreamById = new Map<string, ToolStreamEntry>();
|
private toolStreamById = new Map<string, ToolStreamEntry>();
|
||||||
private toolStreamOrder: string[] = [];
|
private toolStreamOrder: string[] = [];
|
||||||
|
refreshSessionsAfterChat = false;
|
||||||
basePath = "";
|
basePath = "";
|
||||||
private popStateHandler = () =>
|
private popStateHandler = () =>
|
||||||
onPopStateInternal(
|
onPopStateInternal(
|
||||||
|
|||||||
@ -14,18 +14,29 @@ export type SessionsState = {
|
|||||||
sessionsIncludeUnknown: boolean;
|
sessionsIncludeUnknown: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function loadSessions(state: SessionsState) {
|
export async function loadSessions(
|
||||||
|
state: SessionsState,
|
||||||
|
overrides?: {
|
||||||
|
activeMinutes?: number;
|
||||||
|
limit?: number;
|
||||||
|
includeGlobal?: boolean;
|
||||||
|
includeUnknown?: boolean;
|
||||||
|
},
|
||||||
|
) {
|
||||||
if (!state.client || !state.connected) return;
|
if (!state.client || !state.connected) return;
|
||||||
if (state.sessionsLoading) return;
|
if (state.sessionsLoading) return;
|
||||||
state.sessionsLoading = true;
|
state.sessionsLoading = true;
|
||||||
state.sessionsError = null;
|
state.sessionsError = null;
|
||||||
try {
|
try {
|
||||||
|
const includeGlobal = overrides?.includeGlobal ?? state.sessionsIncludeGlobal;
|
||||||
|
const includeUnknown = overrides?.includeUnknown ?? state.sessionsIncludeUnknown;
|
||||||
|
const activeMinutes =
|
||||||
|
overrides?.activeMinutes ?? toNumber(state.sessionsFilterActive, 0);
|
||||||
|
const limit = overrides?.limit ?? toNumber(state.sessionsFilterLimit, 0);
|
||||||
const params: Record<string, unknown> = {
|
const params: Record<string, unknown> = {
|
||||||
includeGlobal: state.sessionsIncludeGlobal,
|
includeGlobal,
|
||||||
includeUnknown: state.sessionsIncludeUnknown,
|
includeUnknown,
|
||||||
};
|
};
|
||||||
const activeMinutes = toNumber(state.sessionsFilterActive, 0);
|
|
||||||
const limit = toNumber(state.sessionsFilterLimit, 0);
|
|
||||||
if (activeMinutes > 0) params.activeMinutes = activeMinutes;
|
if (activeMinutes > 0) params.activeMinutes = activeMinutes;
|
||||||
if (limit > 0) params.limit = limit;
|
if (limit > 0) params.limit = limit;
|
||||||
const res = (await state.client.request("sessions.list", params)) as
|
const res = (await state.client.request("sessions.list", params)) as
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user