@warlock.js/ai-groq 4.6.0
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/CHANGELOG.md +13 -0
- package/LICENSE +21 -0
- package/README.md +123 -0
- package/cjs/index.cjs +281 -0
- package/cjs/index.cjs.map +1 -0
- package/esm/config.type.d.mts +122 -0
- package/esm/config.type.d.mts.map +1 -0
- package/esm/index.d.mts +4 -0
- package/esm/index.mjs +4 -0
- package/esm/known-models.d.mts +62 -0
- package/esm/known-models.d.mts.map +1 -0
- package/esm/known-models.mjs +124 -0
- package/esm/known-models.mjs.map +1 -0
- package/esm/sdk.d.mts +100 -0
- package/esm/sdk.d.mts.map +1 -0
- package/esm/sdk.mjs +154 -0
- package/esm/sdk.mjs.map +1 -0
- package/llms-full.txt +122 -0
- package/llms.txt +9 -0
- package/package.json +40 -0
- package/skills/setup-groq/SKILL.md +112 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog — @warlock.js/ai-groq
|
|
2
|
+
|
|
3
|
+
All notable changes to `@warlock.js/ai-groq` are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). `@warlock.js/*` packages are released in lockstep — every package shares the same version number, so a version below may list only the changes that affected this package.
|
|
6
|
+
|
|
7
|
+
## 4.6.0
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- **First release.** `GroqSDK` — a thin wrapper over `@warlock.js/ai-openai` that points one internal `OpenAISDK` at Groq's OpenAI-compatible endpoint (`https://api.groq.com/openai/v1`) with `provider: "groq"`, delegating transport, streaming, structured output, error wrapping, and token accounting to the battle-tested adapter. Serves Groq-hosted open models (`llama-3.3-70b-versatile`, `llama-3.1-8b-instant`, `openai/gpt-oss-*`, `deepseek-r1-distill-llama-70b`) on LPU hardware via `.model()` and `.count()`. `GROQ_BASE_URL` / `GROQ_PROVIDER` / `GROQ_KNOWN_MODELS` exported.
|
|
12
|
+
- **Groq-aware capability inference** — because Groq ids are upstream open-weight names, not OpenAI's, the wrapper carries its own lists: `vision` is auto-set for `gpt-oss` / `llama-4` / `llama-3.2-*-vision`; `reasoning` for `gpt-oss` / `deepseek-r1` / `qwq` / `qwen3`. An explicit `vision` / `reasoning` / `structuredOutput` always wins. Exported as `inferVisionCapability` / `inferReasoningCapability`.
|
|
13
|
+
- **Default pricing registry** (USD per 1,000,000 tokens) for the known Groq models as the final fallback; resolution per-model > SDK-level `pricing[name]` > built-in default > `undefined`. No embeddings endpoint on Groq (`.embedder()` is delegated for symmetry but calls fail upstream) and no `image()`.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Hassan Zohdy
|
|
4
|
+
|
|
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:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
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,123 @@
|
|
|
1
|
+
# @warlock.js/ai-groq
|
|
2
|
+
|
|
3
|
+
Groq adapter for [`@warlock.js/ai`](../ai). Groq serves open models (Llama, GPT-OSS, DeepSeek-R1 distill) fast on its LPU hardware and speaks the **OpenAI Chat Completions** wire protocol verbatim, so this package is a **thin wrapper** over [`@warlock.js/ai-openai`](../ai-openai): `GroqSDK` builds one internal `OpenAISDK` pointed at Groq's `baseURL` with `provider: "groq"` and delegates every call to it. It does not re-implement the transport, streaming, structured output, error wrapping, or token accounting.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @warlock.js/ai @warlock.js/ai-openai @warlock.js/ai-groq @warlock.js/seal openai
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
> `@warlock.js/seal` is the recommended Standard Schema library for tool inputs and structured output. Any Standard Schema V1 library works (Zod, Valibot, …).
|
|
10
|
+
|
|
11
|
+
## Quick start
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { GroqSDK } from "@warlock.js/ai-groq";
|
|
15
|
+
import { ai } from "@warlock.js/ai";
|
|
16
|
+
|
|
17
|
+
const groq = new GroqSDK({ apiKey: process.env.GROQ_API_KEY! });
|
|
18
|
+
|
|
19
|
+
const myAgent = ai.agent({
|
|
20
|
+
model: groq.model({ name: "llama-3.3-70b-versatile" }),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const result = await myAgent.execute("Hello!");
|
|
24
|
+
console.log(result.text);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Construct one SDK per account and reuse it everywhere — the single underlying `OpenAI` client (connection pool, auth, rate-limit state) is shared by every model it produces.
|
|
28
|
+
|
|
29
|
+
## API surface
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
new GroqSDK(config: GroqSDKConfig) // = OpenAI ClientOptions + Groq baseURL/provider defaults
|
|
33
|
+
.model(config: GroqModelConfig) // → ModelContract
|
|
34
|
+
.embedder(config: GroqEmbedderConfig) // → EmbedderContract (see caveat below)
|
|
35
|
+
.count(text, model?) // approximate token count
|
|
36
|
+
|
|
37
|
+
GroqModelConfig {
|
|
38
|
+
name: string; // Groq-hosted open-weight id, e.g. "llama-3.3-70b-versatile", "openai/gpt-oss-120b"
|
|
39
|
+
temperature?: number;
|
|
40
|
+
maxTokens?: number;
|
|
41
|
+
vision?: boolean; // override auto-inference (gpt-oss, llama-4, llama-3.2-*-vision)
|
|
42
|
+
reasoning?: boolean; // override auto-inference (gpt-oss, deepseek-r1, qwq, qwen3)
|
|
43
|
+
structuredOutput?: boolean; // default true
|
|
44
|
+
// ...neutral ModelConfig fields pass through
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Base URL & model families
|
|
49
|
+
|
|
50
|
+
`baseURL` defaults to `https://api.groq.com/openai/v1` (Groq's OpenAI-compatible endpoint) — override it only to route through a proxy or self-hosted gateway. `provider` defaults to `"groq"` and flows through to `ModelContract.provider`, `AgentReport.model.provider`, and logs. Every other upstream OpenAI `ClientOptions` field (`timeout`, `maxRetries`, `defaultHeaders`, `fetch`, …) is forwarded verbatim to the inner client. Both constants are exported as `GROQ_BASE_URL` and `GROQ_PROVIDER`.
|
|
51
|
+
|
|
52
|
+
A curated (not exhaustive, not an allow-list) set of current production ids is exported as `GROQ_KNOWN_MODELS`:
|
|
53
|
+
|
|
54
|
+
| Model id | Notes |
|
|
55
|
+
| --- | --- |
|
|
56
|
+
| `llama-3.3-70b-versatile` | Flagship general-purpose text |
|
|
57
|
+
| `llama-3.1-8b-instant` | Fastest / cheapest small text |
|
|
58
|
+
| `openai/gpt-oss-120b` / `openai/gpt-oss-20b` | OpenAI open-weight family — vision + reasoning capable |
|
|
59
|
+
| `deepseek-r1-distill-llama-70b` | DeepSeek-R1-style reasoning |
|
|
60
|
+
|
|
61
|
+
`name` is the upstream open-weight id (e.g. `openai/gpt-oss-120b`), NOT an OpenAI id. `groq.model()` accepts any string, so a newly launched Groq id works the moment Groq ships it.
|
|
62
|
+
|
|
63
|
+
## Capabilities
|
|
64
|
+
|
|
65
|
+
The whole reason this wrapper exists: Groq's ids aren't OpenAI's, so the OpenAI adapter's prefix inference would never fire. `GroqSDK` carries its **own** name lists and injects the result as explicit capability config, which wins over the inner adapter's inference. An explicit caller value always wins.
|
|
66
|
+
|
|
67
|
+
| Capability | Default |
|
|
68
|
+
| --- | --- |
|
|
69
|
+
| `vision` | Inferred from the Groq id — `true` for `gpt-oss`, `llama-4`, `llama-3.2-*-vision`; `false` otherwise (e.g. `llama-3.3-70b-versatile`). |
|
|
70
|
+
| `reasoning` | Inferred from the Groq id — `true` for `gpt-oss`, `deepseek-r1` / `deepseek-r1-distill`, `qwq`, `qwen3`; `false` otherwise. Drives whether `reasoning.effort` maps to `reasoning_effort` on the wire. |
|
|
71
|
+
| `structuredOutput` | `true` — Groq accepts OpenAI-style `response_format`. |
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
groq.model({ name: "openai/gpt-oss-120b" }); // vision + reasoning auto-true
|
|
75
|
+
groq.model({ name: "deepseek-r1-distill-llama-70b" }); // reasoning auto-true
|
|
76
|
+
groq.model({ name: "some-custom-llama", vision: true }); // explicit override
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Reasoning models accept a discrete effort knob forwarded by the inner adapter as OpenAI's `reasoning_effort`:
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
const model = groq.model({ name: "deepseek-r1-distill-llama-70b" });
|
|
83
|
+
await model.complete(messages, { reasoning: { effort: "high" } }); // → reasoning_effort: "high"
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Embeddings — not available on Groq
|
|
87
|
+
|
|
88
|
+
As of mid-2026 Groq exposes **no** OpenAI-compatible embeddings endpoint. `groq.embedder({ name })` constructs (delegated to the inner adapter for API symmetry) but a live `.embed()` call fails at the provider. Use [`@warlock.js/ai-openai`](../ai-openai) or `@warlock.js/ai-google` for retrieval embeddings.
|
|
89
|
+
|
|
90
|
+
## No image generation
|
|
91
|
+
|
|
92
|
+
Groq hosts no image-generation API, so `GroqSDK` intentionally does **not** expose `image()`. The structural absence of the method is the capability guard — `ai.groq.image(...)` is a compile-time error rather than a runtime failure.
|
|
93
|
+
|
|
94
|
+
## Pricing
|
|
95
|
+
|
|
96
|
+
The adapter ships built-in default rates (USD per 1,000,000 tokens) for the known Groq models as the final fallback. Supply your own `pricing` registry (keyed by model name) to win per id:
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
const groq = new GroqSDK({
|
|
100
|
+
apiKey: process.env.GROQ_API_KEY!,
|
|
101
|
+
pricing: {
|
|
102
|
+
"llama-3.3-70b-versatile": { input: 0.59, output: 0.79 },
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Resolution at `model()` time: per-model `pricing` > SDK-level `pricing[name]` > adapter built-in default for the id > `undefined`. Built-in defaults exist for `llama-3.3-70b-versatile`, `llama-3.1-8b-instant`, `openai/gpt-oss-120b`, `openai/gpt-oss-20b`, and `deepseek-r1-distill-llama-70b`.
|
|
108
|
+
|
|
109
|
+
## Setup skill
|
|
110
|
+
|
|
111
|
+
For agent wiring, capability inference, reasoning, and pricing detail, see the bundled setup skill: [`skills/setup-groq/SKILL.md`](./skills/setup-groq/SKILL.md).
|
|
112
|
+
|
|
113
|
+
## Tests
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
npm test
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Covers baseURL / provider wiring, Groq-specific vision & reasoning inference, pricing resolution, and count / embedder delegation.
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
|
|
123
|
+
MIT
|
package/cjs/index.cjs
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _warlock_js_ai_openai = require("@warlock.js/ai-openai");
|
|
3
|
+
|
|
4
|
+
//#region ../@warlock.js/ai-groq/src/known-models.ts
|
|
5
|
+
/**
|
|
6
|
+
* Default base URL for Groq's OpenAI-compatible Chat Completions
|
|
7
|
+
* endpoint. Groq exposes the same wire protocol as OpenAI under this
|
|
8
|
+
* prefix, which is exactly why `GroqSDK` can delegate to the
|
|
9
|
+
* battle-tested `OpenAISDK` instead of reimplementing the transport.
|
|
10
|
+
*
|
|
11
|
+
* Verified against Groq's "OpenAI Compatibility" docs (mid-2026).
|
|
12
|
+
* Override via `new GroqSDK({ baseURL })` if Groq ever relocates it.
|
|
13
|
+
*/
|
|
14
|
+
const GROQ_BASE_URL = "https://api.groq.com/openai/v1";
|
|
15
|
+
/**
|
|
16
|
+
* The provider label every model produced by `GroqSDK` self-identifies
|
|
17
|
+
* with. Flows through to `ModelContract.provider`, `AgentReport.model`,
|
|
18
|
+
* logs, and any provider-aware middleware. Kept as a constant so the
|
|
19
|
+
* wrapper and the inner `OpenAISDK` agree on one spelling.
|
|
20
|
+
*/
|
|
21
|
+
const GROQ_PROVIDER = "groq";
|
|
22
|
+
/**
|
|
23
|
+
* Substrings identifying Groq-hosted model ids whose family accepts
|
|
24
|
+
* image input (vision).
|
|
25
|
+
*
|
|
26
|
+
* Groq hosts *open* models on its LPU hardware, so the ids are the
|
|
27
|
+
* upstream open-weight names rather than OpenAI's — which is why the
|
|
28
|
+
* OpenAI adapter's `gpt-4o*` prefix inference would never fire here and
|
|
29
|
+
* this provider must carry its OWN list. Verified against Groq's
|
|
30
|
+
* supported-models catalog (mid-2026):
|
|
31
|
+
*
|
|
32
|
+
* - `openai/gpt-oss-*` — natively multimodal OpenAI open-weight family
|
|
33
|
+
* (the current production vision + reasoning models on Groq).
|
|
34
|
+
* - `llama-4` / `llama-3.2-*-vision` — Meta's multimodal Llama families.
|
|
35
|
+
* Kept as substrings so any still-hosted or re-introduced variant is
|
|
36
|
+
* covered even though some `llama-4` ids were deprecated in 2026.
|
|
37
|
+
*
|
|
38
|
+
* Matched as a substring (not a prefix) because Groq prefixes several
|
|
39
|
+
* ids with an org segment (`openai/`, `meta-llama/`) and appends size /
|
|
40
|
+
* date suffixes. Override per-model via
|
|
41
|
+
* `groq.model({ name, vision: true | false })`.
|
|
42
|
+
*/
|
|
43
|
+
const VISION_CAPABLE_SUBSTRINGS = [
|
|
44
|
+
"gpt-oss",
|
|
45
|
+
"llama-4",
|
|
46
|
+
"llama-3.2-11b-vision",
|
|
47
|
+
"llama-3.2-90b-vision",
|
|
48
|
+
"vision"
|
|
49
|
+
];
|
|
50
|
+
/**
|
|
51
|
+
* Substrings identifying Groq-hosted model ids that expose an internal
|
|
52
|
+
* reasoning / thinking channel and accept the `reasoning_effort`
|
|
53
|
+
* request parameter on the OpenAI-compatible Chat Completions endpoint.
|
|
54
|
+
*
|
|
55
|
+
* Verified against Groq's catalog (mid-2026):
|
|
56
|
+
* - `gpt-oss` — the OpenAI open-weight family reasons by default.
|
|
57
|
+
* - `deepseek-r1-distill` — DeepSeek-R1-style reasoning at Groq speed.
|
|
58
|
+
* - `qwq` / `qwen3` — Qwen reasoning families (when hosted).
|
|
59
|
+
*
|
|
60
|
+
* Matched as a substring for the same org-prefix / suffix reason as the
|
|
61
|
+
* vision list. Override per-model via
|
|
62
|
+
* `groq.model({ name, reasoning: true | false })`.
|
|
63
|
+
*/
|
|
64
|
+
const REASONING_CAPABLE_SUBSTRINGS = [
|
|
65
|
+
"gpt-oss",
|
|
66
|
+
"deepseek-r1",
|
|
67
|
+
"deepseek-r1-distill",
|
|
68
|
+
"qwq",
|
|
69
|
+
"qwen3"
|
|
70
|
+
];
|
|
71
|
+
/**
|
|
72
|
+
* Infer whether a Groq-hosted model id supports vision based on the
|
|
73
|
+
* known multimodal-family substrings. Unknown ids default to `false`
|
|
74
|
+
* so passing an image attachment to a text-only model (e.g.
|
|
75
|
+
* `llama-3.3-70b-versatile`) surfaces a clear, agent-side capability
|
|
76
|
+
* error instead of an opaque upstream 400.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* inferVisionCapability("openai/gpt-oss-120b"); // → true
|
|
80
|
+
* inferVisionCapability("meta-llama/llama-4-scout"); // → true
|
|
81
|
+
* inferVisionCapability("llama-3.3-70b-versatile"); // → false
|
|
82
|
+
* inferVisionCapability("llama-3.1-8b-instant"); // → false
|
|
83
|
+
*/
|
|
84
|
+
function inferVisionCapability(modelId) {
|
|
85
|
+
const normalized = modelId.toLowerCase();
|
|
86
|
+
return VISION_CAPABLE_SUBSTRINGS.some((fragment) => normalized.includes(fragment));
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Infer whether a Groq-hosted model id is a reasoning model based on
|
|
90
|
+
* the known reasoning-family substrings. Unknown ids default to `false`
|
|
91
|
+
* so the adapter never forwards an unsupported `reasoning_effort` param
|
|
92
|
+
* to a non-reasoning model (which would 400).
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* inferReasoningCapability("openai/gpt-oss-20b"); // → true
|
|
96
|
+
* inferReasoningCapability("deepseek-r1-distill-llama-70b"); // → true
|
|
97
|
+
* inferReasoningCapability("llama-3.3-70b-versatile"); // → false
|
|
98
|
+
*/
|
|
99
|
+
function inferReasoningCapability(modelId) {
|
|
100
|
+
const normalized = modelId.toLowerCase();
|
|
101
|
+
return REASONING_CAPABLE_SUBSTRINGS.some((fragment) => normalized.includes(fragment));
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Curated list of current Groq production chat model ids (mid-2026),
|
|
105
|
+
* for autocomplete, docs, and default selection. NOT exhaustive and NOT
|
|
106
|
+
* a runtime allow-list — `groq.model({ name })` accepts any string, so
|
|
107
|
+
* a newly launched id works the moment Groq ships it without a package
|
|
108
|
+
* bump. Deprecated ids (e.g. several `llama-4` variants retired in 2026)
|
|
109
|
+
* are intentionally excluded.
|
|
110
|
+
*
|
|
111
|
+
* - `llama-3.3-70b-versatile` — flagship general-purpose text model.
|
|
112
|
+
* - `llama-3.1-8b-instant` — fastest/cheapest small text model.
|
|
113
|
+
* - `openai/gpt-oss-120b` / `openai/gpt-oss-20b` — OpenAI open-weight
|
|
114
|
+
* family; vision + reasoning capable.
|
|
115
|
+
* - `deepseek-r1-distill-llama-70b` — DeepSeek-R1-style reasoning.
|
|
116
|
+
*/
|
|
117
|
+
const GROQ_KNOWN_MODELS = [
|
|
118
|
+
"llama-3.3-70b-versatile",
|
|
119
|
+
"llama-3.1-8b-instant",
|
|
120
|
+
"openai/gpt-oss-120b",
|
|
121
|
+
"openai/gpt-oss-20b",
|
|
122
|
+
"deepseek-r1-distill-llama-70b"
|
|
123
|
+
];
|
|
124
|
+
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region ../@warlock.js/ai-groq/src/sdk.ts
|
|
127
|
+
/**
|
|
128
|
+
* Groq-backed implementation of `SDKAdapterContract`.
|
|
129
|
+
*
|
|
130
|
+
* **Role.** The package entry point for Groq-hosted open models
|
|
131
|
+
* (`llama-3.3-70b-versatile`, `llama-3.1-8b-instant`,
|
|
132
|
+
* `openai/gpt-oss-*`, `deepseek-r1-distill-*`, …) served on Groq's fast
|
|
133
|
+
* LPU hardware. Because Groq exposes the OpenAI Chat Completions wire
|
|
134
|
+
* protocol verbatim, `GroqSDK` is a **thin wrapper over the already
|
|
135
|
+
* battle-tested {@link OpenAISDK}** rather than a fresh transport
|
|
136
|
+
* implementation — it owns one internal `OpenAISDK` pointed at Groq's
|
|
137
|
+
* `baseURL` with the `"groq"` provider label, and delegates `model()` /
|
|
138
|
+
* `embedder()` / `count()` to it.
|
|
139
|
+
*
|
|
140
|
+
* **Why a wrapper and not `OpenAISDK` directly?** Groq hosts *open*
|
|
141
|
+
* models whose ids are the upstream open-weight names (`llama-…`,
|
|
142
|
+
* `openai/gpt-oss-…`), not OpenAI's (`gpt-4o`, `o3`). The OpenAI
|
|
143
|
+
* adapter's capability inference keys on OpenAI prefixes and would never
|
|
144
|
+
* fire here, so every Groq model would come back with `vision`/
|
|
145
|
+
* `reasoning` silently `false`. `GroqSDK` fixes that by computing
|
|
146
|
+
* **this provider's own** vision/reasoning inference (see
|
|
147
|
+
* `known-models.ts`) and injecting the result as explicit capability
|
|
148
|
+
* config — which wins over the inner adapter's inference — plus a set of
|
|
149
|
+
* default per-model pricing rates. Everything else (transport, retries,
|
|
150
|
+
* streaming, structured output, error wrapping, usage accounting) is
|
|
151
|
+
* inherited unchanged from `OpenAISDK`.
|
|
152
|
+
*
|
|
153
|
+
* **Responsibility.**
|
|
154
|
+
* - Owns: one long-lived internal `OpenAISDK` (auth + Groq base URL) and
|
|
155
|
+
* this provider's capability + default-pricing inference.
|
|
156
|
+
* - Does NOT own: the wire protocol, streaming loop, structured-output
|
|
157
|
+
* mapping, or error wrapping — all inherited from `OpenAISDK`.
|
|
158
|
+
*
|
|
159
|
+
* Modeled as a class (see §4.2 of code-style.md — "long-lived state
|
|
160
|
+
* across many calls"), fronted by FP usage like the other adapters.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* const groq = new GroqSDK({ apiKey: process.env.GROQ_API_KEY! });
|
|
164
|
+
* const model = groq.model({ name: "llama-3.3-70b-versatile", temperature: 0.7 });
|
|
165
|
+
* const reasoner = groq.model({ name: "openai/gpt-oss-120b" }); // vision + reasoning auto-true
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* // Compose into an `ai.groq` namespace for ergonomic agent wiring
|
|
169
|
+
* const ai = { agent, tool, systemPrompt, groq: new GroqSDK({ apiKey }) };
|
|
170
|
+
* const myAgent = ai.agent({ model: ai.groq.model({ name: "llama-3.1-8b-instant" }) });
|
|
171
|
+
*/
|
|
172
|
+
var GroqSDK = class {
|
|
173
|
+
constructor(config) {
|
|
174
|
+
const { baseURL, provider, pricing, ...clientOptions } = config;
|
|
175
|
+
this.provider = provider ?? "groq";
|
|
176
|
+
this.pricing = pricing;
|
|
177
|
+
this.openai = new _warlock_js_ai_openai.OpenAISDK({
|
|
178
|
+
...clientOptions,
|
|
179
|
+
baseURL: baseURL ?? "https://api.groq.com/openai/v1",
|
|
180
|
+
provider: this.provider,
|
|
181
|
+
pricing
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Build a `ModelContract` bound to the internal Groq-pointed client.
|
|
186
|
+
*
|
|
187
|
+
* The wrapper's whole job lives here: it computes **Groq's** vision /
|
|
188
|
+
* reasoning inference from the model id and forwards the result as
|
|
189
|
+
* *explicit* `vision` / `reasoning` config to the inner
|
|
190
|
+
* `OpenAISDK.model()`. Because explicit capability config wins over the
|
|
191
|
+
* inner adapter's OpenAI-prefix inference, the returned model reports
|
|
192
|
+
* the right capabilities even though the id isn't an OpenAI name. A
|
|
193
|
+
* caller-supplied `vision` / `reasoning` still wins over this
|
|
194
|
+
* inference (we only fill the gap when the field is omitted).
|
|
195
|
+
*
|
|
196
|
+
* Pricing resolution: per-model `config.pricing` wins; otherwise this
|
|
197
|
+
* SDK's `pricing` registry keyed by `config.name`; otherwise the
|
|
198
|
+
* adapter's built-in default rate for the model; otherwise `undefined`
|
|
199
|
+
* (no cost computed).
|
|
200
|
+
*/
|
|
201
|
+
model(config) {
|
|
202
|
+
const resolvedPricing = config.pricing ?? this.pricing?.[config.name] ?? defaultPricingFor(config.name);
|
|
203
|
+
return this.openai.model({
|
|
204
|
+
...config,
|
|
205
|
+
vision: config.vision ?? inferVisionCapability(config.name),
|
|
206
|
+
reasoning: config.reasoning ?? inferReasoningCapability(config.name),
|
|
207
|
+
structuredOutput: config.structuredOutput ?? true,
|
|
208
|
+
pricing: resolvedPricing
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Rough offline token-count estimate. Delegated straight to the inner
|
|
213
|
+
* `OpenAISDK`, which uses the core character-heuristic
|
|
214
|
+
* (`approximateTokenCount`). Good for budgeting / quota guards, not for
|
|
215
|
+
* billing.
|
|
216
|
+
*/
|
|
217
|
+
async count(text, model) {
|
|
218
|
+
return this.openai.count(text, model);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Build an embedder bound to the internal client. Delegated to the
|
|
222
|
+
* inner `OpenAISDK`.
|
|
223
|
+
*
|
|
224
|
+
* IMPORTANT: as of mid-2026 Groq does **not** expose an
|
|
225
|
+
* OpenAI-compatible embeddings endpoint, so a live `.embed()` /
|
|
226
|
+
* `.embedMany()` call will fail at the provider. The method is kept for
|
|
227
|
+
* adapter symmetry; use `@warlock.js/ai-openai` or
|
|
228
|
+
* `@warlock.js/ai-google` for retrieval embeddings.
|
|
229
|
+
*/
|
|
230
|
+
embedder(config) {
|
|
231
|
+
return this.openai.embedder(config);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
* Built-in default USD-per-1,000,000-token rates for the current Groq
|
|
236
|
+
* production models (mid-2026), used as the last fallback in `model()`'s
|
|
237
|
+
* pricing resolution. A per-model or SDK-level `pricing` entry always
|
|
238
|
+
* wins over these. Returns `undefined` for any unlisted id so cost stays
|
|
239
|
+
* an honest absence rather than a false zero. Update when Groq revises
|
|
240
|
+
* its public price list.
|
|
241
|
+
*/
|
|
242
|
+
function defaultPricingFor(name) {
|
|
243
|
+
return GROQ_DEFAULT_PRICING[name];
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Default per-million-token USD rates for known Groq models. Kept inline
|
|
247
|
+
* (not exported) so the public surface stays the inference helpers; a
|
|
248
|
+
* caller who wants different numbers supplies `pricing` on the SDK or
|
|
249
|
+
* per model.
|
|
250
|
+
*/
|
|
251
|
+
const GROQ_DEFAULT_PRICING = {
|
|
252
|
+
"llama-3.3-70b-versatile": {
|
|
253
|
+
input: .59,
|
|
254
|
+
output: .79
|
|
255
|
+
},
|
|
256
|
+
"llama-3.1-8b-instant": {
|
|
257
|
+
input: .05,
|
|
258
|
+
output: .08
|
|
259
|
+
},
|
|
260
|
+
"openai/gpt-oss-120b": {
|
|
261
|
+
input: .15,
|
|
262
|
+
output: .75
|
|
263
|
+
},
|
|
264
|
+
"openai/gpt-oss-20b": {
|
|
265
|
+
input: .1,
|
|
266
|
+
output: .5
|
|
267
|
+
},
|
|
268
|
+
"deepseek-r1-distill-llama-70b": {
|
|
269
|
+
input: .75,
|
|
270
|
+
output: .99
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
//#endregion
|
|
275
|
+
exports.GROQ_BASE_URL = GROQ_BASE_URL;
|
|
276
|
+
exports.GROQ_KNOWN_MODELS = GROQ_KNOWN_MODELS;
|
|
277
|
+
exports.GROQ_PROVIDER = GROQ_PROVIDER;
|
|
278
|
+
exports.GroqSDK = GroqSDK;
|
|
279
|
+
exports.inferReasoningCapability = inferReasoningCapability;
|
|
280
|
+
exports.inferVisionCapability = inferVisionCapability;
|
|
281
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["OpenAISDK"],"sources":["../../../../../../@warlock.js/ai-groq/src/known-models.ts","../../../../../../@warlock.js/ai-groq/src/sdk.ts"],"sourcesContent":["/**\n * Default base URL for Groq's OpenAI-compatible Chat Completions\n * endpoint. Groq exposes the same wire protocol as OpenAI under this\n * prefix, which is exactly why `GroqSDK` can delegate to the\n * battle-tested `OpenAISDK` instead of reimplementing the transport.\n *\n * Verified against Groq's \"OpenAI Compatibility\" docs (mid-2026).\n * Override via `new GroqSDK({ baseURL })` if Groq ever relocates it.\n */\nexport const GROQ_BASE_URL = \"https://api.groq.com/openai/v1\";\n\n/**\n * The provider label every model produced by `GroqSDK` self-identifies\n * with. Flows through to `ModelContract.provider`, `AgentReport.model`,\n * logs, and any provider-aware middleware. Kept as a constant so the\n * wrapper and the inner `OpenAISDK` agree on one spelling.\n */\nexport const GROQ_PROVIDER = \"groq\";\n\n/**\n * Substrings identifying Groq-hosted model ids whose family accepts\n * image input (vision).\n *\n * Groq hosts *open* models on its LPU hardware, so the ids are the\n * upstream open-weight names rather than OpenAI's — which is why the\n * OpenAI adapter's `gpt-4o*` prefix inference would never fire here and\n * this provider must carry its OWN list. Verified against Groq's\n * supported-models catalog (mid-2026):\n *\n * - `openai/gpt-oss-*` — natively multimodal OpenAI open-weight family\n * (the current production vision + reasoning models on Groq).\n * - `llama-4` / `llama-3.2-*-vision` — Meta's multimodal Llama families.\n * Kept as substrings so any still-hosted or re-introduced variant is\n * covered even though some `llama-4` ids were deprecated in 2026.\n *\n * Matched as a substring (not a prefix) because Groq prefixes several\n * ids with an org segment (`openai/`, `meta-llama/`) and appends size /\n * date suffixes. Override per-model via\n * `groq.model({ name, vision: true | false })`.\n */\nconst VISION_CAPABLE_SUBSTRINGS = [\n \"gpt-oss\",\n \"llama-4\",\n \"llama-3.2-11b-vision\",\n \"llama-3.2-90b-vision\",\n \"vision\",\n];\n\n/**\n * Substrings identifying Groq-hosted model ids that expose an internal\n * reasoning / thinking channel and accept the `reasoning_effort`\n * request parameter on the OpenAI-compatible Chat Completions endpoint.\n *\n * Verified against Groq's catalog (mid-2026):\n * - `gpt-oss` — the OpenAI open-weight family reasons by default.\n * - `deepseek-r1-distill` — DeepSeek-R1-style reasoning at Groq speed.\n * - `qwq` / `qwen3` — Qwen reasoning families (when hosted).\n *\n * Matched as a substring for the same org-prefix / suffix reason as the\n * vision list. Override per-model via\n * `groq.model({ name, reasoning: true | false })`.\n */\nconst REASONING_CAPABLE_SUBSTRINGS = [\n \"gpt-oss\",\n \"deepseek-r1\",\n \"deepseek-r1-distill\",\n \"qwq\",\n \"qwen3\",\n];\n\n/**\n * Infer whether a Groq-hosted model id supports vision based on the\n * known multimodal-family substrings. Unknown ids default to `false`\n * so passing an image attachment to a text-only model (e.g.\n * `llama-3.3-70b-versatile`) surfaces a clear, agent-side capability\n * error instead of an opaque upstream 400.\n *\n * @example\n * inferVisionCapability(\"openai/gpt-oss-120b\"); // → true\n * inferVisionCapability(\"meta-llama/llama-4-scout\"); // → true\n * inferVisionCapability(\"llama-3.3-70b-versatile\"); // → false\n * inferVisionCapability(\"llama-3.1-8b-instant\"); // → false\n */\nexport function inferVisionCapability(modelId: string): boolean {\n const normalized = modelId.toLowerCase();\n\n return VISION_CAPABLE_SUBSTRINGS.some((fragment) => normalized.includes(fragment));\n}\n\n/**\n * Infer whether a Groq-hosted model id is a reasoning model based on\n * the known reasoning-family substrings. Unknown ids default to `false`\n * so the adapter never forwards an unsupported `reasoning_effort` param\n * to a non-reasoning model (which would 400).\n *\n * @example\n * inferReasoningCapability(\"openai/gpt-oss-20b\"); // → true\n * inferReasoningCapability(\"deepseek-r1-distill-llama-70b\"); // → true\n * inferReasoningCapability(\"llama-3.3-70b-versatile\"); // → false\n */\nexport function inferReasoningCapability(modelId: string): boolean {\n const normalized = modelId.toLowerCase();\n\n return REASONING_CAPABLE_SUBSTRINGS.some((fragment) => normalized.includes(fragment));\n}\n\n/**\n * Curated list of current Groq production chat model ids (mid-2026),\n * for autocomplete, docs, and default selection. NOT exhaustive and NOT\n * a runtime allow-list — `groq.model({ name })` accepts any string, so\n * a newly launched id works the moment Groq ships it without a package\n * bump. Deprecated ids (e.g. several `llama-4` variants retired in 2026)\n * are intentionally excluded.\n *\n * - `llama-3.3-70b-versatile` — flagship general-purpose text model.\n * - `llama-3.1-8b-instant` — fastest/cheapest small text model.\n * - `openai/gpt-oss-120b` / `openai/gpt-oss-20b` — OpenAI open-weight\n * family; vision + reasoning capable.\n * - `deepseek-r1-distill-llama-70b` — DeepSeek-R1-style reasoning.\n */\nexport const GROQ_KNOWN_MODELS = [\n \"llama-3.3-70b-versatile\",\n \"llama-3.1-8b-instant\",\n \"openai/gpt-oss-120b\",\n \"openai/gpt-oss-20b\",\n \"deepseek-r1-distill-llama-70b\",\n] as const;\n","import type {\n EmbedderContract,\n ModelContract,\n ModelPricing,\n SDKAdapterContract,\n} from \"@warlock.js/ai\";\nimport { OpenAISDK } from \"@warlock.js/ai-openai\";\nimport type {\n GroqEmbedderConfig,\n GroqModelConfig,\n GroqSDKConfig,\n} from \"./config.type\";\nimport {\n GROQ_BASE_URL,\n GROQ_PROVIDER,\n inferReasoningCapability,\n inferVisionCapability,\n} from \"./known-models\";\n\n/**\n * Groq-backed implementation of `SDKAdapterContract`.\n *\n * **Role.** The package entry point for Groq-hosted open models\n * (`llama-3.3-70b-versatile`, `llama-3.1-8b-instant`,\n * `openai/gpt-oss-*`, `deepseek-r1-distill-*`, …) served on Groq's fast\n * LPU hardware. Because Groq exposes the OpenAI Chat Completions wire\n * protocol verbatim, `GroqSDK` is a **thin wrapper over the already\n * battle-tested {@link OpenAISDK}** rather than a fresh transport\n * implementation — it owns one internal `OpenAISDK` pointed at Groq's\n * `baseURL` with the `\"groq\"` provider label, and delegates `model()` /\n * `embedder()` / `count()` to it.\n *\n * **Why a wrapper and not `OpenAISDK` directly?** Groq hosts *open*\n * models whose ids are the upstream open-weight names (`llama-…`,\n * `openai/gpt-oss-…`), not OpenAI's (`gpt-4o`, `o3`). The OpenAI\n * adapter's capability inference keys on OpenAI prefixes and would never\n * fire here, so every Groq model would come back with `vision`/\n * `reasoning` silently `false`. `GroqSDK` fixes that by computing\n * **this provider's own** vision/reasoning inference (see\n * `known-models.ts`) and injecting the result as explicit capability\n * config — which wins over the inner adapter's inference — plus a set of\n * default per-model pricing rates. Everything else (transport, retries,\n * streaming, structured output, error wrapping, usage accounting) is\n * inherited unchanged from `OpenAISDK`.\n *\n * **Responsibility.**\n * - Owns: one long-lived internal `OpenAISDK` (auth + Groq base URL) and\n * this provider's capability + default-pricing inference.\n * - Does NOT own: the wire protocol, streaming loop, structured-output\n * mapping, or error wrapping — all inherited from `OpenAISDK`.\n *\n * Modeled as a class (see §4.2 of code-style.md — \"long-lived state\n * across many calls\"), fronted by FP usage like the other adapters.\n *\n * @example\n * const groq = new GroqSDK({ apiKey: process.env.GROQ_API_KEY! });\n * const model = groq.model({ name: \"llama-3.3-70b-versatile\", temperature: 0.7 });\n * const reasoner = groq.model({ name: \"openai/gpt-oss-120b\" }); // vision + reasoning auto-true\n *\n * @example\n * // Compose into an `ai.groq` namespace for ergonomic agent wiring\n * const ai = { agent, tool, systemPrompt, groq: new GroqSDK({ apiKey }) };\n * const myAgent = ai.agent({ model: ai.groq.model({ name: \"llama-3.1-8b-instant\" }) });\n */\nexport class GroqSDK implements SDKAdapterContract {\n /**\n * The wrapped OpenAI-compatible adapter, pre-pointed at Groq's\n * `baseURL` and labeled with the `\"groq\"` provider. All real wire work\n * happens here; `GroqSDK` only enriches the per-model config before\n * delegating.\n */\n private readonly openai: OpenAISDK;\n private readonly provider: string;\n private readonly pricing?: Record<string, ModelPricing>;\n\n public constructor(config: GroqSDKConfig) {\n const { baseURL, provider, pricing, ...clientOptions } = config;\n\n this.provider = provider ?? GROQ_PROVIDER;\n this.pricing = pricing;\n\n // Build the inner OpenAI-compatible client pointed at Groq. Forward\n // every other upstream ClientOptions (timeout, maxRetries,\n // defaultHeaders, fetch, …) verbatim — they type-check, so dropping\n // them would be a silent footgun. We pass `pricing` through too so\n // the inner registry stays a fallback, while THIS class's `model()`\n // layers Groq default rates on top.\n this.openai = new OpenAISDK({\n ...clientOptions,\n baseURL: baseURL ?? GROQ_BASE_URL,\n provider: this.provider,\n pricing,\n });\n }\n\n /**\n * Build a `ModelContract` bound to the internal Groq-pointed client.\n *\n * The wrapper's whole job lives here: it computes **Groq's** vision /\n * reasoning inference from the model id and forwards the result as\n * *explicit* `vision` / `reasoning` config to the inner\n * `OpenAISDK.model()`. Because explicit capability config wins over the\n * inner adapter's OpenAI-prefix inference, the returned model reports\n * the right capabilities even though the id isn't an OpenAI name. A\n * caller-supplied `vision` / `reasoning` still wins over this\n * inference (we only fill the gap when the field is omitted).\n *\n * Pricing resolution: per-model `config.pricing` wins; otherwise this\n * SDK's `pricing` registry keyed by `config.name`; otherwise the\n * adapter's built-in default rate for the model; otherwise `undefined`\n * (no cost computed).\n */\n public model(config: GroqModelConfig): ModelContract {\n const resolvedPricing =\n config.pricing ?? this.pricing?.[config.name] ?? defaultPricingFor(config.name);\n\n return this.openai.model({\n ...config,\n // Fill capability inference only when the caller didn't pin it —\n // explicit caller config always wins, then Groq inference, then\n // (inside OpenAISDK) the harmless OpenAI inference that won't match.\n vision: config.vision ?? inferVisionCapability(config.name),\n reasoning: config.reasoning ?? inferReasoningCapability(config.name),\n structuredOutput: config.structuredOutput ?? true,\n pricing: resolvedPricing,\n });\n }\n\n /**\n * Rough offline token-count estimate. Delegated straight to the inner\n * `OpenAISDK`, which uses the core character-heuristic\n * (`approximateTokenCount`). Good for budgeting / quota guards, not for\n * billing.\n */\n public async count(text: string, model?: string): Promise<number> {\n return this.openai.count(text, model);\n }\n\n /**\n * Build an embedder bound to the internal client. Delegated to the\n * inner `OpenAISDK`.\n *\n * IMPORTANT: as of mid-2026 Groq does **not** expose an\n * OpenAI-compatible embeddings endpoint, so a live `.embed()` /\n * `.embedMany()` call will fail at the provider. The method is kept for\n * adapter symmetry; use `@warlock.js/ai-openai` or\n * `@warlock.js/ai-google` for retrieval embeddings.\n */\n public embedder(config: GroqEmbedderConfig): EmbedderContract {\n return this.openai.embedder(config);\n }\n\n // NOTE: `image()` is intentionally NOT implemented. Groq hosts no\n // image-generation API, and `SDKAdapterContract.image` is optional —\n // its structural absence IS the capability guard, so\n // `ai.groq.image(...)` is a compile-time error rather than a runtime\n // surprise (mirrors Anthropic / Bedrock / Ollama).\n}\n\n/**\n * Built-in default USD-per-1,000,000-token rates for the current Groq\n * production models (mid-2026), used as the last fallback in `model()`'s\n * pricing resolution. A per-model or SDK-level `pricing` entry always\n * wins over these. Returns `undefined` for any unlisted id so cost stays\n * an honest absence rather than a false zero. Update when Groq revises\n * its public price list.\n */\nfunction defaultPricingFor(name: string): ModelPricing | undefined {\n return GROQ_DEFAULT_PRICING[name];\n}\n\n/**\n * Default per-million-token USD rates for known Groq models. Kept inline\n * (not exported) so the public surface stays the inference helpers; a\n * caller who wants different numbers supplies `pricing` on the SDK or\n * per model.\n */\nconst GROQ_DEFAULT_PRICING: Record<string, ModelPricing> = {\n \"llama-3.3-70b-versatile\": { input: 0.59, output: 0.79 },\n \"llama-3.1-8b-instant\": { input: 0.05, output: 0.08 },\n \"openai/gpt-oss-120b\": { input: 0.15, output: 0.75 },\n \"openai/gpt-oss-20b\": { input: 0.1, output: 0.5 },\n \"deepseek-r1-distill-llama-70b\": { input: 0.75, output: 0.99 },\n};\n"],"mappings":";;;;;;;;;;;;;AASA,MAAa,gBAAgB;;;;;;;AAQ7B,MAAa,gBAAgB;;;;;;;;;;;;;;;;;;;;;;AAuB7B,MAAM,4BAA4B;CAChC;CACA;CACA;CACA;CACA;AACF;;;;;;;;;;;;;;;AAgBA,MAAM,+BAA+B;CACnC;CACA;CACA;CACA;CACA;AACF;;;;;;;;;;;;;;AAeA,SAAgB,sBAAsB,SAA0B;CAC9D,MAAM,aAAa,QAAQ,YAAY;CAEvC,OAAO,0BAA0B,MAAM,aAAa,WAAW,SAAS,QAAQ,CAAC;AACnF;;;;;;;;;;;;AAaA,SAAgB,yBAAyB,SAA0B;CACjE,MAAM,aAAa,QAAQ,YAAY;CAEvC,OAAO,6BAA6B,MAAM,aAAa,WAAW,SAAS,QAAQ,CAAC;AACtF;;;;;;;;;;;;;;;AAgBA,MAAa,oBAAoB;CAC/B;CACA;CACA;CACA;CACA;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC9DA,IAAa,UAAb,MAAmD;CAWjD,AAAO,YAAY,QAAuB;EACxC,MAAM,EAAE,SAAS,UAAU,SAAS,GAAG,kBAAkB;EAEzD,KAAK,WAAW;EAChB,KAAK,UAAU;EAQf,KAAK,SAAS,IAAIA,gCAAU;GAC1B,GAAG;GACH,SAAS;GACT,UAAU,KAAK;GACf;EACF,CAAC;CACH;;;;;;;;;;;;;;;;;;CAmBA,AAAO,MAAM,QAAwC;EACnD,MAAM,kBACJ,OAAO,WAAW,KAAK,UAAU,OAAO,SAAS,kBAAkB,OAAO,IAAI;EAEhF,OAAO,KAAK,OAAO,MAAM;GACvB,GAAG;GAIH,QAAQ,OAAO,UAAU,sBAAsB,OAAO,IAAI;GAC1D,WAAW,OAAO,aAAa,yBAAyB,OAAO,IAAI;GACnE,kBAAkB,OAAO,oBAAoB;GAC7C,SAAS;EACX,CAAC;CACH;;;;;;;CAQA,MAAa,MAAM,MAAc,OAAiC;EAChE,OAAO,KAAK,OAAO,MAAM,MAAM,KAAK;CACtC;;;;;;;;;;;CAYA,AAAO,SAAS,QAA8C;EAC5D,OAAO,KAAK,OAAO,SAAS,MAAM;CACpC;AAOF;;;;;;;;;AAUA,SAAS,kBAAkB,MAAwC;CACjE,OAAO,qBAAqB;AAC9B;;;;;;;AAQA,MAAM,uBAAqD;CACzD,2BAA2B;EAAE,OAAO;EAAM,QAAQ;CAAK;CACvD,wBAAwB;EAAE,OAAO;EAAM,QAAQ;CAAK;CACpD,uBAAuB;EAAE,OAAO;EAAM,QAAQ;CAAK;CACnD,sBAAsB;EAAE,OAAO;EAAK,QAAQ;CAAI;CAChD,iCAAiC;EAAE,OAAO;EAAM,QAAQ;CAAK;AAC/D"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { OpenAISDKConfig } from "@warlock.js/ai-openai";
|
|
2
|
+
import { EmbedderConfig, ModelConfig, ModelPricing } from "@warlock.js/ai";
|
|
3
|
+
|
|
4
|
+
//#region ../@warlock.js/ai-groq/src/config.type.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for the Groq SDK adapter.
|
|
7
|
+
*
|
|
8
|
+
* Groq speaks the OpenAI Chat Completions wire protocol, so this type
|
|
9
|
+
* is structurally `OpenAISDKConfig` (which is `openai`'s `ClientOptions`
|
|
10
|
+
* + `provider` + `pricing`) with two ergonomic differences:
|
|
11
|
+
*
|
|
12
|
+
* - `baseURL` is **optional** here — it defaults to Groq's
|
|
13
|
+
* OpenAI-compatible endpoint (`https://api.groq.com/openai/v1`) when
|
|
14
|
+
* omitted, so the common path is just `{ apiKey }`. Override it only
|
|
15
|
+
* to point at a proxy/gateway.
|
|
16
|
+
* - `provider` defaults to `"groq"` (not `"openai"`), so every model the
|
|
17
|
+
* SDK produces self-identifies as Groq on `ModelContract.provider`,
|
|
18
|
+
* `AgentReport.model`, logs, and provider-aware middleware.
|
|
19
|
+
*
|
|
20
|
+
* Every other upstream `ClientOptions` field (`timeout`, `maxRetries`,
|
|
21
|
+
* `defaultHeaders`, `fetch`, `organization`, …) is forwarded verbatim to
|
|
22
|
+
* the internal `OpenAISDK` it wraps.
|
|
23
|
+
*
|
|
24
|
+
* `pricing` is an optional SDK-level registry keyed by model name.
|
|
25
|
+
* Resolution at `model()` call time: per-model `pricing` > this SDK
|
|
26
|
+
* registry > the adapter's built-in default rates for known Groq models
|
|
27
|
+
* > `undefined` (no cost computed).
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // Common path — apiKey only; baseURL + provider default to Groq.
|
|
31
|
+
* new GroqSDK({ apiKey: process.env.GROQ_API_KEY! });
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* // SDK-level pricing registry — USD per 1,000,000 tokens.
|
|
35
|
+
* new GroqSDK({
|
|
36
|
+
* apiKey,
|
|
37
|
+
* pricing: { "llama-3.3-70b-versatile": { input: 0.59, output: 0.79 } },
|
|
38
|
+
* });
|
|
39
|
+
*/
|
|
40
|
+
type GroqSDKConfig = Omit<OpenAISDKConfig, "baseURL" | "provider"> & {
|
|
41
|
+
/**
|
|
42
|
+
* Override Groq's OpenAI-compatible endpoint. Defaults to
|
|
43
|
+
* `https://api.groq.com/openai/v1` when omitted — set this only to
|
|
44
|
+
* route through a proxy or self-hosted gateway.
|
|
45
|
+
*/
|
|
46
|
+
baseURL?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Override the upstream provider label. Defaults to `"groq"`; flows
|
|
49
|
+
* through to `ModelContract.provider` and every report/log derived
|
|
50
|
+
* from it.
|
|
51
|
+
*/
|
|
52
|
+
provider?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Per-model USD pricing registry, keyed by model name. Surfaced onto
|
|
55
|
+
* every model produced by `model()`; per-model `GroqModelConfig.pricing`
|
|
56
|
+
* still wins when both are set, and the adapter's built-in default
|
|
57
|
+
* rates fill the gap when neither is provided.
|
|
58
|
+
*/
|
|
59
|
+
pricing?: Record<string, ModelPricing>;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Per-model configuration for `GroqSDK.model()`. `name` is the
|
|
63
|
+
* Groq-hosted model id — the upstream open-weight name (e.g.
|
|
64
|
+
* `"llama-3.3-70b-versatile"`, `"openai/gpt-oss-120b"`,
|
|
65
|
+
* `"deepseek-r1-distill-llama-70b"`), NOT an OpenAI id.
|
|
66
|
+
*
|
|
67
|
+
* The capability overrides mirror the OpenAI adapter, but their
|
|
68
|
+
* auto-inference is driven by **Groq's** model-name lists
|
|
69
|
+
* (`known-models.ts`) rather than OpenAI's — that is the core reason
|
|
70
|
+
* this wrapper exists. Any explicit `true`/`false` always wins over
|
|
71
|
+
* inference.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* groq.model({ name: "llama-3.3-70b-versatile" }); // text, no vision/reasoning
|
|
75
|
+
* groq.model({ name: "openai/gpt-oss-120b" }); // vision + reasoning auto-true
|
|
76
|
+
* groq.model({ name: "custom-llama", vision: true }); // explicit override
|
|
77
|
+
*/
|
|
78
|
+
type GroqModelConfig = ModelConfig & {
|
|
79
|
+
/**
|
|
80
|
+
* Override the auto-inferred vision capability. When omitted, the
|
|
81
|
+
* adapter checks the model id against Groq's known multimodal families
|
|
82
|
+
* (see `known-models.ts`) — `true` for `gpt-oss` / `llama-4` /
|
|
83
|
+
* `llama-3.2-*-vision`, `false` otherwise. Explicit `true`/`false`
|
|
84
|
+
* always wins.
|
|
85
|
+
*/
|
|
86
|
+
vision?: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Override the auto-inferred reasoning capability. When omitted, the
|
|
89
|
+
* adapter checks the model id against Groq's known reasoning families
|
|
90
|
+
* (see `known-models.ts`) — `true` for `gpt-oss` / `deepseek-r1` /
|
|
91
|
+
* `qwq` / `qwen3`, `false` otherwise. Drives whether
|
|
92
|
+
* `ModelCallOptions.reasoning` maps to `reasoning_effort` on the wire.
|
|
93
|
+
* Explicit `true`/`false` always wins.
|
|
94
|
+
*/
|
|
95
|
+
reasoning?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Override the inferred `structuredOutput` capability. Defaults to
|
|
98
|
+
* `true` — Groq's Chat Completions endpoint accepts OpenAI-style
|
|
99
|
+
* `response_format`. Set `false` (or pass `responseFormat` on the
|
|
100
|
+
* underlying model) for a model that rejects strict `json_schema`, so
|
|
101
|
+
* the agent re-injects a soft schema hint into the system prompt.
|
|
102
|
+
*/
|
|
103
|
+
structuredOutput?: boolean;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Per-embedder configuration for `GroqSDK.embedder()`. Mirrors the
|
|
107
|
+
* neutral {@link EmbedderConfig}.
|
|
108
|
+
*
|
|
109
|
+
* NOTE: as of mid-2026 Groq does **not** expose an OpenAI-compatible
|
|
110
|
+
* embeddings endpoint — `embedder()` is delegated to the inner
|
|
111
|
+
* `OpenAISDK` for API symmetry, but a live `.embed()` call will fail at
|
|
112
|
+
* the provider. Use a dedicated embeddings provider
|
|
113
|
+
* (`@warlock.js/ai-openai` / `@warlock.js/ai-google`) for retrieval.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* // Will construct, but Groq currently has no embeddings model to call.
|
|
117
|
+
* groq.embedder({ name: "some-future-embeddings-model" });
|
|
118
|
+
*/
|
|
119
|
+
type GroqEmbedderConfig = EmbedderConfig;
|
|
120
|
+
//#endregion
|
|
121
|
+
export { GroqEmbedderConfig, GroqModelConfig, GroqSDKConfig };
|
|
122
|
+
//# sourceMappingURL=config.type.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.type.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai-groq/src/config.type.ts"],"mappings":";;;;;;AAsCA;;;;;;;;;;;;;;;;;AAmBuC;AAoBvC;;;;;;;;;AAyBkB;AAiBlB;;;;AAA+C;KAjFnC,aAAA,GAAgB,IAAA,CAAK,eAAA;;;;;;EAM/B,OAAA;;;;;;EAMA,QAAA;;;;;;;EAOA,OAAA,GAAU,MAAA,SAAe,YAAA;AAAA;;;;;;;;;;;;;;;;;;KAoBf,eAAA,GAAkB,WAAW;;;;;;;;EAQvC,MAAA;;;;;;;;;EASA,SAAA;;;;;;;;EAQA,gBAAA;AAAA;;;;;;;;;;;;;;;KAiBU,kBAAA,GAAqB,cAAc"}
|
package/esm/index.d.mts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { GroqEmbedderConfig, GroqModelConfig, GroqSDKConfig } from "./config.type.mjs";
|
|
2
|
+
import { GroqSDK } from "./sdk.mjs";
|
|
3
|
+
import { GROQ_BASE_URL, GROQ_KNOWN_MODELS, GROQ_PROVIDER, inferReasoningCapability, inferVisionCapability } from "./known-models.mjs";
|
|
4
|
+
export { GROQ_BASE_URL, GROQ_KNOWN_MODELS, GROQ_PROVIDER, type GroqEmbedderConfig, type GroqModelConfig, GroqSDK, type GroqSDKConfig, inferReasoningCapability, inferVisionCapability };
|
package/esm/index.mjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { GROQ_BASE_URL, GROQ_KNOWN_MODELS, GROQ_PROVIDER, inferReasoningCapability, inferVisionCapability } from "./known-models.mjs";
|
|
2
|
+
import { GroqSDK } from "./sdk.mjs";
|
|
3
|
+
|
|
4
|
+
export { GROQ_BASE_URL, GROQ_KNOWN_MODELS, GROQ_PROVIDER, GroqSDK, inferReasoningCapability, inferVisionCapability };
|