@elytrasec/engine 0.3.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.
@@ -0,0 +1,6 @@
1
+ import {
2
+ AnthropicProvider
3
+ } from "./chunk-3DB6S2GZ.js";
4
+ export {
5
+ AnthropicProvider
6
+ };
@@ -0,0 +1,63 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
8
+ // src/ai/providers/anthropic.ts
9
+ var DEFAULT_MODEL = "claude-sonnet-4-20250514";
10
+ var MAX_RETRIES = 3;
11
+ var BASE_DELAY_MS = 1e3;
12
+ var AnthropicProvider = class {
13
+ name = "anthropic";
14
+ apiKey;
15
+ defaultModel;
16
+ constructor(apiKey, model) {
17
+ this.apiKey = apiKey;
18
+ this.defaultModel = model ?? DEFAULT_MODEL;
19
+ }
20
+ async complete(params) {
21
+ const { default: Anthropic } = await import("@anthropic-ai/sdk");
22
+ const client = new Anthropic({ apiKey: this.apiKey });
23
+ const model = params.model ?? this.defaultModel;
24
+ const systemMsg = params.messages.find((m) => m.role === "system");
25
+ const conversationMsgs = params.messages.filter((m) => m.role !== "system").map((m) => ({ role: m.role, content: m.content }));
26
+ const response = await this.withRetry(async () => {
27
+ return client.messages.create({
28
+ model,
29
+ max_tokens: params.maxTokens,
30
+ system: systemMsg?.content,
31
+ messages: conversationMsgs
32
+ });
33
+ });
34
+ const textBlock = response.content.find(
35
+ (block) => block.type === "text"
36
+ );
37
+ if (!textBlock || textBlock.type !== "text") {
38
+ return { text: "" };
39
+ }
40
+ return { text: textBlock.text };
41
+ }
42
+ async withRetry(fn) {
43
+ let lastError;
44
+ for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
45
+ try {
46
+ return await fn();
47
+ } catch (err) {
48
+ lastError = err;
49
+ const status = err.status;
50
+ const isRetryable = status === 429 || status !== void 0 && status >= 500;
51
+ if (!isRetryable || attempt === MAX_RETRIES) throw err;
52
+ const delay = BASE_DELAY_MS * Math.pow(2, attempt);
53
+ await new Promise((resolve) => setTimeout(resolve, delay));
54
+ }
55
+ }
56
+ throw lastError;
57
+ }
58
+ };
59
+
60
+ export {
61
+ __require,
62
+ AnthropicProvider
63
+ };