mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 09:01:14 +00:00
22 lines
664 B
TypeScript
22 lines
664 B
TypeScript
import { tool } from "@opencode-ai/plugin"
|
|
|
|
export default tool({
|
|
description: "Sleep for a specified number of milliseconds",
|
|
args: {
|
|
ms: tool.schema.number().describe("Number of milliseconds to sleep"),
|
|
},
|
|
async execute(args, context) {
|
|
if (context.abort.aborted) {
|
|
throw new Error("Sleep aborted")
|
|
}
|
|
await new Promise<void>((resolve, reject) => {
|
|
const timeout = setTimeout(resolve, args.ms)
|
|
const onAbort = () => {
|
|
clearTimeout(timeout)
|
|
reject(new Error("Sleep aborted"))
|
|
}
|
|
context.abort.addEventListener("abort", onAbort, { once: true })
|
|
})
|
|
return `Slept for ${args.ms}ms`
|
|
},
|
|
})
|