@artinet/sdk
Version:
A TypeScript SDK for building collaborative AI agents.
44 lines (43 loc) • 1.11 kB
JavaScript
/**
* Copyright 2025 The Artinet Project
* SPDX-License-Identifier: Apache-2.0
*/
/**
* Generates a timestamp in ISO 8601 format.
* @returns The current timestamp as a string.
*/
export function getCurrentTimestamp() {
return new Date().toISOString();
}
/**
* Sleeps for a given number of milliseconds.
* @param ms - The number of milliseconds to sleep.
* @returns A promise that resolves when the sleep is complete.
*
* @example
* ```typescript
* await sleep(1000);
* ```
*/
export function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
/**
* Formats a JSON object into a string with indentation.
* @param json - The JSON object to format.
* @returns A string representation of the JSON object.
*/
export function formatJson(json) {
return JSON.stringify(json, null, 2);
}
/**
* Formats an error into a standard error object for logging.
* @param error - The error to format.
* @returns A standard error object.
*/
export function formatError(error) {
if (error instanceof Error) {
return error;
}
return new Error(String(error));
}