@wrongstack/providers 0.1.3 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,17 +1,21 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
1
+ MIT License
4
2
 
5
- Copyright 2026 ECOSTACK TECHNOLOGY OÜ
3
+ Copyright (c) 2026 ECOSTACK TECHNOLOGY OÜ
6
4
 
7
- Licensed under the Apache License, Version 2.0 (the "License");
8
- you may not use this file except in compliance with the License.
9
- You may obtain a copy of the License at
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
10
11
 
11
- http://www.apache.org/licenses/LICENSE-2.0
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
12
14
 
13
- Unless required by applicable law or agreed to in writing, software
14
- distributed under the License is distributed on an "AS IS" BASIS,
15
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- See the License for the specific language governing permissions and
17
- limitations under the License.
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # @wrongstack/providers
2
+
3
+ LLM provider adapters for WrongStack: Anthropic, OpenAI, Google, OpenAI-compatible (Mistral, Groq, DeepSeek, Together, Fireworks, OpenRouter, …).
4
+
5
+ Most providers ride a single declarative `WireFormatConfig` adapter; only the three majors (Anthropic / OpenAI / Google) have hand-written classes. Adding a new provider is usually a 20-line preset, not a new file.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pnpm add @wrongstack/providers @wrongstack/core
11
+ ```
12
+
13
+ `@wrongstack/core` is a peer of every provider — providers depend on the core `Provider` interface, message types, and tool format.
14
+
15
+ ## What's in here
16
+
17
+ ```
18
+ src/
19
+ anthropic.ts native Anthropic Messages API
20
+ openai.ts native OpenAI Chat Completions API
21
+ google.ts native Google Gemini generateContent API
22
+ openai-compatible.ts drop-in for any /v1/chat/completions endpoint
23
+ wire-adapter.ts declarative adapter — pass a WireFormatConfig
24
+ presets/ wire configs for anthropic / openai / google / mistral
25
+ sse.ts SSE parser with 256 KB buffer cap
26
+ aggregate.ts tool_use stream-event aggregator
27
+ tool-format/ tools ↔ Anthropic / OpenAI converters
28
+ stop-reason.ts normalize provider stop_reason → canonical
29
+ error-parse.ts parse provider HTTP error envelopes
30
+ capabilities.ts map models.dev capability strings → bool flags
31
+ ```
32
+
33
+ ## Quick example
34
+
35
+ ```ts
36
+ import { AnthropicProvider } from '@wrongstack/providers';
37
+
38
+ const provider = new AnthropicProvider({
39
+ apiKey: process.env.ANTHROPIC_API_KEY!,
40
+ modelId: 'claude-sonnet-4-6',
41
+ });
42
+
43
+ const stream = provider.stream({
44
+ messages: [{ role: 'user', content: 'hello' }],
45
+ tools: [],
46
+ });
47
+
48
+ for await (const event of stream) {
49
+ if (event.type === 'text_delta') process.stdout.write(event.text);
50
+ }
51
+ ```
52
+
53
+ ## Using a preset (OpenAI-compatible service)
54
+
55
+ ```ts
56
+ import { OpenAICompatibleProvider } from '@wrongstack/providers';
57
+
58
+ const groq = new OpenAICompatibleProvider({
59
+ id: 'groq',
60
+ apiKey: process.env.GROQ_API_KEY!,
61
+ baseURL: 'https://api.groq.com/openai/v1',
62
+ modelId: 'llama-3.3-70b-versatile',
63
+ capabilities: { tools: true, vision: false, maxContext: 128_000 },
64
+ });
65
+ ```
66
+
67
+ ## Wire-format adapter (declarative)
68
+
69
+ For a new provider that doesn't fit one of the existing presets, write a `WireFormatConfig` and plug it into `WireAdapter`. See [docs/provider-author-guide.md](../../docs/provider-author-guide.md) for the full spec.
70
+
71
+ ```ts
72
+ import { WireAdapter } from '@wrongstack/providers';
73
+ import type { WireFormatConfig } from '@wrongstack/core';
74
+
75
+ const myWire: WireFormatConfig = {
76
+ family: 'openai',
77
+ endpoint: 'https://api.myprovider.com/v1/chat/completions',
78
+ authHeader: (key) => ({ 'Authorization': `Bearer ${key}` }),
79
+ // tool format, message shape, stream parsing — see WireFormatConfig type
80
+ };
81
+
82
+ const provider = new WireAdapter({
83
+ id: 'myprovider',
84
+ apiKey: '…',
85
+ modelId: 'my-model-1',
86
+ wire: myWire,
87
+ capabilities: { tools: true, maxContext: 32_000 },
88
+ });
89
+ ```
90
+
91
+ ## Tool input parsing (`parseToolInput`)
92
+
93
+ All four stream parsers (anthropic / openai / aggregate + the three OpenAI-compatible presets) run tool-call JSON through one canonical helper: [`_tool-input.ts`](src/_tool-input.ts). It guarantees the agent always receives a `Record<string, unknown>` for `tool_use.input`, never a parse-error or `null`. Invalid or non-object inputs are wrapped under `{ __raw: ... }` instead of crashing the provider runner.
94
+
95
+ ## Capabilities
96
+
97
+ The capability flags on each provider come from [models.dev](https://models.dev) catalog data, mapped by `capabilitiesFor()`. The agent uses them to pick adaptive context-management thresholds, gate vision/reasoning features, and refuse tools on models that don't support tool calls.
98
+
99
+ ## License
100
+
101
+ MIT
package/dist/index.d.ts CHANGED
@@ -360,6 +360,9 @@ declare const googleWireFormat: WireFormatConfig<GoogleStreamState>;
360
360
  */
361
361
  declare function capabilitiesFor(registry: ModelsRegistry, providerId: string, modelId: string): Promise<Capabilities>;
362
362
 
363
+ declare const CAPABILITIES_BY_FAMILY: Record<WireFamily, Capabilities>;
364
+ declare function capabilitiesForFamily(family: WireFamily, overrides?: Partial<Capabilities>): Capabilities;
365
+
363
366
  /**
364
367
  * Provider HTTP error bodies come in three or four shapes depending on
365
368
  * vendor. Rather than dump the raw JSON into the error message (which is
@@ -459,4 +462,4 @@ declare function buildProviderFactoriesFromRegistry(opts: BuildFactoriesOptions)
459
462
  */
460
463
  declare function makeProviderFromConfig(id: string, cfg: ProviderConfig): Provider;
461
464
 
462
- export { AnthropicProvider, type AnthropicProviderOptions, type BuildFactoriesOptions, type CompatibilityQuirks, type ConvertOptions, GoogleProvider, type GoogleProviderOptions, type OpenAIChoice, type OpenAICompatibleOptions, OpenAICompatibleProvider, type OpenAIMessage, OpenAIProvider, type OpenAIProviderOptions, type OpenAIToolCall, WireAdapter, type WireFactoryOptions, type WireFormatConfig, WireFormatProvider, anthropicWireFormat, buildProviderFactoriesFromRegistry, capabilitiesFor, contentFromAnthropic, contentFromOpenAI, createWireFormatFactory, defineWireFormat, googleWireFormat, makeProviderFromConfig, messagesToOpenAI, mistralWireFormat, normalizeAnthropic, normalizeOpenAI, openaiWireFormat, parseProviderHttpError, toolsToAnthropic, toolsToOpenAI };
465
+ export { AnthropicProvider, type AnthropicProviderOptions, type BuildFactoriesOptions, CAPABILITIES_BY_FAMILY, type CompatibilityQuirks, type ConvertOptions, GoogleProvider, type GoogleProviderOptions, type OpenAIChoice, type OpenAICompatibleOptions, OpenAICompatibleProvider, type OpenAIMessage, OpenAIProvider, type OpenAIProviderOptions, type OpenAIToolCall, WireAdapter, type WireFactoryOptions, type WireFormatConfig, WireFormatProvider, anthropicWireFormat, buildProviderFactoriesFromRegistry, capabilitiesFor, capabilitiesForFamily, contentFromAnthropic, contentFromOpenAI, createWireFormatFactory, defineWireFormat, googleWireFormat, makeProviderFromConfig, messagesToOpenAI, mistralWireFormat, normalizeAnthropic, normalizeOpenAI, openaiWireFormat, parseProviderHttpError, toolsToAnthropic, toolsToOpenAI };