mirror of
https://github.com/volcengine/OpenViking.git
synced 2026-09-30 17:28:07 +08:00
* refactor(openclaw): add setup and routing modules * docs(openclaw): align docs and healthcheck with peer routing * refactor(openclaw): wire modular runtime into core * fix(openclaw): package plugin runtime directory
42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
import type { OpenVikingClient } from "./client.js";
|
|
|
|
export function withTimeout<T>(promise: Promise<T>, timeoutMs: number, timeoutMessage: string): Promise<T> {
|
|
return new Promise((resolve, reject) => {
|
|
const timer = setTimeout(() => reject(new Error(timeoutMessage)), timeoutMs);
|
|
promise.then(
|
|
(value) => {
|
|
clearTimeout(timer);
|
|
resolve(value);
|
|
},
|
|
(err) => {
|
|
clearTimeout(timer);
|
|
reject(err);
|
|
},
|
|
);
|
|
});
|
|
}
|
|
|
|
export async function quickHealthCheck(
|
|
client: OpenVikingClient,
|
|
agentId: string | undefined,
|
|
timeoutMs: number,
|
|
): Promise<boolean> {
|
|
try {
|
|
await client.healthCheck(timeoutMs, agentId);
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export async function quickRecallPrecheck(
|
|
client: OpenVikingClient,
|
|
agentId?: string,
|
|
): Promise<{ ok: true } | { ok: false; reason: string }> {
|
|
const healthOk = await quickHealthCheck(client, agentId, 500);
|
|
if (healthOk) {
|
|
return { ok: true };
|
|
}
|
|
return { ok: false, reason: "health check failed" };
|
|
}
|