Skip to content

Commit ec718a5

Browse files
committed
fix(session): use current native LLM constructors
1 parent fa1bdb0 commit ec718a5

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

packages/opencode/src/session/llm-native.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import type { JsonSchema, LLMRequest, ProviderMetadata, ToolDefinition } from "@opencode-ai/llm"
2-
import { LLM } from "@opencode-ai/llm"
1+
import type { JsonSchema, LLMRequest, ProviderMetadata } from "@opencode-ai/llm"
2+
import { LLM, Message, SystemPart, ToolCallPart, ToolDefinition, ToolResultPart } from "@opencode-ai/llm"
3+
import "@opencode-ai/llm/providers"
34
import type { ModelMessage } from "ai"
45
import type { Provider } from "@/provider/provider"
56

@@ -71,7 +72,7 @@ const mediaPart = (part: Record<string, unknown>) => {
7172
const toolResult = (part: Record<string, unknown>) => {
7273
const output = isRecord(part.output) ? part.output : { type: "json", value: part.output }
7374
const type = output.type === "text" ? "text" : output.type === "error-text" ? "error" : "json"
74-
return LLM.toolResult({
75+
return ToolResultPart.make({
7576
id: typeof part.toolCallId === "string" ? part.toolCallId : "",
7677
name: typeof part.toolName === "string" ? part.toolName : "",
7778
result: "value" in output ? output.value : output,
@@ -92,7 +93,7 @@ const contentPart = (part: unknown) => {
9293
providerMetadata: providerMetadata(part.providerOptions),
9394
}
9495
if (part.type === "tool-call")
95-
return LLM.toolCall({
96+
return ToolCallPart.make({
9697
id: typeof part.toolCallId === "string" ? part.toolCallId : "",
9798
name: typeof part.toolName === "string" ? part.toolName : "",
9899
input: part.input,
@@ -104,14 +105,14 @@ const contentPart = (part: unknown) => {
104105
}
105106

106107
const content = (value: ModelMessage["content"]) =>
107-
typeof value === "string" ? [LLM.text(value)] : value.map(contentPart)
108+
typeof value === "string" ? [{ type: "text" as const, text: value }] : value.map(contentPart)
108109

109110
const messages = (input: readonly ModelMessage[]) => {
110-
const system = input.flatMap((message) => (message.role === "system" ? [LLM.system(message.content)] : []))
111+
const system = input.flatMap((message) => (message.role === "system" ? [SystemPart.make(message.content)] : []))
111112
const messages = input.flatMap((message) => {
112113
if (message.role === "system") return []
113114
return [
114-
LLM.message({
115+
Message.make({
115116
role: message.role,
116117
content: content(message.content),
117118
native: isRecord(message.providerOptions) ? { providerOptions: message.providerOptions } : undefined,
@@ -129,7 +130,7 @@ const schema = (value: unknown): JsonSchema => {
129130

130131
const tools = (input: Record<string, ToolInput> | undefined): ToolDefinition[] =>
131132
Object.entries(input ?? {}).map(([name, item]) =>
132-
LLM.toolDefinition({
133+
ToolDefinition.make({
133134
name,
134135
description: item.description ?? "",
135136
inputSchema: schema(item.inputSchema),
@@ -173,7 +174,7 @@ export const request = (input: RequestInput) => {
173174
const converted = messages(input.messages)
174175
return LLM.request({
175176
model: model(input.model, input.headers),
176-
system: [...(input.system ?? []).map(LLM.system), ...converted.system],
177+
system: [...(input.system ?? []).map(SystemPart.make), ...converted.system],
177178
messages: converted.messages,
178179
tools: tools(input.tools),
179180
toolChoice: input.toolChoice,

0 commit comments

Comments
 (0)