Skip to content

Commit 8db7487

Browse files
committed
refactor(core): consolidate tool architecture
1 parent 0fd73a2 commit 8db7487

466 files changed

Lines changed: 9405 additions & 11071 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎bun.lock‎

Lines changed: 18 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
"packages/slack"
3737
],
3838
"catalog": {
39-
"@effect/opentelemetry": "4.0.0-beta.98",
40-
"@effect/platform-node": "4.0.0-beta.98",
41-
"@effect/sql-sqlite-bun": "4.0.0-beta.98",
39+
"@effect/opentelemetry": "4.0.0-beta.101",
40+
"@effect/platform-node": "4.0.0-beta.101",
41+
"@effect/sql-sqlite-bun": "4.0.0-beta.101",
4242
"@npmcli/arborist": "9.4.0",
4343
"@types/bun": "1.3.13",
4444
"@types/cross-spawn": "6.0.6",
@@ -50,6 +50,7 @@
5050
"@opentui/solid": "0.4.5",
5151
"@tanstack/solid-virtual": "3.13.32",
5252
"@shikijs/stream": "4.2.0",
53+
"@standard-schema/spec": "1.1.0",
5354
"ulid": "3.0.1",
5455
"@kobalte/core": "0.13.11",
5556
"@corvu/drawer": "0.2.4",
@@ -68,7 +69,7 @@
6869
"dompurify": "3.3.1",
6970
"drizzle-kit": "1.0.0-rc.2",
7071
"drizzle-orm": "1.0.0-rc.2",
71-
"effect": "4.0.0-beta.98",
72+
"effect": "4.0.0-beta.101",
7273
"ai": "6.0.168",
7374
"cross-spawn": "7.0.6",
7475
"hono": "4.10.7",
@@ -151,7 +152,8 @@
151152
"@opentui/keymap": "catalog:",
152153
"@opentui/solid": "catalog:",
153154
"@types/bun": "catalog:",
154-
"@types/node": "catalog:"
155+
"@types/node": "catalog:",
156+
"effect": "catalog:"
155157
},
156158
"patchedDependencies": {
157159
"@npmcli/[email protected]": "patches/@npmcli%[email protected]",
@@ -165,7 +167,7 @@
165167
"@ai-sdk/[email protected]": "patches/@ai-sdk%[email protected]",
166168
"@pierre/[email protected]": "patches/@pierre%[email protected]",
167169
"@modelcontextprotocol/[email protected]": "patches/@modelcontextprotocol%[email protected]",
168-
"[email protected].98": "patches/[email protected].98.patch",
170+
"[email protected].101": "patches/[email protected].101.patch",
169171
"@tanstack/[email protected]": "patches/@tanstack%[email protected]"
170172
}
171173
}

‎packages/ai/src/protocols/anthropic-messages.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Effect, Schema } from "effect"
2+
import { Tool } from "@opencode-ai/schema/tool"
23
import { Route } from "../route/client"
34
import { Auth } from "../route/auth"
45
import { Endpoint } from "../route/endpoint"
@@ -19,7 +20,6 @@ import {
1920
type ProviderMetadata,
2021
type ToolCallPart,
2122
type ToolDefinition,
22-
type ToolContent,
2323
type ToolResultPart,
2424
} from "../schema"
2525
import { JsonObject, optionalArray, optionalNull, ProviderShared } from "./shared"
@@ -425,7 +425,7 @@ const lowerMedia = Effect.fn("AnthropicMessages.lowerMedia")(function* (part: Me
425425
// Tool results may carry structured text, images, and documents. Keep media as provider-native
426426
// content instead of JSON-stringifying base64 into a prompt string.
427427
const lowerToolResultContentItem = Effect.fn("AnthropicMessages.lowerToolResultContentItem")(function* (
428-
item: ToolContent,
428+
item: Tool.Content,
429429
) {
430430
if (item.type === "text") return { type: "text" as const, text: item.text } satisfies AnthropicTextBlock
431431
return yield* lowerMedia({ type: "media", mediaType: item.mime, data: item.uri, filename: item.name })
@@ -436,7 +436,7 @@ const lowerToolResultContent = Effect.fn("AnthropicMessages.lowerToolResultConte
436436
// with existing cassettes and provider expectations.
437437
if (part.result.type !== "content") return ProviderShared.toolResultText(part)
438438
// Preserve the narrowed array element type when compiled through a consumer package.
439-
const content: ReadonlyArray<ToolContent> = part.result.value
439+
const content: ReadonlyArray<Tool.Content> = part.result.value
440440
return yield* Effect.forEach(content, lowerToolResultContentItem)
441441
})
442442

‎packages/ai/src/protocols/gemini.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Effect, Schema } from "effect"
2+
import { Tool } from "@opencode-ai/schema/tool"
23
import { Route } from "../route/client"
34
import { Auth } from "../route/auth"
45
import { Endpoint } from "../route/endpoint"
@@ -16,7 +17,6 @@ import {
1617
type TextPart,
1718
type ToolCallPart,
1819
type ToolDefinition,
19-
type ToolContent,
2020
} from "../schema"
2121
import { JsonObject, optionalArray, ProviderShared } from "./shared"
2222
import { GeminiToolSchema } from "./utils/gemini-tool-schema"
@@ -289,7 +289,7 @@ const lowerMessages = Effect.fn("Gemini.lowerMessages")(function* (request: LLMR
289289
})
290290
continue
291291
}
292-
const content: ReadonlyArray<ToolContent> = part.result.value
292+
const content: ReadonlyArray<Tool.Content> = part.result.value
293293
const text = content.filter((item) => item.type === "text").map((item) => item.text)
294294
const media: GeminiInlineDataPart[] = []
295295
for (const item of content) {

‎packages/ai/src/protocols/open-responses.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Effect, Schema } from "effect"
2+
import type { Content } from "@opencode-ai/schema/tool"
23
import { HttpTransport } from "../route/transport"
34
import { Protocol } from "../route/protocol"
45
import {
@@ -14,7 +15,6 @@ import {
1415
type TextPart,
1516
type ToolCallPart,
1617
type ToolDefinition,
17-
type ToolContent,
1818
type ToolResultPart,
1919
} from "../schema"
2020
import { JsonObject, optionalArray, optionalNull, ProviderShared } from "./shared"
@@ -371,7 +371,7 @@ const lowerUserContent = Effect.fn("OpenResponses.lowerUserContent")(function* (
371371
// Tool results may carry structured text, images, and files. Keep media as provider-native
372372
// content instead of JSON-stringifying base64 into a prompt string.
373373
const lowerToolResultContentItem = Effect.fn("OpenResponses.lowerToolResultContentItem")(function* (
374-
item: ToolContent,
374+
item: Content,
375375
request: LLMRequest,
376376
extension: Extension,
377377
) {
@@ -392,7 +392,7 @@ const lowerToolResultOutput = Effect.fn("OpenResponses.lowerToolResultOutput")(f
392392
// compatibility with existing cassettes and provider expectations.
393393
if (part.result.type !== "content") return ProviderShared.toolResultText(part)
394394
// Preserve the narrowed array element type when compiled through a consumer package.
395-
const content: ReadonlyArray<ToolContent> = part.result.value
395+
const content: ReadonlyArray<Content> = part.result.value
396396
return yield* Effect.forEach(content, (item) => lowerToolResultContentItem(item, request, extension))
397397
})
398398

@@ -496,7 +496,7 @@ const lowerMessages = Effect.fn("OpenResponses.lowerMessages")(function* (reques
496496
if (store !== false && itemID && !hostedToolReferences.has(itemID))
497497
input.push({ type: "item_reference", id: itemID })
498498
if (store === false && part.result.type === "content") {
499-
const content: ReadonlyArray<ToolContent> = part.result.value
499+
const content: ReadonlyArray<Content> = part.result.value
500500
input.push({
501501
role: "user",
502502
content: yield* Effect.forEach(content, (item) => lowerToolResultContentItem(item, request, extension)),

‎packages/ai/src/protocols/openai-chat.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Effect, Schema } from "effect"
2+
import { Tool } from "@opencode-ai/schema/tool"
23
import { Route } from "../route/client"
34
import { Auth } from "../route/auth"
45
import { Endpoint } from "../route/endpoint"
@@ -17,7 +18,6 @@ import {
1718
type TextPart,
1819
type ToolCallPart,
1920
type ToolDefinition,
20-
type ToolContent,
2121
} from "../schema"
2222
import { classifyProviderFailure } from "../provider-error"
2323
import { isRecord, JsonObject, optionalArray, optionalNull, ProviderShared } from "./shared"
@@ -335,7 +335,7 @@ const lowerToolMessages = Effect.fn("OpenAIChat.lowerToolMessages")(function* (m
335335
messages.push({ role: "tool", tool_call_id: part.id, content: ProviderShared.toolResultText(part) })
336336
continue
337337
}
338-
const content: ReadonlyArray<ToolContent> = part.result.value
338+
const content: ReadonlyArray<Tool.Content> = part.result.value
339339
const text = content.filter((item) => item.type === "text").map((item) => item.text)
340340
messages.push({ role: "tool", tool_call_id: part.id, content: text.join("\n") })
341341
const files = content.filter((item) => item.type === "file")

‎packages/ai/src/protocols/shared.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Buffer } from "node:buffer"
2+
import { Tool } from "@opencode-ai/schema/tool"
23
import { Effect, Schema, Stream } from "effect"
34
import * as Sse from "effect/unstable/encoding/Sse"
45
import { Headers, HttpClientRequest } from "effect/unstable/http"
@@ -9,7 +10,6 @@ import {
910
type ContentPart,
1011
type LLMRequest,
1112
type MediaPart,
12-
type ToolFileContent,
1313
type TextPart,
1414
type ToolResultPart,
1515
} from "../schema"
@@ -206,7 +206,7 @@ export const validateMedia = Effect.fn("ProviderShared.validateMedia")(function*
206206
return { mime, base64, dataUrl: `data:${mime};base64,${base64}`, bytes } satisfies ValidatedMedia
207207
})
208208

209-
export const validateToolFile = (route: string, part: ToolFileContent, supportedMimes: ReadonlySet<string>) =>
209+
export const validateToolFile = (route: string, part: Tool.FileContent, supportedMimes: ReadonlySet<string>) =>
210210
validateMedia(route, { type: "media", mediaType: part.mime, data: part.uri, filename: part.name }, supportedMimes)
211211

212212
export const trimBaseUrl = (value: string) => value.replace(/\/+$/, "")

‎packages/ai/src/schema/errors.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Schema } from "effect"
2+
import { Tool } from "@opencode-ai/schema/tool"
23
import { ModelID, ProviderID, ProviderMetadata, RouteID } from "./ids"
34

45
export const ProviderFailureClassification = Schema.Literal("context-overflow")
@@ -152,8 +153,4 @@ export class LLMError extends Schema.TaggedErrorClass<LLMError>()("LLM.Error", {
152153
* Anything thrown or yielded by a handler that is not a `ToolFailure` is
153154
* treated as a defect and fails the stream.
154155
*/
155-
export class ToolFailure extends Schema.TaggedErrorClass<ToolFailure>()("LLM.ToolFailure", {
156-
message: Schema.String,
157-
error: Schema.optional(Schema.Defect()),
158-
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
159-
}) {}
156+
export class ToolFailure extends Tool.Error {}

0 commit comments

Comments
 (0)