apache / apache/maka

refactor(runtime): decompose ai-sdk-backend.ts (4874 lines, 6 concerns)

Open
#3,909 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
5.4k
Forks
502
Avg merge
1d 2h
Merged PRs (30d)
716

Description

## Summary

`packages/runtime/src/ai-sdk-backend.ts` is 4,874 lines mixing provider adapter, tool schema building, prompt assembly, tool call settlement, streaming projection, and image overflow recovery in a single file.

## Evidence

- `packages/runtime/src/ai-sdk-backend.ts:21-39` — docstring describes 6 concerns
- File spans tool schema binding, provider request projection, background task management, and tool result settlement
- The `BackendFactory` interface is the natural seam — the adapter orchestrates the stream pipeline but currently owns every supporting function

## Proposed Decomposition

1. **`ai-sdk-backend.ts`** — stream pipeline orchestration only
2. **`tool-schema-builder.ts`** — tool schema binding and provider-specific adaptations
3. **`provider-request-capture.ts`** — provider request projection and background task management
4. **`image-overflow-handler.ts`** — image overflow recovery for vision-capable providers

## Acceptance Criteria

- [ ] `ai-sdk-backend.ts` is under 2,000 lines
- [ ] Tool schema building is independently testable
- [ ] Provider request capture is independently testable
- [ ] All existing tests pass
- [ ] No new cross-module cycles

## Labels

refactor, help wanted

Contributor guide

Open the contributing guide

Research direction

Start with packages/runtime/src/ai-sdk-backend.ts:21-39 and trace the BackendFactory seam through the stream pipeline. Compare the supporting concerns with the proposed tool-schema-builder.ts, provider-request-capture.ts, and image-overflow-handler.ts modules. Done means the backend file is under 2,000 lines, the extracted areas are independently testable, existing tests pass, and no cross-module cycles are introduced.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
ai, backend
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.