@agtlantis/core 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -5
- package/dist/errors/index.d.ts +4 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +3 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/types.d.ts +69 -0
- package/dist/errors/types.d.ts.map +1 -0
- package/dist/errors/types.js +116 -0
- package/dist/errors/types.js.map +1 -0
- package/dist/errors/utils.d.ts +17 -0
- package/dist/errors/utils.d.ts.map +1 -0
- package/dist/errors/utils.js +16 -0
- package/dist/errors/utils.js.map +1 -0
- package/dist/execution/constants.d.ts +7 -0
- package/dist/execution/constants.d.ts.map +1 -0
- package/dist/execution/constants.js +7 -0
- package/dist/execution/constants.js.map +1 -0
- package/dist/execution/index.d.ts +8 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +7 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/execution/mapping.d.ts +17 -0
- package/dist/execution/mapping.d.ts.map +1 -0
- package/dist/execution/mapping.js +197 -0
- package/dist/execution/mapping.js.map +1 -0
- package/dist/execution/shared.d.ts +86 -0
- package/dist/execution/shared.d.ts.map +1 -0
- package/dist/execution/shared.js +100 -0
- package/dist/execution/shared.js.map +1 -0
- package/dist/execution/simple-host.d.ts +56 -0
- package/dist/execution/simple-host.d.ts.map +1 -0
- package/dist/execution/simple-host.js +126 -0
- package/dist/execution/simple-host.js.map +1 -0
- package/dist/execution/streaming-host.d.ts +79 -0
- package/dist/execution/streaming-host.d.ts.map +1 -0
- package/dist/execution/streaming-host.js +276 -0
- package/dist/execution/streaming-host.js.map +1 -0
- package/dist/execution/testing/fixtures.d.ts +67 -0
- package/dist/execution/testing/fixtures.d.ts.map +1 -0
- package/dist/execution/testing/fixtures.js +145 -0
- package/dist/execution/testing/fixtures.js.map +1 -0
- package/dist/execution/testing/helpers.d.ts +218 -0
- package/dist/execution/testing/helpers.d.ts.map +1 -0
- package/dist/execution/testing/helpers.js +327 -0
- package/dist/execution/testing/helpers.js.map +1 -0
- package/dist/execution/testing/host-configs.d.ts +56 -0
- package/dist/execution/testing/host-configs.d.ts.map +1 -0
- package/dist/execution/testing/host-configs.js +154 -0
- package/dist/execution/testing/host-configs.js.map +1 -0
- package/dist/execution/testing/vitest-assertions.d.ts +102 -0
- package/dist/execution/testing/vitest-assertions.d.ts.map +1 -0
- package/dist/execution/testing/vitest-assertions.js +142 -0
- package/dist/execution/testing/vitest-assertions.js.map +1 -0
- package/dist/execution/types.d.ts +432 -0
- package/dist/execution/types.d.ts.map +1 -0
- package/dist/execution/types.js +2 -0
- package/dist/execution/types.js.map +1 -0
- package/dist/execution/utils.d.ts +68 -0
- package/dist/execution/utils.d.ts.map +1 -0
- package/dist/execution/utils.js +93 -0
- package/dist/execution/utils.js.map +1 -0
- package/dist/index.d.ts +10 -1506
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -2979
- package/dist/index.js.map +1 -1
- package/dist/observability/index.d.ts +4 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +2 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/logger.d.ts +161 -0
- package/dist/observability/logger.d.ts.map +1 -0
- package/dist/observability/logger.js +31 -0
- package/dist/observability/logger.js.map +1 -0
- package/dist/observability/types.d.ts +46 -0
- package/dist/observability/types.d.ts.map +1 -0
- package/dist/observability/types.js +2 -0
- package/dist/observability/types.js.map +1 -0
- package/dist/patterns/index.d.ts +2 -0
- package/dist/patterns/index.d.ts.map +1 -0
- package/dist/patterns/index.js +2 -0
- package/dist/patterns/index.js.map +1 -0
- package/dist/patterns/progressive/index.d.ts +2 -0
- package/dist/patterns/progressive/index.d.ts.map +1 -0
- package/dist/patterns/progressive/index.js +2 -0
- package/dist/patterns/progressive/index.js.map +1 -0
- package/dist/patterns/progressive/progressive-pattern.d.ts +174 -0
- package/dist/patterns/progressive/progressive-pattern.d.ts.map +1 -0
- package/dist/patterns/progressive/progressive-pattern.js +260 -0
- package/dist/patterns/progressive/progressive-pattern.js.map +1 -0
- package/dist/pricing/calculator.d.ts +71 -0
- package/dist/pricing/calculator.d.ts.map +1 -0
- package/dist/pricing/calculator.js +127 -0
- package/dist/pricing/calculator.js.map +1 -0
- package/dist/pricing/config.d.ts +61 -0
- package/dist/pricing/config.d.ts.map +1 -0
- package/dist/pricing/config.js +87 -0
- package/dist/pricing/config.js.map +1 -0
- package/dist/pricing/defaults.d.ts +29 -0
- package/dist/pricing/defaults.d.ts.map +1 -0
- package/dist/pricing/defaults.js +139 -0
- package/dist/pricing/defaults.js.map +1 -0
- package/dist/pricing/index.d.ts +40 -0
- package/dist/pricing/index.d.ts.map +1 -0
- package/dist/pricing/index.js +43 -0
- package/dist/pricing/index.js.map +1 -0
- package/dist/pricing/types.d.ts +96 -0
- package/dist/pricing/types.d.ts.map +1 -0
- package/dist/pricing/types.js +7 -0
- package/dist/pricing/types.js.map +1 -0
- package/dist/pricing/validator.d.ts +55 -0
- package/dist/pricing/validator.d.ts.map +1 -0
- package/dist/pricing/validator.js +84 -0
- package/dist/pricing/validator.js.map +1 -0
- package/dist/prompt/errors.d.ts +112 -0
- package/dist/prompt/errors.d.ts.map +1 -0
- package/dist/prompt/errors.js +174 -0
- package/dist/prompt/errors.js.map +1 -0
- package/dist/prompt/file-prompt-repository.d.ts +80 -0
- package/dist/prompt/file-prompt-repository.d.ts.map +1 -0
- package/dist/prompt/file-prompt-repository.js +287 -0
- package/dist/prompt/file-prompt-repository.js.map +1 -0
- package/dist/prompt/index.d.ts +34 -0
- package/dist/prompt/index.d.ts.map +1 -0
- package/dist/prompt/index.js +37 -0
- package/dist/prompt/index.js.map +1 -0
- package/dist/prompt/prompt-template.d.ts +64 -0
- package/dist/prompt/prompt-template.d.ts.map +1 -0
- package/dist/prompt/prompt-template.js +90 -0
- package/dist/prompt/prompt-template.js.map +1 -0
- package/dist/prompt/template.d.ts +23 -0
- package/dist/prompt/template.d.ts.map +1 -0
- package/dist/prompt/template.js +70 -0
- package/dist/prompt/template.js.map +1 -0
- package/dist/prompt/types.d.ts +148 -0
- package/dist/prompt/types.d.ts.map +1 -0
- package/dist/prompt/types.js +7 -0
- package/dist/prompt/types.js.map +1 -0
- package/dist/provider/base-file-manager.d.ts +14 -0
- package/dist/provider/base-file-manager.d.ts.map +1 -0
- package/dist/provider/base-file-manager.js +91 -0
- package/dist/provider/base-file-manager.js.map +1 -0
- package/dist/provider/base-provider.d.ts +41 -0
- package/dist/provider/base-provider.d.ts.map +1 -0
- package/dist/provider/base-provider.js +21 -0
- package/dist/provider/base-provider.js.map +1 -0
- package/dist/provider/file-cache.d.ts +14 -0
- package/dist/provider/file-cache.d.ts.map +1 -0
- package/dist/provider/file-cache.js +29 -0
- package/dist/provider/file-cache.js.map +1 -0
- package/dist/provider/file-source.d.ts +32 -0
- package/dist/provider/file-source.d.ts.map +1 -0
- package/dist/provider/file-source.js +180 -0
- package/dist/provider/file-source.js.map +1 -0
- package/dist/provider/file-utils.d.ts +5 -0
- package/dist/provider/file-utils.d.ts.map +1 -0
- package/dist/provider/file-utils.js +15 -0
- package/dist/provider/file-utils.js.map +1 -0
- package/dist/provider/google/factory.d.ts +107 -0
- package/dist/provider/google/factory.d.ts.map +1 -0
- package/dist/provider/google/factory.js +143 -0
- package/dist/provider/google/factory.js.map +1 -0
- package/dist/provider/google/file-manager.d.ts +10 -0
- package/dist/provider/google/file-manager.d.ts.map +1 -0
- package/dist/provider/google/file-manager.js +93 -0
- package/dist/provider/google/file-manager.js.map +1 -0
- package/dist/provider/google/index.d.ts +8 -0
- package/dist/provider/google/index.d.ts.map +1 -0
- package/dist/provider/google/index.js +10 -0
- package/dist/provider/google/index.js.map +1 -0
- package/dist/provider/hash.d.ts +3 -0
- package/dist/provider/hash.d.ts.map +1 -0
- package/dist/provider/hash.js +34 -0
- package/dist/provider/hash.js.map +1 -0
- package/dist/provider/index.d.ts +10 -0
- package/dist/provider/index.d.ts.map +1 -0
- package/dist/provider/index.js +12 -0
- package/dist/provider/index.js.map +1 -0
- package/dist/provider/noop-file-manager.d.ts +9 -0
- package/dist/provider/noop-file-manager.d.ts.map +1 -0
- package/dist/provider/noop-file-manager.js +28 -0
- package/dist/provider/noop-file-manager.js.map +1 -0
- package/dist/provider/openai/factory.d.ts +67 -0
- package/dist/provider/openai/factory.d.ts.map +1 -0
- package/dist/provider/openai/factory.js +100 -0
- package/dist/provider/openai/factory.js.map +1 -0
- package/dist/provider/openai/file-manager.d.ts +17 -0
- package/dist/provider/openai/file-manager.d.ts.map +1 -0
- package/dist/provider/openai/file-manager.js +108 -0
- package/dist/provider/openai/file-manager.js.map +1 -0
- package/dist/provider/openai/index.d.ts +8 -0
- package/dist/provider/openai/index.d.ts.map +1 -0
- package/dist/provider/openai/index.js +8 -0
- package/dist/provider/openai/index.js.map +1 -0
- package/dist/provider/types.d.ts +105 -0
- package/dist/provider/types.d.ts.map +1 -0
- package/dist/provider/types.js +19 -0
- package/dist/provider/types.js.map +1 -0
- package/dist/session/index.d.ts +7 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +5 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/simple-session.d.ts +98 -0
- package/dist/session/simple-session.d.ts.map +1 -0
- package/dist/session/simple-session.js +299 -0
- package/dist/session/simple-session.js.map +1 -0
- package/dist/session/streaming-session.d.ts +90 -0
- package/dist/session/streaming-session.d.ts.map +1 -0
- package/dist/session/streaming-session.js +151 -0
- package/dist/session/streaming-session.js.map +1 -0
- package/dist/session/test-utils.d.ts +19 -0
- package/dist/session/test-utils.d.ts.map +1 -0
- package/dist/session/test-utils.js +65 -0
- package/dist/session/test-utils.js.map +1 -0
- package/dist/session/types.d.ts +219 -0
- package/dist/session/types.d.ts.map +1 -0
- package/dist/session/types.js +181 -0
- package/dist/session/types.js.map +1 -0
- package/dist/session/usage-extractors.d.ts +7 -0
- package/dist/session/usage-extractors.d.ts.map +1 -0
- package/dist/session/usage-extractors.js +71 -0
- package/dist/session/usage-extractors.js.map +1 -0
- package/dist/testing/fixtures.d.ts +34 -0
- package/dist/testing/fixtures.d.ts.map +1 -0
- package/dist/testing/fixtures.js +65 -0
- package/dist/testing/fixtures.js.map +1 -0
- package/dist/testing/helpers.d.ts +20 -0
- package/dist/testing/helpers.d.ts.map +1 -0
- package/dist/testing/helpers.js +32 -0
- package/dist/testing/helpers.js.map +1 -0
- package/dist/testing/index.d.ts +7 -519
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +21 -2123
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/mock-provider.d.ts +79 -0
- package/dist/testing/mock-provider.d.ts.map +1 -0
- package/dist/testing/mock-provider.js +152 -0
- package/dist/testing/mock-provider.js.map +1 -0
- package/dist/testing/mock.d.ts +29 -0
- package/dist/testing/mock.d.ts.map +1 -0
- package/dist/testing/mock.js +154 -0
- package/dist/testing/mock.js.map +1 -0
- package/dist/testing/test-execution.d.ts +14 -0
- package/dist/testing/test-execution.d.ts.map +1 -0
- package/dist/testing/test-execution.js +108 -0
- package/dist/testing/test-execution.js.map +1 -0
- package/dist/utils/deep-merge.d.ts +6 -0
- package/dist/utils/deep-merge.d.ts.map +1 -0
- package/dist/utils/deep-merge.js +24 -0
- package/dist/utils/deep-merge.js.map +1 -0
- package/dist/validation/errors.d.ts +28 -0
- package/dist/validation/errors.d.ts.map +1 -0
- package/dist/validation/errors.js +38 -0
- package/dist/validation/errors.js.map +1 -0
- package/dist/validation/index.d.ts +5 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +4 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/types.d.ts +49 -0
- package/dist/validation/types.d.ts.map +1 -0
- package/dist/validation/types.js +2 -0
- package/dist/validation/types.js.map +1 -0
- package/dist/validation/validation-history.d.ts +12 -0
- package/dist/validation/validation-history.d.ts.map +1 -0
- package/dist/validation/validation-history.js +29 -0
- package/dist/validation/validation-history.js.map +1 -0
- package/dist/validation/with-validation.d.ts +38 -0
- package/dist/validation/with-validation.d.ts.map +1 -0
- package/dist/validation/with-validation.js +58 -0
- package/dist/validation/with-validation.js.map +1 -0
- package/package.json +71 -75
- package/dist/base-provider-2TTw5HAa.d.cts +0 -1254
- package/dist/base-provider-2TTw5HAa.d.ts +0 -1254
- package/dist/index.cjs +0 -3085
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -1506
- package/dist/testing/index.cjs +0 -2167
- package/dist/testing/index.cjs.map +0 -1
- package/dist/testing/index.d.cts +0 -520
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in pricing tables (USD per million tokens).
|
|
3
|
+
*
|
|
4
|
+
* These are the default prices for common models. They can be overridden
|
|
5
|
+
* using `configurePricing()` (global) or `Provider.withPricing()` (per-provider).
|
|
6
|
+
*
|
|
7
|
+
* Last updated: January 2025
|
|
8
|
+
*
|
|
9
|
+
* @module pricing/defaults
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* OpenAI model pricing.
|
|
13
|
+
* @see https://openai.com/pricing
|
|
14
|
+
*/
|
|
15
|
+
export const OPENAI_PRICING = {
|
|
16
|
+
'gpt-4o': { inputPricePerMillion: 2.5, outputPricePerMillion: 10.0 },
|
|
17
|
+
'gpt-4o-mini': { inputPricePerMillion: 0.15, outputPricePerMillion: 0.6 },
|
|
18
|
+
'gpt-4-turbo': { inputPricePerMillion: 10.0, outputPricePerMillion: 30.0 },
|
|
19
|
+
'gpt-4-turbo-preview': {
|
|
20
|
+
inputPricePerMillion: 10.0,
|
|
21
|
+
outputPricePerMillion: 30.0,
|
|
22
|
+
},
|
|
23
|
+
'gpt-4': { inputPricePerMillion: 30.0, outputPricePerMillion: 60.0 },
|
|
24
|
+
'gpt-4-32k': { inputPricePerMillion: 60.0, outputPricePerMillion: 120.0 },
|
|
25
|
+
'gpt-3.5-turbo': { inputPricePerMillion: 0.5, outputPricePerMillion: 1.5 },
|
|
26
|
+
'gpt-3.5-turbo-16k': {
|
|
27
|
+
inputPricePerMillion: 3.0,
|
|
28
|
+
outputPricePerMillion: 4.0,
|
|
29
|
+
},
|
|
30
|
+
'o1': { inputPricePerMillion: 15.0, outputPricePerMillion: 60.0 },
|
|
31
|
+
'o1-mini': { inputPricePerMillion: 3.0, outputPricePerMillion: 12.0 },
|
|
32
|
+
'o1-preview': { inputPricePerMillion: 15.0, outputPricePerMillion: 60.0 },
|
|
33
|
+
'o3': { inputPricePerMillion: 20.0, outputPricePerMillion: 80.0 },
|
|
34
|
+
'o3-mini': { inputPricePerMillion: 4.0, outputPricePerMillion: 16.0 },
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Google Gemini model pricing.
|
|
38
|
+
* @see https://ai.google.dev/gemini-api/docs/pricing
|
|
39
|
+
*/
|
|
40
|
+
export const GOOGLE_PRICING = {
|
|
41
|
+
'gemini-2.5-flash': {
|
|
42
|
+
inputPricePerMillion: 0.15,
|
|
43
|
+
outputPricePerMillion: 0.6,
|
|
44
|
+
cachedInputPricePerMillion: 0.0375,
|
|
45
|
+
},
|
|
46
|
+
'gemini-2.5-flash-lite': {
|
|
47
|
+
inputPricePerMillion: 0.075,
|
|
48
|
+
outputPricePerMillion: 0.3,
|
|
49
|
+
cachedInputPricePerMillion: 0.01875,
|
|
50
|
+
},
|
|
51
|
+
'gemini-2.5-pro': {
|
|
52
|
+
inputPricePerMillion: 1.25,
|
|
53
|
+
outputPricePerMillion: 10.0,
|
|
54
|
+
cachedInputPricePerMillion: 0.3125,
|
|
55
|
+
},
|
|
56
|
+
'gemini-2.0-flash': {
|
|
57
|
+
inputPricePerMillion: 0.1,
|
|
58
|
+
outputPricePerMillion: 0.4,
|
|
59
|
+
cachedInputPricePerMillion: 0.025,
|
|
60
|
+
},
|
|
61
|
+
'gemini-2.0-flash-lite': {
|
|
62
|
+
inputPricePerMillion: 0.075,
|
|
63
|
+
outputPricePerMillion: 0.3,
|
|
64
|
+
cachedInputPricePerMillion: 0.01875,
|
|
65
|
+
},
|
|
66
|
+
'gemini-1.5-pro': {
|
|
67
|
+
inputPricePerMillion: 1.25,
|
|
68
|
+
outputPricePerMillion: 5.0,
|
|
69
|
+
cachedInputPricePerMillion: 0.3125,
|
|
70
|
+
},
|
|
71
|
+
'gemini-1.5-flash': {
|
|
72
|
+
inputPricePerMillion: 0.075,
|
|
73
|
+
outputPricePerMillion: 0.3,
|
|
74
|
+
cachedInputPricePerMillion: 0.01875,
|
|
75
|
+
},
|
|
76
|
+
'gemini-1.5-flash-8b': {
|
|
77
|
+
inputPricePerMillion: 0.0375,
|
|
78
|
+
outputPricePerMillion: 0.15,
|
|
79
|
+
cachedInputPricePerMillion: 0.01,
|
|
80
|
+
},
|
|
81
|
+
'gemini-pro': { inputPricePerMillion: 0.5, outputPricePerMillion: 1.5 },
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Anthropic Claude model pricing.
|
|
85
|
+
* @see https://www.anthropic.com/pricing
|
|
86
|
+
*/
|
|
87
|
+
export const ANTHROPIC_PRICING = {
|
|
88
|
+
'claude-opus-4-5-20250514': {
|
|
89
|
+
inputPricePerMillion: 15.0,
|
|
90
|
+
outputPricePerMillion: 75.0,
|
|
91
|
+
cachedInputPricePerMillion: 1.875,
|
|
92
|
+
},
|
|
93
|
+
'claude-sonnet-4-20250514': {
|
|
94
|
+
inputPricePerMillion: 3.0,
|
|
95
|
+
outputPricePerMillion: 15.0,
|
|
96
|
+
cachedInputPricePerMillion: 0.375,
|
|
97
|
+
},
|
|
98
|
+
'claude-3-5-sonnet-20241022': {
|
|
99
|
+
inputPricePerMillion: 3.0,
|
|
100
|
+
outputPricePerMillion: 15.0,
|
|
101
|
+
cachedInputPricePerMillion: 0.375,
|
|
102
|
+
},
|
|
103
|
+
'claude-3-5-haiku-20241022': {
|
|
104
|
+
inputPricePerMillion: 0.8,
|
|
105
|
+
outputPricePerMillion: 4.0,
|
|
106
|
+
cachedInputPricePerMillion: 0.1,
|
|
107
|
+
},
|
|
108
|
+
'claude-3-opus-20240229': {
|
|
109
|
+
inputPricePerMillion: 15.0,
|
|
110
|
+
outputPricePerMillion: 75.0,
|
|
111
|
+
cachedInputPricePerMillion: 1.875,
|
|
112
|
+
},
|
|
113
|
+
'claude-3-sonnet-20240229': {
|
|
114
|
+
inputPricePerMillion: 3.0,
|
|
115
|
+
outputPricePerMillion: 15.0,
|
|
116
|
+
cachedInputPricePerMillion: 0.375,
|
|
117
|
+
},
|
|
118
|
+
'claude-3-haiku-20240307': {
|
|
119
|
+
inputPricePerMillion: 0.25,
|
|
120
|
+
outputPricePerMillion: 1.25,
|
|
121
|
+
cachedInputPricePerMillion: 0.03,
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
export const DEFAULT_PRICING_CONFIG = {
|
|
125
|
+
providers: {
|
|
126
|
+
openai: OPENAI_PRICING,
|
|
127
|
+
google: GOOGLE_PRICING,
|
|
128
|
+
anthropic: ANTHROPIC_PRICING,
|
|
129
|
+
},
|
|
130
|
+
fallback: {
|
|
131
|
+
inputPricePerMillion: 1.0,
|
|
132
|
+
outputPricePerMillion: 5.0,
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
export const DEFAULT_FALLBACK_PRICING = {
|
|
136
|
+
inputPricePerMillion: 1.0,
|
|
137
|
+
outputPricePerMillion: 5.0,
|
|
138
|
+
};
|
|
139
|
+
//# sourceMappingURL=defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../src/pricing/defaults.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAoB;IAC7C,QAAQ,EAAE,EAAE,oBAAoB,EAAE,GAAG,EAAE,qBAAqB,EAAE,IAAI,EAAE;IACpE,aAAa,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,qBAAqB,EAAE,GAAG,EAAE;IACz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EAAE;QAC1B,oBAAoB,EAAE,GAAG;QACzB,qBAAqB,EAAE,IAAI;QAC3B,0BAA0B,EAAE,KAAK;KAClC;IACD,yBAAyB,EAAE;QACzB,oBAAoB,EAAE,IAAI;QAC1B,qBAAqB,EAAE,IAAI;QAC3B,0BAA0B,EAAE,IAAI;KACjC;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAA4B;IAC7D,SAAS,EAAE;QACT,MAAM,EAAE,cAAc;QACtB,MAAM,EAAE,cAAc;QACtB,SAAS,EAAE,iBAAiB;KAC7B;IACD,QAAQ,EAAE;QACR,oBAAoB,EAAE,GAAG;QACzB,qBAAqB,EAAE,GAAG;KAC3B;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,wBAAwB,GAAiB;IACpD,oBAAoB,EAAE,GAAG;IACzB,qBAAqB,EAAE,GAAG;CAC3B,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pricing module for cost calculation.
|
|
3
|
+
*
|
|
4
|
+
* Provides types and functions for calculating LLM usage costs
|
|
5
|
+
* based on token counts and model pricing.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import {
|
|
10
|
+
* configurePricing,
|
|
11
|
+
* calculateCost,
|
|
12
|
+
* calculateCostFromUsage,
|
|
13
|
+
* } from '@agtlantis/core';
|
|
14
|
+
*
|
|
15
|
+
* // Configure custom pricing (optional)
|
|
16
|
+
* configurePricing({
|
|
17
|
+
* providers: {
|
|
18
|
+
* google: {
|
|
19
|
+
* 'gemini-2.5-flash': { inputPricePerMillion: 0.5, outputPricePerMillion: 3.0 },
|
|
20
|
+
* },
|
|
21
|
+
* },
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // Calculate cost from token counts
|
|
25
|
+
* const cost = calculateCost({
|
|
26
|
+
* inputTokens: 1000,
|
|
27
|
+
* outputTokens: 500,
|
|
28
|
+
* model: 'gemini-2.5-flash',
|
|
29
|
+
* provider: 'google',
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @module pricing
|
|
34
|
+
*/
|
|
35
|
+
export type { ProviderType, ModelPricing, ProviderPricing, PricingConfig, CalculateCostParams, CostResult, } from './types.js';
|
|
36
|
+
export { configurePricing, getPricingConfig, resetPricingConfig, getEffectivePricing, type PricingSource, type EffectivePricingResult, } from './config.js';
|
|
37
|
+
export { validateModelPricing, validateProviderPricing, validatePricingConfig, } from './validator.js';
|
|
38
|
+
export { getModelPricing, calculateCost, calculateCostFromUsage, calculateTotalCost, } from './calculator.js';
|
|
39
|
+
export { OPENAI_PRICING, GOOGLE_PRICING, ANTHROPIC_PRICING, DEFAULT_PRICING_CONFIG, DEFAULT_FALLBACK_PRICING, } from './defaults.js';
|
|
40
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pricing/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAGH,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,aAAa,EACb,mBAAmB,EACnB,UAAU,GACX,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,sBAAsB,GAC5B,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,oBAAoB,EACpB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,eAAe,EACf,aAAa,EACb,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pricing module for cost calculation.
|
|
3
|
+
*
|
|
4
|
+
* Provides types and functions for calculating LLM usage costs
|
|
5
|
+
* based on token counts and model pricing.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import {
|
|
10
|
+
* configurePricing,
|
|
11
|
+
* calculateCost,
|
|
12
|
+
* calculateCostFromUsage,
|
|
13
|
+
* } from '@agtlantis/core';
|
|
14
|
+
*
|
|
15
|
+
* // Configure custom pricing (optional)
|
|
16
|
+
* configurePricing({
|
|
17
|
+
* providers: {
|
|
18
|
+
* google: {
|
|
19
|
+
* 'gemini-2.5-flash': { inputPricePerMillion: 0.5, outputPricePerMillion: 3.0 },
|
|
20
|
+
* },
|
|
21
|
+
* },
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // Calculate cost from token counts
|
|
25
|
+
* const cost = calculateCost({
|
|
26
|
+
* inputTokens: 1000,
|
|
27
|
+
* outputTokens: 500,
|
|
28
|
+
* model: 'gemini-2.5-flash',
|
|
29
|
+
* provider: 'google',
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @module pricing
|
|
34
|
+
*/
|
|
35
|
+
// Configuration
|
|
36
|
+
export { configurePricing, getPricingConfig, resetPricingConfig, getEffectivePricing, } from './config.js';
|
|
37
|
+
// Validation
|
|
38
|
+
export { validateModelPricing, validateProviderPricing, validatePricingConfig, } from './validator.js';
|
|
39
|
+
// Calculation
|
|
40
|
+
export { getModelPricing, calculateCost, calculateCostFromUsage, calculateTotalCost, } from './calculator.js';
|
|
41
|
+
// Defaults (for reference/inspection)
|
|
42
|
+
export { OPENAI_PRICING, GOOGLE_PRICING, ANTHROPIC_PRICING, DEFAULT_PRICING_CONFIG, DEFAULT_FALLBACK_PRICING, } from './defaults.js';
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pricing/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAYH,gBAAgB;AAChB,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,GAGpB,MAAM,aAAa,CAAC;AAErB,aAAa;AACb,OAAO,EACL,oBAAoB,EACpB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AAExB,cAAc;AACd,OAAO,EACL,eAAe,EACf,aAAa,EACb,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AAEzB,sCAAsC;AACtC,OAAO,EACL,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pricing types for cost calculation.
|
|
3
|
+
*
|
|
4
|
+
* @module pricing/types
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* AI provider type identifier.
|
|
8
|
+
*
|
|
9
|
+
* Common values: 'google', 'openai', 'anthropic', 'mock'
|
|
10
|
+
* Extensible to support custom providers.
|
|
11
|
+
*/
|
|
12
|
+
export type ProviderType = string;
|
|
13
|
+
/**
|
|
14
|
+
* Pricing for a specific model in USD per million tokens.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const gpt4Pricing: ModelPricing = {
|
|
19
|
+
* inputPricePerMillion: 2.5,
|
|
20
|
+
* outputPricePerMillion: 10.0,
|
|
21
|
+
* cachedInputPricePerMillion: 1.25, // 50% discount for cached tokens
|
|
22
|
+
* };
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export interface ModelPricing {
|
|
26
|
+
inputPricePerMillion: number;
|
|
27
|
+
outputPricePerMillion: number;
|
|
28
|
+
/** Defaults to inputPricePerMillion if not set */
|
|
29
|
+
cachedInputPricePerMillion?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Pricing map for a provider's models.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const googlePricing: ProviderPricing = {
|
|
37
|
+
* 'gemini-2.5-flash': { inputPricePerMillion: 0.3, outputPricePerMillion: 2.5 },
|
|
38
|
+
* 'gemini-2.5-pro': { inputPricePerMillion: 1.25, outputPricePerMillion: 10.0 },
|
|
39
|
+
* };
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export type ProviderPricing = Record<string, ModelPricing>;
|
|
43
|
+
/**
|
|
44
|
+
* Global pricing configuration.
|
|
45
|
+
*
|
|
46
|
+
* Allows overriding built-in pricing defaults for any provider/model.
|
|
47
|
+
* Used with `configurePricing()` for global overrides or
|
|
48
|
+
* `Provider.withPricing()` for provider-level overrides.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const config: PricingConfig = {
|
|
53
|
+
* providers: {
|
|
54
|
+
* google: {
|
|
55
|
+
* 'gemini-2.5-flash': { inputPricePerMillion: 0.5, outputPricePerMillion: 3.0 },
|
|
56
|
+
* },
|
|
57
|
+
* },
|
|
58
|
+
* fallback: {
|
|
59
|
+
* inputPricePerMillion: 1.0,
|
|
60
|
+
* outputPricePerMillion: 5.0,
|
|
61
|
+
* },
|
|
62
|
+
* };
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export interface PricingConfig {
|
|
66
|
+
providers?: Partial<Record<ProviderType, ProviderPricing>>;
|
|
67
|
+
fallback?: ModelPricing;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Parameters for cost calculation.
|
|
71
|
+
*/
|
|
72
|
+
export interface CalculateCostParams {
|
|
73
|
+
/**
|
|
74
|
+
* Total input tokens INCLUDING cached tokens.
|
|
75
|
+
* The cost calculator subtracts cachedInputTokens to get non-cached tokens.
|
|
76
|
+
*/
|
|
77
|
+
inputTokens: number;
|
|
78
|
+
outputTokens: number;
|
|
79
|
+
/**
|
|
80
|
+
* Cached input tokens count (optional).
|
|
81
|
+
* Must be <= inputTokens. Cached tokens are billed at a lower rate.
|
|
82
|
+
*/
|
|
83
|
+
cachedInputTokens?: number;
|
|
84
|
+
model: string;
|
|
85
|
+
provider: ProviderType;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Result of cost calculation.
|
|
89
|
+
*/
|
|
90
|
+
export interface CostResult {
|
|
91
|
+
total: number;
|
|
92
|
+
inputCost: number;
|
|
93
|
+
outputCost: number;
|
|
94
|
+
cachedInputCost: number;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/pricing/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC;AAElC;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,YAAY;IAC3B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,kDAAkD;IAClD,0BAA0B,CAAC,EAAE,MAAM,CAAC;CACrC;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,aAAa;IAC5B,SAAS,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC,CAAC;IAC3D,QAAQ,CAAC,EAAE,YAAY,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,YAAY,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;CACzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/pricing/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pricing validation utilities.
|
|
3
|
+
*
|
|
4
|
+
* Provides fail-fast validation for pricing configuration to catch
|
|
5
|
+
* invalid values (negative, NaN, Infinity) at configuration time.
|
|
6
|
+
*
|
|
7
|
+
* @module pricing/validator
|
|
8
|
+
*/
|
|
9
|
+
import type { ModelPricing, PricingConfig, ProviderPricing } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Validates a ModelPricing object.
|
|
12
|
+
* Ensures all price values are non-negative and finite.
|
|
13
|
+
*
|
|
14
|
+
* @throws {Error} If any price value is invalid
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* validateModelPricing(
|
|
19
|
+
* { inputPricePerMillion: 2.5, outputPricePerMillion: 10.0 },
|
|
20
|
+
* 'openai/gpt-4o'
|
|
21
|
+
* );
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function validateModelPricing(pricing: ModelPricing, context: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* Validates a ProviderPricing object.
|
|
27
|
+
*
|
|
28
|
+
* @throws {Error} If any model pricing is invalid
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* validateProviderPricing({
|
|
33
|
+
* 'gemini-2.5-flash': { inputPricePerMillion: 0.3, outputPricePerMillion: 2.5 },
|
|
34
|
+
* 'gemini-2.5-pro': { inputPricePerMillion: 1.25, outputPricePerMillion: 10.0 },
|
|
35
|
+
* }, 'google');
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function validateProviderPricing(pricing: ProviderPricing, providerContext?: string): void;
|
|
39
|
+
/**
|
|
40
|
+
* Validates a PricingConfig object.
|
|
41
|
+
*
|
|
42
|
+
* @throws {Error} If any pricing configuration is invalid
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* validatePricingConfig({
|
|
47
|
+
* providers: {
|
|
48
|
+
* google: { 'gemini-2.5-flash': { inputPricePerMillion: 0.3, outputPricePerMillion: 2.5 } },
|
|
49
|
+
* },
|
|
50
|
+
* fallback: { inputPricePerMillion: 1.0, outputPricePerMillion: 5.0 },
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function validatePricingConfig(config: PricingConfig): void;
|
|
55
|
+
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/pricing/validator.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAe/E;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,MAAM,GACd,IAAI,CAmBN;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,eAAe,EACxB,eAAe,CAAC,EAAE,MAAM,GACvB,IAAI,CAKN;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAYjE"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pricing validation utilities.
|
|
3
|
+
*
|
|
4
|
+
* Provides fail-fast validation for pricing configuration to catch
|
|
5
|
+
* invalid values (negative, NaN, Infinity) at configuration time.
|
|
6
|
+
*
|
|
7
|
+
* @module pricing/validator
|
|
8
|
+
*/
|
|
9
|
+
function validatePriceValue(value, fieldName, context) {
|
|
10
|
+
if (!Number.isFinite(value)) {
|
|
11
|
+
throw new Error(`${context}: ${fieldName} must be a finite number`);
|
|
12
|
+
}
|
|
13
|
+
if (value < 0) {
|
|
14
|
+
throw new Error(`${context}: ${fieldName} cannot be negative`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Validates a ModelPricing object.
|
|
19
|
+
* Ensures all price values are non-negative and finite.
|
|
20
|
+
*
|
|
21
|
+
* @throws {Error} If any price value is invalid
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* validateModelPricing(
|
|
26
|
+
* { inputPricePerMillion: 2.5, outputPricePerMillion: 10.0 },
|
|
27
|
+
* 'openai/gpt-4o'
|
|
28
|
+
* );
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export function validateModelPricing(pricing, context) {
|
|
32
|
+
validatePriceValue(pricing.inputPricePerMillion, 'inputPricePerMillion', context);
|
|
33
|
+
validatePriceValue(pricing.outputPricePerMillion, 'outputPricePerMillion', context);
|
|
34
|
+
if (pricing.cachedInputPricePerMillion !== undefined) {
|
|
35
|
+
validatePriceValue(pricing.cachedInputPricePerMillion, 'cachedInputPricePerMillion', context);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Validates a ProviderPricing object.
|
|
40
|
+
*
|
|
41
|
+
* @throws {Error} If any model pricing is invalid
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* validateProviderPricing({
|
|
46
|
+
* 'gemini-2.5-flash': { inputPricePerMillion: 0.3, outputPricePerMillion: 2.5 },
|
|
47
|
+
* 'gemini-2.5-pro': { inputPricePerMillion: 1.25, outputPricePerMillion: 10.0 },
|
|
48
|
+
* }, 'google');
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export function validateProviderPricing(pricing, providerContext) {
|
|
52
|
+
for (const [model, modelPricing] of Object.entries(pricing)) {
|
|
53
|
+
const context = providerContext ? `${providerContext}/${model}` : model;
|
|
54
|
+
validateModelPricing(modelPricing, context);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Validates a PricingConfig object.
|
|
59
|
+
*
|
|
60
|
+
* @throws {Error} If any pricing configuration is invalid
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* validatePricingConfig({
|
|
65
|
+
* providers: {
|
|
66
|
+
* google: { 'gemini-2.5-flash': { inputPricePerMillion: 0.3, outputPricePerMillion: 2.5 } },
|
|
67
|
+
* },
|
|
68
|
+
* fallback: { inputPricePerMillion: 1.0, outputPricePerMillion: 5.0 },
|
|
69
|
+
* });
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export function validatePricingConfig(config) {
|
|
73
|
+
if (config.providers) {
|
|
74
|
+
for (const [providerKey, pricing] of Object.entries(config.providers)) {
|
|
75
|
+
if (pricing) {
|
|
76
|
+
validateProviderPricing(pricing, providerKey);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (config.fallback) {
|
|
81
|
+
validateModelPricing(config.fallback, 'fallback');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/pricing/validator.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,SAAS,kBAAkB,CACzB,KAAa,EAC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AM,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;YACtE,IAAI,OAAO,EAAE,CAAC;gBACZ,uBAAuB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;YAChD,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QACpB,oBAAoB,CAAC,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IACpD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt module error classes for @agtlantis/core.
|
|
3
|
+
*
|
|
4
|
+
* Each error type has a specific code and context for precise error handling.
|
|
5
|
+
*/
|
|
6
|
+
import { AgtlantisError, type AgtlantisErrorCode } from '../errors/index.js';
|
|
7
|
+
export declare enum PromptErrorCode {
|
|
8
|
+
/** Generic prompt error */
|
|
9
|
+
PROMPT_ERROR = "PROMPT_ERROR",
|
|
10
|
+
/** Prompt not found in repository */
|
|
11
|
+
NOT_FOUND = "PROMPT_NOT_FOUND",
|
|
12
|
+
/** Invalid prompt file format (e.g., malformed YAML) */
|
|
13
|
+
INVALID_FORMAT = "PROMPT_INVALID_FORMAT",
|
|
14
|
+
/** Template compilation failed */
|
|
15
|
+
TEMPLATE_ERROR = "PROMPT_TEMPLATE_ERROR",
|
|
16
|
+
/** File I/O operation failed */
|
|
17
|
+
IO_ERROR = "PROMPT_IO_ERROR"
|
|
18
|
+
}
|
|
19
|
+
declare module '../errors/index.js' {
|
|
20
|
+
interface AgtlantisErrorCodeMap {
|
|
21
|
+
prompt: PromptErrorCode;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export interface PromptErrorOptions {
|
|
25
|
+
code?: PromptErrorCode;
|
|
26
|
+
cause?: Error;
|
|
27
|
+
context?: Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Base error class for prompt operations.
|
|
31
|
+
* Use specific error subclasses for more precise error handling.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* throw new PromptError('Something went wrong', {
|
|
36
|
+
* code: PromptErrorCode.PROMPT_ERROR,
|
|
37
|
+
* context: { promptId: 'greeting' }
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare class PromptError extends AgtlantisError<PromptErrorCode & AgtlantisErrorCode> {
|
|
42
|
+
constructor(message: string, options?: PromptErrorOptions);
|
|
43
|
+
/**
|
|
44
|
+
* Creates a PromptError from an unknown error.
|
|
45
|
+
*/
|
|
46
|
+
static from(error: unknown, code?: PromptErrorCode, context?: Record<string, unknown>): PromptError;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Error thrown when a prompt is not found in the repository.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* throw new PromptNotFoundError('greeting', '1.0.0');
|
|
54
|
+
* // Error: Prompt 'greeting' version '1.0.0' not found
|
|
55
|
+
*
|
|
56
|
+
* throw new PromptNotFoundError('greeting');
|
|
57
|
+
* // Error: Prompt 'greeting' not found
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare class PromptNotFoundError extends PromptError {
|
|
61
|
+
readonly promptId: string;
|
|
62
|
+
readonly version?: string;
|
|
63
|
+
constructor(promptId: string, version?: string, options?: Omit<PromptErrorOptions, 'code'>);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Error thrown when a prompt file has invalid format.
|
|
67
|
+
* Examples: malformed YAML, missing required fields, invalid schema.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* throw new PromptInvalidFormatError('greeting', 'Missing required field: system');
|
|
72
|
+
* // Error: Invalid format for prompt 'greeting': Missing required field: system
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare class PromptInvalidFormatError extends PromptError {
|
|
76
|
+
readonly promptId: string;
|
|
77
|
+
readonly details: string;
|
|
78
|
+
constructor(promptId: string, details: string, options?: Omit<PromptErrorOptions, 'code'>);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Error thrown when template compilation fails.
|
|
82
|
+
* Examples: invalid Handlebars syntax, missing helper.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* throw new PromptTemplateError('greeting', 'Unexpected token {{/if}}');
|
|
87
|
+
* // Error: Template compilation failed for prompt 'greeting': Unexpected token {{/if}}
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare class PromptTemplateError extends PromptError {
|
|
91
|
+
readonly promptId: string;
|
|
92
|
+
readonly details: string;
|
|
93
|
+
constructor(promptId: string, details: string, options?: Omit<PromptErrorOptions, 'code'>);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Error thrown when file I/O operations fail.
|
|
97
|
+
* Examples: read failure, write failure, directory access denied.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* throw new PromptIOError('read', '/path/to/prompt.yaml', {
|
|
102
|
+
* cause: originalError
|
|
103
|
+
* });
|
|
104
|
+
* // Error: Failed to read prompt file: /path/to/prompt.yaml
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export declare class PromptIOError extends PromptError {
|
|
108
|
+
readonly operation: 'read' | 'write' | 'list';
|
|
109
|
+
readonly path: string;
|
|
110
|
+
constructor(operation: 'read' | 'write' | 'list', path: string, options?: Omit<PromptErrorOptions, 'code'>);
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/prompt/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,KAAK,kBAAkB,EAAE,MAAM,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