refactor(tool): use Session.Service directly in TaskTool (#21975)
This commit is contained in:
@@ -36,6 +36,7 @@ export const TaskTool = Tool.define(
|
|||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const agent = yield* Agent.Service
|
const agent = yield* Agent.Service
|
||||||
const config = yield* Config.Service
|
const config = yield* Config.Service
|
||||||
|
const sessions = yield* Session.Service
|
||||||
|
|
||||||
const run = Effect.fn("TaskTool.execute")(function* (params: z.infer<typeof parameters>, ctx: Tool.Context) {
|
const run = Effect.fn("TaskTool.execute")(function* (params: z.infer<typeof parameters>, ctx: Tool.Context) {
|
||||||
const cfg = yield* config.get()
|
const cfg = yield* config.get()
|
||||||
@@ -62,15 +63,13 @@ export const TaskTool = Tool.define(
|
|||||||
|
|
||||||
const taskID = params.task_id
|
const taskID = params.task_id
|
||||||
const session = taskID
|
const session = taskID
|
||||||
? yield* Effect.promise(() => {
|
? yield* sessions.get(SessionID.make(taskID)).pipe(
|
||||||
const id = SessionID.make(taskID)
|
Effect.catchCause(() => Effect.succeed(undefined)),
|
||||||
return Session.get(id).catch(() => undefined)
|
)
|
||||||
})
|
|
||||||
: undefined
|
: undefined
|
||||||
const nextSession =
|
const nextSession =
|
||||||
session ??
|
session ??
|
||||||
(yield* Effect.promise(() =>
|
(yield* sessions.create({
|
||||||
Session.create({
|
|
||||||
parentID: ctx.sessionID,
|
parentID: ctx.sessionID,
|
||||||
title: params.description + ` (@${next.name} subagent)`,
|
title: params.description + ` (@${next.name} subagent)`,
|
||||||
permission: [
|
permission: [
|
||||||
@@ -98,8 +97,7 @@ export const TaskTool = Tool.define(
|
|||||||
permission: item,
|
permission: item,
|
||||||
})) ?? []),
|
})) ?? []),
|
||||||
],
|
],
|
||||||
}),
|
}))
|
||||||
))
|
|
||||||
|
|
||||||
const msg = yield* Effect.sync(() => MessageV2.get({ sessionID: ctx.sessionID, messageID: ctx.messageID }))
|
const msg = yield* Effect.sync(() => MessageV2.get({ sessionID: ctx.sessionID, messageID: ctx.messageID }))
|
||||||
if (msg.info.role !== "assistant") return yield* Effect.fail(new Error("Not an assistant message"))
|
if (msg.info.role !== "assistant") return yield* Effect.fail(new Error("Not an assistant message"))
|
||||||
|
|||||||
Reference in New Issue
Block a user