refactor(tool): convert question tool internals to Effect (#21808)

This commit is contained in:
Kit Langton
2026-04-10 09:42:06 -04:00
committed by GitHub
parent ce19c051be
commit 157c5d77f8
+14 -15
View File
@@ -20,27 +20,26 @@ export const QuestionTool = Tool.defineEffect<typeof parameters, Metadata, Quest
return { return {
description: DESCRIPTION, description: DESCRIPTION,
parameters, parameters,
async execute(params: z.infer<typeof parameters>, ctx: Tool.Context<Metadata>) { execute: (params: z.infer<typeof parameters>, ctx: Tool.Context<Metadata>) =>
const answers = await question Effect.gen(function* () {
.ask({ const answers = yield* question.ask({
sessionID: ctx.sessionID, sessionID: ctx.sessionID,
questions: params.questions, questions: params.questions,
tool: ctx.callID ? { messageID: ctx.messageID, callID: ctx.callID } : undefined, tool: ctx.callID ? { messageID: ctx.messageID, callID: ctx.callID } : undefined,
}) })
.pipe(Effect.runPromise)
const formatted = params.questions const formatted = params.questions
.map((q, i) => `"${q.question}"="${answers[i]?.length ? answers[i].join(", ") : "Unanswered"}"`) .map((q, i) => `"${q.question}"="${answers[i]?.length ? answers[i].join(", ") : "Unanswered"}"`)
.join(", ") .join(", ")
return { return {
title: `Asked ${params.questions.length} question${params.questions.length > 1 ? "s" : ""}`, title: `Asked ${params.questions.length} question${params.questions.length > 1 ? "s" : ""}`,
output: `User has answered your questions: ${formatted}. You can now continue with the user's answers in mind.`, output: `User has answered your questions: ${formatted}. You can now continue with the user's answers in mind.`,
metadata: { metadata: {
answers, answers,
}, },
} }
}, }).pipe(Effect.runPromise),
} }
}), }),
) )