refactor(providers,executor): deepen three shallow modules#5052
Conversation
Extract the ~20 scattered subflow node-ID parsing/building helpers and their regex patterns into a single SubflowNodeIdCodec. All patterns now live in one place; subflow-utils and execution state delegate to it. Pure refactor — byte-identical output, ordering, and error modes.
The near-identical streaming-response assembly (timing segments, cost, token counts, onComplete wiring, success/logs/metadata envelope) that was copy-pasted across ~16 providers now goes through createStreamingExecution. Each provider injects only its stream iterable and delta extractors. Gemini is intentionally left as-is (its assembly is structurally divergent). Pure refactor — identical StreamingExecution shape, cost, tokens, timing, and callback order per provider.
Replace the identical inline tool-schema literals repeated across ~16 providers with shared adaptOpenAIChatToolSchema / adaptAnthropicToolSchema helpers. Content building reverts to calling the attachments builders directly (the per-provider content seam was pure pass-through indirection). Pure refactor — byte-identical tool-schema and content output.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Executor: Introduces Providers: Adds Docs: The add-model skill now points contributors at these helpers when extending provider code. New unit tests cover the codec, streaming factory, and tool adapters. Reviewed by Cursor Bugbot for commit 7454b84. Configure here. |
Greptile SummaryThis PR deepens three shallow modules through pure refactoring: subflow node-ID parsing is consolidated behind a single
Confidence Score: 5/5Safe to merge — purely structural consolidation with no behavioural changes across the executor and 16 providers. Every regex, string template, and stream-assembly block is moved verbatim into the new shared modules. The finalizeTiming call pattern (called or omitted) is preserved per-provider to match each provider's original drain-callback behaviour. The full test suite (987 tests) passes, typecheck is clean, and three new dedicated unit-test files cover the codec, factory, and adapters. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant P as Provider (e.g. anthropic/core.ts)
participant F as createStreamingExecution()
participant O as NormalizedBlockOutput
participant S as ReadableStream (native)
P->>F: "createStreamingExecution({ model, timing, initialTokens, initialCost, createStream })"
F->>O: construct output object (placeholder timing)
F->>P: "invoke createStream({ output, finalizeTiming })"
P->>S: "wire native stream factory (createReadableStreamFrom*)"
S-->>F: ReadableStream returned
F-->>P: "return { stream, execution }"
note over S: stream drains asynchronously
S->>O: write content / tokens / cost
S->>F: call finalizeTiming()
F->>O: "overwrite providerTiming.endTime and duration (+ segment if kind='simple')"
Reviews (2): Last reviewed commit: "refactor(providers): drop placeholder st..." | Re-trigger Greptile |
…-schema helpers When editing provider code, reuse createStreamingExecution and the tool-schema-adapter helpers instead of hand-rolling.
… factory Build the output object before creating the stream so the factory returns a fully-typed StreamingExecution without 'undefined as unknown as ReadableStream'. Keeps the strict API-validation boundary ratchet green (double-cast count back to baseline). No behavior change: the same output reference is mutated on drain.
|
@greptile |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 7454b84. Configure here.
Summary
SubflowNodeIdCodec;subflow-utilsand execution state delegate to it.StreamingExecutionassembly (timing segments, cost, tokens,onCompletewiring, envelope) copy-pasted across ~16 providers into onecreateStreamingExecutionfactory; providers inject only their stream iterable + delta extractors. Gemini left as-is (structurally divergent).adaptOpenAIChatToolSchema/adaptAnthropicToolSchemahelpers; content building reverts to calling theattachmentsbuilders directly (the per-provider content seam was pure pass-through indirection).Type of Change
Testing
check:api-validationpasses.HEAD— byte-identical output, ordering, cost/token/timing, and error modes. Zero behavior change.Checklist