promptopskit 0.0.1

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 ADDED
@@ -0,0 +1,211 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Predictability at Scale, Inc.
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.
22
+ Apache License
23
+ Version 2.0, January 2004
24
+ http://www.apache.org/licenses/
25
+
26
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
27
+
28
+ 1. Definitions.
29
+
30
+ "License" shall mean the terms and conditions for use, reproduction,
31
+ and distribution as defined by Sections 1 through 9 of this document.
32
+
33
+ "Licensor" shall mean the copyright owner or entity authorized by
34
+ the copyright owner that is granting the License.
35
+
36
+ "Legal Entity" shall mean the union of the acting entity and all
37
+ other entities that control, are controlled by, or are under common
38
+ control with that entity. For the purposes of this definition,
39
+ "control" means (i) the power, direct or indirect, to cause the
40
+ direction or management of such entity, whether by contract or
41
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
42
+ outstanding shares, or (iii) beneficial ownership of such entity.
43
+
44
+ "You" (or "Your") shall mean an individual or Legal Entity
45
+ exercising permissions granted by this License.
46
+
47
+ "Source" form shall mean the preferred form for making modifications,
48
+ including but not limited to software source code, documentation
49
+ source, and configuration files.
50
+
51
+ "Object" form shall mean any form resulting from mechanical
52
+ transformation or translation of a Source form, including but
53
+ not limited to compiled object code, generated documentation,
54
+ and conversions to other media types.
55
+
56
+ "Work" shall mean the work of authorship, whether in Source or
57
+ Object form, made available under the License, as indicated by a
58
+ copyright notice that is included in or attached to the work
59
+ (an example is provided in the Appendix below).
60
+
61
+ "Derivative Works" shall mean any work, whether in Source or Object
62
+ form, that is based on (or derived from) the Work and for which the
63
+ editorial revisions, annotations, elaborations, or other modifications
64
+ represent, as a whole, an original work of authorship. For the purposes
65
+ of this License, Derivative Works shall not include works that remain
66
+ separable from, or merely link (or bind by name) to the interfaces of,
67
+ the Work and Derivative Works thereof.
68
+
69
+ "Contribution" shall mean any work of authorship, including
70
+ the original version of the Work and any modifications or additions
71
+ to that Work or Derivative Works thereof, that is intentionally
72
+ submitted to the Licensor for inclusion in the Work by the copyright owner
73
+ or by an individual or Legal Entity authorized to submit on behalf of
74
+ the copyright owner. For the purposes of this definition, "submitted"
75
+ means any form of electronic, verbal, or written communication sent
76
+ to the Licensor or its representatives, including but not limited to
77
+ communication on electronic mailing lists, source code control systems,
78
+ and issue tracking systems that are managed by, or on behalf of, the
79
+ Licensor for the purpose of discussing and improving the Work, but
80
+ excluding communication that is conspicuously marked or otherwise
81
+ designated in writing by the copyright owner as "Not a Contribution."
82
+
83
+ "Contributor" shall mean Licensor and any individual or Legal Entity
84
+ on behalf of whom a Contribution has been received by the Licensor and
85
+ subsequently incorporated within the Work.
86
+
87
+ 2. Grant of Copyright License. Subject to the terms and conditions of
88
+ this License, each Contributor hereby grants to You a perpetual,
89
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
90
+ copyright license to reproduce, prepare Derivative Works of,
91
+ publicly display, publicly perform, sublicense, and distribute the
92
+ Work and such Derivative Works in Source or Object form.
93
+
94
+ 3. Grant of Patent License. Subject to the terms and conditions of
95
+ this License, each Contributor hereby grants to You a perpetual,
96
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
97
+ (except as stated in this section) patent license to make, have made,
98
+ use, offer to sell, sell, import, and otherwise transfer the Work,
99
+ where such license applies only to those patent claims licensable
100
+ by such Contributor that are necessarily infringed by their
101
+ Contribution(s) alone or by combination of their Contribution(s)
102
+ with the Work to which such Contribution(s) was submitted. If You
103
+ institute patent litigation against any entity (including a
104
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
105
+ or a Contribution incorporated within the Work constitutes direct
106
+ or contributory patent infringement, then any patent licenses
107
+ granted to You under this License for that Work shall terminate
108
+ as of the date such litigation is filed.
109
+
110
+ 4. Redistribution. You may reproduce and distribute copies of the
111
+ Work or Derivative Works thereof in any medium, with or without
112
+ modifications, and in Source or Object form, provided that You
113
+ meet the following conditions:
114
+
115
+ (a) You must give any other recipients of the Work or
116
+ Derivative Works a copy of this License; and
117
+
118
+ (b) You must cause any modified files to carry prominent notices
119
+ stating that You changed the files; and
120
+
121
+ (c) You must retain, in the Source form of any Derivative Works
122
+ that You distribute, all copyright, patent, trademark, and
123
+ attribution notices from the Source form of the Work,
124
+ excluding those notices that do not pertain to any part of
125
+ the Derivative Works; and
126
+
127
+ (d) If the Work includes a "NOTICE" text file as part of its
128
+ distribution, then any Derivative Works that You distribute must
129
+ include a readable copy of the attribution notices contained
130
+ within such NOTICE file, excluding any notices that do not
131
+ pertain to any part of the Derivative Works, in at least one
132
+ of the following places: within a NOTICE text file distributed
133
+ as part of the Derivative Works; within the Source form or
134
+ documentation, if provided along with the Derivative Works; or,
135
+ within a display generated by the Derivative Works, if and
136
+ wherever such third-party notices normally appear. The contents
137
+ of the NOTICE file are for informational purposes only and
138
+ do not modify the License. You may add Your own attribution
139
+ notices within Derivative Works that You distribute, alongside
140
+ or as an addendum to the NOTICE text from the Work, provided
141
+ that such additional attribution notices cannot be construed
142
+ as modifying the License.
143
+
144
+ You may add Your own copyright statement to Your modifications and
145
+ may provide additional or different license terms and conditions
146
+ for use, reproduction, or distribution of Your modifications, or
147
+ for any such Derivative Works as a whole, provided Your use,
148
+ reproduction, and distribution of the Work otherwise complies with
149
+ the conditions stated in this License.
150
+
151
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
152
+ any Contribution intentionally submitted for inclusion in the Work
153
+ by You to the Licensor shall be under the terms and conditions of
154
+ this License, without any additional terms or conditions.
155
+ Notwithstanding the above, nothing herein shall supersede or modify
156
+ the terms of any separate license agreement you may have executed
157
+ with Licensor regarding such Contributions.
158
+
159
+ 6. Trademarks. This License does not grant permission to use the trade
160
+ names, trademarks, service marks, or product names of the Licensor,
161
+ except as required for reasonable and customary use in describing the
162
+ origin of the Work and reproducing the content of the NOTICE file.
163
+
164
+ 7. Disclaimer of Warranty. Unless required by applicable law or
165
+ agreed to in writing, Licensor provides the Work (and each
166
+ Contributor provides its Contributions) on an "AS IS" BASIS,
167
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
168
+ implied, including, without limitation, any warranties or conditions
169
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
170
+ PARTICULAR PURPOSE. You are solely responsible for determining the
171
+ appropriateness of using or redistributing the Work and assume any
172
+ risks associated with Your exercise of permissions under this License.
173
+
174
+ 8. Limitation of Liability. In no event and under no legal theory,
175
+ whether in tort (including negligence), contract, or otherwise,
176
+ unless required by applicable law (such as deliberate and grossly
177
+ negligent acts) or agreed to in writing, shall any Contributor be
178
+ liable to You for damages, including any direct, indirect, special,
179
+ incidental, or consequential damages of any character arising as a
180
+ result of this License or out of the use or inability to use the
181
+ Work (including but not limited to damages for loss of goodwill,
182
+ work stoppage, computer failure or malfunction, or any and all
183
+ other commercial damages or losses), even if such Contributor
184
+ has been advised of the possibility of such damages.
185
+
186
+ 9. Accepting Warranty or Additional Liability. While redistributing
187
+ the Work or Derivative Works thereof, You may choose to offer,
188
+ and charge a fee for, acceptance of support, warranty, indemnity,
189
+ or other liability obligations and/or rights consistent with this
190
+ License. However, in accepting such obligations, You may act only
191
+ on Your own behalf and on Your sole responsibility, not on behalf
192
+ of any other Contributor, and only if You agree to indemnify,
193
+ defend, and hold each Contributor harmless for any liability
194
+ incurred by, or claims asserted against, such Contributor by reason
195
+ of your accepting any such warranty or additional liability.
196
+
197
+ END OF TERMS AND CONDITIONS
198
+
199
+ Copyright 2026 PredictabilityAtScale
200
+
201
+ Licensed under the Apache License, Version 2.0 (the "License");
202
+ you may not use this file except in compliance with the License.
203
+ You may obtain a copy of the License at
204
+
205
+ http://www.apache.org/licenses/LICENSE-2.0
206
+
207
+ Unless required by applicable law or agreed to in writing, software
208
+ distributed under the License is distributed on an "AS IS" BASIS,
209
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
210
+ See the License for the specific language governing permissions and
211
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,309 @@
1
+ # PromptOpsKit
2
+
3
+ [![npm version](https://img.shields.io/npm/v/promptopskit.svg)](https://www.npmjs.com/package/promptopskit)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
5
+ [![Node.js](https://img.shields.io/badge/node-%3E%3D20-brightgreen.svg)](https://nodejs.org)
6
+
7
+ Open-source developer toolkit for managing prompts, system instructions, tools, and model settings **as code**. One `npm install` gives you both a runtime library and a CLI.
8
+
9
+ PromptOpsKit treats every prompt as a Markdown file — YAML front matter defines model settings, sampling parameters, reasoning levels, tool bindings, and override rules, while H1 headings separate system instructions from prompt templates. Variables use `{{ mustache }}` syntax, shared instructions are composed via `includes`, and environment/tier overrides let the same prompt target dev vs. prod or free vs. pro without duplication.
10
+
11
+ Provider adapters for OpenAI, Anthropic, Gemini, and OpenRouter produce a ready-to-send **request body only** — no HTTP client, no auth, no headers. Your application owns transport, so PromptOpsKit slots into any stack without opinions about how you call the API.
12
+
13
+ ### Why PromptOpsKit?
14
+
15
+ - **Version-control your prompts** — plain Markdown files that diff, review, and merge like any other code.
16
+ - **One prompt, many providers** — write once, render for OpenAI, Anthropic, Gemini, or OpenRouter with correct body shapes.
17
+ - **Override without forking** — environment and tier overrides swap models and parameters without duplicating prompt files.
18
+ - **Compose and share** — `includes` lets you define shared tone, policy, or safety instructions once and reuse them everywhere.
19
+ - **Validate early** — Zod schema validation, Levenshtein-based "did you mean?" suggestions for typos, and variable usage checks catch mistakes before runtime.
20
+ - **Compile for production** — pre-compile `.md` to JSON or ESM so deployments skip parsing entirely.
21
+ - **No lock-in** — body-only output means you choose the HTTP client, auth strategy, and infrastructure.
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ npm install promptopskit
27
+ ```
28
+
29
+ ## Quick Start
30
+
31
+ ### 1. Scaffold starter prompts
32
+
33
+ ```bash
34
+ npx promptopskit init ./prompts
35
+ ```
36
+
37
+ This creates:
38
+
39
+ ```
40
+ prompts/
41
+ ├── hello.md # Sample prompt with variables
42
+ ├── hello.test.yaml # Test sidecar with sample inputs
43
+ └── shared/
44
+ └── tone.md # Shared system instructions (included via composition)
45
+ ```
46
+
47
+ ### 2. Write a prompt
48
+
49
+ ```markdown
50
+ ---
51
+ id: support.reply
52
+ schema_version: 1
53
+ provider: openai
54
+ model: gpt-5.4
55
+ reasoning:
56
+ effort: medium
57
+ sampling:
58
+ temperature: 0.7
59
+ context:
60
+ inputs:
61
+ - user_message
62
+ includes:
63
+ - ./shared/tone.md
64
+ ---
65
+
66
+ # System instructions
67
+
68
+ You are a helpful support assistant.
69
+
70
+ # Prompt template
71
+
72
+ {{ user_message }}
73
+ ```
74
+
75
+ ### 3. Render for a provider
76
+
77
+ ```typescript
78
+ import { createPromptOpsKit } from 'promptopskit';
79
+
80
+ const kit = createPromptOpsKit({ sourceDir: './prompts' });
81
+
82
+ const result = await kit.renderPrompt({
83
+ path: 'support/reply',
84
+ provider: 'openai',
85
+ variables: { user_message: 'How do I reset my password?' },
86
+ });
87
+
88
+ // result.request.body is ready for fetch()
89
+ const response = await fetch('https://api.openai.com/v1/chat/completions', {
90
+ method: 'POST',
91
+ headers: {
92
+ 'Content-Type': 'application/json',
93
+ 'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`,
94
+ },
95
+ body: JSON.stringify(result.request.body),
96
+ });
97
+ ```
98
+
99
+ ## Features
100
+
101
+ - **Prompts as Markdown** — YAML front matter for settings, H1 headings for sections (`# System instructions`, `# Prompt template`, `# Notes`)
102
+ - **Variable interpolation** — `{{ variable }}` syntax with strict and permissive modes
103
+ - **Composition** — `includes` to share system instructions across prompts, with circular detection
104
+ - **Overrides** — Environment and tier-based overrides (base → env → tier → runtime)
105
+ - **4 provider adapters** — OpenAI, Anthropic, Gemini, OpenRouter — body-only output
106
+ - **Validation** — Zod schema validation, Levenshtein-based "did you mean?" for typos, variable usage checks
107
+ - **Caching** — LRU cache with mtime-based invalidation
108
+ - **CLI** — init, validate, compile, render, inspect
109
+ - **Compiled artifacts** — Pre-compile `.md` → JSON or ESM for production
110
+
111
+ ## Provider Adapters
112
+
113
+ Each adapter produces a `{ body, provider, model }` object shaped for the target API. You handle the HTTP call.
114
+
115
+ ```typescript
116
+ // OpenAI
117
+ import { createPromptOpsKit } from 'promptopskit';
118
+ const kit = createPromptOpsKit({ sourceDir: './prompts' });
119
+ const { request } = await kit.renderPrompt({ path: 'hello', provider: 'openai', variables: { name: 'World' } });
120
+ // request.body → { model, messages, temperature, reasoning_effort, ... }
121
+
122
+ // Anthropic — system is a top-level field, max_tokens defaults to 4096
123
+ const { request } = await kit.renderPrompt({ path: 'hello', provider: 'anthropic', variables: { name: 'World' } });
124
+ // request.body → { model, messages, system, max_tokens, ... }
125
+
126
+ // Gemini — contents/systemInstruction/generationConfig structure
127
+ const { request } = await kit.renderPrompt({ path: 'hello', provider: 'gemini', variables: { name: 'World' } });
128
+ // request.body → { contents, systemInstruction, generationConfig, ... }
129
+
130
+ // OpenRouter — same shape as OpenAI, different provider label
131
+ const { request } = await kit.renderPrompt({ path: 'hello', provider: 'openrouter', variables: { name: 'World' } });
132
+ ```
133
+
134
+ Provider adapters are also available as direct imports:
135
+
136
+ ```typescript
137
+ import { openaiAdapter } from 'promptopskit/openai';
138
+ import { anthropicAdapter } from 'promptopskit/anthropic';
139
+ import { geminiAdapter } from 'promptopskit/gemini';
140
+ import { openrouterAdapter } from 'promptopskit/openrouter';
141
+ ```
142
+
143
+ ## Overrides
144
+
145
+ Define environment and tier overrides in front matter. Precedence: **base → environment → tier → runtime**. Scalars and arrays are replaced, not merged.
146
+
147
+ ```markdown
148
+ ---
149
+ id: support.reply
150
+ schema_version: 1
151
+ provider: openai
152
+ model: gpt-5.4
153
+ sampling:
154
+ temperature: 0.7
155
+ environments:
156
+ dev:
157
+ model: gpt-5.4-mini
158
+ sampling:
159
+ temperature: 0.2
160
+ prod:
161
+ model: gpt-5.4
162
+ tiers:
163
+ free:
164
+ model: gpt-5.4-mini
165
+ pro:
166
+ model: gpt-5.4
167
+ ---
168
+ ```
169
+
170
+ ```typescript
171
+ const result = await kit.renderPrompt({
172
+ path: 'support/reply',
173
+ provider: 'openai',
174
+ environment: 'dev',
175
+ tier: 'pro',
176
+ variables: { user_message: '...' },
177
+ });
178
+ ```
179
+
180
+ ## Composition
181
+
182
+ Share system instructions across prompts using `includes`. Included system instructions are prepended before local ones.
183
+
184
+ ```markdown
185
+ ---
186
+ id: support.reply
187
+ schema_version: 1
188
+ includes:
189
+ - ./shared/tone.md
190
+ ---
191
+
192
+ # System instructions
193
+
194
+ Handle support requests carefully.
195
+ ```
196
+
197
+ ## CLI
198
+
199
+ ```bash
200
+ # Scaffold starter prompts
201
+ promptopskit init [dir]
202
+
203
+ # Validate all .md files in a directory
204
+ promptopskit validate <dir> [--strict]
205
+
206
+ # Compile .md → JSON/ESM artifacts
207
+ promptopskit compile <src> <out> [--dry-run] [--format json|esm] [--no-clean]
208
+
209
+ # Render a prompt preview (auto-loads .test.yaml sidecar)
210
+ promptopskit render <file> [--env <name>] [--tier <name>] [--vars <file>] [--json]
211
+
212
+ # Print normalized asset as JSON
213
+ promptopskit inspect <file>
214
+ ```
215
+
216
+ ## Inline Source
217
+
218
+ Render prompts from strings without files:
219
+
220
+ ```typescript
221
+ const result = await kit.renderPrompt({
222
+ source: `---
223
+ id: inline
224
+ schema_version: 1
225
+ provider: openai
226
+ model: gpt-5.4
227
+ ---
228
+
229
+ # Prompt template
230
+
231
+ Hello {{ name }}!`,
232
+ provider: 'openai',
233
+ variables: { name: 'World' },
234
+ });
235
+ ```
236
+
237
+ ## Testing Helpers
238
+
239
+ ```typescript
240
+ import { createMockAsset, createMockResolvedAsset, parseTestPrompt } from 'promptopskit/testing';
241
+
242
+ const asset = createMockAsset({ model: 'gpt-5.4' });
243
+ const resolved = createMockResolvedAsset();
244
+ const parsed = parseTestPrompt('---\nid: test\nschema_version: 1\n---\n\nHello');
245
+ ```
246
+
247
+ ## API Reference
248
+
249
+ ### `createPromptOpsKit(config)`
250
+
251
+ Creates a `PromptOpsKit` instance.
252
+
253
+ | Option | Type | Default | Description |
254
+ |--------|------|---------|-------------|
255
+ | `sourceDir` | `string` | — | Path to prompt `.md` files (required) |
256
+ | `compiledDir` | `string` | — | Path to compiled artifacts |
257
+ | `mode` | `'auto' \| 'compiled-only' \| 'source-only'` | `'auto'` | Resolution strategy |
258
+ | `cache` | `boolean` | `true` | Enable LRU cache with mtime invalidation |
259
+
260
+ ### `kit.renderPrompt(options)`
261
+
262
+ Renders a prompt for a specific provider. Returns `{ resolved, request, warnings }`.
263
+
264
+ | Option | Type | Description |
265
+ |--------|------|-------------|
266
+ | `path` | `string` | Prompt path (no extension), e.g. `'support/reply'` |
267
+ | `source` | `string` | Inline prompt source (alternative to path) |
268
+ | `provider` | `string` | `'openai'`, `'anthropic'`, `'gemini'`, `'openrouter'` |
269
+ | `variables` | `Record<string, string>` | Template variables |
270
+ | `environment` | `string` | Environment override name |
271
+ | `tier` | `string` | Tier override name |
272
+ | `history` | `Array<{ role, content }>` | Conversation history |
273
+ | `strict` | `boolean` | Fail on missing variables |
274
+
275
+ ### `kit.loadPrompt(path)` / `kit.resolvePrompt(path, options)` / `kit.validatePrompt(path)`
276
+
277
+ Lower-level methods for loading, resolving (includes + overrides), and validating individual prompts.
278
+
279
+ ### Standalone Functions
280
+
281
+ ```typescript
282
+ import { parsePrompt, interpolate, extractVariables, resolveIncludes, applyOverrides, validateAsset, getAdapter } from 'promptopskit';
283
+ ```
284
+
285
+ ## Schema
286
+
287
+ Prompt files use YAML front matter with these fields:
288
+
289
+ | Field | Type | Description |
290
+ |-------|------|-------------|
291
+ | `id` | `string` | Unique prompt identifier (required) |
292
+ | `schema_version` | `number` | Schema version, currently `1` |
293
+ | `provider` | `string` | `openai`, `anthropic`, `google`, `openrouter`, `any` |
294
+ | `model` | `string` | Model name |
295
+ | `fallback_models` | `string[]` | Fallback model list |
296
+ | `reasoning` | `object` | `{ effort, budget_tokens }` |
297
+ | `sampling` | `object` | `{ temperature, top_p, frequency_penalty, presence_penalty, stop, max_output_tokens }` |
298
+ | `response` | `object` | `{ format, stream }` |
299
+ | `tools` | `array` | Tool references (string names or inline definitions) |
300
+ | `mcp` | `object` | MCP server references |
301
+ | `context` | `object` | `{ inputs, history }` — declare expected variables |
302
+ | `includes` | `string[]` | Paths to included prompt files |
303
+ | `environments` | `object` | Named environment overrides |
304
+ | `tiers` | `object` | Named tier overrides |
305
+ | `metadata` | `object` | `{ owner, tags, review_required, stable }` |
306
+
307
+ ## License
308
+
309
+ [MIT](LICENSE)
@@ -0,0 +1,88 @@
1
+ import {
2
+ renderSections
3
+ } from "./chunk-HEFOFQ2K.js";
4
+
5
+ // src/providers/anthropic.ts
6
+ var anthropicAdapter = {
7
+ name: "anthropic",
8
+ validate(asset) {
9
+ const errors = [];
10
+ const warnings = [];
11
+ if (!asset.model) {
12
+ errors.push("Anthropic adapter requires a model to be specified.");
13
+ }
14
+ if (asset.sampling?.frequency_penalty !== void 0) {
15
+ warnings.push("Anthropic does not support frequency_penalty. It will be ignored.");
16
+ }
17
+ if (asset.sampling?.presence_penalty !== void 0) {
18
+ warnings.push("Anthropic does not support presence_penalty. It will be ignored.");
19
+ }
20
+ if (asset.reasoning?.effort !== void 0) {
21
+ warnings.push("Anthropic uses budget_tokens for thinking, not effort. effort will be mapped approximately.");
22
+ }
23
+ return { valid: errors.length === 0, errors, warnings };
24
+ },
25
+ render(asset, runtime) {
26
+ const sections = renderSections(asset, {
27
+ variables: runtime.variables,
28
+ strict: runtime.strict
29
+ });
30
+ const messages = [];
31
+ if (runtime.history) {
32
+ for (const msg of runtime.history) {
33
+ messages.push({ role: msg.role, content: msg.content });
34
+ }
35
+ }
36
+ if (sections.prompt_template) {
37
+ messages.push({ role: "user", content: sections.prompt_template });
38
+ }
39
+ const body = {
40
+ model: asset.model,
41
+ messages
42
+ };
43
+ if (sections.system_instructions) {
44
+ body.system = sections.system_instructions;
45
+ }
46
+ if (asset.sampling?.temperature !== void 0) body.temperature = asset.sampling.temperature;
47
+ if (asset.sampling?.top_p !== void 0) body.top_p = asset.sampling.top_p;
48
+ if (asset.sampling?.stop !== void 0) body.stop_sequences = asset.sampling.stop;
49
+ if (asset.sampling?.max_output_tokens !== void 0) {
50
+ body.max_tokens = asset.sampling.max_output_tokens;
51
+ } else {
52
+ body.max_tokens = 4096;
53
+ }
54
+ if (asset.reasoning?.budget_tokens) {
55
+ body.thinking = {
56
+ type: "enabled",
57
+ budget_tokens: asset.reasoning.budget_tokens
58
+ };
59
+ }
60
+ if (asset.response?.stream !== void 0) {
61
+ body.stream = asset.response.stream;
62
+ }
63
+ if (asset.tools && asset.tools.length > 0) {
64
+ body.tools = asset.tools.map((tool) => {
65
+ if (typeof tool === "string") {
66
+ const def = runtime.toolRegistry?.[tool];
67
+ if (def) return def;
68
+ return { name: tool };
69
+ }
70
+ return {
71
+ name: tool.name,
72
+ description: tool.description,
73
+ input_schema: tool.input_schema ?? { type: "object", properties: {} }
74
+ };
75
+ });
76
+ }
77
+ return {
78
+ body,
79
+ provider: "anthropic",
80
+ model: asset.model ?? "unknown"
81
+ };
82
+ }
83
+ };
84
+
85
+ export {
86
+ anthropicAdapter
87
+ };
88
+ //# sourceMappingURL=chunk-B5UFGNDV.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/providers/anthropic.ts"],"sourcesContent":["import type { ResolvedPromptAsset } from '../schema/index.js';\r\nimport type {\r\n ProviderAdapter,\r\n ProviderRequest,\r\n ValidationResult,\r\n RuntimeRenderOptions,\r\n} from './types.js';\r\nimport { renderSections } from '../renderer/index.js';\r\n\r\n/**\r\n * Anthropic provider adapter.\r\n * Produces request bodies compatible with the Anthropic Messages API.\r\n */\r\nexport const anthropicAdapter: ProviderAdapter = {\r\n name: 'anthropic',\r\n\r\n validate(asset: ResolvedPromptAsset): ValidationResult {\r\n const errors: string[] = [];\r\n const warnings: string[] = [];\r\n\r\n if (!asset.model) {\r\n errors.push('Anthropic adapter requires a model to be specified.');\r\n }\r\n\r\n if (asset.sampling?.frequency_penalty !== undefined) {\r\n warnings.push('Anthropic does not support frequency_penalty. It will be ignored.');\r\n }\r\n if (asset.sampling?.presence_penalty !== undefined) {\r\n warnings.push('Anthropic does not support presence_penalty. It will be ignored.');\r\n }\r\n if (asset.reasoning?.effort !== undefined) {\r\n warnings.push('Anthropic uses budget_tokens for thinking, not effort. effort will be mapped approximately.');\r\n }\r\n\r\n return { valid: errors.length === 0, errors, warnings };\r\n },\r\n\r\n render(asset: ResolvedPromptAsset, runtime: RuntimeRenderOptions): ProviderRequest {\r\n const sections = renderSections(asset, {\r\n variables: runtime.variables,\r\n strict: runtime.strict,\r\n });\r\n\r\n const messages: Array<Record<string, unknown>> = [];\r\n\r\n // History\r\n if (runtime.history) {\r\n for (const msg of runtime.history) {\r\n messages.push({ role: msg.role, content: msg.content });\r\n }\r\n }\r\n\r\n // User message (prompt template)\r\n if (sections.prompt_template) {\r\n messages.push({ role: 'user', content: sections.prompt_template });\r\n }\r\n\r\n const body: Record<string, unknown> = {\r\n model: asset.model,\r\n messages,\r\n };\r\n\r\n // System goes as top-level field in Anthropic\r\n if (sections.system_instructions) {\r\n body.system = sections.system_instructions;\r\n }\r\n\r\n // Sampling params\r\n if (asset.sampling?.temperature !== undefined) body.temperature = asset.sampling.temperature;\r\n if (asset.sampling?.top_p !== undefined) body.top_p = asset.sampling.top_p;\r\n if (asset.sampling?.stop !== undefined) body.stop_sequences = asset.sampling.stop;\r\n if (asset.sampling?.max_output_tokens !== undefined) {\r\n body.max_tokens = asset.sampling.max_output_tokens;\r\n } else {\r\n // Anthropic requires max_tokens\r\n body.max_tokens = 4096;\r\n }\r\n\r\n // Thinking/reasoning\r\n if (asset.reasoning?.budget_tokens) {\r\n body.thinking = {\r\n type: 'enabled',\r\n budget_tokens: asset.reasoning.budget_tokens,\r\n };\r\n }\r\n\r\n // Streaming\r\n if (asset.response?.stream !== undefined) {\r\n body.stream = asset.response.stream;\r\n }\r\n\r\n // Tools\r\n if (asset.tools && asset.tools.length > 0) {\r\n body.tools = asset.tools.map((tool) => {\r\n if (typeof tool === 'string') {\r\n const def = runtime.toolRegistry?.[tool];\r\n if (def) return def;\r\n return { name: tool };\r\n }\r\n return {\r\n name: tool.name,\r\n description: tool.description,\r\n input_schema: tool.input_schema ?? { type: 'object', properties: {} },\r\n };\r\n });\r\n }\r\n\r\n return {\r\n body,\r\n provider: 'anthropic',\r\n model: asset.model ?? 'unknown',\r\n };\r\n },\r\n};\r\n"],"mappings":";;;;;AAaO,IAAM,mBAAoC;AAAA,EAC/C,MAAM;AAAA,EAEN,SAAS,OAA8C;AACrD,UAAM,SAAmB,CAAC;AAC1B,UAAM,WAAqB,CAAC;AAE5B,QAAI,CAAC,MAAM,OAAO;AAChB,aAAO,KAAK,qDAAqD;AAAA,IACnE;AAEA,QAAI,MAAM,UAAU,sBAAsB,QAAW;AACnD,eAAS,KAAK,mEAAmE;AAAA,IACnF;AACA,QAAI,MAAM,UAAU,qBAAqB,QAAW;AAClD,eAAS,KAAK,kEAAkE;AAAA,IAClF;AACA,QAAI,MAAM,WAAW,WAAW,QAAW;AACzC,eAAS,KAAK,6FAA6F;AAAA,IAC7G;AAEA,WAAO,EAAE,OAAO,OAAO,WAAW,GAAG,QAAQ,SAAS;AAAA,EACxD;AAAA,EAEA,OAAO,OAA4B,SAAgD;AACjF,UAAM,WAAW,eAAe,OAAO;AAAA,MACrC,WAAW,QAAQ;AAAA,MACnB,QAAQ,QAAQ;AAAA,IAClB,CAAC;AAED,UAAM,WAA2C,CAAC;AAGlD,QAAI,QAAQ,SAAS;AACnB,iBAAW,OAAO,QAAQ,SAAS;AACjC,iBAAS,KAAK,EAAE,MAAM,IAAI,MAAM,SAAS,IAAI,QAAQ,CAAC;AAAA,MACxD;AAAA,IACF;AAGA,QAAI,SAAS,iBAAiB;AAC5B,eAAS,KAAK,EAAE,MAAM,QAAQ,SAAS,SAAS,gBAAgB,CAAC;AAAA,IACnE;AAEA,UAAM,OAAgC;AAAA,MACpC,OAAO,MAAM;AAAA,MACb;AAAA,IACF;AAGA,QAAI,SAAS,qBAAqB;AAChC,WAAK,SAAS,SAAS;AAAA,IACzB;AAGA,QAAI,MAAM,UAAU,gBAAgB,OAAW,MAAK,cAAc,MAAM,SAAS;AACjF,QAAI,MAAM,UAAU,UAAU,OAAW,MAAK,QAAQ,MAAM,SAAS;AACrE,QAAI,MAAM,UAAU,SAAS,OAAW,MAAK,iBAAiB,MAAM,SAAS;AAC7E,QAAI,MAAM,UAAU,sBAAsB,QAAW;AACnD,WAAK,aAAa,MAAM,SAAS;AAAA,IACnC,OAAO;AAEL,WAAK,aAAa;AAAA,IACpB;AAGA,QAAI,MAAM,WAAW,eAAe;AAClC,WAAK,WAAW;AAAA,QACd,MAAM;AAAA,QACN,eAAe,MAAM,UAAU;AAAA,MACjC;AAAA,IACF;AAGA,QAAI,MAAM,UAAU,WAAW,QAAW;AACxC,WAAK,SAAS,MAAM,SAAS;AAAA,IAC/B;AAGA,QAAI,MAAM,SAAS,MAAM,MAAM,SAAS,GAAG;AACzC,WAAK,QAAQ,MAAM,MAAM,IAAI,CAAC,SAAS;AACrC,YAAI,OAAO,SAAS,UAAU;AAC5B,gBAAM,MAAM,QAAQ,eAAe,IAAI;AACvC,cAAI,IAAK,QAAO;AAChB,iBAAO,EAAE,MAAM,KAAK;AAAA,QACtB;AACA,eAAO;AAAA,UACL,MAAM,KAAK;AAAA,UACX,aAAa,KAAK;AAAA,UAClB,cAAc,KAAK,gBAAgB,EAAE,MAAM,UAAU,YAAY,CAAC,EAAE;AAAA,QACtE;AAAA,MACF,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,MACL;AAAA,MACA,UAAU;AAAA,MACV,OAAO,MAAM,SAAS;AAAA,IACxB;AAAA,EACF;AACF;","names":[]}