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,44 +63,41 @@ 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: [
|
...(canTodo
|
||||||
...(canTodo
|
? []
|
||||||
? []
|
: [
|
||||||
: [
|
{
|
||||||
{
|
permission: "todowrite" as const,
|
||||||
permission: "todowrite" as const,
|
pattern: "*" as const,
|
||||||
pattern: "*" as const,
|
action: "deny" as const,
|
||||||
action: "deny" as const,
|
},
|
||||||
},
|
]),
|
||||||
]),
|
...(canTask
|
||||||
...(canTask
|
? []
|
||||||
? []
|
: [
|
||||||
: [
|
{
|
||||||
{
|
permission: id,
|
||||||
permission: id,
|
pattern: "*" as const,
|
||||||
pattern: "*" as const,
|
action: "deny" as const,
|
||||||
action: "deny" as const,
|
},
|
||||||
},
|
]),
|
||||||
]),
|
...(cfg.experimental?.primary_tools?.map((item) => ({
|
||||||
...(cfg.experimental?.primary_tools?.map((item) => ({
|
pattern: "*",
|
||||||
pattern: "*",
|
action: "allow" as const,
|
||||||
action: "allow" as const,
|
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