Skip to content

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

Description

@0xMudit

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

Activity

  1. added theissue type on Aug 29, 2026
  2. jackeyfaker77 commented on Sep 4, 2026

    @jackeyfaker77
    Contributor

    I’d like to take the remaining tool-schema-builder slice of #3909, against current main after #4779.

    Plan:

    • extract tool-mode validation, availability projection, AI SDK provider/function schema binding, and Code Mode nested-schema validation from ai-sdk-turn.ts into tool-schema-builder.ts;
    • keep tool execution and settlement in AiSdkTurn and ToolRuntime;
    • add focused direct tests for direct/Code Mode surfaces, provider-native versus function bindings, nesting eligibility, diagnostics, and input validation;
    • preserve existing behavior and introduce no new dependency cycles.

    #4779 has already reduced ai-sdk-backend.ts below 2,000 lines and extracted several major responsibilities, so this PR will use Refs #3909 and will not claim to close the entire tracking issue.

    中文对照:

    我想认领 #3909 中尚未完成的 tool-schema-builder 小切片,基于 #4779 合并后的最新 main。

    计划:

    • 从 ai-sdk-turn.ts 中抽出工具模式校验、可用工具投影、AI SDK provider/function schema 绑定,以及 Code Mode 嵌套工具参数校验;
    • 工具执行与结果结算仍由 AiSdkTurn 和 ToolRuntime 负责;
    • 为 direct/Code Mode 工具面、原生 provider 工具与 function 工具绑定、嵌套资格、诊断数据和参数校验增加独立测试;
    • 保持现有行为,不引入新的依赖循环。
  3. Astro-Han commented on Sep 17, 2026

    @Astro-Han
    Contributor

    Closing this as an issue for now: the direction has not been confirmed by a maintainer, and the tracker only keeps proposals that already have an agreed scope. Please continue it in GitHub Discussions (https://github.com/apache/maka/discussions); once the shape and acceptance criteria are settled there, open an issue with that scope and it will be picked up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions