refactor: deduplicate shared utilities across commands and SDK#125
Merged
RyanLee-Dev merged 1 commit intomainfrom May 11, 2026
Merged
refactor: deduplicate shared utilities across commands and SDK#125RyanLee-Dev merged 1 commit intomainfrom
RyanLee-Dev merged 1 commit intomainfrom
Conversation
…y-run boilerplate Extract shared utilities to eliminate code duplication across commands and SDK: - src/utils/image.ts: IMAGE_MIME_TYPES, localFileToDataUri, resolveImageInput, toDataUri - src/utils/prompt.ts: promptOrFail for interactive input with non-interactive fallback - src/sdk/client.ts: streamSSE<T> generic method for SSE stream consumption - src/output/formatter.ts: dryRun helper for consistent dry-run output Fix SDK→Command architectural inversion (sdk/vision imported from commands/vision). Fix SSE stream: empty data events now skip (continue) instead of terminating (break). Standardize toMerged import to es-toolkit/object across all SDK modules.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
IMAGE_MIME_TYPES、localFileToDataUri、resolveImageInput、toDataUritosrc/utils/image.ts, eliminating 3x MIME_TYPES duplication and 5x image encoding duplicationstreamSSE<T>to SDKClientbase class, eliminating identical 12-line SSE consumption loops in text/speech SDKpromptOrFailtosrc/utils/prompt.ts, eliminating identical 10-line interactive input blocks in image/video commandsdryRuntosrc/output/formatter.ts, unifying dry-run output across 5 commandssdk/visionno longer imports fromcommands/vision)continue) instead of terminating the stream (break)toMergedimport toes-toolkit/objectin music SDKNet: 15 files, -48 lines, zero new abstractions layers, every extracted function called by 2+ sites.
Test plan
bun run typecheck— zero errorsbun test— 143 pass, 0 failstreaming skips empty SSE data eventscovers the SSE behavior fix