mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-18 00:02:45 +00:00
Add file-trigger hook example
This commit is contained in:
parent
e7097d911a
commit
0ef73ad1dc
4 changed files with 62 additions and 0 deletions
22
.opencode/tool/sleep.ts
Normal file
22
.opencode/tool/sleep.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
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`
|
||||
},
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue