Files
OpenViking/examples/openclaw-plugin/process-manager.ts
T
Mingjian Que d9e40b0974 refactor(openclaw): add setup and routing modules (#2654)
* 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
2026-06-17 10:26:23 +08:00

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" };
}