@executioncontrolprotocol/anthropic 0.13.2

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,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Rockbound Digital Inc.
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # `@executioncontrolprotocol/anthropic`
2
+
3
+ Anthropic Messages API model provider for ECP (`anthropic.generate` / `anthropic.evaluate`).
4
+
5
+ ## Auth
6
+
7
+ - Extension config `apiKey`, or
8
+ - `ANTHROPIC_API_KEY` from the process environment (Node)
9
+
10
+ Browser demo BYOK uses the vault secret `ANTHROPIC_API_KEY` with local execution and the
11
+ `anthropic-dangerous-direct-browser-access` header.
12
+
13
+ ## Multimodal `files`
14
+
15
+ Optional `files` on `model.generate` are portable `FileRef` values. Supported MIME types:
16
+
17
+ | Kind | MIME |
18
+ | ---- | ---- |
19
+ | Image | `image/jpeg`, `image/png`, `image/gif`, `image/webp` |
20
+ | Document | `application/pdf` |
21
+
22
+ Unsupported MIME types are rejected before the API call.
@@ -0,0 +1,10 @@
1
+ import { type Registry } from "@executioncontrolprotocol/core";
2
+ export { ANTHROPIC_GENERATE_DOCUMENT_MEDIA_TYPES, ANTHROPIC_GENERATE_IMAGE_MEDIA_TYPES, ANTHROPIC_GENERATE_MEDIA_TYPES, isAnthropicDocumentMediaType, isAnthropicGenerateMediaType, isAnthropicImageMediaType, } from "./media-types.js";
3
+ export { ANTHROPIC_DEFAULT_MAX_TOKENS, ANTHROPIC_DEFAULT_MODEL, buildAnthropicUserContent, resolveAnthropicModel, resolveAnthropicSamplingOptions, } from "./messages.js";
4
+ export { resolveAnthropicApiKey } from "./resolve-api-key.js";
5
+ /** Anthropic model provider. @category Extensions */
6
+ export declare const anthropicExtension: import("@executioncontrolprotocol/core").ExtensionDefinition;
7
+ /** Register Anthropic extension. @category Extensions */
8
+ export declare function registerAnthropicExtension(registry?: Registry): Promise<void>;
9
+ export default anthropicExtension;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,QAAQ,EACd,MAAM,gCAAgC,CAAA;AAcvC,OAAO,EACL,uCAAuC,EACvC,oCAAoC,EACpC,8BAA8B,EAC9B,4BAA4B,EAC5B,4BAA4B,EAC5B,yBAAyB,GAC1B,MAAM,kBAAkB,CAAA;AACzB,OAAO,EACL,4BAA4B,EAC5B,uBAAuB,EACvB,yBAAyB,EACzB,qBAAqB,EACrB,+BAA+B,GAChC,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AAiC7D,qDAAqD;AACrD,eAAO,MAAM,kBAAkB,8DAyIrB,CAAA;AAIV,yDAAyD;AACzD,wBAAsB,0BAA0B,CAC9C,QAAQ,GAAE,QAAyB,GAClC,OAAO,CAAC,IAAI,CAAC,CAIf;AAED,eAAe,kBAAkB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,166 @@
1
+ import { catalogExtension, capabilityFor, defineExtension, globalRegistry, BROWSER_RUNTIME_ID, NODE_RUNTIME_ID, toProviderChatTurns, } from "@executioncontrolprotocol/core";
2
+ import { modelGenerateInputSchema, modelGenerateOutputSchema, } from "@executioncontrolprotocol/types";
3
+ import { z } from "zod";
4
+ import { buildAnthropicUserContent, resolveAnthropicModel, resolveAnthropicSamplingOptions, ANTHROPIC_DEFAULT_MODEL, } from "./messages.js";
5
+ import { resolveAnthropicApiKey } from "./resolve-api-key.js";
6
+ export { ANTHROPIC_GENERATE_DOCUMENT_MEDIA_TYPES, ANTHROPIC_GENERATE_IMAGE_MEDIA_TYPES, ANTHROPIC_GENERATE_MEDIA_TYPES, isAnthropicDocumentMediaType, isAnthropicGenerateMediaType, isAnthropicImageMediaType, } from "./media-types.js";
7
+ export { ANTHROPIC_DEFAULT_MAX_TOKENS, ANTHROPIC_DEFAULT_MODEL, buildAnthropicUserContent, resolveAnthropicModel, resolveAnthropicSamplingOptions, } from "./messages.js";
8
+ export { resolveAnthropicApiKey } from "./resolve-api-key.js";
9
+ async function anthropicMessages(apiKey, body) {
10
+ const res = await fetch("https://api.anthropic.com/v1/messages", {
11
+ method: "POST",
12
+ headers: {
13
+ "x-api-key": apiKey,
14
+ "anthropic-version": "2023-06-01",
15
+ "content-type": "application/json",
16
+ "anthropic-dangerous-direct-browser-access": "true",
17
+ },
18
+ body: JSON.stringify(body),
19
+ });
20
+ if (!res.ok) {
21
+ let detail = "";
22
+ try {
23
+ detail = (await res.text()).slice(0, 500).trim();
24
+ }
25
+ catch {
26
+ detail = "";
27
+ }
28
+ throw new Error(detail ? `Anthropic API error: ${res.status} (${detail})` : `Anthropic API error: ${res.status}`);
29
+ }
30
+ const data = (await res.json());
31
+ return data.content.find((c) => c.type === "text")?.text ?? "";
32
+ }
33
+ /** Anthropic model provider. @category Extensions */
34
+ export const anthropicExtension = defineExtension("@executioncontrolprotocol", "anthropic")
35
+ .withSupportedRuntimes([NODE_RUNTIME_ID, BROWSER_RUNTIME_ID])
36
+ .withConfig({
37
+ apiKey: z.string().optional(),
38
+ defaultModel: z.string().optional(),
39
+ })
40
+ .withMetadata({
41
+ summary: "Anthropic Messages API for browser and Node hosts.",
42
+ description: "Calls the Anthropic Messages API for multimodal chat completion and harness evaluation. Supports images and documents on the final user turn when files are supplied.",
43
+ })
44
+ .withCapabilities([
45
+ capabilityFor("@executioncontrolprotocol/anthropic", "generate")
46
+ .withExecution("local")
47
+ .withInput(modelGenerateInputSchema)
48
+ .withOutput(modelGenerateOutputSchema)
49
+ .withMetadata({
50
+ summary: "Generate text with multimodal Anthropic Messages.",
51
+ description: "Runs chat completion against the Anthropic Messages API. Accepts images and documents on the final user turn in browser and Node hosts. Requires a configured API key. Supports system prompts, prior turns, and sampling options.",
52
+ useCases: [
53
+ "Workflow step analyzes an uploaded image alongside a user question.",
54
+ "Browser or server harness needs long-context chat with document attachments.",
55
+ ],
56
+ samplePrompts: [
57
+ "Describe this image and answer the user's question.",
58
+ "Generate a reply using Claude with the attached PDF.",
59
+ ],
60
+ })
61
+ .withHandler(async (raw, ctx) => {
62
+ const input = modelGenerateInputSchema.parse(raw);
63
+ const cfg = ctx.extensionConfig ?? {};
64
+ const apiKey = resolveAnthropicApiKey(cfg);
65
+ if (!apiKey)
66
+ throw new Error("Anthropic API key required");
67
+ const model = resolveAnthropicModel(input, cfg);
68
+ const sampling = resolveAnthropicSamplingOptions(input.options);
69
+ const turns = toProviderChatTurns({
70
+ system: input.system,
71
+ messages: input.messages,
72
+ prompt: input.prompt,
73
+ context: input.context,
74
+ });
75
+ const systemParts = turns
76
+ .filter((turn) => turn.role === "system")
77
+ .map((turn) => turn.content);
78
+ const priorAndCurrent = turns.filter((turn) => turn.role !== "system");
79
+ const messages = [];
80
+ for (let i = 0; i < priorAndCurrent.length; i++) {
81
+ const turn = priorAndCurrent[i];
82
+ const isLast = i === priorAndCurrent.length - 1;
83
+ if (turn.role !== "user" && turn.role !== "assistant") {
84
+ continue;
85
+ }
86
+ if (isLast && turn.role === "user") {
87
+ const content = await buildAnthropicUserContent(turn.content, input.files, ctx);
88
+ messages.push({ role: "user", content });
89
+ }
90
+ else {
91
+ messages.push({ role: turn.role, content: turn.content });
92
+ }
93
+ }
94
+ ctx.usage.increment({ modelCalls: 1 });
95
+ const text = await anthropicMessages(apiKey, {
96
+ model,
97
+ ...sampling,
98
+ ...(systemParts.length > 0 ? { system: systemParts.join("\n\n") } : {}),
99
+ messages,
100
+ });
101
+ return { text };
102
+ }),
103
+ capabilityFor("@executioncontrolprotocol/anthropic", "evaluate")
104
+ .withExecution("local")
105
+ .withInput(z.object({
106
+ artifact: z.unknown(),
107
+ criteria: z.unknown().optional(),
108
+ goal: z.string().optional(),
109
+ classifiedIntent: z.string().optional(),
110
+ model: z.string().optional(),
111
+ }))
112
+ .withOutput(z.object({ approved: z.boolean(), feedback: z.string().optional() }))
113
+ .withMetadata({
114
+ summary: "Judge harness outputs with an Anthropic model.",
115
+ description: "Scores harness artifacts against a goal, rubric, and optional classified intent. Returns approved and feedback. Skips when no API key is configured. Used by harness eval gates, not end-user chat.",
116
+ useCases: [
117
+ "Harness matrix uses a cloud judge with intent-aware rubrics.",
118
+ "Eval approves FAQ answers separately from workflow patch outputs.",
119
+ ],
120
+ samplePrompts: [
121
+ "Evaluate whether this harness artifact passes the rubric.",
122
+ "Judge the classified intent output for this eval case.",
123
+ ],
124
+ })
125
+ .withHandler(async (input, ctx) => {
126
+ const cfg = ctx.extensionConfig ?? {};
127
+ const apiKey = resolveAnthropicApiKey(cfg);
128
+ if (!apiKey)
129
+ return { approved: true, feedback: "skipped (no API key)" };
130
+ const row = input;
131
+ const prompt = [
132
+ "You are an eval judge for ECP harness outputs.",
133
+ 'Reply with JSON only: {"approved":true,"feedback":"ok"} or {"approved":false,"feedback":"reason"}.',
134
+ `Goal: ${row.goal ?? "quality check"}`,
135
+ row.classifiedIntent ? `Classified intent: ${row.classifiedIntent}` : "",
136
+ row.criteria ? `Rubric: ${JSON.stringify(row.criteria)}` : "",
137
+ `Artifact: ${JSON.stringify(row.artifact)}`,
138
+ ]
139
+ .filter((line) => line.length > 0)
140
+ .join("\n");
141
+ ctx.usage.increment({ modelCalls: 1 });
142
+ const content = await anthropicMessages(apiKey, {
143
+ model: row.model ??
144
+ cfg.defaultModel ??
145
+ ANTHROPIC_DEFAULT_MODEL,
146
+ max_tokens: 1024,
147
+ messages: [{ role: "user", content: prompt }],
148
+ });
149
+ try {
150
+ return JSON.parse(content);
151
+ }
152
+ catch {
153
+ return { approved: true, feedback: content };
154
+ }
155
+ }),
156
+ ])
157
+ .build();
158
+ catalogExtension(anthropicExtension);
159
+ /** Register Anthropic extension. @category Extensions */
160
+ export async function registerAnthropicExtension(registry = globalRegistry) {
161
+ if (!registry.getExtension("@executioncontrolprotocol/anthropic")) {
162
+ await registry.registerExtension(anthropicExtension);
163
+ }
164
+ }
165
+ export default anthropicExtension;
166
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,mBAAmB,GAGpB,MAAM,gCAAgC,CAAA;AACvC,OAAO,EACL,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EACL,yBAAyB,EACzB,qBAAqB,EACrB,+BAA+B,EAC/B,uBAAuB,GACxB,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AAE7D,OAAO,EACL,uCAAuC,EACvC,oCAAoC,EACpC,8BAA8B,EAC9B,4BAA4B,EAC5B,4BAA4B,EAC5B,yBAAyB,GAC1B,MAAM,kBAAkB,CAAA;AACzB,OAAO,EACL,4BAA4B,EAC5B,uBAAuB,EACvB,yBAAyB,EACzB,qBAAqB,EACrB,+BAA+B,GAChC,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AAE7D,KAAK,UAAU,iBAAiB,CAC9B,MAAc,EACd,IAA6B;IAE7B,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,uCAAuC,EAAE;QAC/D,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,WAAW,EAAE,MAAM;YACnB,mBAAmB,EAAE,YAAY;YACjC,cAAc,EAAE,kBAAkB;YAClC,2CAA2C,EAAE,MAAM;SACpD;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;KAC3B,CAAC,CAAA;IACF,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,IAAI,MAAM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E_MEDIA_TYPES: readonly ["image/jpeg", "image/png", "image/gif", "image/webp"];
3
+ /** Anthropic Messages document MIME types. @category Extensions */
4
+ export declare const ANTHROPIC_GENERATE_DOCUMENT_MEDIA_TYPES: readonly ["application/pdf"];
5
+ /** All MIME types accepted by anthropic.generate files. @category Extensions */
6
+ export declare const ANTHROPIC_GENERATE_MEDIA_TYPES: readonly ["image/jpeg", "image/png", "image/gif", "image/webp", "application/pdf"];
7
+ /** Anthropic image MIME union. @category Extensions */
8
+ export type AnthropicGenerateImageMediaType = (typeof ANTHROPIC_GENERATE_IMAGE_MEDIA_TYPES)[number];
9
+ /** Anthropic document MIME union. @category Extensions */
10
+ export type AnthropicGenerateDocumentMediaType = (typeof ANTHROPIC_GENERATE_DOCUMENT_MEDIA_TYPES)[number];
11
+ /** Anthropic generate file MIME union. @category Extensions */
12
+ export type AnthropicGenerateMediaType = (typeof ANTHROPIC_GENERATE_MEDIA_TYPES)[number];
13
+ /** Whether MIME is an Anthropic image block type. @category Extensions */
14
+ export declare function isAnthropicImageMediaType(mediaType: string): mediaType is AnthropicGenerateImageMediaType;
15
+ /** Whether MIME is an Anthropic document block type. @category Extensions */
16
+ export declare function isAnthropicDocumentMediaType(mediaType: string): mediaType is AnthropicGenerateDocumentMediaType;
17
+ /** Whether MIME is accepted by anthropic.generate files. @category Extensions */
18
+ export declare function isAnthropicGenerateMediaType(mediaType: string): mediaType is AnthropicGenerateMediaType;
19
+ //# sourceMappingURL=media-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media-types.d.ts","sourceRoot":"","sources":["../src/media-types.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,eAAO,MAAM,oCAAoC,iEAKvC,CAAA;AAEV,mEAAmE;AACnE,eAAO,MAAM,uCAAuC,8BAA+B,CAAA;AAEnF,gFAAgF;AAChF,eAAO,MAAM,8BAA8B,oFAGjC,CAAA;AAEV,uDAAuD;AACvD,MAAM,MAAM,+BAA+B,GACzC,CAAC,OAAO,oCAAoC,CAAC,CAAC,MAAM,CAAC,CAAA;AAEvD,0DAA0D;AAC1D,MAAM,MAAM,kCAAkC,GAC5C,CAAC,OAAO,uCAAuC,CAAC,CAAC,MAAM,CAAC,CAAA;AAE1D,+DAA+D;AAC/D,MAAM,MAAM,0BAA0B,GAAG,CAAC,OAAO,8BAA8B,CAAC,CAAC,MAAM,CAAC,CAAA;AAKxF,0EAA0E;AAC1E,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,IAAI,+BAA+B,CAEzG;AAED,6EAA6E;AAC7E,wBAAgB,4BAA4B,CAC1C,SAAS,EAAE,MAAM,GAChB,SAAS,IAAI,kCAAkC,CAEjD;AAED,iFAAiF;AACjF,wBAAgB,4BAA4B,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,IAAI,0BAA0B,CAEvG"}
@@ -0,0 +1,29 @@
1
+ /** Anthropic Messages image MIME types. @category Extensions */
2
+ export const ANTHROPIC_GENERATE_IMAGE_MEDIA_TYPES = [
3
+ "image/jpeg",
4
+ "image/png",
5
+ "image/gif",
6
+ "image/webp",
7
+ ];
8
+ /** Anthropic Messages document MIME types. @category Extensions */
9
+ export const ANTHROPIC_GENERATE_DOCUMENT_MEDIA_TYPES = ["application/pdf"];
10
+ /** All MIME types accepted by anthropic.generate files. @category Extensions */
11
+ export const ANTHROPIC_GENERATE_MEDIA_TYPES = [
12
+ ...ANTHROPIC_GENERATE_IMAGE_MEDIA_TYPES,
13
+ ...ANTHROPIC_GENERATE_DOCUMENT_MEDIA_TYPES,
14
+ ];
15
+ const IMAGE_SET = new Set(ANTHROPIC_GENERATE_IMAGE_MEDIA_TYPES);
16
+ const DOCUMENT_SET = new Set(ANTHROPIC_GENERATE_DOCUMENT_MEDIA_TYPES);
17
+ /** Whether MIME is an Anthropic image block type. @category Extensions */
18
+ export function isAnthropicImageMediaType(mediaType) {
19
+ return IMAGE_SET.has(mediaType);
20
+ }
21
+ /** Whether MIME is an Anthropic document block type. @category Extensions */
22
+ export function isAnthropicDocumentMediaType(mediaType) {
23
+ return DOCUMENT_SET.has(mediaType);
24
+ }
25
+ /** Whether MIME is accepted by anthropic.generate files. @category Extensions */
26
+ export function isAnthropicGenerateMediaType(mediaType) {
27
+ return IMAGE_SET.has(mediaType) || DOCUMENT_SET.has(mediaType);
28
+ }
29
+ //# sourceMappingURL=media-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media-types.js","sourceRoot":"","sources":["../src/media-types.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,MAAM,CAAC,MAAM,oCAAoC,GAAG;IAClD,YAAY;IACZ,WAAW;IACX,WAAW;IACX,YAAY;CACJ,CAAA;AAEV,mEAAmE;AACnE,MAAM,CAAC,MAAM,uCAAuC,GAAG,CAAC,iBAAiB,CAAU,CAAA;AAEnF,gFAAgF;AAChF,MAAM,CAAC,MAAM,8BAA8B,GAAG;IAC5C,GAAG,oCAAoC;IACvC,GAAG,uCAAuC;CAClC,CAAA;AAaV,MAAM,SAAS,GAAG,IAAI,GAAG,CAAS,oCAAoC,CAAC,CAAA;AACvE,MAAM,YAAY,GAAG,IAAI,GAAG,CAAS,uCAAuC,CAAC,CAAA;AAE7E,0EAA0E;AAC1E,MAAM,UAAU,yBAAyB,CAAC,SAAiB;IACzD,OAAO,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;AACjC,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,4BAA4B,CAC1C,SAAiB;IAEjB,OAAO,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;AACpC,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,4BAA4B,CAAC,SAAiB;IAC5D,OAAO,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;AAChE,CAAC"}
@@ -0,0 +1,50 @@
1
+ import { type FileRef, type ModelGenerateInput } from "@executioncontrolprotocol/types";
2
+ import { type FileCapabilityContext } from "@executioncontrolprotocol/core";
3
+ import { type AnthropicGenerateDocumentMediaType, type AnthropicGenerateImageMediaType } from "./media-types.js";
4
+ /** Default max tokens when options omit max_tokens. @category Extensions */
5
+ export declare const ANTHROPIC_DEFAULT_MAX_TOKENS = 4096;
6
+ /** Default Claude model for generate. @category Extensions */
7
+ export declare const ANTHROPIC_DEFAULT_MODEL = "claude-sonnet-4-5";
8
+ interface AnthropicTextBlock {
9
+ type: "text";
10
+ text: string;
11
+ }
12
+ interface AnthropicImageBlock {
13
+ type: "image";
14
+ source: {
15
+ type: "base64";
16
+ media_type: AnthropicGenerateImageMediaType;
17
+ data: string;
18
+ } | {
19
+ type: "url";
20
+ url: string;
21
+ };
22
+ }
23
+ interface AnthropicDocumentBlock {
24
+ type: "document";
25
+ source: {
26
+ type: "base64";
27
+ media_type: AnthropicGenerateDocumentMediaType;
28
+ data: string;
29
+ } | {
30
+ type: "url";
31
+ url: string;
32
+ };
33
+ }
34
+ /** Anthropic user message content block. @category Extensions */
35
+ export type AnthropicContentBlock = AnthropicTextBlock | AnthropicImageBlock | AnthropicDocumentBlock;
36
+ /**
37
+ * Map portable file refs to Anthropic Messages content blocks (media before text).
38
+ * @category Extensions
39
+ */
40
+ export declare function buildAnthropicUserContent(prompt: string, files: FileRef[] | undefined, ctx: FileCapabilityContext): Promise<AnthropicContentBlock[]>;
41
+ /** Resolve sampling options for Anthropic (temperature XOR top_p). @category Extensions */
42
+ export declare function resolveAnthropicSamplingOptions(options: Record<string, unknown> | undefined): {
43
+ max_tokens: number;
44
+ temperature?: number;
45
+ top_p?: number;
46
+ };
47
+ /** Build Messages API body fields from normalized generate input. @category Extensions */
48
+ export declare function resolveAnthropicModel(input: Pick<ModelGenerateInput, "model">, cfg: Record<string, unknown>): string;
49
+ export {};
50
+ //# sourceMappingURL=messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AAAA,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C,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAC3C;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CA0B9D;AAED,0FAA0F;AAC1F,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,IAAI,CAAC,kBAAkB,EAAE,OAAO,CAAC,EACxC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC3B,MAAM,CAER"}
@@ -0,0 +1,92 @@
1
+ import { FILE_REF_KINDS, } from "@executioncontrolprotocol/types";
2
+ import { resolveFile } from "@executioncontrolprotocol/core";
3
+ import { isAnthropicDocumentMediaType, isAnthropicGenerateMediaType, isAnthropicImageMediaType, } from "./media-types.js";
4
+ /** Default max tokens when options omit max_tokens. @category Extensions */
5
+ export const ANTHROPIC_DEFAULT_MAX_TOKENS = 4096;
6
+ /** Default Claude model for generate. @category Extensions */
7
+ export const ANTHROPIC_DEFAULT_MODEL = "claude-sonnet-4-5";
8
+ function bytesToBase64(bytes) {
9
+ if (typeof Buffer !== "undefined") {
10
+ return Buffer.from(bytes).toString("base64");
11
+ }
12
+ let binary = "";
13
+ for (const byte of bytes) {
14
+ binary += String.fromCharCode(byte);
15
+ }
16
+ return btoa(binary);
17
+ }
18
+ function normalizeMediaType(mediaType, fallbackHint) {
19
+ const raw = (mediaType ?? fallbackHint ?? "").split(";")[0]?.trim().toLowerCase() ?? "";
20
+ if (raw === "image/jpg")
21
+ return "image/jpeg";
22
+ return raw;
23
+ }
24
+ /**
25
+ * Map portable file refs to Anthropic Messages content blocks (media before text).
26
+ * @category Extensions
27
+ */
28
+ export async function buildAnthropicUserContent(prompt, files, ctx) {
29
+ const mediaBlocks = [];
30
+ for (const ref of files ?? []) {
31
+ if (ref.kind === FILE_REF_KINDS.URL) {
32
+ const mediaType = normalizeMediaType(ref.mediaType);
33
+ if (!mediaType || !isAnthropicGenerateMediaType(mediaType)) {
34
+ throw new Error(`Unsupported Anthropic generate file media type: ${mediaType || "(missing)"}. Allowed: image/jpeg, image/png, image/gif, image/webp, application/pdf`);
35
+ }
36
+ if (isAnthropicImageMediaType(mediaType)) {
37
+ mediaBlocks.push({ type: "image", source: { type: "url", url: ref.url } });
38
+ }
39
+ else {
40
+ mediaBlocks.push({ type: "document", source: { type: "url", url: ref.url } });
41
+ }
42
+ continue;
43
+ }
44
+ const resolved = await resolveFile(ref, ctx, { allowRemoteUrls: false });
45
+ const mediaType = normalizeMediaType(resolved.mediaType, ref.mediaType);
46
+ if (!mediaType || !isAnthropicGenerateMediaType(mediaType)) {
47
+ throw new Error(`Unsupported Anthropic generate file media type: ${mediaType || "(missing)"}. Allowed: image/jpeg, image/png, image/gif, image/webp, application/pdf`);
48
+ }
49
+ const data = bytesToBase64(resolved.bytes);
50
+ if (isAnthropicImageMediaType(mediaType)) {
51
+ mediaBlocks.push({
52
+ type: "image",
53
+ source: { type: "base64", media_type: mediaType, data },
54
+ });
55
+ }
56
+ else if (isAnthropicDocumentMediaType(mediaType)) {
57
+ mediaBlocks.push({
58
+ type: "document",
59
+ source: { type: "base64", media_type: mediaType, data },
60
+ });
61
+ }
62
+ }
63
+ return [...mediaBlocks, { type: "text", text: prompt }];
64
+ }
65
+ /** Resolve sampling options for Anthropic (temperature XOR top_p). @category Extensions */
66
+ export function resolveAnthropicSamplingOptions(options) {
67
+ const maxTokensRaw = options?.max_tokens ?? options?.maxTokens;
68
+ const max_tokens = typeof maxTokensRaw === "number" && Number.isFinite(maxTokensRaw) && maxTokensRaw > 0
69
+ ? Math.floor(maxTokensRaw)
70
+ : ANTHROPIC_DEFAULT_MAX_TOKENS;
71
+ const temperature = typeof options?.temperature === "number" && Number.isFinite(options.temperature)
72
+ ? options.temperature
73
+ : undefined;
74
+ const topP = typeof options?.top_p === "number" && Number.isFinite(options.top_p)
75
+ ? options.top_p
76
+ : typeof options?.topP === "number" && Number.isFinite(options.topP)
77
+ ? options.topP
78
+ : undefined;
79
+ // Anthropic rejects setting both temperature and top_p.
80
+ if (temperature !== undefined) {
81
+ return { max_tokens, temperature };
82
+ }
83
+ if (topP !== undefined) {
84
+ return { max_tokens, top_p: topP };
85
+ }
86
+ return { max_tokens };
87
+ }
88
+ /** Build Messages API body fields from normalized generate input. @category Extensions */
89
+ export function resolveAnthropicModel(input, cfg) {
90
+ return input.model ?? cfg.defaultModel ?? ANTHROPIC_DEFAULT_MODEL;
91
+ }
92
+ //# sourceMappingURL=messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.js","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,GAGf,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAE,WAAW,EAA8B,MAAM,gCAAgC,CAAA;AACxF,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,EAC5B,yBAAyB,GAG1B,MAAM,kBAAkB,CAAA;AAEzB,4EAA4E;AAC5E,MAAM,CAAC,MAAM,4BAA4B,GAAG,IAAI,CAAA;AAEhD,8DAA8D;AAC9D,MAAM,CAAC,MAAM,uBAAuB,GAAG,mBAAmB,CAAA;AAyC1D,SAAS,aAAa,CAAC,KAAiB;IACtC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;IAC9C,CAAC;IACD,IAAI,MAAM,GAAG,EAAE,CAAA;IACf,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAA;IACrC,CAAC;IACD,OAAO,IAAI,CAAC,MAAM,CAAC,CAAA;AACrB,CAAC;AAED,SAAS,kBAAkB,CAAC,SAA6B,EAAE,YAAqB;IAC9E,MAAM,GAAG,GAAG,CAAC,SAAS,IAAI,YAAY,IAAI,EAAE,CAAC,CAAC,KAA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AO,EAAE,WAAW,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC;QAC9E,CAAC,CAAC,OAAO,CAAC,WAAW;QACrB,CAAC,CAAC,SAAS,CAAA;IACf,MAAM,IAAI,GACR,OAAO,OAAO,EAAE,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC;QAClE,CAAC,CAAC,OAAO,CAAC,KAAK;QACf,CAAC,CAAC,OAAO,OAAO,EAAE,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC;YAClE,CAAC,CAAC,OAAO,CAAC,IAAI;YACd,CAAC,CAAC,SAAS,CAAA;IAEjB,wDAAwD;IACxD,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC9B,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,CAAA;IACpC,CAAC;IACD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,CAAA;IACpC,CAAC;IACD,OAAO,EAAE,UAAU,EAAE,CAAA;AACvB,CAAC;AAED,0FAA0F;AAC1F,MAAM,UAAU,qBAAqB,CACnC,KAAwC,EACxC,GAA4B;IAE5B,OAAO,KAAK,CAAC,KAAK,IAAK,GAAG,CAAC,YAAmC,IAAI,uBAAuB,CAAA;AAC3F,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** Resolve Anthropic API key from extension config, optionally process.env on Node. */
2
+ export declare function resolveAnthropicApiKey(cfg: Record<string, unknown>): string;
3
+ //# sourceMappingURL=resolve-api-key.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-api-key.d.ts","sourceRoot":"","sources":["../src/resolve-api-key.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAO3E"}
@@ -0,0 +1,11 @@
1
+ /** Resolve Anthropic API key from extension config, optionally process.env on Node. */
2
+ export function resolveAnthropicApiKey(cfg) {
3
+ const fromConfig = cfg.apiKey;
4
+ if (fromConfig)
5
+ return fromConfig;
6
+ if (typeof process !== "undefined" && process.env?.ANTHROPIC_API_KEY) {
7
+ return process.env.ANTHROPIC_API_KEY;
8
+ }
9
+ return "";
10
+ }
11
+ //# sourceMappingURL=resolve-api-key.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-api-key.js","sourceRoot":"","sources":["../src/resolve-api-key.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,MAAM,UAAU,sBAAsB,CAAC,GAA4B;IACjE,MAAM,UAAU,GAAG,GAAG,CAAC,MAA4B,CAAA;IACnD,IAAI,UAAU;QAAE,OAAO,UAAU,CAAA;IACjC,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,EAAE,iBAAiB,EAAE,CAAC;QACrE,OAAO,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAA;IACtC,CAAC;IACD,OAAO,EAAE,CAAA;AACX,CAAC"}
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@executioncontrolprotocol/anthropic",
3
+ "version": "0.13.2",
4
+ "description": "Anthropic Claude model provider for ECP",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "peerDependencies": {
20
+ "zod": "^3.24.0",
21
+ "@executioncontrolprotocol/core": "^0.13.2",
22
+ "@executioncontrolprotocol/types": "^0.13.2"
23
+ },
24
+ "devDependencies": {
25
+ "typescript": "^5.7.0",
26
+ "zod": "^3.24.0",
27
+ "@executioncontrolprotocol/core": "^0.13.2",
28
+ "@executioncontrolprotocol/types": "^0.13.2"
29
+ },
30
+ "scripts": {
31
+ "build": "tsc -b"
32
+ }
33
+ }