Skip to content

refactor: deduplicate shared utilities across commands and SDK#125

Merged
RyanLee-Dev merged 1 commit intomainfrom
refactor/deduplicate-shared-utilities
May 11, 2026
Merged

refactor: deduplicate shared utilities across commands and SDK#125
RyanLee-Dev merged 1 commit intomainfrom
refactor/deduplicate-shared-utilities

Conversation

@RyanLee-Dev
Copy link
Copy Markdown
Collaborator

Summary

  • Extract IMAGE_MIME_TYPESlocalFileToDataUriresolveImageInputtoDataUri to src/utils/image.ts, eliminating 3x MIME_TYPES duplication and 5x image encoding duplication
  • Add streamSSE<T> to SDK Client base class, eliminating identical 12-line SSE consumption loops in text/speech SDK
  • Add promptOrFail to src/utils/prompt.ts, eliminating identical 10-line interactive input blocks in image/video commands
  • Add dryRun to src/output/formatter.ts, unifying dry-run output across 5 commands
  • Fix SDK→Command architectural inversion (sdk/vision no longer imports from commands/vision)
  • Fix SSE stream bug: empty data events now skip (continue) instead of terminating the stream (break)
  • Standardize toMerged import to es-toolkit/object in music SDK

Net: 15 files, -48 lines, zero new abstractions layers, every extracted function called by 2+ sites.

Test plan

  • bun run typecheck — zero errors
  • bun test — 143 pass, 0 fail
  • New test: streaming skips empty SSE data events covers the SSE behavior fix

…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.
@RyanLee-Dev RyanLee-Dev merged commit 10507df into main May 11, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant