mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-22 11:55:46 +00:00
refactor(task): simplify effect wrappers
This commit is contained in:
@@ -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,
|
||||
}
|
||||
}),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user