Skip to content

Commit a2884a2

Browse files
authored
Split public LLM provider code from internal (#734)
1 parent cbd3fde commit a2884a2

67 files changed

Lines changed: 633 additions & 6627 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: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/src/testing/mocks/database.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ export interface DbSpies {
241241
*
242242
* @example
243243
* ```typescript
244-
* import db from '@codebuff/internal/db'
244+
* const db = createMockDbOperations()
245245
*
246246
* describe('my test', () => {
247247
* let dbSpies: DbSpies

common/src/testing/setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export interface TestSetupResult {
114114
* @example
115115
* ```typescript
116116
* import * as analytics from '@codebuff/common/analytics'
117-
* import db from '@codebuff/internal/db'
117+
* const db = createMockDbOperations()
118118
*
119119
* describe('my test', () => {
120120
* const setup = createTestSetup({

docs/architecture.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ The public SDK used by the CLI and available to external users via `@codebuff/sd
5252
- **Executes tool calls locally** on the user's machine (file edits, terminal commands, code search)
5353
- Manages model provider selection: Claude OAuth, ChatGPT OAuth, or Codebuff backend
5454
- Handles credentials, retry logic, and error transformation
55-
- **Depends on:** `agent-runtime`, `common`, `internal` (for OpenAI-compatible provider)
55+
- **Depends on:** `agent-runtime`, `common`, `llm-providers`
5656

5757
### `packages/agent-runtime/` — Agent Execution Engine
5858

@@ -113,17 +113,23 @@ The Codebuff web server, marketing site, and API.
113113

114114
### `packages/internal/` — Internal Utilities
115115

116-
Server-side utilities, database schema, and vendor forks shared between `web` and `sdk`.
116+
Server-side utilities, database schema, and service integrations shared by private server packages.
117117

118118
- **Key areas:**
119119
- `src/db/` — Drizzle ORM schema (`schema.ts`), migrations, Docker Compose for local Postgres
120120
- `src/env.ts` — Server environment variable validation (@t3-oss/env-nextjs)
121121
- `src/loops/` — Loops email service integration (transactional emails)
122-
- `src/openai-compatible/` — Forked OpenAI-compatible AI SDK provider (used by the SDK to call the Codebuff backend)
123-
- `src/openrouter-ai-sdk/` — Forked OpenRouter AI SDK provider (used by the web server)
124122
- `src/templates/` — Agent template fetching and validation
125123
- **Depends on:** `common`
126124

125+
### `packages/llm-providers/` — Public LLM Provider Shims
126+
127+
Provider adapters that are safe for public packages to depend on.
128+
129+
- **Key areas:**
130+
- `src/openai-compatible/` — Forked OpenAI-compatible AI SDK provider used by the SDK for the Codebuff backend and ChatGPT OAuth flows
131+
- **Depends on:** AI SDK provider packages
132+
127133
### `packages/billing/` — Billing & Credits
128134

129135
Credit management, subscription handling, and usage tracking.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"release:freebuff": "bun run --cwd=freebuff release",
3434
"clean-ts": "find . -name '*.tsbuildinfo' -type f -delete && find . -name '.next' -type d -exec rm -rf {} + 2>/dev/null || true && find . -name 'node_modules' -type d -exec rm -rf {} + 2>/dev/null || true && bun install",
3535
"typecheck": "bun scripts/check-env-architecture.ts && bun --filter='*' run typecheck && echo '✅ All type checks passed!'",
36-
"test": "bun --filter='{@codebuff/common,@codebuff/agents,@codebuff/agent-runtime,@codebuff/sdk,@codebuff/web,@codebuff/cli,@codebuff/evals,@codebuff/scripts}' run test",
36+
"test": "bun --filter='{@codebuff/common,@codebuff/agents,@codebuff/agent-runtime,@codebuff/llm-providers,@codebuff/sdk,@codebuff/web,@codebuff/cli,@codebuff/evals,@codebuff/scripts}' run test",
3737
"init-worktree": "bun scripts/init-worktree.ts",
3838
"cleanup-worktree": "bun scripts/cleanup-worktree.ts",
3939
"generate-tool-definitions": "bun scripts/generate-tool-definitions.ts"

packages/agent-runtime/src/__tests__/loop-agent-steps.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import * as analytics from '@codebuff/common/analytics'
22
import { TEST_USER_ID } from '@codebuff/common/old-constants'
33
import { createTestAgentRuntimeParams } from '@codebuff/common/testing/fixtures/agent-runtime'
44
import { clearMockedModules } from '@codebuff/common/testing/mock-modules'
5-
import { setupDbSpies } from '@codebuff/common/testing/mocks/database'
5+
import {
6+
createMockDbOperations,
7+
setupDbSpies,
8+
} from '@codebuff/common/testing/mocks/database'
69
import { getInitialSessionState } from '@codebuff/common/types/session-state'
710
import { AbortError, promptSuccess } from '@codebuff/common/util/error'
811
import { assistantMessage, userMessage } from '@codebuff/common/util/messages'
9-
import db from '@codebuff/internal/db'
1012
import {
1113
afterAll,
1214
afterEach,
@@ -61,7 +63,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
6163
llmCallCount = 0
6264

6365
// Setup spies for database operations using typed helper
64-
dbSpies = setupDbSpies(db)
66+
dbSpies = setupDbSpies(createMockDbOperations())
6567

6668
agentRuntimeImpl.promptAiSdkStream = mock(async function* ({}) {
6769
llmCallCount++

packages/agent-runtime/src/__tests__/run-agent-step-tools.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import * as analytics from '@codebuff/common/analytics'
22
import { TEST_USER_ID } from '@codebuff/common/old-constants'
33
import { TEST_AGENT_RUNTIME_IMPL } from '@codebuff/common/testing/impl/agent-runtime'
4-
import { setupDbSpies } from '@codebuff/common/testing/mocks/database'
4+
import {
5+
createMockDbOperations,
6+
setupDbSpies,
7+
} from '@codebuff/common/testing/mocks/database'
58
import { getInitialSessionState } from '@codebuff/common/types/session-state'
69
import { promptSuccess } from '@codebuff/common/util/error'
710
import { assistantMessage, userMessage } from '@codebuff/common/util/messages'
8-
import db from '@codebuff/internal/db'
911
import {
1012
afterAll,
1113
afterEach,
@@ -66,7 +68,7 @@ describe('runAgentStep - set_output tool', () => {
6668
}
6769

6870
// Setup spies for database operations using typed helper
69-
dbSpies = setupDbSpies(db)
71+
dbSpies = setupDbSpies(createMockDbOperations())
7072

7173
// Mock analytics
7274
spyOn(analytics, 'trackEvent').mockImplementation(() => {})

packages/agent-runtime/src/prompt-agent-stream.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ import { globalStopSequence } from './constants'
33
import type { AgentTemplate } from './templates/types'
44
import type { TrackEventFn } from '@codebuff/common/types/contracts/analytics'
55
import type { SendActionFn } from '@codebuff/common/types/contracts/client'
6-
import type { CacheDebugUsageData, PromptAiSdkStreamFn } from '@codebuff/common/types/contracts/llm'
6+
import type {
7+
CacheDebugUsageData,
8+
PromptAiSdkStreamFn,
9+
} from '@codebuff/common/types/contracts/llm'
710
import type { Logger } from '@codebuff/common/types/contracts/logger'
811
import type { ParamsOf } from '@codebuff/common/types/function-params'
912
import type { Message } from '@codebuff/common/types/messages/codebuff-message'
10-
import type { OpenRouterProviderOptions } from '@codebuff/internal/openrouter-ai-sdk'
13+
import type { OpenRouterProviderOptions } from '@codebuff/common/types/agent-template'
1114
import type { ToolSet } from 'ai'
1215

1316
export const getAgentStreamFromTemplate = (params: {

packages/internal/package.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@
2222
"types": "./src/loops/index.ts",
2323
"default": "./src/loops/index.ts"
2424
},
25-
"./openrouter-ai-sdk": {
26-
"bun": "./src/openrouter-ai-sdk/index.ts",
27-
"import": "./src/openrouter-ai-sdk/index.ts",
28-
"types": "./src/openrouter-ai-sdk/index.ts",
29-
"default": "./src/openrouter-ai-sdk/index.ts"
30-
},
3125
"./env": {
3226
"react-server": "./src/env.react-server.ts",
3327
"browser": "./src/env.browser.ts",
@@ -58,7 +52,6 @@
5852
"bun": "1.3.11"
5953
},
6054
"dependencies": {
61-
"@ai-sdk/provider-utils": "^3.0.17",
6255
"@codebuff/common": "workspace:*",
6356
"drizzle-kit": "0.31.8",
6457
"drizzle-orm": "0.45.1",

packages/internal/src/openai-compatible/completion/map-openai-compatible-finish-reason.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)