MCPcopy Index your code
hub / github.com/anomalyco/opencode / nativeTools

Function nativeTools

packages/opencode/src/session/llm/native-runtime.ts:169–193  ·  view source on GitHub ↗
(tools: Record<string, Tool>, input: Pick<StreamInput, "messages" | "abort">)

Source from the content-addressed store, hash-verified

167}
168
169export function nativeTools(tools: Record<string, Tool>, input: Pick<StreamInput, "messages" | "abort">) {
170 return Object.fromEntries(
171 Object.entries(tools).map(([name, item]) => [
172 name,
173 // Tool execution remains opencode-owned. The native runtime only adapts
174 // the @opencode-ai/llm tool call back into the AI SDK Tool.execute shape.
175 NativeTool.make({
176 description: item.description ?? "",
177 jsonSchema: nativeSchema(item.inputSchema),
178 execute: (args: unknown, ctx) =>
179 Effect.tryPromise({
180 try: () => {
181 if (!item.execute) throw new Error(`Tool has no execute handler: ${name}`)
182 return item.execute(args, {
183 toolCallId: ctx?.id ?? name,
184 messages: input.messages,
185 abortSignal: input.abort,
186 })
187 },
188 catch: (error) => new ToolFailure({ message: errorMessage(error), error }),
189 }),
190 }),
191 ]),
192 )
193}
194
195export * as LLMNativeRuntime from "./native-runtime"

Callers 1

streamFunction · 0.85

Calls 4

errorMessageFunction · 0.90
nativeSchemaFunction · 0.85
executeMethod · 0.65
makeMethod · 0.45

Tested by

no test coverage detected