Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(provider): load Claude SDK only when needed #8104

Closedonmax(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/8104/headopened View on GitHub

Showing 4 changed files with 115 additions and 27 deletions (loading 1).

x
0 of 4 viewed, 4 left
13 additions and 0 deletionsapps/server/src/provider/Layers/ClaudeAdapter.lazy.test.tsAdded
View file
@@ -0,0 +1,13 @@
+import { describe, expect, it, vi } from "vite-plus/test";
+​
+vi.mock("@anthropic-ai/claude-agent-sdk", () => {
+ throw new Error("Claude SDK loaded eagerly.");
+});
+​
+describe("ClaudeAdapter module loading", () => {
+ it("does not load the Claude SDK while importing the adapter", async () => {
+ await expect(import("./ClaudeAdapter.ts")).resolves.toMatchObject({
+ makeClaudeAdapter: expect.any(Function),
+ });
+ });
+});
64 additions and 0 deletionsapps/server/src/provider/Layers/ClaudeAdapter.test.tsModified
View file
@@ -23,6 +23,7 @@
} from "@t3tools/contracts";
import { createModelSelection } from "@t3tools/shared/model";
import { assert, describe, it } from "@effect/vitest";
+import { vi } from "vite-plus/test";
import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
import * as Fiber from "effect/Fiber";
@@ -40,6 +41,34 @@
import { makeClaudeAdapter, type ClaudeAdapterLiveOptions } from "./ClaudeAdapter.ts";
const decodeClaudeSettings = Schema.decodeSync(ClaudeSettings);
​
+const lazyClaudeSdk = vi.hoisted(() => {