Commit Graph

47 Commits

Author SHA1 Message Date
93ef2611c0 Merge pull request 'feat: add ClaudeCodeProvider for subscription users' (#10) from feat/claude-code-provider into main
Reviewed-on: #10
2026-05-21 12:25:34 +00:00
c8c579da8b docs: rewrite README
Full rewrite focused on what consumers actually need: install, a
working snippet per provider, and the public API surface.

Changes vs the previous version:
- Document ClaudeCodeProvider, including the subscription-via-CLI
  auth path that the new provider enables.
- Remove the ProviderRegistry section (the class was removed in R1).
- Drop the stale Provider Comparison and Detailed Capabilities
  tables; vendor capabilities and model lists move too fast for a
  README to track.
- Remove the inaccurate Zero Dependencies and Comprehensive Testing
  claims (post-refactor 44/91 tests need updating).
- Refresh default models (Gemini 1.5 -> 2.5) and the package list to
  match the current build.
- Add a brief Architecture note covering the base hooks introduced
  in R2 and the OpenWebUI strategy split from R3.

README is 315 lines (was 701).
2026-05-21 14:25:01 +02:00
e10ce7f53a feat: add ClaudeCodeProvider for subscription users
Wraps @anthropic-ai/claude-agent-sdk so Claude Pro/Max subscribers (who
do not have a console API key) can use this library by authenticating
through the local `claude` CLI. Subscribers run `claude login` once and
the provider picks up the credentials automatically.

Provider behavior:
- query() is invoked in single-turn mode (maxTurns: 1, allowedTools: [])
  to behave as plain text completion by default. Both knobs are
  configurable for agentic use cases.
- Conversation history is flattened to a single prompt with role labels.
- doStream() emits text deltas as the SDK yields successive assistant
  messages. doComplete() accumulates and returns the final result.
- SDKAssistantMessageError codes (authentication_failed, billing_error,
  rate_limit, model_not_found, ...) map to AIErrorType variants.
- ClaudeCodeConfig.apiKey is optional — when omitted the SDK falls back
  to ANTHROPIC_API_KEY or local subscription credentials. The base
  validator is overridden to allow this.

Tradeoffs:
- Requires the `claude` CLI installed and logged in on the host. This
  is not suitable for typical server-side production deployments; it is
  the official path for subscription accounts.
- Higher latency (CLI process spawn) than the direct Anthropic API.
- The agent SDK is heavy. Bundle grows ~750KB; bun build now uses
  --target node so the SDK's Node built-in imports resolve correctly.

Wired into PROVIDER_REGISTRY ('claude-code'), createClaudeCodeProvider,
SUPPORTED_PROVIDERS, and re-exported from the package entry.
2026-05-21 14:16:11 +02:00
6298a0027d chore(release): 2.0.1
Patch release covering three internal refactors (see PRs #7, #8, #9):

- Extract shared constants, parameterize validators, simplify factory
- Pull validateConnection / validateModelName / error mapping into base
- Split OpenWebUI into strategy classes by backend

Public API surface and method signatures are unchanged. A handful of
error message strings were reworded (error type and status code remain
identical), and BaseAIProvider gained new protected hooks with no-op
defaults.
v2.0.1
2026-05-21 13:54:31 +02:00
8e430b2659 Merge pull request 'refactor: split OpenWebUI into strategy classes by backend' (#9) from refactor/openwebui-strategy-split into main
Reviewed-on: #9
2026-05-21 11:51:34 +00:00
3d985a95a8 refactor: split OpenWebUI into strategy classes by backend
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.
2026-05-21 13:51:08 +02:00
eacd76d259 Merge pull request 'refactor: pull validateConnection / validateModelName / error mapping into base' (#8) from refactor/template-method-pullup into main
Reviewed-on: #8
2026-05-21 11:46:55 +00:00
b36d57711b refactor: pull validateConnection / validateModelName / error mapping into base
Form Template Method / Pull Up Method from the Refactoring Guru catalog.

The three SDK-based providers (Claude, OpenAI, Gemini) each had their own
near-identical implementations of:

  - validateConnection: try a tiny request, catch errors, map a handful
    of patterns, warn on the rest
  - validateModelName: iterate regex patterns, warn on no match
  - handle{X}Error: switch on HTTP status, map to AIProviderError with
    brand-flavored messages

These collapse into three protected hooks on BaseAIProvider:

  - getModelNamePatterns(): RegExp[]
  - sendValidationProbe(): Promise<void>
  - mapProviderError(error): AIProviderError | null
  - providerErrorMessages(): Partial<Record<number, string>>

The base owns the wrapping logic (warning, status -> error-type map,
common message patterns). Providers only contribute their unique parts.

Side effects:

  - normalizeError now consults mapProviderError before generic mapping,
    so provider-specific patterns work via the existing try/catch in
    BaseAIProvider.complete/stream. The per-provider try/catch wrappers
    around doComplete/doStream are removed.
  - The unknown-error message becomes `${providerName} error: ${msg}`
    instead of the hardcoded `Provider error:` / `Claude API error:` etc.
  - OpenWebUI's HTTP-based validateConnection is preserved (override),
    since its non-SDK shape doesn't fit the SDK probe pattern.
2026-05-21 13:43:07 +02:00
8e73296ac2 Merge pull request 'refactor: extract constants, parameterize validators, simplify factory' (#7) from refactor/quick-wins-factory-validators-constants into main
Reviewed-on: #7
2026-05-21 11:36:34 +00:00
bb37e61eaf refactor: extract constants, parameterize validators, simplify factory
Quick-win refactors from the Refactoring Guru catalog:

- Replace Magic Number with Symbolic Constant: extract DEFAULT_TIMEOUT_MS,
  DEFAULT_MAX_RETRIES, DEFAULT_MAX_TOKENS, DEFAULT_TEMPERATURE, default
  models per provider, and validation prompt into src/constants.ts.
- Parameterize Method: collapse validateTemperature / validateTopP /
  validateMaxTokens (and the inline timeout/maxRetries checks) into a
  single validateNumberInRange helper with bounds metadata.
- Inline Class / Remove Middle Man: drop the unused ProviderRegistry
  class from utils/factory.ts. createProvider now dispatches through
  the PROVIDER_REGISTRY const directly instead of a parallel switch.

Also fixes stale VERSION constant in src/index.ts (was 1.3.1).
2026-05-21 13:35:12 +02:00
797fad1b00 chore(release): 2.0.0
Major release: @google/generative-ai → @google/genai migration changes
the type signature of GeminiConfig.safetySettings, which is a breaking
change for consumers using that option.

Other changes accumulated since 1.3.3:
- @anthropic-ai/sdk 0.65 → 0.97
- openai 4 → 6
- @types/node 24 → 25
- TypeScript 6 support (peer widened to ^5 || ^6)
- Default Gemini model: gemini-1.5-flash → gemini-2.5-flash
v2.0.0
2026-05-21 12:56:46 +02:00
fbe66623a1 Merge pull request 'chore(deps)!: migrate from @google/generative-ai to @google/genai' (#6) from chore/deps-google-genai-migration into main
Reviewed-on: #6
2026-05-21 10:56:04 +00:00
c658c67a0c chore(deps)!: migrate from @google/generative-ai to @google/genai
The @google/generative-ai SDK has been deprecated by Google. This switches
to the successor @google/genai package and rewrites the Gemini provider
against the new stateless models/chats API.

BREAKING CHANGE: GeminiConfig.safetySettings now uses the SafetySetting
type from @google/genai. Consumers passing this field must update their
import from '@google/generative-ai' to '@google/genai'. The shape of the
type is similar but not identical.

Notable simplifications enabled by the new SDK:
- No per-model client caching: generateContent specifies model per-call
- Single code path for both single- and multi-turn (full contents array
  is passed to generateContent directly; no more startChat branching)
- Stream chunks expose .text as a property (was .text() method)
- Stream iteration is direct on the response (no .stream sub-property)

Default model bumped from gemini-1.5-flash to gemini-2.5-flash.
2026-05-21 12:54:48 +02:00
442e535d17 Merge pull request 'chore(deps): support TypeScript 6 (widen peer to ^5 || ^6)' (#5) from chore/deps-typescript-6 into main
Reviewed-on: #5
2026-05-21 10:49:23 +00:00
bcdf04a77f chore(deps): support TypeScript 6 (widen peer to ^5 || ^6)
- Add typescript ^6.0.0 as devDependency for verified builds
- Widen peerDependency to ^5 || ^6 to keep TS 5 consumers supported
- tsconfig.build.json: set explicit rootDir (required by TS 6 when outDir is set)
- tsconfig.build.json: replace deprecated moduleResolution "node" with "bundler"
2026-05-21 12:49:05 +02:00
10dcb9da85 Merge pull request 'chore(deps): update openai to ^6.0.0' (#4) from chore/deps-openai-v6 into main
Reviewed-on: #4
2026-05-21 10:46:42 +00:00
a596d0adc3 chore(deps): update openai to ^6.0.0 2026-05-21 12:46:30 +02:00
7b3a8297b8 Merge pull request 'chore(deps): update @anthropic-ai/sdk to ^0.97.0' (#3) from chore/deps-anthropic-sdk-0.97 into main
Reviewed-on: #3
2026-05-21 10:45:53 +00:00
b58e1d833f chore(deps): update @anthropic-ai/sdk to ^0.97.0 2026-05-21 12:42:26 +02:00
5c95c972ce Merge pull request 'chore(deps): update @types/node to v25' (#2) from chore/deps-types-node-25 into main
Reviewed-on: #2
2026-05-21 10:41:46 +00:00
a476ec7b25 chore(deps): update @types/node to v25 2026-05-21 12:41:25 +02:00
d5b0938369 Merge pull request 'chore(deps): bump openai to ^4.104.0 and @types/bun to ^1.3.14' (#1) from chore/deps-bump-safe into main
Reviewed-on: #1
2026-05-21 10:28:59 +00:00
fc87aac15a chore(release): 1.3.3
Patch release covering the dependency refresh from the previous commit.
Local version was at 1.3.1 while npm registry already had 1.3.2 published,
so this bumps to 1.3.3.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 12:28:02 +02:00
473e5551d0 chore(deps): bump openai to ^4.104.0 and @types/bun to ^1.3.14
Also refreshes bun.lock to pick up @anthropic-ai/sdk 0.65.0 and
@types/node 24.12.4 within existing version ranges. All bumps stay
within the same major to avoid breaking changes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 12:25:03 +02:00
0b1a7d90da docs: update README with new features and architecture details 2025-10-01 14:32:50 +02:00
989261916c Merge pull request 'chore(deps): update dependency @types/node to v24' (#5) from renovate/node-24.x into main
Reviewed-on: #5
2025-10-01 11:59:39 +00:00
9da39d3241 Merge pull request 'fix(deps): update dependency @anthropic-ai/sdk to ^0.65.0' (#4) from renovate/anthropic-ai-sdk-0.x into main
Reviewed-on: #4
2025-10-01 11:59:34 +00:00
4f7bd24b5f chore(deps): update dependency @types/node to v24 2025-10-01 11:44:55 +00:00
781cf466fa fix(deps): update dependency @anthropic-ai/sdk to ^0.65.0 2025-10-01 11:44:50 +00:00
ccbe3772ab Merge pull request 'chore: Configure Renovate' (#3) from renovate/configure into main
Reviewed-on: #3
2025-10-01 11:42:04 +00:00
ddcb327888 Add renovate.json 2025-10-01 11:37:20 +00:00
010f52c9ee build: update version to 1.3.1 in package.json 2025-09-04 15:51:56 +02:00
7acb0cc5f9 Merge pull request 'chore: Remove json markdown stuff' (#2) from jank/simple-ai-provider:main into main
Reviewed-on: #2
2025-09-04 13:51:22 +00:00
901666b513 chore: Remove json markdown stuff 2025-09-04 15:50:34 +02:00
fa73a7a5fd Merge pull request 'feat: Add typed stuff' (#1) from jank/simple-ai-provider:main into main
Reviewed-on: #1
Reviewed-by: Jan-Marlon Leibl <jleibl@proton.me>
2025-09-04 13:35:24 +00:00
027a2ba2ed chore: Update version 2025-09-04 15:34:53 +02:00
09a0862896 chore: fix some stuff idk 2025-09-04 15:28:44 +02:00
c801abc2e8 chore: Update readme 2025-09-04 15:18:38 +02:00
900ed70162 feat: Add typed stuff 2025-09-04 15:13:09 +02:00
18769c134d feat(docs): add structured output example and details 2025-09-04 14:49:01 +02:00
5da20536af refactor: update provider documentation and improve comments 2025-05-28 13:00:25 +02:00
9bf8030ad5 feat: add LICENSE file and update README and version 2025-05-28 12:33:37 +02:00
8015f8fc10 chore: update version to 1.1.0 in package.json 2025-05-28 12:31:34 +02:00
664a775724 feat(docs): update README with OpenWebUI support details 2025-05-28 12:31:11 +02:00
5da37f388f feat: add Google Gemini provider integration and docs 2025-05-28 12:13:29 +02:00
aa2fd98cc1 feat: add OpenAI provider integration and examples 2025-05-28 12:04:10 +02:00
42902445fb feat: add initial implementation of Simple AI Provider package 2025-05-28 11:54:24 +02:00