xonecas.io
64875
Mc

mini-coder / commit 39cffff

refactor(llm-api): fold turn-tools.ts into turn.ts

turn-tools.ts contained a single 24-line function (toCoreTool) used
exclusively by turn.ts. Moving it inline removes the unnecessary file
and import hop.

xonecas2026-03-14 39cffffed3624df802f43392b129ff5512abfc67 parent 6548a80

2 files changed

src/llm-api/turn-tools.ts+0−24
@@ -1,24 +0,0 @@
1-import type { FlexibleSchema } from "ai";
2-import { dynamicTool, jsonSchema } from "ai";
3-import type { ToolDef } from "./types.ts";
4-
5-function isZodSchema(s: unknown): boolean {
6- return s !== null && typeof s === "object" && "_def" in (s as object);
7-}
8-
9-export function toCoreTool(def: ToolDef): ReturnType<typeof dynamicTool> {
10- const schema = isZodSchema(def.schema)
11- ? (def.schema as FlexibleSchema<unknown>)
12- : jsonSchema(def.schema);
13- return dynamicTool({
14- description: def.description,
15- inputSchema: schema,
16- execute: async (input: unknown) => {
17- try {
18- return await def.execute(input);
19- } catch (err) {
20- throw err instanceof Error ? err : new Error(String(err));
21- }
22- },
23- });
24-}
src/llm-api/turn.ts+23−3
@@ -1,5 +1,5 @@
1-import type { StepResult } from "ai";
2-import { stepCountIs, streamText } from "ai";
1+import type { FlexibleSchema, StepResult } from "ai";
2+import { dynamicTool, jsonSchema, stepCountIs, streamText } from "ai";
33 import { isApiLogEnabled, logApiEvent } from "./api-log.ts";
44 import {
55 getReasoningDeltaFromStreamChunk,
@@ -32,7 +32,6 @@ import {
3232 mapStreamChunkToTurnEvent,
3333 shouldLogStreamChunk,
3434 } from "./turn-stream-events.ts";
35-import { toCoreTool } from "./turn-tools.ts";
3635 import type { ToolDef, TurnEvent } from "./types.ts";
3736
3837 type StreamTextOptions = Parameters<typeof streamText>[0];
@@ -53,6 +52,27 @@ function isRecord(value: unknown): value is Record<string, unknown> {
5352 return value !== null && typeof value === "object";
5453 }
5554
55+function isZodSchema(s: unknown): boolean {
56+ return s !== null && typeof s === "object" && "_def" in (s as object);
57+}
58+
59+function toCoreTool(def: ToolDef): ReturnType<typeof dynamicTool> {
60+ const schema = isZodSchema(def.schema)
61+ ? (def.schema as FlexibleSchema<unknown>)
62+ : jsonSchema(def.schema);
63+ return dynamicTool({
64+ description: def.description,
65+ inputSchema: schema,
66+ execute: async (input: unknown) => {
67+ try {
68+ return await def.execute(input);
69+ } catch (err) {
70+ throw err instanceof Error ? err : new Error(String(err));
71+ }
72+ },
73+ });
74+}
75+
5676 const mergeDeep = (
5777 target: Record<string, unknown>,
5878 source: Record<string, unknown>,