25 lines
1.1 KiB
TypeScript
25 lines
1.1 KiB
TypeScript
//#region src/utils.d.ts
|
||
declare function randomUUID(): string;
|
||
declare function partialJSONParse(json: string): unknown;
|
||
/**
|
||
* Safely parses a JSON string into a plain object for tool arguments.
|
||
* Handles two failure modes:
|
||
* 1. Malformed JSON (SyntaxError from JSON.parse)
|
||
* 2. Valid JSON that isn't a plain object (e.g. "", [], null, 42, true)
|
||
* Falls back to an empty object for safety in both cases.
|
||
*/
|
||
declare function safeParseToolArgs(raw: string): Record<string, unknown>;
|
||
/**
|
||
* Returns an exponential backoff function suitable for Phoenix.js
|
||
* `reconnectAfterMs` and `rejoinAfterMs` options.
|
||
*
|
||
* @param baseMs - Initial delay for the first retry attempt.
|
||
* @param maxMs - Upper bound — delays are capped at this value.
|
||
*
|
||
* Phoenix calls the returned function with a 1-based `tries` count.
|
||
* The delay doubles on each attempt: baseMs, 2×baseMs, 4×baseMs, …, maxMs.
|
||
*/
|
||
declare function phoenixExponentialBackoff(baseMs: number, maxMs: number): (tries: number) => number;
|
||
//#endregion
|
||
export { partialJSONParse, phoenixExponentialBackoff, randomUUID, safeParseToolArgs };
|
||
//# sourceMappingURL=utils.d.mts.map
|