refactor: split OpenWebUI into strategy classes by backend #9

Merged
jleibl merged 1 commits from refactor/openwebui-strategy-split into main 2026-05-21 11:51:35 +00:00
Owner

Replace Conditional with Polymorphism from the Refactoring Guru catalog.

The OpenWebUIProvider previously contained two parallel implementations
(completeWithChat / completeWithOllama, streamWithChat / streamWithOllama,
plus branching in validateConnection) selected by a useOllamaProxy
boolean. The 987-line file is split into:

  • openwebui-types.ts wire-format response types
  • openwebui-http.ts shared HTTP client (auth, timeout)
  • openwebui-strategies.ts OpenWebUIStrategy interface plus
    OpenWebUIChatStrategy and
    OpenWebUIOllamaStrategy implementations
  • openwebui.ts thin provider that picks one strategy at
    construction and delegates

OpenWebUIProvider and OpenWebUIConfig (including useOllamaProxy) stay
in their original locations, so consumer imports are unchanged.

Side effects:

  • Error mapping now goes through the base mapProviderError / providerErrorMessages
    hooks added in R2, removing handleOpenWebUIError and its duplicated status switch.
  • providerInfo.version bumped to 2.0.0 to reflect the rewrite.
Replace Conditional with Polymorphism from the Refactoring Guru catalog. The OpenWebUIProvider previously contained two parallel implementations (completeWithChat / completeWithOllama, streamWithChat / streamWithOllama, plus branching in validateConnection) selected by a `useOllamaProxy` boolean. The 987-line file is split into: - openwebui-types.ts wire-format response types - openwebui-http.ts shared HTTP client (auth, timeout) - openwebui-strategies.ts OpenWebUIStrategy interface plus OpenWebUIChatStrategy and OpenWebUIOllamaStrategy implementations - openwebui.ts thin provider that picks one strategy at construction and delegates OpenWebUIProvider and OpenWebUIConfig (including useOllamaProxy) stay in their original locations, so consumer imports are unchanged. Side effects: - Error mapping now goes through the base mapProviderError / providerErrorMessages hooks added in R2, removing handleOpenWebUIError and its duplicated status switch. - providerInfo.version bumped to 2.0.0 to reflect the rewrite.
jleibl added 1 commit 2026-05-21 11:51:30 +00:00
Replace Conditional with Polymorphism from the Refactoring Guru catalog.

The OpenWebUIProvider previously contained two parallel implementations
(completeWithChat / completeWithOllama, streamWithChat / streamWithOllama,
plus branching in validateConnection) selected by a `useOllamaProxy`
boolean. The 987-line file is split into:

  - openwebui-types.ts       wire-format response types
  - openwebui-http.ts        shared HTTP client (auth, timeout)
  - openwebui-strategies.ts  OpenWebUIStrategy interface plus
                             OpenWebUIChatStrategy and
                             OpenWebUIOllamaStrategy implementations
  - openwebui.ts             thin provider that picks one strategy at
                             construction and delegates

OpenWebUIProvider and OpenWebUIConfig (including useOllamaProxy) stay
in their original locations, so consumer imports are unchanged.

Side effects:
- Error mapping now goes through the base mapProviderError / providerErrorMessages
  hooks added in R2, removing handleOpenWebUIError and its duplicated status switch.
- providerInfo.version bumped to 2.0.0 to reflect the rewrite.
jleibl merged commit 8e430b2659 into main 2026-05-21 11:51:35 +00:00
jleibl referenced this issue from a commit 2026-05-21 11:54:34 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: jleibl/simple-ai-provider#9