promptfoo 0.107.0 → 0.107.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.
Files changed (141) hide show
  1. package/dist/package.json +20 -17
  2. package/dist/src/app/assets/{index-aPpzVtDP.js → index-DmqkyVHC.js} +234 -234
  3. package/dist/src/app/assets/{index.es-BZ4ADnog.js → index.es-BSriX8RW.js} +1 -1
  4. package/dist/src/app/assets/{sync-ulUFOpow.js → sync-CAUebwzg.js} +1 -1
  5. package/dist/src/app/index.html +1 -1
  6. package/dist/src/assertions/answerRelevance.d.ts.map +1 -1
  7. package/dist/src/assertions/contains.d.ts.map +1 -1
  8. package/dist/src/assertions/contextRecall.d.ts.map +1 -1
  9. package/dist/src/assertions/contextRelevance.d.ts.map +1 -1
  10. package/dist/src/assertions/cost.d.ts.map +1 -1
  11. package/dist/src/assertions/equals.d.ts.map +1 -1
  12. package/dist/src/assertions/factuality.d.ts.map +1 -1
  13. package/dist/src/assertions/geval.d.ts.map +1 -1
  14. package/dist/src/assertions/guardrails.d.ts.map +1 -1
  15. package/dist/src/assertions/javascript.d.ts.map +1 -1
  16. package/dist/src/assertions/latency.d.ts.map +1 -1
  17. package/dist/src/assertions/llmRubric.d.ts.map +1 -1
  18. package/dist/src/assertions/modelGradedClosedQa.d.ts.map +1 -1
  19. package/dist/src/assertions/moderation.d.ts.map +1 -1
  20. package/dist/src/assertions/openai.d.ts.map +1 -1
  21. package/dist/src/assertions/python.d.ts.map +1 -1
  22. package/dist/src/assertions/redteam.d.ts.map +1 -1
  23. package/dist/src/assertions/regex.d.ts.map +1 -1
  24. package/dist/src/assertions/similar.d.ts.map +1 -1
  25. package/dist/src/assertions/sql.d.ts.map +1 -1
  26. package/dist/src/assertions/startsWith.d.ts.map +1 -1
  27. package/dist/src/assertions/xml.d.ts.map +1 -1
  28. package/dist/src/commands/auth.d.ts.map +1 -1
  29. package/dist/src/commands/auth.js +4 -5
  30. package/dist/src/commands/auth.js.map +1 -1
  31. package/dist/src/commands/init.d.ts.map +1 -1
  32. package/dist/src/commands/init.js +14 -2
  33. package/dist/src/commands/init.js.map +1 -1
  34. package/dist/src/database/tables.d.ts +22 -0
  35. package/dist/src/database/tables.d.ts.map +1 -1
  36. package/dist/src/fetch.js +1 -1
  37. package/dist/src/fetch.js.map +1 -1
  38. package/dist/src/globalConfig/cloud.d.ts +1 -0
  39. package/dist/src/globalConfig/cloud.d.ts.map +1 -1
  40. package/dist/src/globalConfig/cloud.js +11 -10
  41. package/dist/src/globalConfig/cloud.js.map +1 -1
  42. package/dist/src/matchers.d.ts.map +1 -1
  43. package/dist/src/matchers.js +79 -39
  44. package/dist/src/matchers.js.map +1 -1
  45. package/dist/src/onboarding.d.ts.map +1 -1
  46. package/dist/src/onboarding.js +5 -8
  47. package/dist/src/onboarding.js.map +1 -1
  48. package/dist/src/prompts/grading.d.ts +1 -10
  49. package/dist/src/prompts/grading.d.ts.map +1 -1
  50. package/dist/src/prompts/grading.js +37 -42
  51. package/dist/src/prompts/grading.js.map +1 -1
  52. package/dist/src/prompts/processors/javascript.d.ts.map +1 -1
  53. package/dist/src/prompts/processors/python.d.ts.map +1 -1
  54. package/dist/src/providers/adaline.gateway.d.ts.map +1 -1
  55. package/dist/src/providers/adaline.gateway.js +6 -5
  56. package/dist/src/providers/adaline.gateway.js.map +1 -1
  57. package/dist/src/providers/anthropic/completion.d.ts +15 -0
  58. package/dist/src/providers/anthropic/completion.d.ts.map +1 -0
  59. package/dist/src/providers/anthropic/completion.js +93 -0
  60. package/dist/src/providers/anthropic/completion.js.map +1 -0
  61. package/dist/src/providers/anthropic/defaults.d.ts +18 -0
  62. package/dist/src/providers/anthropic/defaults.d.ts.map +1 -0
  63. package/dist/src/providers/anthropic/defaults.js +105 -0
  64. package/dist/src/providers/anthropic/defaults.js.map +1 -0
  65. package/dist/src/providers/anthropic/generic.d.ts +37 -0
  66. package/dist/src/providers/anthropic/generic.d.ts.map +1 -0
  67. package/dist/src/providers/anthropic/generic.js +46 -0
  68. package/dist/src/providers/anthropic/generic.js.map +1 -0
  69. package/dist/src/providers/anthropic/messages.d.ts +23 -0
  70. package/dist/src/providers/anthropic/messages.d.ts.map +1 -0
  71. package/dist/src/providers/anthropic/messages.js +129 -0
  72. package/dist/src/providers/anthropic/messages.js.map +1 -0
  73. package/dist/src/providers/anthropic/types.d.ts +26 -0
  74. package/dist/src/providers/anthropic/types.d.ts.map +1 -0
  75. package/dist/src/providers/anthropic/types.js +3 -0
  76. package/dist/src/providers/anthropic/types.js.map +1 -0
  77. package/dist/src/providers/anthropic/util.d.ts +18 -0
  78. package/dist/src/providers/anthropic/util.d.ts.map +1 -0
  79. package/dist/src/providers/anthropic/util.js +192 -0
  80. package/dist/src/providers/anthropic/util.js.map +1 -0
  81. package/dist/src/providers/bedrock.d.ts +12 -12
  82. package/dist/src/providers/bedrock.d.ts.map +1 -1
  83. package/dist/src/providers/bedrock.js +14 -12
  84. package/dist/src/providers/bedrock.js.map +1 -1
  85. package/dist/src/providers/defaults.d.ts +1 -12
  86. package/dist/src/providers/defaults.d.ts.map +1 -1
  87. package/dist/src/providers/defaults.js +24 -22
  88. package/dist/src/providers/defaults.js.map +1 -1
  89. package/dist/src/providers/openai/realtime.d.ts +68 -0
  90. package/dist/src/providers/openai/realtime.d.ts.map +1 -0
  91. package/dist/src/providers/openai/realtime.js +919 -0
  92. package/dist/src/providers/openai/realtime.js.map +1 -0
  93. package/dist/src/providers/openai/util.d.ts +10 -0
  94. package/dist/src/providers/openai/util.d.ts.map +1 -1
  95. package/dist/src/providers/openai/util.js +32 -2
  96. package/dist/src/providers/openai/util.js.map +1 -1
  97. package/dist/src/providers/registry.d.ts.map +1 -1
  98. package/dist/src/providers/registry.js +30 -11
  99. package/dist/src/providers/registry.js.map +1 -1
  100. package/dist/src/redteam/constants.d.ts +1 -1
  101. package/dist/src/redteam/constants.d.ts.map +1 -1
  102. package/dist/src/redteam/constants.js +7 -0
  103. package/dist/src/redteam/constants.js.map +1 -1
  104. package/dist/src/redteam/extraction/entities.d.ts.map +1 -1
  105. package/dist/src/redteam/extraction/entities.js +2 -0
  106. package/dist/src/redteam/extraction/entities.js.map +1 -1
  107. package/dist/src/redteam/graders.d.ts.map +1 -1
  108. package/dist/src/redteam/graders.js +2 -0
  109. package/dist/src/redteam/graders.js.map +1 -1
  110. package/dist/src/redteam/plugins/index.d.ts.map +1 -1
  111. package/dist/src/redteam/plugins/index.js +2 -0
  112. package/dist/src/redteam/plugins/index.js.map +1 -1
  113. package/dist/src/redteam/plugins/toolDiscovery.d.ts +13 -0
  114. package/dist/src/redteam/plugins/toolDiscovery.d.ts.map +1 -0
  115. package/dist/src/redteam/plugins/toolDiscovery.js +102 -0
  116. package/dist/src/redteam/plugins/toolDiscovery.js.map +1 -0
  117. package/dist/src/redteam/providers/shared.d.ts.map +1 -1
  118. package/dist/src/redteam/strategies/iterative.js +1 -1
  119. package/dist/src/redteam/strategies/iterative.js.map +1 -1
  120. package/dist/src/types/env.d.ts +3 -0
  121. package/dist/src/types/env.d.ts.map +1 -1
  122. package/dist/src/types/env.js +1 -0
  123. package/dist/src/types/env.js.map +1 -1
  124. package/dist/src/types/index.d.ts +291 -0
  125. package/dist/src/types/index.d.ts.map +1 -1
  126. package/dist/src/types/providers.d.ts +13 -0
  127. package/dist/src/types/providers.d.ts.map +1 -1
  128. package/dist/src/util/database.d.ts +2 -0
  129. package/dist/src/util/database.d.ts.map +1 -1
  130. package/dist/src/util/objectUtils.d.ts.map +1 -1
  131. package/dist/src/util/time.d.ts.map +1 -1
  132. package/dist/src/validators/providers.d.ts +20 -0
  133. package/dist/src/validators/providers.d.ts.map +1 -1
  134. package/dist/src/validators/redteam.d.ts +8 -0
  135. package/dist/src/validators/redteam.d.ts.map +1 -1
  136. package/dist/tsconfig.tsbuildinfo +1 -1
  137. package/package.json +20 -17
  138. package/dist/src/providers/anthropic.d.ts +0 -84
  139. package/dist/src/providers/anthropic.d.ts.map +0 -1
  140. package/dist/src/providers/anthropic.js +0 -505
  141. package/dist/src/providers/anthropic.js.map +0 -1
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AnthropicCompletionProvider = void 0;
7
+ const sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
8
+ const cache_1 = require("../../cache");
9
+ const envars_1 = require("../../envars");
10
+ const logger_1 = __importDefault(require("../../logger"));
11
+ const generic_1 = require("./generic");
12
+ class AnthropicCompletionProvider extends generic_1.AnthropicGenericProvider {
13
+ constructor(modelName, options = {}) {
14
+ super(modelName, options);
15
+ }
16
+ async callApi(prompt) {
17
+ if (!this.apiKey) {
18
+ throw new Error('Anthropic API key is not set. Set the ANTHROPIC_API_KEY environment variable or add `apiKey` to the provider config.');
19
+ }
20
+ let stop;
21
+ try {
22
+ stop = (0, envars_1.getEnvString)('ANTHROPIC_STOP')
23
+ ? JSON.parse((0, envars_1.getEnvString)('ANTHROPIC_STOP') || '')
24
+ : ['<|im_end|>', '<|endoftext|>'];
25
+ }
26
+ catch (err) {
27
+ throw new Error(`ANTHROPIC_STOP is not a valid JSON string: ${err}`);
28
+ }
29
+ const params = {
30
+ model: this.modelName,
31
+ prompt: `${sdk_1.default.HUMAN_PROMPT} ${prompt} ${sdk_1.default.AI_PROMPT}`,
32
+ max_tokens_to_sample: this.config?.max_tokens_to_sample || (0, envars_1.getEnvInt)('ANTHROPIC_MAX_TOKENS', 1024),
33
+ temperature: this.config.temperature ?? (0, envars_1.getEnvFloat)('ANTHROPIC_TEMPERATURE', 0),
34
+ stop_sequences: stop,
35
+ };
36
+ logger_1.default.debug(`Calling Anthropic API: ${JSON.stringify(params)}`);
37
+ const cache = await (0, cache_1.getCache)();
38
+ const cacheKey = `anthropic:${JSON.stringify(params)}`;
39
+ if ((0, cache_1.isCacheEnabled)()) {
40
+ // Try to get the cached response
41
+ const cachedResponse = await cache.get(cacheKey);
42
+ if (cachedResponse) {
43
+ logger_1.default.debug(`Returning cached response for ${prompt}: ${cachedResponse}`);
44
+ return {
45
+ output: JSON.parse(cachedResponse),
46
+ tokenUsage: {},
47
+ };
48
+ }
49
+ }
50
+ let response;
51
+ try {
52
+ response = await this.anthropic.completions.create(params);
53
+ }
54
+ catch (err) {
55
+ return {
56
+ error: `API call error: ${String(err)}`,
57
+ };
58
+ }
59
+ logger_1.default.debug(`\tAnthropic API response: ${JSON.stringify(response)}`);
60
+ if ((0, cache_1.isCacheEnabled)()) {
61
+ try {
62
+ await cache.set(cacheKey, JSON.stringify(response.completion));
63
+ }
64
+ catch (err) {
65
+ logger_1.default.error(`Failed to cache response: ${String(err)}`);
66
+ }
67
+ }
68
+ try {
69
+ return {
70
+ output: response.completion,
71
+ tokenUsage: {}, // TODO: add token usage once Anthropic API supports it
72
+ };
73
+ }
74
+ catch (err) {
75
+ return {
76
+ error: `API response error: ${String(err)}: ${JSON.stringify(response)}`,
77
+ };
78
+ }
79
+ }
80
+ }
81
+ exports.AnthropicCompletionProvider = AnthropicCompletionProvider;
82
+ // NOTE: As of March 15, 2025, all legacy completion models are retired
83
+ // and should not be used for new applications.
84
+ // Recommended alternatives:
85
+ // - For claude-1.x and claude-instant-1.x: use claude-3-5-haiku-20241022
86
+ // - For claude-2.x: use claude-3-5-sonnet-20241022
87
+ AnthropicCompletionProvider.ANTHROPIC_COMPLETION_MODELS = [
88
+ // All models below are deprecated and will be retired soon
89
+ // Only kept for reference - migrate to newer models in new code
90
+ 'claude-2.0', // Deprecated, retiring July 21, 2025
91
+ 'claude-2.1', // Deprecated, retiring July 21, 2025
92
+ ];
93
+ //# sourceMappingURL=completion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"completion.js","sourceRoot":"","sources":["../../../../src/providers/anthropic/completion.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA0C;AAC1C,uCAAuD;AACvD,yCAAoE;AACpE,0DAAkC;AAGlC,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AG,EAAE,CAAC;YACb,OAAO;gBACL,KAAK,EAAE,uBAAuB,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE;aACzE,CAAC;QACJ,CAAC;IACH,CAAC;;AA1FH,kEA2FC;AA1FC,uEAAuE;AACvE,+CAA+C;AAC/C,4BAA4B;AAC5B,yEAAyE;AACzE,mDAAmD;AAC5C,uDAA2B,GAAG;IACnC,2DAA2D;IAC3D,gEAAgE;IAChE,YAAY,EAAE,qCAAqC;IACnD,YAAY,EAAE,qCAAqC;CACpD,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { DefaultProviders, ProviderResponse } from '../../types';
2
+ import type { EnvOverrides } from '../../types/env';
3
+ import { AnthropicMessagesProvider } from './messages';
4
+ export declare const DEFAULT_ANTHROPIC_MODEL = "claude-3-7-sonnet-20250219";
5
+ export declare class AnthropicLlmRubricProvider extends AnthropicMessagesProvider {
6
+ constructor(modelName: string, options?: {
7
+ env?: EnvOverrides;
8
+ config?: Record<string, any>;
9
+ });
10
+ callApi(prompt: string): Promise<ProviderResponse>;
11
+ }
12
+ /**
13
+ * Gets all default Anthropic providers with the given environment overrides
14
+ * @param env - Optional environment overrides
15
+ * @returns Anthropic provider implementations for various functions
16
+ */
17
+ export declare function getAnthropicProviders(env?: EnvOverrides): Pick<DefaultProviders, 'datasetGenerationProvider' | 'gradingJsonProvider' | 'gradingProvider' | 'llmRubricProvider' | 'suggestionsProvider' | 'synthesizeProvider'>;
18
+ //# sourceMappingURL=defaults.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../../../src/providers/anthropic/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAGvD,eAAO,MAAM,uBAAuB,+BAA+B,CAAC;AA2BpE,qBAAa,0BAA2B,SAAQ,yBAAyB;gBAErE,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE;QAAE,GAAG,CAAC,EAAE,YAAY,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAAO;IAoC9D,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;CA2BzD;AAWD;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,CAAC,EAAE,YAAY,GACjB,IAAI,CACL,gBAAgB,EACd,2BAA2B,GAC3B,qBAAqB,GACrB,iBAAiB,GACjB,mBAAmB,GACnB,qBAAqB,GACrB,oBAAoB,CACvB,CAaA"}
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AnthropicLlmRubricProvider = exports.DEFAULT_ANTHROPIC_MODEL = void 0;
4
+ exports.getAnthropicProviders = getAnthropicProviders;
5
+ const messages_1 = require("./messages");
6
+ // Default model to use for all default providers
7
+ exports.DEFAULT_ANTHROPIC_MODEL = 'claude-3-7-sonnet-20250219';
8
+ /**
9
+ * Helper function to create a lazy-loaded provider. This allows the .env file to be
10
+ * loaded first before the provider is initialized.
11
+ * @param factory Factory function that creates provider instance with optional env
12
+ * @returns Object with getter that lazily initializes the provider with the latest env
13
+ */
14
+ function createLazyProvider(factory) {
15
+ const instances = new Map();
16
+ return {
17
+ getInstance(env) {
18
+ // Use a simple cache key strategy - empty string for undefined env
19
+ const cacheKey = env ? JSON.stringify(env) : '';
20
+ if (!instances.has(cacheKey)) {
21
+ instances.set(cacheKey, factory(env));
22
+ }
23
+ return instances.get(cacheKey);
24
+ },
25
+ };
26
+ }
27
+ // LLM Rubric Provider
28
+ class AnthropicLlmRubricProvider extends messages_1.AnthropicMessagesProvider {
29
+ constructor(modelName, options = {}) {
30
+ const { env, config = {} } = options;
31
+ super(modelName, {
32
+ env,
33
+ config: {
34
+ tool_choice: { type: 'tool', name: 'grade_output' },
35
+ tools: [
36
+ {
37
+ name: 'grade_output',
38
+ description: 'Grade the given output based on specific criteria',
39
+ input_schema: {
40
+ type: 'object',
41
+ properties: {
42
+ pass: {
43
+ type: 'boolean',
44
+ description: 'Whether the output passes the criteria',
45
+ },
46
+ score: {
47
+ type: 'number',
48
+ description: 'The score assigned to the output',
49
+ },
50
+ reason: {
51
+ type: 'string',
52
+ description: 'The reason for the given grade',
53
+ },
54
+ },
55
+ required: ['pass', 'score', 'reason'],
56
+ },
57
+ },
58
+ ],
59
+ ...config,
60
+ },
61
+ });
62
+ }
63
+ async callApi(prompt) {
64
+ const result = await super.callApi(prompt);
65
+ if (typeof result.output !== 'string') {
66
+ return {
67
+ error: `Anthropic LLM rubric grader - malformed non-string output\n\n${JSON.stringify(result.output)}`,
68
+ };
69
+ }
70
+ try {
71
+ const functionCall = JSON.parse(result.output);
72
+ return {
73
+ output: functionCall.input,
74
+ };
75
+ }
76
+ catch (err) {
77
+ return {
78
+ error: `Anthropic LLM rubric grader - invalid JSON: ${err}\n\n${result.output}`,
79
+ };
80
+ }
81
+ }
82
+ }
83
+ exports.AnthropicLlmRubricProvider = AnthropicLlmRubricProvider;
84
+ // Private provider factories with lazy loading
85
+ const gradingProviderFactory = createLazyProvider((env) => new messages_1.AnthropicMessagesProvider(exports.DEFAULT_ANTHROPIC_MODEL, { env }));
86
+ const llmRubricProviderFactory = createLazyProvider((env) => new AnthropicLlmRubricProvider(exports.DEFAULT_ANTHROPIC_MODEL, { env }));
87
+ /**
88
+ * Gets all default Anthropic providers with the given environment overrides
89
+ * @param env - Optional environment overrides
90
+ * @returns Anthropic provider implementations for various functions
91
+ */
92
+ function getAnthropicProviders(env) {
93
+ // Get providers with the provided environment variables
94
+ const gradingProvider = gradingProviderFactory.getInstance(env);
95
+ const llmRubricProvider = llmRubricProviderFactory.getInstance(env);
96
+ return {
97
+ datasetGenerationProvider: gradingProvider,
98
+ gradingJsonProvider: gradingProvider,
99
+ gradingProvider,
100
+ llmRubricProvider,
101
+ suggestionsProvider: gradingProvider,
102
+ synthesizeProvider: gradingProvider,
103
+ };
104
+ }
105
+ //# sourceMappingURL=defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../../../src/providers/anthropic/defaults.ts"],"names":[],"mappings":";;;AAkHA,sDAuBC;AAvID,yCAAuD;AAEvD,iDAAiD;AACpC,QAAA,uBAAuB,GAAG,4BAA4B,CAAC;AAEpE;;;;;GAKG;AACH,SAAS,kBAAkB,CAAI,OAAkC;IAG/D,MAAM,SAAS,GAAG,IAAI,GAAG,EAAa,CAAC;IAEvC,OAAO;QACL,WAAW,CAAC,GAAkB;YAC5B,mEAAmE;YACnE,MAAM,QAAQ,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAEhD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC7B,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;YACxC,CAAC;YACD,OAAO,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAE,CAAC;QAClC,CAAC;KACF,CAAC;AACJ,CAAC;AAED,sBAAsB;AACtB,MAAa,0BAA2B,SAAQ,oCAAyB;IACvE,YACE,SAAiB,EACjB,UAAgE,EAAE;QAElE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC;QACrC,KAAK,CAAC,SAAS,EAAE;YACf,GAAG;YACH,MAAM,EAAE;gBACN,WAAW,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE;gBACnD,KAAK,EAAE;oBACL;wBACE,IAAI,EAAE,cAAc;wBACp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F,MAAM,wBAAwB,GAAG,kBAAkB,CACjD,CAAC,GAAkB,EAAE,EAAE,CAAC,IAAI,0BAA0B,CAAC,+BAAuB,EAAE,EAAE,GAAG,EAAE,CAAC,CACzF,CAAC;AAEF;;;;GAIG;AACH,SAAgB,qBAAqB,CACnC,GAAkB;IAUlB,wDAAwD;IACxD,MAAM,eAAe,GAAG,sBAAsB,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAChE,MAAM,iBAAiB,GAAG,wBAAwB,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAEpE,OAAO;QACL,yBAAyB,EAAE,eAAe;QAC1C,mBAAmB,EAAE,eAAe;QACpC,eAAe;QACf,iBAAiB;QACjB,mBAAmB,EAAE,eAAe;QACpC,kBAAkB,EAAE,eAAe;KACpC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,37 @@
1
+ import Anthropic from '@anthropic-ai/sdk';
2
+ import type { ApiProvider, ProviderResponse } from '../../types';
3
+ import type { EnvOverrides } from '../../types/env';
4
+ /**
5
+ * Base options shared by all Anthropic provider implementations
6
+ */
7
+ export interface AnthropicBaseOptions {
8
+ apiKey?: string;
9
+ apiBaseUrl?: string;
10
+ headers?: Record<string, string>;
11
+ cost?: number;
12
+ }
13
+ /**
14
+ * Generic provider class for Anthropic APIs
15
+ * Serves as a base class with shared functionality for all Anthropic providers
16
+ */
17
+ export declare class AnthropicGenericProvider implements ApiProvider {
18
+ modelName: string;
19
+ config: AnthropicBaseOptions;
20
+ env?: EnvOverrides;
21
+ apiKey?: string;
22
+ anthropic: Anthropic;
23
+ constructor(modelName: string, options?: {
24
+ config?: AnthropicBaseOptions;
25
+ id?: string;
26
+ env?: EnvOverrides;
27
+ });
28
+ id(): string;
29
+ toString(): string;
30
+ getApiKey(): string | undefined;
31
+ getApiBaseUrl(): string | undefined;
32
+ /**
33
+ * Base implementation - should be overridden by specific provider implementations
34
+ */
35
+ callApi(prompt: string): Promise<ProviderResponse>;
36
+ }
37
+ //# sourceMappingURL=generic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../../../src/providers/anthropic/generic.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAE1C,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,qBAAa,wBAAyB,YAAW,WAAW;IAC1D,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,oBAAoB,CAAC;IAC7B,GAAG,CAAC,EAAE,YAAY,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,SAAS,CAAC;gBAGnB,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE;QACP,MAAM,CAAC,EAAE,oBAAoB,CAAC;QAC9B,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,GAAG,CAAC,EAAE,YAAY,CAAC;KACf;IAcR,EAAE,IAAI,MAAM;IAIZ,QAAQ,IAAI,MAAM;IAIlB,SAAS,IAAI,MAAM,GAAG,SAAS;IAI/B,aAAa,IAAI,MAAM,GAAG,SAAS;IAMnC;;OAEG;IACG,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAGzD"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AnthropicGenericProvider = void 0;
7
+ const sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
8
+ const envars_1 = require("../../envars");
9
+ /**
10
+ * Generic provider class for Anthropic APIs
11
+ * Serves as a base class with shared functionality for all Anthropic providers
12
+ */
13
+ class AnthropicGenericProvider {
14
+ constructor(modelName, options = {}) {
15
+ const { config, id, env } = options;
16
+ this.env = env;
17
+ this.modelName = modelName;
18
+ this.config = config || {};
19
+ this.apiKey = this.getApiKey();
20
+ this.anthropic = new sdk_1.default({
21
+ apiKey: this.apiKey,
22
+ baseURL: this.getApiBaseUrl(),
23
+ });
24
+ this.id = id ? () => id : this.id;
25
+ }
26
+ id() {
27
+ return `anthropic:${this.modelName}`;
28
+ }
29
+ toString() {
30
+ return `[Anthropic Provider ${this.modelName}]`;
31
+ }
32
+ getApiKey() {
33
+ return this.config?.apiKey || this.env?.ANTHROPIC_API_KEY || (0, envars_1.getEnvString)('ANTHROPIC_API_KEY');
34
+ }
35
+ getApiBaseUrl() {
36
+ return (this.config?.apiBaseUrl || this.env?.ANTHROPIC_BASE_URL || (0, envars_1.getEnvString)('ANTHROPIC_BASE_URL'));
37
+ }
38
+ /**
39
+ * Base implementation - should be overridden by specific provider implementations
40
+ */
41
+ async callApi(prompt) {
42
+ throw new Error('Not implemented: callApi must be implemented by subclasses');
43
+ }
44
+ }
45
+ exports.AnthropicGenericProvider = AnthropicGenericProvider;
46
+ //# sourceMappingURL=generic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generic.js","sourceRoot":"","sources":["../../../../src/providers/anthropic/generic.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA0C;AAC1C,yCAA4C;AAc5C;;;GAGG;AACH,MAAa,wBAAwB;IAOnC,YACE,SAAiB,EACjB,UAII,EAAE;QAEN,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;QACpC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAC/B,IAAI,CAAC,SAAS,GAAG,IAAI,aAAS,CAAC;YAC7B,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE;SAC9B,CAAC,CAAC;QACH,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;IACpC,CAAC;IAED,EAAE;QACA,OAAO,aAAa,IAAI,CAAC,SAAS,EAAE,CAAC;IACvC,CAAC;IAED,QAAQ;QACN,OAAO,uBAAuB,IAAI,CAAC,SAAS,GAAG,CAAC;IAClD,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,EAAE,MAAM,IAAI,IAAI,CAAC,GAAG,EAAE,iBAAiB,IAAI,IAAA,qBAAY,EAAC,mBAAmB,CAAC,CAAC;IACjG,CAAC;IAED,aAAa;QACX,OAAO,CACL,IAAI,CAAC,MAAM,EAAE,UAAU,IAAI,IAAI,CAAC,GAAG,EAAE,kBAAkB,IAAI,IAAA,qBAAY,EAAC,oBAAoB,CAAC,CAC9F,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,MAAc;QAC1B,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;IAChF,CAAC;CACF;AAnDD,4DAmDC"}
@@ -0,0 +1,23 @@
1
+ import type { ProviderResponse } from '../../types';
2
+ import type { EnvOverrides } from '../../types/env';
3
+ import { AnthropicGenericProvider } from './generic';
4
+ import type { AnthropicMessageOptions } from './types';
5
+ export declare class AnthropicMessagesProvider extends AnthropicGenericProvider {
6
+ config: AnthropicMessageOptions;
7
+ static ANTHROPIC_MODELS: {
8
+ id: string;
9
+ cost: {
10
+ input: number;
11
+ output: number;
12
+ };
13
+ }[];
14
+ static ANTHROPIC_MODELS_NAMES: string[];
15
+ constructor(modelName: string, options?: {
16
+ id?: string;
17
+ config?: AnthropicMessageOptions;
18
+ env?: EnvOverrides;
19
+ });
20
+ toString(): string;
21
+ callApi(prompt: string): Promise<ProviderResponse>;
22
+ }
23
+ //# sourceMappingURL=messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../../src/providers/anthropic/messages.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AASvD,qBAAa,yBAA0B,SAAQ,wBAAwB;IAC7D,MAAM,EAAE,uBAAuB,CAAC;IAExC,MAAM,CAAC,gBAAgB;;;;;;QAAoB;IAE3C,MAAM,CAAC,sBAAsB,WAA6C;gBAGxE,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,uBAAuB,CAAC;QAAC,GAAG,CAAC,EAAE,YAAY,CAAA;KAAO;IAUrF,QAAQ,IAAI,MAAM;IAOZ,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAyHzD"}
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AnthropicMessagesProvider = void 0;
7
+ const sdk_1 = require("@anthropic-ai/sdk");
8
+ const cache_1 = require("../../cache");
9
+ const envars_1 = require("../../envars");
10
+ const logger_1 = __importDefault(require("../../logger"));
11
+ const util_1 = require("../../util");
12
+ const generic_1 = require("./generic");
13
+ const util_2 = require("./util");
14
+ class AnthropicMessagesProvider extends generic_1.AnthropicGenericProvider {
15
+ constructor(modelName, options = {}) {
16
+ if (!AnthropicMessagesProvider.ANTHROPIC_MODELS_NAMES.includes(modelName)) {
17
+ logger_1.default.warn(`Using unknown Anthropic model: ${modelName}`);
18
+ }
19
+ super(modelName, options);
20
+ const { id } = options;
21
+ this.id = id ? () => id : this.id;
22
+ }
23
+ toString() {
24
+ if (!this.modelName) {
25
+ throw new Error('Anthropic model name is not set. Please provide a valid model name.');
26
+ }
27
+ return `[Anthropic Messages Provider ${this.modelName}]`;
28
+ }
29
+ async callApi(prompt) {
30
+ if (!this.apiKey) {
31
+ throw new Error('Anthropic API key is not set. Set the ANTHROPIC_API_KEY environment variable or add `apiKey` to the provider config.');
32
+ }
33
+ if (!this.modelName) {
34
+ throw new Error('Anthropic model name is not set. Please provide a valid model name.');
35
+ }
36
+ const { system, extractedMessages, thinking } = (0, util_2.parseMessages)(prompt);
37
+ const params = {
38
+ model: this.modelName,
39
+ ...(system ? { system } : {}),
40
+ max_tokens: this.config?.max_tokens ||
41
+ (0, envars_1.getEnvInt)('ANTHROPIC_MAX_TOKENS', this.config.thinking || thinking ? 2048 : 1024),
42
+ messages: extractedMessages,
43
+ stream: false,
44
+ temperature: this.config.thinking || thinking
45
+ ? this.config.temperature
46
+ : this.config.temperature || (0, envars_1.getEnvFloat)('ANTHROPIC_TEMPERATURE', 0),
47
+ ...(this.config.tools ? { tools: (0, util_1.maybeLoadFromExternalFile)(this.config.tools) } : {}),
48
+ ...(this.config.tool_choice ? { tool_choice: this.config.tool_choice } : {}),
49
+ ...(this.config.thinking || thinking ? { thinking: this.config.thinking || thinking } : {}),
50
+ ...(typeof this.config?.extra_body === 'object' && this.config.extra_body
51
+ ? this.config.extra_body
52
+ : {}),
53
+ };
54
+ logger_1.default.debug(`Calling Anthropic Messages API: ${JSON.stringify(params)}`);
55
+ const headers = {
56
+ ...(this.config.headers || {}),
57
+ };
58
+ // Add beta features header if specified
59
+ if (this.config.beta?.length) {
60
+ headers['anthropic-beta'] = this.config.beta.join(',');
61
+ }
62
+ const cache = await (0, cache_1.getCache)();
63
+ const cacheKey = `anthropic:${JSON.stringify(params)}`;
64
+ if ((0, cache_1.isCacheEnabled)()) {
65
+ // Try to get the cached response
66
+ const cachedResponse = await cache.get(cacheKey);
67
+ if (cachedResponse) {
68
+ logger_1.default.debug(`Returning cached response for ${prompt}: ${cachedResponse}`);
69
+ try {
70
+ const parsedCachedResponse = JSON.parse(cachedResponse);
71
+ return {
72
+ output: (0, util_2.outputFromMessage)(parsedCachedResponse, this.config.showThinking ?? true),
73
+ tokenUsage: (0, util_2.getTokenUsage)(parsedCachedResponse, true),
74
+ cost: (0, util_2.calculateAnthropicCost)(this.modelName, this.config, parsedCachedResponse.usage?.input_tokens, parsedCachedResponse.usage?.output_tokens),
75
+ };
76
+ }
77
+ catch {
78
+ // Could be an old cache item, which was just the text content from TextBlock.
79
+ return {
80
+ output: cachedResponse,
81
+ tokenUsage: {},
82
+ };
83
+ }
84
+ }
85
+ }
86
+ try {
87
+ const response = await this.anthropic.messages.create(params, {
88
+ ...(typeof headers === 'object' && Object.keys(headers).length > 0 ? { headers } : {}),
89
+ });
90
+ logger_1.default.debug(`Anthropic Messages API response: ${JSON.stringify(response)}`);
91
+ if ((0, cache_1.isCacheEnabled)()) {
92
+ try {
93
+ await cache.set(cacheKey, JSON.stringify(response));
94
+ }
95
+ catch (err) {
96
+ logger_1.default.error(`Failed to cache response: ${String(err)}`);
97
+ }
98
+ }
99
+ if ('stream' in response) {
100
+ // Handle streaming response
101
+ return {
102
+ output: 'Streaming response not supported in this context',
103
+ error: 'Streaming should be disabled for this use case',
104
+ };
105
+ }
106
+ return {
107
+ output: (0, util_2.outputFromMessage)(response, this.config.showThinking ?? true),
108
+ tokenUsage: (0, util_2.getTokenUsage)(response, false),
109
+ cost: (0, util_2.calculateAnthropicCost)(this.modelName, this.config, response.usage?.input_tokens, response.usage?.output_tokens),
110
+ };
111
+ }
112
+ catch (err) {
113
+ logger_1.default.error(`Anthropic Messages API call error: ${err instanceof Error ? err.message : String(err)}`);
114
+ if (err instanceof sdk_1.APIError && err.error) {
115
+ const errorDetails = err.error;
116
+ return {
117
+ error: `API call error: ${errorDetails.error.message}, status ${err.status}, type ${errorDetails.error.type}`,
118
+ };
119
+ }
120
+ return {
121
+ error: `API call error: ${err instanceof Error ? err.message : String(err)}`,
122
+ };
123
+ }
124
+ }
125
+ }
126
+ exports.AnthropicMessagesProvider = AnthropicMessagesProvider;
127
+ AnthropicMessagesProvider.ANTHROPIC_MODELS = util_2.ANTHROPIC_MODELS;
128
+ AnthropicMessagesProvider.ANTHROPIC_MODELS_NAMES = util_2.ANTHROPIC_MODELS.map((model) => model.id);
129
+ //# sourceMappingURL=messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.js","sourceRoot":"","sources":["../../../../src/providers/anthropic/messages.ts"],"names":[],"mappings":";;;;;;AACA,2CAA6C;AAC7C,uCAAuD;AACvD,yCAAsD;AACtD,0DAAkC;AAGlC,qCAAuD;AACvD,uCAAqD;AAErD,iCAMgB;AAEhB,MAAa,yBAA0B,SAAQ,kCAAwB;IAOrE,YACE,SAAiB,EACjB,UAAiF,EAAE;QAEnF,IAAI,CAAC,yBAAyB,CAAC,sBAAsB,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;YAC1E,gBAAM,CAAC,IAAI,CAAC,kCAAkC,SAAS,EAAE,CAAC,CAAC;QAC7D,CAAC;QACD,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAC1B,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,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9G,CAAC;YACJ,CAAC;YACD,OAAO;gBACL,KAAK,EAAE,mBAAmB,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;aAC7E,CAAC;QACJ,CAAC;IACH,CAAC;;AAlJH,8DAmJC;AAhJQ,0CAAgB,GAAG,uBAAgB,CAAC;AAEpC,gDAAsB,GAAG,uBAAgB,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type Anthropic from '@anthropic-ai/sdk';
2
+ export interface AnthropicMessageOptions {
3
+ apiBaseUrl?: string;
4
+ apiKey?: string;
5
+ cost?: number;
6
+ extra_body?: Record<string, any>;
7
+ headers?: Record<string, string>;
8
+ max_tokens?: number;
9
+ model?: string;
10
+ temperature?: number;
11
+ thinking?: Anthropic.Messages.ThinkingConfigParam;
12
+ tool_choice?: Anthropic.Messages.ToolChoice;
13
+ tools?: Anthropic.Tool[];
14
+ top_k?: number;
15
+ top_p?: number;
16
+ beta?: string[];
17
+ showThinking?: boolean;
18
+ }
19
+ export interface AnthropicCompletionOptions {
20
+ apiKey?: string;
21
+ max_tokens_to_sample?: number;
22
+ temperature?: number;
23
+ top_p?: number;
24
+ top_k?: number;
25
+ }
26
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/providers/anthropic/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,mBAAmB,CAAC;AAE/C,MAAM,WAAW,uBAAuB;IACtC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,SAAS,CAAC,QAAQ,CAAC,mBAAmB,CAAC;IAClD,WAAW,CAAC,EAAE,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC;IAC5C,KAAK,CAAC,EAAE,SAAS,CAAC,IAAI,EAAE,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,0BAA0B;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/providers/anthropic/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,18 @@
1
+ import type Anthropic from '@anthropic-ai/sdk';
2
+ import type { TokenUsage } from '../../types';
3
+ export declare const ANTHROPIC_MODELS: {
4
+ id: string;
5
+ cost: {
6
+ input: number;
7
+ output: number;
8
+ };
9
+ }[];
10
+ export declare function outputFromMessage(message: Anthropic.Messages.Message, showThinking: boolean): string;
11
+ export declare function parseMessages(messages: string): {
12
+ system?: Anthropic.TextBlockParam[];
13
+ extractedMessages: Anthropic.MessageParam[];
14
+ thinking?: Anthropic.ThinkingConfigParam;
15
+ };
16
+ export declare function calculateAnthropicCost(modelName: string, config: any, promptTokens?: number, completionTokens?: number): number | undefined;
17
+ export declare function getTokenUsage(data: any, cached: boolean): Partial<TokenUsage>;
18
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../../src/providers/anthropic/util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAI9C,eAAO,MAAM,gBAAgB;;;;;;GAqD5B,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,UA4B3F;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG;IAC/C,MAAM,CAAC,EAAE,SAAS,CAAC,cAAc,EAAE,CAAC;IACpC,iBAAiB,EAAE,SAAS,CAAC,YAAY,EAAE,CAAC;IAC5C,QAAQ,CAAC,EAAE,SAAS,CAAC,mBAAmB,CAAC;CAC1C,CA8EA;AAED,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,GAAG,EACX,YAAY,CAAC,EAAE,MAAM,EACrB,gBAAgB,CAAC,EAAE,MAAM,GACxB,MAAM,GAAG,SAAS,CAEpB;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAc7E"}