Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion common/src/testing/mocks/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export interface DbSpies {
*
* @example
* ```typescript
* import db from '@codebuff/internal/db'
* const db = createMockDbOperations()
*
* describe('my test', () => {
* let dbSpies: DbSpies
Expand Down
2 changes: 1 addition & 1 deletion common/src/testing/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export interface TestSetupResult {
* @example
* ```typescript
* import * as analytics from '@codebuff/common/analytics'
* import db from '@codebuff/internal/db'
* const db = createMockDbOperations()
*
* describe('my test', () => {
* const setup = createTestSetup({
Expand Down
14 changes: 10 additions & 4 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The public SDK used by the CLI and available to external users via `@codebuff/sd
- **Executes tool calls locally** on the user's machine (file edits, terminal commands, code search)
- Manages model provider selection: Claude OAuth, ChatGPT OAuth, or Codebuff backend
- Handles credentials, retry logic, and error transformation
- **Depends on:** `agent-runtime`, `common`, `internal` (for OpenAI-compatible provider)
- **Depends on:** `agent-runtime`, `common`, `llm-providers`

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

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

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

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

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

### `packages/llm-providers/` — Public LLM Provider Shims

Provider adapters that are safe for public packages to depend on.

- **Key areas:**
- `src/openai-compatible/` — Forked OpenAI-compatible AI SDK provider used by the SDK for the Codebuff backend and ChatGPT OAuth flows
- **Depends on:** AI SDK provider packages

### `packages/billing/` — Billing & Credits

Credit management, subscription handling, and usage tracking.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"release:freebuff": "bun run --cwd=freebuff release",
"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",
"typecheck": "bun scripts/check-env-architecture.ts && bun --filter='*' run typecheck && echo '✅ All type checks passed!'",
"test": "bun --filter='{@codebuff/common,@codebuff/agents,@codebuff/agent-runtime,@codebuff/sdk,@codebuff/web,@codebuff/cli,@codebuff/evals,@codebuff/scripts}' run test",
"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",
"init-worktree": "bun scripts/init-worktree.ts",
"cleanup-worktree": "bun scripts/cleanup-worktree.ts",
"generate-tool-definitions": "bun scripts/generate-tool-definitions.ts"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import * as analytics from '@codebuff/common/analytics'
import { TEST_USER_ID } from '@codebuff/common/old-constants'
import { createTestAgentRuntimeParams } from '@codebuff/common/testing/fixtures/agent-runtime'
import { clearMockedModules } from '@codebuff/common/testing/mock-modules'
import { setupDbSpies } from '@codebuff/common/testing/mocks/database'
import {
createMockDbOperations,
setupDbSpies,
} from '@codebuff/common/testing/mocks/database'
import { getInitialSessionState } from '@codebuff/common/types/session-state'
import { AbortError, promptSuccess } from '@codebuff/common/util/error'
import { assistantMessage, userMessage } from '@codebuff/common/util/messages'
import db from '@codebuff/internal/db'
import {
afterAll,
afterEach,
Expand Down Expand Up @@ -61,7 +63,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
llmCallCount = 0

// Setup spies for database operations using typed helper
dbSpies = setupDbSpies(db)
dbSpies = setupDbSpies(createMockDbOperations())

agentRuntimeImpl.promptAiSdkStream = mock(async function* ({}) {
llmCallCount++
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import * as analytics from '@codebuff/common/analytics'
import { TEST_USER_ID } from '@codebuff/common/old-constants'
import { TEST_AGENT_RUNTIME_IMPL } from '@codebuff/common/testing/impl/agent-runtime'
import { setupDbSpies } from '@codebuff/common/testing/mocks/database'
import {
createMockDbOperations,
setupDbSpies,
} from '@codebuff/common/testing/mocks/database'
import { getInitialSessionState } from '@codebuff/common/types/session-state'
import { promptSuccess } from '@codebuff/common/util/error'
import { assistantMessage, userMessage } from '@codebuff/common/util/messages'
import db from '@codebuff/internal/db'
import {
afterAll,
afterEach,
Expand Down Expand Up @@ -66,7 +68,7 @@ describe('runAgentStep - set_output tool', () => {
}

// Setup spies for database operations using typed helper
dbSpies = setupDbSpies(db)
dbSpies = setupDbSpies(createMockDbOperations())

// Mock analytics
spyOn(analytics, 'trackEvent').mockImplementation(() => {})
Expand Down
7 changes: 5 additions & 2 deletions packages/agent-runtime/src/prompt-agent-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import { globalStopSequence } from './constants'
import type { AgentTemplate } from './templates/types'
import type { TrackEventFn } from '@codebuff/common/types/contracts/analytics'
import type { SendActionFn } from '@codebuff/common/types/contracts/client'
import type { CacheDebugUsageData, PromptAiSdkStreamFn } from '@codebuff/common/types/contracts/llm'
import type {
CacheDebugUsageData,
PromptAiSdkStreamFn,
} from '@codebuff/common/types/contracts/llm'
import type { Logger } from '@codebuff/common/types/contracts/logger'
import type { ParamsOf } from '@codebuff/common/types/function-params'
import type { Message } from '@codebuff/common/types/messages/codebuff-message'
import type { OpenRouterProviderOptions } from '@codebuff/internal/openrouter-ai-sdk'
import type { OpenRouterProviderOptions } from '@codebuff/common/types/agent-template'
import type { ToolSet } from 'ai'

export const getAgentStreamFromTemplate = (params: {
Expand Down
7 changes: 0 additions & 7 deletions packages/internal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@
"types": "./src/loops/index.ts",
"default": "./src/loops/index.ts"
},
"./openrouter-ai-sdk": {
"bun": "./src/openrouter-ai-sdk/index.ts",
"import": "./src/openrouter-ai-sdk/index.ts",
"types": "./src/openrouter-ai-sdk/index.ts",
"default": "./src/openrouter-ai-sdk/index.ts"
},
"./env": {
"react-server": "./src/env.react-server.ts",
"browser": "./src/env.browser.ts",
Expand Down Expand Up @@ -58,7 +52,6 @@
"bun": "1.3.11"
},
"dependencies": {
"@ai-sdk/provider-utils": "^3.0.17",
"@codebuff/common": "workspace:*",
"drizzle-kit": "0.31.8",
"drizzle-orm": "0.45.1",
Expand Down

This file was deleted.

This file was deleted.

Loading
Loading