|
|
@@ -9,13 +9,10 @@ import { InstanceRef } from "../../src/effect/instance-ref"
|
|
|
import { HttpClientRequest, HttpClientResponse } from "effect/unstable/http"
|
|
|
import z from "zod"
|
|
|
import { LLM } from "../../src/session/llm"
|
|
|
-import { LLMClient, RequestExecutor, WebSocketExecutor } from "@opencode-ai/llm/route"
|
|
|
-import { Auth } from "@/auth"
|
|
|
-import { Config } from "@/config/config"
|
|
|
+import { LLMClient, RequestExecutor } from "@opencode-ai/llm/route"
|
|
|
import { Provider } from "@/provider/provider"
|
|
|
import { ProviderTransform } from "@/provider/transform"
|
|
|
import { ModelsDev } from "@opencode-ai/core/models-dev"
|
|
|
-import { Plugin } from "@/plugin"
|
|
|
|
|
|
import { testEffect } from "../lib/effect"
|
|
|
import type { Agent } from "../../src/agent/agent"
|
|
|
@@ -27,6 +24,9 @@ import { LLMAISDK } from "@/session/llm/ai-sdk"
|
|
|
import { Session as SessionNs } from "@/session/session"
|
|
|
import { ProviderV2 } from "@opencode-ai/core/provider"
|
|
|
import { ModelV2 } from "@opencode-ai/core/model"
|
|
|
+import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
|
|
|
+import { LayerNode } from "@opencode-ai/core/effect/layer-node"
|
|
|
+import { LayerNodePlatform } from "@opencode-ai/core/effect/app-node-platform"
|
|
|
|
|
|
type ConfigModel = NonNullable<NonNullable<ConfigV1.Info["provider"]>[string]["models"]>[string]
|
|
|
|
|
|
@@ -52,15 +52,13 @@ const openAIConfig = (model: ModelsDev.Provider["models"][string], baseURL: stri
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-const it = testEffect(Layer.mergeAll(LLM.defaultLayer, Provider.defaultLayer))
|
|
|
+const it = testEffect(AppNodeBuilder.build(LayerNode.group([LLM.node, Provider.node])))
|
|
|
|
|
|
// LLM.stream returns a Stream, not an Effect, so we can't use the serviceUse proxy.
|
|
|
const drain = (input: LLM.StreamInput) => LLM.Service.use((svc) => svc.stream(input).pipe(Stream.runDrain))
|
|
|
|
|
|
-// drainWith builds an isolated runtime so the custom layer fully owns LLM and
|
|
|
-// its transitive deps — `Effect.provide(layer)` over an existing runtime layers
|
|
|
-// the new services on top, but transitive Service overrides (e.g. RequestExecutor)
|
|
|
-// resolved through the outer LLM.defaultLayer leak through.
|
|
|
+// drainWith builds an isolated runtime so custom replacements fully own LLM and
|
|
|
+// its transitive deps.
|
|
|
const drainWith = (layer: Layer.Layer<LLM.Service>, input: LLM.StreamInput) =>
|
|
|
Effect.gen(function* () {
|
|
|
const ctx = yield* InstanceRef
|
|
|
@@ -75,15 +73,14 @@ const drainWith = (layer: Layer.Layer<LLM.Service>, input: LLM.StreamInput) =>
|
|
|
)
|
|
|
})
|
|
|
|
|
|
-function llmLayerWithExecutor(executor: Layer.Layer<RequestExecutor.Service>, flags: Partial<RuntimeFlags.Info> = {}) {
|
|
|
- return LLM.layer.pipe(
|
|
|
- Layer.provide(Auth.defaultLayer),
|
|
|
- Layer.provide(Config.defaultLayer),
|
|
|
- Layer.provide(Provider.defaultLayer),
|
|
|
- Layer.provide(Plugin.defaultLayer),
|
|
|
- Layer.provide(LLMClient.layer.pipe(Layer.provide(Layer.mergeAll(executor, WebSocketExecutor.layer)))),
|
|
|
- Layer.provide(RuntimeFlags.layer(flags)),
|
|
|
- )
|
|
|
+function llmLayerWithExecutor(options: {
|
|
|
+ executor?: Layer.Layer<RequestExecutor.Service>
|
|
|
+ flags?: Partial<RuntimeFlags.Info>
|
|
|
+} = {}) {
|
|
|
+ return AppNodeBuilder.build(LLM.node, [
|
|
|
+ [RuntimeFlags.node, RuntimeFlags.layer(options.flags)],
|
|
|
+ ...(options.executor ? ([[LayerNodePlatform.requestExecutor, options.executor]] as const) : []),
|
|
|
+ ])
|
|
|
}
|
|
|
|
|
|
describe("session.llm.hasToolCalls", () => {
|
|
|
@@ -1129,14 +1126,10 @@ describe("session.llm.stream", () => {
|
|
|
} satisfies Agent.Info
|
|
|
|
|
|
yield* drainWith(
|
|
|
- LLM.layer.pipe(
|
|
|
- Layer.provide(Auth.defaultLayer),
|
|
|
- Layer.provide(Config.defaultLayer),
|
|
|
- Layer.provide(Provider.defaultLayer),
|
|
|
- Layer.provide(Plugin.defaultLayer),
|
|
|
- Layer.provide(failingNativeClient),
|
|
|
- Layer.provide(RuntimeFlags.layer({ experimentalNativeLlm: false })),
|
|
|
- ),
|
|
|
+ AppNodeBuilder.build(LLM.node, [
|
|
|
+ [LayerNodePlatform.llmClient, failingNativeClient],
|
|
|
+ [RuntimeFlags.node, RuntimeFlags.layer({ experimentalNativeLlm: false })],
|
|
|
+ ]),
|
|
|
{
|
|
|
user: {
|
|
|
id: MessageID.make("msg_user-native-flag-off"),
|
|
|
@@ -1199,7 +1192,7 @@ describe("session.llm.stream", () => {
|
|
|
temperature: 0.2,
|
|
|
} satisfies Agent.Info
|
|
|
|
|
|
- yield* drainWith(llmLayerWithExecutor(RequestExecutor.defaultLayer, { experimentalNativeLlm: true }), {
|
|
|
+ yield* drainWith(llmLayerWithExecutor({ flags: { experimentalNativeLlm: true } }), {
|
|
|
user: {
|
|
|
id: MessageID.make("msg_user-native"),
|
|
|
sessionID,
|
|
|
@@ -1282,7 +1275,7 @@ describe("session.llm.stream", () => {
|
|
|
permission: [{ permission: "*", pattern: "*", action: "allow" }],
|
|
|
} satisfies Agent.Info
|
|
|
|
|
|
- yield* drainWith(llmLayerWithExecutor(executor, { experimentalNativeLlm: true }), {
|
|
|
+ yield* drainWith(llmLayerWithExecutor({ executor, flags: { experimentalNativeLlm: true } }), {
|
|
|
user: {
|
|
|
id: MessageID.make("msg_user-native-injected-tool"),
|
|
|
sessionID,
|
|
|
@@ -1371,7 +1364,7 @@ describe("session.llm.stream", () => {
|
|
|
permission: [{ permission: "*", pattern: "*", action: "allow" }],
|
|
|
} satisfies Agent.Info
|
|
|
|
|
|
- yield* drainWith(llmLayerWithExecutor(RequestExecutor.defaultLayer, { experimentalNativeLlm: true }), {
|
|
|
+ yield* drainWith(llmLayerWithExecutor({ flags: { experimentalNativeLlm: true } }), {
|
|
|
user: {
|
|
|
id: MessageID.make("msg_user-native-tool"),
|
|
|
sessionID,
|