The best way to control Claude Code, Codex and more from any computer or phone

main
ts 24 lines 687 Bytes
Raw
1 import type * as Response from "effect/ai/Response"
2
3 const finishReasonMap: Record<string, Response.FinishReason> = {
4 content_filter: "content-filter",
5 function_call: "tool-calls",
6 length: "length",
7 stop: "stop",
8 tool_calls: "tool-calls"
9 }
10
11 /** @internal */
12 export const resolveFinishReason = (
13 finishReason: string | null | undefined,
14 hasToolCalls: boolean
15 ): Response.FinishReason => {
16 if (finishReason == null) {
17 return hasToolCalls ? "tool-calls" : "stop"
18 }
19 const reason = Object.hasOwn(finishReasonMap, finishReason) ? finishReasonMap[finishReason] : undefined
20 if (reason == null) {
21 return hasToolCalls ? "tool-calls" : "unknown"
22 }
23 return reason
24 }