mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 01:31:08 +00:00
chore: enable no-unnecessary-type-arguments
This commit is contained in:
@@ -20,7 +20,6 @@
|
||||
"typescript/consistent-return": "off",
|
||||
"typescript/no-explicit-any": "error",
|
||||
"typescript/no-extraneous-class": "off",
|
||||
"typescript/no-unnecessary-type-arguments": "off",
|
||||
"typescript/no-unnecessary-type-conversion": "off",
|
||||
"typescript/no-unsafe-type-assertion": "off",
|
||||
"unicorn/consistent-function-scoping": "off",
|
||||
|
||||
@@ -286,7 +286,7 @@ async function callBrowserProxy(params: {
|
||||
? Math.max(1, Math.floor(params.timeoutMs))
|
||||
: DEFAULT_BROWSER_PROXY_TIMEOUT_MS;
|
||||
const gatewayTimeoutMs = proxyTimeoutMs + BROWSER_PROXY_GATEWAY_TIMEOUT_SLACK_MS;
|
||||
const payload = await browserToolDeps.callGatewayTool<{ payloadJSON?: string; payload?: string }>(
|
||||
const payload = await browserToolDeps.callGatewayTool(
|
||||
"node.invoke",
|
||||
{ timeoutMs: gatewayTimeoutMs },
|
||||
{
|
||||
|
||||
@@ -101,11 +101,7 @@ const listIrcDirectoryGroupsFromConfig = createResolvedDirectoryEntriesLister<Re
|
||||
},
|
||||
});
|
||||
|
||||
const ircConfigAdapter = createScopedChannelConfigAdapter<
|
||||
ResolvedIrcAccount,
|
||||
ResolvedIrcAccount,
|
||||
CoreConfig
|
||||
>({
|
||||
const ircConfigAdapter = createScopedChannelConfigAdapter<ResolvedIrcAccount, ResolvedIrcAccount>({
|
||||
sectionKey: "irc",
|
||||
listAccountIds: listIrcAccountIds,
|
||||
resolveAccount: adaptScopedAccountAccessor(resolveIrcAccount),
|
||||
|
||||
@@ -11,14 +11,12 @@ import {
|
||||
type ResolvedMatrixAccount,
|
||||
} from "./matrix/accounts.js";
|
||||
import { normalizeMatrixAllowList } from "./matrix/monitor/allowlist.js";
|
||||
import type { CoreConfig } from "./types.js";
|
||||
|
||||
export { DEFAULT_ACCOUNT_ID };
|
||||
|
||||
export const matrixConfigAdapter = createScopedChannelConfigAdapter<
|
||||
ResolvedMatrixAccount,
|
||||
ReturnType<typeof resolveMatrixAccountConfig>,
|
||||
CoreConfig
|
||||
ReturnType<typeof resolveMatrixAccountConfig>
|
||||
>({
|
||||
sectionKey: "matrix",
|
||||
listAccountIds: listMatrixAccountIds,
|
||||
|
||||
@@ -580,7 +580,7 @@ async function runGatewayPrompt(prompt: string): Promise<PromptResult> {
|
||||
try {
|
||||
const url = `ws://127.0.0.1:${port}`;
|
||||
await waitForGatewayReady(url, gatewayToken);
|
||||
const agentRes = await callGateway<{ runId?: string }>({
|
||||
const agentRes = await callGateway({
|
||||
url,
|
||||
token: gatewayToken,
|
||||
method: "agent",
|
||||
@@ -607,7 +607,7 @@ async function runGatewayPrompt(prompt: string): Promise<PromptResult> {
|
||||
tmpDir,
|
||||
};
|
||||
}
|
||||
const waitRes = await callGateway<{ status?: string; error?: string; payloads?: unknown[] }>({
|
||||
const waitRes = await callGateway({
|
||||
url,
|
||||
token: gatewayToken,
|
||||
method: "agent.wait",
|
||||
|
||||
@@ -105,7 +105,7 @@ export function collectClawHubPublishablePluginPackages(
|
||||
const publishable: PublishablePluginPackage[] = [];
|
||||
const validationErrors: string[] = [];
|
||||
|
||||
for (const candidate of collectExtensionPackageJsonCandidates<PluginPackageJson>(rootDir)) {
|
||||
for (const candidate of collectExtensionPackageJsonCandidates(rootDir)) {
|
||||
const { extensionId, packageDir, packageJson } = candidate;
|
||||
if (packageJson.openclaw?.release?.publishToClawHub !== true) {
|
||||
continue;
|
||||
|
||||
@@ -1144,7 +1144,7 @@ export class AcpGatewayAgent implements Agent {
|
||||
}
|
||||
let result: AgentWaitResult | undefined;
|
||||
try {
|
||||
result = await this.gateway.request<AgentWaitResult>(
|
||||
result = await this.gateway.request(
|
||||
"agent.wait",
|
||||
{
|
||||
runId: pending.idempotencyKey,
|
||||
@@ -1308,7 +1308,7 @@ export class AcpGatewayAgent implements Agent {
|
||||
}
|
||||
|
||||
private async getSessionTranscript(sessionKey: string): Promise<GatewayTranscriptMessage[]> {
|
||||
const result = await this.gateway.request<{ messages?: unknown[] }>("sessions.get", {
|
||||
const result = await this.gateway.request("sessions.get", {
|
||||
key: sessionKey,
|
||||
limit: ACP_LOAD_SESSION_REPLAY_LIMIT,
|
||||
});
|
||||
|
||||
@@ -1181,7 +1181,7 @@ export async function spawnAcpDirect(
|
||||
});
|
||||
}
|
||||
try {
|
||||
const response = await callGateway<{ runId?: string }>({
|
||||
const response = await callGateway({
|
||||
method: "agent",
|
||||
params: {
|
||||
message: params.task,
|
||||
|
||||
@@ -91,11 +91,7 @@ export async function registerExecApprovalRequest(
|
||||
): Promise<ExecApprovalRegistration> {
|
||||
// Two-phase registration is critical: the ID must be registered server-side
|
||||
// before exec returns `approval-pending`, otherwise `/approve` can race and orphan.
|
||||
const registrationResult = await callGatewayTool<{
|
||||
id?: string;
|
||||
expiresAtMs?: number;
|
||||
decision?: string;
|
||||
}>(
|
||||
const registrationResult = await callGatewayTool(
|
||||
"exec.approval.request",
|
||||
{ timeoutMs: DEFAULT_APPROVAL_REQUEST_TIMEOUT_MS },
|
||||
buildExecApprovalRequestToolParams(params),
|
||||
|
||||
@@ -97,7 +97,7 @@ export async function executeNodeHostCommand(
|
||||
);
|
||||
}
|
||||
const argv = buildNodeShellCommand(params.command, nodeInfo?.platform);
|
||||
const prepareRaw = await callGatewayTool<{ payload?: unknown }>(
|
||||
const prepareRaw = await callGatewayTool(
|
||||
"node.invoke",
|
||||
{ timeoutMs: 15_000 },
|
||||
{
|
||||
@@ -370,15 +370,7 @@ export async function executeNodeHostCommand(
|
||||
}
|
||||
|
||||
try {
|
||||
const raw = await callGatewayTool<{
|
||||
payload?: {
|
||||
stdout?: string;
|
||||
stderr?: string;
|
||||
error?: string | null;
|
||||
exitCode?: number | null;
|
||||
timedOut?: boolean;
|
||||
};
|
||||
}>(
|
||||
const raw = await callGatewayTool(
|
||||
"node.invoke",
|
||||
{ timeoutMs: invokeTimeoutMs },
|
||||
buildInvokeParams(approvedByAsk, approvalDecision, approvalId, true),
|
||||
|
||||
@@ -233,11 +233,11 @@ export async function runBeforeToolCallHook(args: {
|
||||
}
|
||||
};
|
||||
try {
|
||||
const requestResult = await callGatewayTool<{
|
||||
const requestResult: {
|
||||
id?: string;
|
||||
status?: string;
|
||||
decision?: string | null;
|
||||
}>(
|
||||
} = await callGatewayTool(
|
||||
"plugin.approval.request",
|
||||
// Buffer beyond the approval timeout so the gateway can clean up
|
||||
// and respond before the client-side RPC timeout fires.
|
||||
@@ -281,10 +281,10 @@ export async function runBeforeToolCallHook(args: {
|
||||
} else {
|
||||
// Wait for the decision, but abort early if the agent run is cancelled
|
||||
// so the user isn't blocked for the full approval timeout.
|
||||
const waitPromise = callGatewayTool<{
|
||||
const waitPromise: Promise<{
|
||||
id?: string;
|
||||
decision?: string | null;
|
||||
}>(
|
||||
}> = callGatewayTool(
|
||||
"plugin.approval.waitDecision",
|
||||
// Buffer beyond the approval timeout so the gateway can clean up
|
||||
// and respond before the client-side RPC timeout fires.
|
||||
|
||||
@@ -122,7 +122,7 @@ export async function waitForAgentRun(params: {
|
||||
}): Promise<AgentWaitResult> {
|
||||
const timeoutMs = Math.max(1, Math.floor(params.timeoutMs));
|
||||
try {
|
||||
const wait = await (params.callGateway ?? runWaitDeps.callGateway)<RawAgentWaitResponse>({
|
||||
const wait = await (params.callGateway ?? runWaitDeps.callGateway)({
|
||||
method: "agent.wait",
|
||||
params: {
|
||||
runId: params.runId,
|
||||
|
||||
@@ -241,7 +241,7 @@ export async function readSubagentOutput(
|
||||
sessionKey: string,
|
||||
outcome?: SubagentRunOutcome,
|
||||
): Promise<string | undefined> {
|
||||
const history = await subagentAnnounceOutputDeps.callGateway<{ messages?: Array<unknown> }>({
|
||||
const history = await subagentAnnounceOutputDeps.callGateway({
|
||||
method: "chat.history",
|
||||
params: { sessionKey, limit: 100 },
|
||||
});
|
||||
@@ -276,7 +276,7 @@ export async function waitForSubagentRunOutcome(
|
||||
timeoutMs: number,
|
||||
): Promise<AgentWaitResult> {
|
||||
const waitMs = Math.max(0, Math.floor(timeoutMs));
|
||||
return await subagentAnnounceOutputDeps.callGateway<AgentWaitResult>({
|
||||
return await subagentAnnounceOutputDeps.callGateway({
|
||||
method: "agent.wait",
|
||||
params: {
|
||||
runId,
|
||||
|
||||
@@ -28,7 +28,7 @@ export async function runAgentStep(params: {
|
||||
sourceTool?: string;
|
||||
}): Promise<string | undefined> {
|
||||
const stepIdem = crypto.randomUUID();
|
||||
const response = await agentStepDeps.callGateway<{ runId?: string }>({
|
||||
const response = await agentStepDeps.callGateway({
|
||||
method: "agent",
|
||||
params: {
|
||||
message: params.message,
|
||||
|
||||
@@ -53,13 +53,13 @@ async function resolveNodePairApproveScopes(
|
||||
gatewayOpts: GatewayCallOptions,
|
||||
requestId: string,
|
||||
): Promise<OperatorScope[]> {
|
||||
const pairing = await callGatewayTool<{
|
||||
const pairing: {
|
||||
pending?: Array<{
|
||||
requestId?: string;
|
||||
commands?: unknown;
|
||||
requiredApproveScopes?: unknown;
|
||||
}>;
|
||||
}>("node.pair.list", gatewayOpts, {}, { scopes: ["operator.pairing"] });
|
||||
} = await callGatewayTool("node.pair.list", gatewayOpts, {}, { scopes: ["operator.pairing"] });
|
||||
const pending = Array.isArray(pairing?.pending) ? pairing.pending : [];
|
||||
const match = pending.find((entry) => entry?.requestId === requestId);
|
||||
if (Array.isArray(match?.requiredApproveScopes)) {
|
||||
|
||||
@@ -82,7 +82,7 @@ export async function isRequesterSpawnedSessionVisible(params: {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
const resolved = await sessionsResolutionDeps.callGateway<{ key?: string }>({
|
||||
const resolved = await sessionsResolutionDeps.callGateway({
|
||||
method: "sessions.resolve",
|
||||
params: {
|
||||
key: params.targetSessionKey,
|
||||
@@ -231,7 +231,7 @@ async function callGatewayResolveSessionId(params: {
|
||||
requesterInternalKey?: string;
|
||||
restrictToSpawned: boolean;
|
||||
}): Promise<string> {
|
||||
const result = await sessionsResolutionDeps.callGateway<{ key?: string }>({
|
||||
const result = await sessionsResolutionDeps.callGateway({
|
||||
method: "sessions.resolve",
|
||||
params: buildSessionIdResolveParams(params),
|
||||
});
|
||||
@@ -288,7 +288,7 @@ async function resolveSessionKeyFromKey(params: {
|
||||
}): Promise<SessionReferenceResolution | null> {
|
||||
try {
|
||||
// Try key-based resolution first so non-standard keys keep working.
|
||||
const result = await sessionsResolutionDeps.callGateway<{ key?: string }>({
|
||||
const result = await sessionsResolutionDeps.callGateway({
|
||||
method: "sessions.resolve",
|
||||
params: {
|
||||
key: params.key,
|
||||
|
||||
@@ -19,7 +19,7 @@ async function resolveSessionKeyByToken(token: string): Promise<string | null> {
|
||||
|
||||
for (const params of attempts) {
|
||||
try {
|
||||
const resolved = await callGateway<{ key?: string }>({
|
||||
const resolved = await callGateway({
|
||||
method: "sessions.resolve",
|
||||
params,
|
||||
timeoutMs: 8_000,
|
||||
|
||||
@@ -334,7 +334,7 @@ export async function resolveFocusTargetSession(params: {
|
||||
|
||||
for (const attempt of attempts) {
|
||||
try {
|
||||
const resolved = await callGateway<{ key?: string }>({
|
||||
const resolved = await callGateway({
|
||||
method: "sessions.resolve",
|
||||
params: attempt,
|
||||
});
|
||||
|
||||
@@ -12,9 +12,9 @@ import {
|
||||
type ConfigWriteTargetLike,
|
||||
} from "./config-write-policy-shared.js";
|
||||
import type { ChannelId } from "./types.core.js";
|
||||
export type ConfigWriteScope = ConfigWriteScopeLike<ChannelId>;
|
||||
export type ConfigWriteTarget = ConfigWriteTargetLike<ChannelId>;
|
||||
export type ConfigWriteAuthorizationResult = ConfigWriteAuthorizationResultLike<ChannelId>;
|
||||
export type ConfigWriteScope = ConfigWriteScopeLike;
|
||||
export type ConfigWriteTarget = ConfigWriteTargetLike;
|
||||
export type ConfigWriteAuthorizationResult = ConfigWriteAuthorizationResultLike;
|
||||
|
||||
function isInternalConfigWriteMessageChannel(channel?: string | null): boolean {
|
||||
return normalizeLowercaseStringOrEmpty(channel) === "webchat";
|
||||
|
||||
@@ -549,12 +549,12 @@ async function runModelRun(params: {
|
||||
}
|
||||
|
||||
const { provider, model } = resolveModelRefOverride(params.model);
|
||||
const response = await callGateway<{
|
||||
const response: {
|
||||
result?: {
|
||||
payloads?: Array<{ text?: string; mediaUrl?: string | null; mediaUrls?: string[] }>;
|
||||
meta?: { agentMeta?: { provider?: string; model?: string } };
|
||||
};
|
||||
}>({
|
||||
} = await callGateway({
|
||||
method: "agent",
|
||||
params: {
|
||||
agentId,
|
||||
@@ -871,12 +871,12 @@ async function runTtsConvert(params: {
|
||||
}) {
|
||||
if (params.transport === "gateway") {
|
||||
const gatewayConnection = buildGatewayConnectionDetailsWithResolvers({ config: loadConfig() });
|
||||
const result = await callGateway<{
|
||||
const result: {
|
||||
audioPath?: string;
|
||||
provider?: string;
|
||||
outputFormat?: string;
|
||||
voiceCompatible?: boolean;
|
||||
}>({
|
||||
} = await callGateway({
|
||||
method: "tts.convert",
|
||||
params: {
|
||||
text: params.text,
|
||||
@@ -964,10 +964,10 @@ async function runTtsConvert(params: {
|
||||
async function runTtsProviders(transport: CapabilityTransport) {
|
||||
const cfg = loadConfig();
|
||||
if (transport === "gateway") {
|
||||
const payload = await callGateway<{
|
||||
const payload: {
|
||||
providers?: Array<Record<string, unknown>>;
|
||||
active?: string;
|
||||
}>({
|
||||
} = await callGateway({
|
||||
method: "tts.providers",
|
||||
timeoutMs: 30_000,
|
||||
});
|
||||
|
||||
@@ -687,7 +687,7 @@ export async function resolveCommandSecretRefsViaGateway(params: {
|
||||
|
||||
let payload: GatewaySecretsResolveResult;
|
||||
try {
|
||||
payload = await callGateway<GatewaySecretsResolveResult>({
|
||||
payload = await callGateway({
|
||||
config: params.config,
|
||||
method: "secrets.resolve",
|
||||
requiredMethods: ["secrets.resolve"],
|
||||
|
||||
@@ -122,14 +122,14 @@ export async function agentViaGatewayCommand(opts: AgentCliOpts, runtime: Runtim
|
||||
const channel = normalizeMessageChannel(opts.channel);
|
||||
const idempotencyKey = normalizeOptionalString(opts.runId) || randomIdempotencyKey();
|
||||
|
||||
const response = await withProgress(
|
||||
const response: GatewayAgentResponse = await withProgress(
|
||||
{
|
||||
label: "Waiting for agent reply…",
|
||||
indeterminate: true,
|
||||
enabled: opts.json !== true,
|
||||
},
|
||||
async () =>
|
||||
await callGateway<GatewayAgentResponse>({
|
||||
await callGateway({
|
||||
method: "agent",
|
||||
params: {
|
||||
message: body,
|
||||
|
||||
@@ -453,7 +453,7 @@ describe("onboard (non-interactive): gateway and remote auth", () => {
|
||||
expect(cfg.gateway?.remote?.token).toBe(token);
|
||||
|
||||
gatewayClientCalls.length = 0;
|
||||
const health = await callGateway<{ ok?: boolean }>({ method: "health" });
|
||||
const health = await callGateway({ method: "health" });
|
||||
expect(health?.ok).toBe(true);
|
||||
const lastCall = gatewayClientCalls[gatewayClientCalls.length - 1];
|
||||
expect(lastCall?.url).toBe(`ws://127.0.0.1:${port}`);
|
||||
|
||||
@@ -31,7 +31,7 @@ export type ChannelStatusSummary = {
|
||||
statusLines: string[];
|
||||
};
|
||||
|
||||
export type ChannelSetupSelectionContribution = FlowContribution<ChannelChoice> & {
|
||||
export type ChannelSetupSelectionContribution = FlowContribution & {
|
||||
kind: "channel";
|
||||
surface: "setup";
|
||||
channel: ChannelChoice;
|
||||
|
||||
@@ -287,7 +287,7 @@ async function bindConversationAndWait(params: {
|
||||
originatingAccountId: params.originatingAccountId,
|
||||
});
|
||||
|
||||
const mainHistory = await params.client.request<{ messages?: unknown[] }>("chat.history", {
|
||||
const mainHistory: { messages?: unknown[] } = await params.client.request("chat.history", {
|
||||
sessionKey: params.sessionKey,
|
||||
limit: 16,
|
||||
});
|
||||
@@ -316,7 +316,7 @@ async function waitForAgentRunOk(
|
||||
runId: string,
|
||||
timeoutMs = LIVE_TIMEOUT_MS,
|
||||
) {
|
||||
const result = await client.request<{ status?: string }>(
|
||||
const result: { status?: string } = await client.request(
|
||||
"agent.wait",
|
||||
{
|
||||
runId,
|
||||
@@ -345,7 +345,7 @@ async function sendChatAndWait(params: {
|
||||
content: string;
|
||||
}>;
|
||||
}) {
|
||||
const started = await params.client.request<{ runId?: string; status?: string }>("chat.send", {
|
||||
const started: { runId?: string; status?: string } = await params.client.request("chat.send", {
|
||||
sessionKey: params.sessionKey,
|
||||
message: params.message,
|
||||
idempotencyKey: params.idempotencyKey,
|
||||
@@ -371,7 +371,7 @@ async function waitForAssistantText(params: {
|
||||
const startedAt = Date.now();
|
||||
|
||||
while (Date.now() - startedAt < timeoutMs) {
|
||||
const history = await params.client.request<{ messages?: unknown[] }>("chat.history", {
|
||||
const history: { messages?: unknown[] } = await params.client.request("chat.history", {
|
||||
sessionKey: params.sessionKey,
|
||||
limit: 16,
|
||||
});
|
||||
@@ -387,7 +387,7 @@ async function waitForAssistantText(params: {
|
||||
await sleep(500);
|
||||
}
|
||||
|
||||
const finalHistory = await params.client.request<{ messages?: unknown[] }>("chat.history", {
|
||||
const finalHistory: { messages?: unknown[] } = await params.client.request("chat.history", {
|
||||
sessionKey: params.sessionKey,
|
||||
limit: 16,
|
||||
});
|
||||
@@ -408,7 +408,7 @@ async function waitForAssistantTurn(params: {
|
||||
const startedAt = Date.now();
|
||||
|
||||
while (Date.now() - startedAt < timeoutMs) {
|
||||
const history = await params.client.request<{ messages?: unknown[] }>("chat.history", {
|
||||
const history: { messages?: unknown[] } = await params.client.request("chat.history", {
|
||||
sessionKey: params.sessionKey,
|
||||
limit: 16,
|
||||
});
|
||||
@@ -421,7 +421,7 @@ async function waitForAssistantTurn(params: {
|
||||
await sleep(500);
|
||||
}
|
||||
|
||||
const finalHistory = await params.client.request<{ messages?: unknown[] }>("chat.history", {
|
||||
const finalHistory: { messages?: unknown[] } = await params.client.request("chat.history", {
|
||||
sessionKey: params.sessionKey,
|
||||
limit: 16,
|
||||
});
|
||||
|
||||
@@ -80,7 +80,7 @@ describe("gateway cli backend connect", () => {
|
||||
token,
|
||||
deviceIdentity,
|
||||
});
|
||||
const health = await client.request<{ ok?: boolean }>("health", undefined, {
|
||||
const health = await client.request("health", undefined, {
|
||||
timeoutMs: 5_000,
|
||||
});
|
||||
expect(health).toMatchObject({
|
||||
|
||||
@@ -1153,7 +1153,7 @@ async function requestGatewayAgentText(params: {
|
||||
params.modelKey,
|
||||
).length;
|
||||
const accepted = await withGatewayLiveProbeTimeout(
|
||||
params.client.request<{ runId?: unknown; status?: unknown }>("agent", {
|
||||
params.client.request("agent", {
|
||||
sessionKey: params.sessionKey,
|
||||
idempotencyKey: params.idempotencyKey,
|
||||
message: params.message,
|
||||
|
||||
@@ -175,10 +175,7 @@ describe("gateway e2e", () => {
|
||||
const sessionKey = "agent:dev:mock-openai";
|
||||
|
||||
const runId = nextGatewayId("run");
|
||||
const payload = await client.request<{
|
||||
status?: unknown;
|
||||
runId?: unknown;
|
||||
}>(
|
||||
const payload = await client.request(
|
||||
"agent",
|
||||
{
|
||||
sessionKey,
|
||||
|
||||
@@ -346,11 +346,10 @@ export function registerControlUiAndPairingSuite(): void {
|
||||
"x-forwarded-for": "203.0.113.10",
|
||||
},
|
||||
});
|
||||
const challengePromise = onceMessage<{
|
||||
type?: string;
|
||||
event?: string;
|
||||
payload?: Record<string, unknown> | null;
|
||||
}>(ws, (o) => o.type === "event" && o.event === "connect.challenge");
|
||||
const challengePromise = onceMessage(
|
||||
ws,
|
||||
(o) => o.type === "event" && o.event === "connect.challenge",
|
||||
);
|
||||
await new Promise<void>((resolve) => ws.once("open", resolve));
|
||||
const challenge = await challengePromise;
|
||||
const nonce = (challenge.payload as { nonce?: unknown } | undefined)?.nonce;
|
||||
@@ -1074,11 +1073,10 @@ export function registerControlUiAndPairingSuite(): void {
|
||||
const socket = new WebSocket(`ws://127.0.0.1:${port}`, {
|
||||
headers: { host: "gateway.example" },
|
||||
});
|
||||
const challengePromise = onceMessage<{
|
||||
type?: string;
|
||||
event?: string;
|
||||
payload?: Record<string, unknown> | null;
|
||||
}>(socket, (o) => o.type === "event" && o.event === "connect.challenge");
|
||||
const challengePromise = onceMessage(
|
||||
socket,
|
||||
(o) => o.type === "event" && o.event === "connect.challenge",
|
||||
);
|
||||
await new Promise<void>((resolve) => socket.once("open", resolve));
|
||||
const challenge = await challengePromise;
|
||||
const nonce = (challenge.payload as { nonce?: unknown } | undefined)?.nonce;
|
||||
|
||||
@@ -321,11 +321,11 @@ export function registerDefaultAuthTokenSuite(): void {
|
||||
|
||||
test("sends connect challenge on open", async () => {
|
||||
const ws = new WebSocket(`ws://127.0.0.1:${port}`);
|
||||
const evtPromise = onceMessage<{
|
||||
const evtPromise: Promise<{
|
||||
type?: string;
|
||||
event?: string;
|
||||
payload?: Record<string, unknown> | null;
|
||||
}>(ws, (o) => o.type === "event" && o.event === "connect.challenge");
|
||||
}> = onceMessage(ws, (o) => o.type === "event" && o.event === "connect.challenge");
|
||||
await new Promise<void>((resolve) => ws.once("open", resolve));
|
||||
const evt = await evtPromise;
|
||||
const nonce = (evt.payload as { nonce?: unknown } | undefined)?.nonce;
|
||||
@@ -350,7 +350,7 @@ export function registerDefaultAuthTokenSuite(): void {
|
||||
test("rejects non-connect first request", async () => {
|
||||
const ws = await openWs(port);
|
||||
ws.send(JSON.stringify({ type: "req", id: "h1", method: "health" }));
|
||||
const res = await onceMessage<{ type?: string; id?: string; ok?: boolean; error?: unknown }>(
|
||||
const res: { type?: string; id?: string; ok?: boolean; error?: unknown } = await onceMessage(
|
||||
ws,
|
||||
(o) => o.type === "res" && o.id === "h1",
|
||||
);
|
||||
|
||||
@@ -63,11 +63,11 @@ const readConnectChallengeNonce = async (ws: WebSocket) => {
|
||||
if (cached) {
|
||||
return cached;
|
||||
}
|
||||
const challenge = await onceMessage<{
|
||||
const challenge: {
|
||||
type?: string;
|
||||
event?: string;
|
||||
payload?: Record<string, unknown> | null;
|
||||
}>(ws, (o) => o.type === "event" && o.event === "connect.challenge");
|
||||
} = await onceMessage(ws, (o) => o.type === "event" && o.event === "connect.challenge");
|
||||
const nonce = (challenge.payload as { nonce?: unknown } | undefined)?.nonce;
|
||||
expect(typeof nonce).toBe("string");
|
||||
return String(nonce);
|
||||
@@ -290,7 +290,7 @@ async function sendRawConnectReq(
|
||||
},
|
||||
}),
|
||||
);
|
||||
return onceMessage<{
|
||||
const response: {
|
||||
type?: string;
|
||||
id?: string;
|
||||
ok?: boolean;
|
||||
@@ -302,7 +302,8 @@ async function sendRawConnectReq(
|
||||
reason?: string;
|
||||
};
|
||||
};
|
||||
}>(ws, isConnectResMessage(params.id));
|
||||
} = await onceMessage(ws, isConnectResMessage(params.id));
|
||||
return response;
|
||||
}
|
||||
|
||||
async function resolvePairedTokenForDeviceIdentityPath(deviceIdentityPath: string): Promise<{
|
||||
|
||||
@@ -15,16 +15,6 @@ const CLI_PRESENCE_TIMEOUT_MS = 3_000;
|
||||
|
||||
let harness: GatewayServerHarness;
|
||||
|
||||
type GatewayFrame = {
|
||||
type?: string;
|
||||
id?: string;
|
||||
ok?: boolean;
|
||||
event?: string;
|
||||
payload?: Record<string, unknown> | null;
|
||||
seq?: number;
|
||||
stateVersion?: { presence?: number; [key: string]: unknown };
|
||||
};
|
||||
|
||||
beforeAll(async () => {
|
||||
harness = await startGatewayServerHarness();
|
||||
});
|
||||
@@ -40,12 +30,9 @@ describe("gateway server health/presence", () => {
|
||||
async () => {
|
||||
const { ws } = await harness.openClient();
|
||||
|
||||
const healthP = onceMessage<GatewayFrame>(ws, (o) => o.type === "res" && o.id === "health1");
|
||||
const statusP = onceMessage<GatewayFrame>(ws, (o) => o.type === "res" && o.id === "status1");
|
||||
const presenceP = onceMessage<GatewayFrame>(
|
||||
ws,
|
||||
(o) => o.type === "res" && o.id === "presence1",
|
||||
);
|
||||
const healthP = onceMessage(ws, (o) => o.type === "res" && o.id === "health1");
|
||||
const statusP = onceMessage(ws, (o) => o.type === "res" && o.id === "status1");
|
||||
const presenceP = onceMessage(ws, (o) => o.type === "res" && o.id === "presence1");
|
||||
|
||||
const sendReq = (id: string, method: string) =>
|
||||
ws.send(JSON.stringify({ type: "req", id, method }));
|
||||
@@ -99,7 +86,7 @@ describe("gateway server health/presence", () => {
|
||||
method: "last-heartbeat",
|
||||
}),
|
||||
);
|
||||
const last = await onceMessage<GatewayFrame>(ws, (o) => o.type === "res" && o.id === "hb-last");
|
||||
const last = await onceMessage(ws, (o) => o.type === "res" && o.id === "hb-last");
|
||||
expect(last.ok).toBe(true);
|
||||
const lastPayload = last.payload as HeartbeatPayload | null | undefined;
|
||||
expect(lastPayload?.status).toBe("sent");
|
||||
@@ -113,10 +100,7 @@ describe("gateway server health/presence", () => {
|
||||
params: { enabled: false },
|
||||
}),
|
||||
);
|
||||
const toggle = await onceMessage<GatewayFrame>(
|
||||
ws,
|
||||
(o) => o.type === "res" && o.id === "hb-toggle-off",
|
||||
);
|
||||
const toggle = await onceMessage(ws, (o) => o.type === "res" && o.id === "hb-toggle-off");
|
||||
expect(toggle.ok).toBe(true);
|
||||
expect((toggle.payload as { enabled?: boolean } | undefined)?.enabled).toBe(false);
|
||||
|
||||
@@ -129,10 +113,7 @@ describe("gateway server health/presence", () => {
|
||||
async () => {
|
||||
const { ws } = await harness.openClient();
|
||||
|
||||
const presenceEventP = onceMessage<GatewayFrame>(
|
||||
ws,
|
||||
(o) => o.type === "event" && o.event === "presence",
|
||||
);
|
||||
const presenceEventP = onceMessage(ws, (o) => o.type === "event" && o.event === "presence");
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
type: "req",
|
||||
@@ -156,7 +137,7 @@ describe("gateway server health/presence", () => {
|
||||
const { ws } = await harness.openClient();
|
||||
|
||||
const runId = randomUUID();
|
||||
const evtPromise = onceMessage<GatewayFrame>(
|
||||
const evtPromise = onceMessage(
|
||||
ws,
|
||||
(o) =>
|
||||
o.type === "event" &&
|
||||
@@ -178,7 +159,7 @@ describe("gateway server health/presence", () => {
|
||||
test("shutdown event is broadcast on close", { timeout: PRESENCE_EVENT_TIMEOUT_MS }, async () => {
|
||||
const localHarness = await startGatewayServerHarness();
|
||||
const { ws } = await localHarness.openClient();
|
||||
const shutdownP = onceMessage<GatewayFrame>(
|
||||
const shutdownP = onceMessage(
|
||||
ws,
|
||||
(o) => o.type === "event" && o.event === "shutdown",
|
||||
SHUTDOWN_EVENT_TIMEOUT_MS,
|
||||
@@ -199,7 +180,7 @@ describe("gateway server health/presence", () => {
|
||||
harness.openClient(),
|
||||
]);
|
||||
const waits = clients.map(({ ws }) =>
|
||||
onceMessage<GatewayFrame>(ws, (o) => o.type === "event" && o.event === "presence"),
|
||||
onceMessage(ws, (o) => o.type === "event" && o.event === "presence"),
|
||||
);
|
||||
clients[0].ws.send(
|
||||
JSON.stringify({
|
||||
@@ -238,7 +219,7 @@ describe("gateway server health/presence", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const presenceP = onceMessage<GatewayFrame>(
|
||||
const presenceP = onceMessage(
|
||||
ws,
|
||||
(o) => o.type === "res" && o.id === "fingerprint",
|
||||
FINGERPRINT_TIMEOUT_MS,
|
||||
@@ -283,7 +264,7 @@ describe("gateway server health/presence", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const presenceP = onceMessage<GatewayFrame>(
|
||||
const presenceP = onceMessage(
|
||||
ws,
|
||||
(o) => o.type === "res" && o.id === "cli-presence",
|
||||
CLI_PRESENCE_TIMEOUT_MS,
|
||||
|
||||
@@ -131,11 +131,7 @@ describe("node.invoke approval bypass", () => {
|
||||
const ws = new WebSocket(`ws://127.0.0.1:${port}`);
|
||||
trackConnectChallengeNonce(ws);
|
||||
const challengePromise = resolveDevice
|
||||
? onceMessage<{
|
||||
type?: string;
|
||||
event?: string;
|
||||
payload?: Record<string, unknown> | null;
|
||||
}>(ws, (o) => o.type === "event" && o.event === "connect.challenge")
|
||||
? onceMessage(ws, (o) => o.type === "event" && o.event === "connect.challenge")
|
||||
: null;
|
||||
await new Promise<void>((resolve) => ws.once("open", resolve));
|
||||
const nonce = (() => {
|
||||
|
||||
@@ -158,7 +158,7 @@ describe("gateway role enforcement", () => {
|
||||
displayName: "node-role-enforcement",
|
||||
});
|
||||
|
||||
const binsPayload = await nodeClient.request<{ bins?: unknown[] }>("skills.bins", {});
|
||||
const binsPayload = await nodeClient.request("skills.bins", {});
|
||||
expect(Array.isArray(binsPayload?.bins)).toBe(true);
|
||||
|
||||
await expect(nodeClient.request("status", {})).rejects.toThrow("unauthorized role");
|
||||
|
||||
@@ -794,11 +794,11 @@ export async function readConnectChallengeNonce(
|
||||
}
|
||||
trackConnectChallengeNonce(ws);
|
||||
try {
|
||||
const evt = await onceMessage<{
|
||||
type?: string;
|
||||
event?: string;
|
||||
payload?: Record<string, unknown> | null;
|
||||
}>(ws, (o) => o.type === "event" && o.event === "connect.challenge", timeoutMs);
|
||||
const evt = await onceMessage(
|
||||
ws,
|
||||
(o) => o.type === "event" && o.event === "connect.challenge",
|
||||
timeoutMs,
|
||||
);
|
||||
const nonce = (evt.payload as { nonce?: unknown } | undefined)?.nonce;
|
||||
if (typeof nonce === "string" && nonce.trim().length > 0) {
|
||||
(ws as TrackedWs)[CONNECT_CHALLENGE_NONCE_KEY] = nonce.trim();
|
||||
|
||||
@@ -159,7 +159,7 @@ export class OpenClawChannelBridge {
|
||||
includeLastMessage?: boolean;
|
||||
}): Promise<ConversationDescriptor[]> {
|
||||
await this.waitUntilReady();
|
||||
const response = await this.requestGateway<SessionListResult>("sessions.list", {
|
||||
const response: SessionListResult = await this.requestGateway("sessions.list", {
|
||||
limit: params?.limit ?? 50,
|
||||
search: params?.search,
|
||||
includeDerivedTitles: params?.includeDerivedTitles ?? true,
|
||||
@@ -192,7 +192,7 @@ export class OpenClawChannelBridge {
|
||||
limit = 20,
|
||||
): Promise<NonNullable<ChatHistoryResult["messages"]>> {
|
||||
await this.waitUntilReady();
|
||||
const response = await this.requestGateway<ChatHistoryResult>("chat.history", {
|
||||
const response: ChatHistoryResult = await this.requestGateway("chat.history", {
|
||||
sessionKey,
|
||||
limit,
|
||||
});
|
||||
|
||||
@@ -257,7 +257,7 @@ export class GatewayChatClient {
|
||||
}
|
||||
|
||||
async listModels(): Promise<GatewayModelChoice[]> {
|
||||
const res = await this.client.request<{ models?: GatewayModelChoice[] }>("models.list");
|
||||
const res = await this.client.request("models.list");
|
||||
return Array.isArray(res?.models) ? res.models : [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ describe("gateway multi-instance e2e", () => {
|
||||
|
||||
const sessionKey = "agent:main:telegram:direct:123456";
|
||||
const idempotencyKey = `idem-${randomUUID()}`;
|
||||
const sendRes = await chatClient.request<{ runId?: string; status?: string }>("chat.send", {
|
||||
const sendRes = await chatClient.request("chat.send", {
|
||||
sessionKey,
|
||||
message: "/context list",
|
||||
idempotencyKey,
|
||||
|
||||
@@ -14,10 +14,6 @@ import { GATEWAY_CLIENT_MODES, GATEWAY_CLIENT_NAMES } from "../../src/utils/mess
|
||||
|
||||
export { extractFirstTextBlock };
|
||||
|
||||
type NodeListPayload = {
|
||||
nodes?: Array<{ nodeId?: string; connected?: boolean; paired?: boolean }>;
|
||||
};
|
||||
|
||||
export type ChatEventPayload = {
|
||||
runId?: string;
|
||||
sessionKey?: string;
|
||||
@@ -348,7 +344,7 @@ export async function waitForNodeStatus(
|
||||
);
|
||||
try {
|
||||
while (Date.now() < deadline) {
|
||||
const list = await client.request<NodeListPayload>("node.list", {});
|
||||
const list = await client.request("node.list", {});
|
||||
const match = list.nodes?.find((n) => n.nodeId === nodeId);
|
||||
if (match?.connected && match?.paired) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user