mirror of
https://github.com/anomalyco/opencode.git
synced 2026-04-28 04:29:42 +00:00
refactor(task): simplify effect wrappers
This commit is contained in:
parent
3f4b9d9ef4
commit
601fe03a3a
2 changed files with 11 additions and 14 deletions
|
|
@ -81,10 +81,9 @@ export const TaskTool = Tool.define(
|
|||
const sessions = yield* Session.Service
|
||||
const status = yield* SessionStatus.Service
|
||||
|
||||
const run = Effect.fn("TaskTool.execute")(function* (
|
||||
params: Schema.Schema.Type<typeof Parameters>,
|
||||
ctx: Tool.Context,
|
||||
) {
|
||||
const run = Effect.fn(
|
||||
"TaskTool.execute",
|
||||
)(function* (params: Schema.Schema.Type<typeof Parameters>, ctx: Tool.Context) {
|
||||
const cfg = yield* config.get()
|
||||
|
||||
if (!ctx.extra?.bypassAgentCheck) {
|
||||
|
|
@ -274,13 +273,12 @@ export const TaskTool = Tool.define(
|
|||
ctx.abort.removeEventListener("abort", cancel)
|
||||
}),
|
||||
)
|
||||
})
|
||||
}, Effect.orDie)
|
||||
|
||||
return {
|
||||
description: DESCRIPTION,
|
||||
parameters: Parameters,
|
||||
execute: (params: Schema.Schema.Type<typeof Parameters>, ctx: Tool.Context) =>
|
||||
run(params, ctx).pipe(Effect.orDie),
|
||||
execute: run,
|
||||
}
|
||||
}),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -110,14 +110,13 @@ export const TaskStatusTool = Tool.define(
|
|||
if (result.state !== "running") return { result, timedOut: false }
|
||||
if (timeout <= 0) return { result, timedOut: true }
|
||||
const sleep = Math.min(POLL_MS, timeout)
|
||||
yield* Effect.sleep(`${sleep} millis`)
|
||||
yield* Effect.sleep(sleep)
|
||||
return yield* waitForTerminal(taskID, timeout - sleep)
|
||||
})
|
||||
|
||||
const run = Effect.fn("TaskStatusTool.execute")(function* (
|
||||
params: Schema.Schema.Type<typeof Parameters>,
|
||||
_ctx: Tool.Context,
|
||||
) {
|
||||
const run = Effect.fn(
|
||||
"TaskStatusTool.execute",
|
||||
)(function* (params: Schema.Schema.Type<typeof Parameters>, _ctx: Tool.Context) {
|
||||
yield* sessions.get(params.task_id)
|
||||
|
||||
const waited =
|
||||
|
|
@ -142,12 +141,12 @@ export const TaskStatusTool = Tool.define(
|
|||
text: outputText,
|
||||
}),
|
||||
}
|
||||
})
|
||||
}, Effect.orDie)
|
||||
|
||||
return {
|
||||
description: DESCRIPTION,
|
||||
parameters: Parameters,
|
||||
execute: (params: Schema.Schema.Type<typeof Parameters>, ctx: Tool.Context) => run(params, ctx).pipe(Effect.orDie),
|
||||
execute: run,
|
||||
}
|
||||
}),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue