Просмотр исходного кода

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

Kit Langton 5 месяцев назад
Родитель
Сommit
157c5d77f8
1 измененных файлов с 14 добавлено и 15 удалено
  1. 14 15
      packages/opencode/src/tool/question.ts

+ 14 - 15
packages/opencode/src/tool/question.ts

@@ -20,27 +20,26 @@ export const QuestionTool = Tool.defineEffect<typeof parameters, Metadata, Quest
     return {
       description: DESCRIPTION,
       parameters,
-      async execute(params: z.infer<typeof parameters>, ctx: Tool.Context<Metadata>) {
-        const answers = await question
-          .ask({
+      execute: (params: z.infer<typeof parameters>, ctx: Tool.Context<Metadata>) =>
+        Effect.gen(function* () {
+          const answers = yield* question.ask({
             sessionID: ctx.sessionID,
             questions: params.questions,
             tool: ctx.callID ? { messageID: ctx.messageID, callID: ctx.callID } : undefined,
           })
-          .pipe(Effect.runPromise)
 
-        const formatted = params.questions
-          .map((q, i) => `"${q.question}"="${answers[i]?.length ? answers[i].join(", ") : "Unanswered"}"`)
-          .join(", ")
+          const formatted = params.questions
+            .map((q, i) => `"${q.question}"="${answers[i]?.length ? answers[i].join(", ") : "Unanswered"}"`)
+            .join(", ")
 
-        return {
-          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.`,
-          metadata: {
-            answers,
-          },
-        }
-      },
+          return {
+            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.`,
+            metadata: {
+              answers,
+            },
+          }
+        }).pipe(Effect.runPromise),
     }
   }),
 )