visual-ai-assertions 0.3.0 → 0.5.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 +6 -10
- package/dist/index.cjs +12 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -10
- package/dist/index.d.ts +8 -10
- package/dist/index.js +12 -26
- package/dist/index.js.map +1 -1
- package/package.json +7 -14
package/README.md
CHANGED
|
@@ -98,9 +98,8 @@ const ai = visualAI();
|
|
|
98
98
|
|
|
99
99
|
// Explicit configuration
|
|
100
100
|
const ai = visualAI({
|
|
101
|
-
provider: "anthropic", // optional — auto-inferred from model or API key
|
|
102
|
-
apiKey: "sk-...", // optional, defaults to provider env var
|
|
103
101
|
model: "claude-sonnet-4-6", // optional, sensible defaults per provider
|
|
102
|
+
apiKey: "sk-...", // optional, defaults to provider env var
|
|
104
103
|
debug: true, // optional, logs prompts/responses to stderr
|
|
105
104
|
maxTokens: 4096, // optional, default 4096
|
|
106
105
|
reasoningEffort: "high", // optional, "low" | "medium" | "high" | "xhigh"
|
|
@@ -109,7 +108,6 @@ const ai = visualAI({
|
|
|
109
108
|
|
|
110
109
|
// Use constants for IDE autocomplete
|
|
111
110
|
const ai = visualAI({
|
|
112
|
-
provider: Provider.ANTHROPIC,
|
|
113
111
|
model: Model.Anthropic.SONNET_4_6,
|
|
114
112
|
});
|
|
115
113
|
```
|
|
@@ -389,18 +387,16 @@ The `VisualAIKnownError` union and `isVisualAIKnownError()` helper are useful wh
|
|
|
389
387
|
|
|
390
388
|
### Optional Configuration
|
|
391
389
|
|
|
392
|
-
| Variable | Description
|
|
393
|
-
| ----------------------- |
|
|
394
|
-
| `
|
|
395
|
-
| `
|
|
396
|
-
| `
|
|
397
|
-
| `VISUAL_AI_TRACK_USAGE` | Enable usage tracking when `trackUsage` is not set in config. Use `"true"` or `"1"` to enable. |
|
|
390
|
+
| Variable | Description |
|
|
391
|
+
| ----------------------- | ---------------------------------------------------------------------------------------------- |
|
|
392
|
+
| `VISUAL_AI_MODEL` | Default model when `model` is not set in config. Overrides the provider's default model. |
|
|
393
|
+
| `VISUAL_AI_DEBUG` | Enable debug logging when `debug` is not set in config. Use `"true"` or `"1"` to enable. |
|
|
394
|
+
| `VISUAL_AI_TRACK_USAGE` | Enable usage tracking when `trackUsage` is not set in config. Use `"true"` or `"1"` to enable. |
|
|
398
395
|
|
|
399
396
|
## Configuration
|
|
400
397
|
|
|
401
398
|
| Option | Type | Default | Description |
|
|
402
399
|
| ----------------- | ------- | ---------------- | ----------------------------------------------------------------------------- |
|
|
403
|
-
| `provider` | string | auto-inferred | `"anthropic"` `"openai"` `"google"` — inferred from model name or API key |
|
|
404
400
|
| `apiKey` | string | env var | API key for the provider |
|
|
405
401
|
| `model` | string | provider default | Model to use |
|
|
406
402
|
| `debug` | boolean | `false` | Log prompts/responses to stderr |
|
package/dist/index.cjs
CHANGED
|
@@ -46,7 +46,6 @@ __export(index_exports, {
|
|
|
46
46
|
Provider: () => Provider,
|
|
47
47
|
StatementResultSchema: () => StatementResultSchema,
|
|
48
48
|
UsageInfoSchema: () => UsageInfoSchema,
|
|
49
|
-
VALID_PROVIDERS: () => VALID_PROVIDERS,
|
|
50
49
|
VisualAIAssertionError: () => VisualAIAssertionError,
|
|
51
50
|
VisualAIAuthError: () => VisualAIAuthError,
|
|
52
51
|
VisualAIConfigError: () => VisualAIConfigError,
|
|
@@ -79,6 +78,8 @@ var Model = {
|
|
|
79
78
|
OpenAI: {
|
|
80
79
|
GPT_5_4: "gpt-5.4",
|
|
81
80
|
GPT_5_4_PRO: "gpt-5.4-pro",
|
|
81
|
+
GPT_5_4_MINI: "gpt-5.4-mini",
|
|
82
|
+
GPT_5_4_NANO: "gpt-5.4-nano",
|
|
82
83
|
GPT_5_2: "gpt-5.2",
|
|
83
84
|
GPT_5_MINI: "gpt-5-mini"
|
|
84
85
|
},
|
|
@@ -89,7 +90,7 @@ var Model = {
|
|
|
89
90
|
};
|
|
90
91
|
var DEFAULT_MODELS = {
|
|
91
92
|
[Provider.ANTHROPIC]: Model.Anthropic.SONNET_4_6,
|
|
92
|
-
[Provider.OPENAI]: Model.OpenAI.
|
|
93
|
+
[Provider.OPENAI]: Model.OpenAI.GPT_5_4_MINI,
|
|
93
94
|
[Provider.GOOGLE]: Model.Google.GEMINI_3_FLASH_PREVIEW
|
|
94
95
|
};
|
|
95
96
|
var DEFAULT_MAX_TOKENS = 4096;
|
|
@@ -726,23 +727,6 @@ function inferProviderFromModel(model) {
|
|
|
726
727
|
return prefixMatch?.[1];
|
|
727
728
|
}
|
|
728
729
|
function resolveProvider(config) {
|
|
729
|
-
if (config.provider) {
|
|
730
|
-
if (!VALID_PROVIDERS.includes(config.provider)) {
|
|
731
|
-
throw new VisualAIConfigError(
|
|
732
|
-
`Unknown provider: "${config.provider}". Supported: ${VALID_PROVIDERS.join(", ")}`
|
|
733
|
-
);
|
|
734
|
-
}
|
|
735
|
-
return config.provider;
|
|
736
|
-
}
|
|
737
|
-
const envProvider = process.env.VISUAL_AI_PROVIDER;
|
|
738
|
-
if (envProvider) {
|
|
739
|
-
if (VALID_PROVIDERS.includes(envProvider)) {
|
|
740
|
-
return envProvider;
|
|
741
|
-
}
|
|
742
|
-
throw new VisualAIConfigError(
|
|
743
|
-
`Invalid VISUAL_AI_PROVIDER: "${envProvider}". Supported: ${VALID_PROVIDERS.join(", ")}`
|
|
744
|
-
);
|
|
745
|
-
}
|
|
746
730
|
const model = config.model ?? process.env.VISUAL_AI_MODEL;
|
|
747
731
|
if (model) {
|
|
748
732
|
const inferred = inferProviderFromModel(model);
|
|
@@ -756,7 +740,7 @@ function resolveProvider(config) {
|
|
|
756
740
|
const detected = apiKeyProviderMap.find(([key]) => process.env[key]);
|
|
757
741
|
if (detected) return detected[1];
|
|
758
742
|
throw new VisualAIConfigError(
|
|
759
|
-
"
|
|
743
|
+
"Cannot determine provider. Set a model name (config or VISUAL_AI_MODEL) or an API key env variable (ANTHROPIC_API_KEY, OPENAI_API_KEY, GOOGLE_API_KEY)."
|
|
760
744
|
);
|
|
761
745
|
}
|
|
762
746
|
function parseBooleanEnv(envName, value) {
|
|
@@ -771,12 +755,6 @@ function parseBooleanEnv(envName, value) {
|
|
|
771
755
|
function resolveConfig(config) {
|
|
772
756
|
const provider = resolveProvider(config);
|
|
773
757
|
const model = config.model ?? process.env.VISUAL_AI_MODEL ?? DEFAULT_MODELS[provider];
|
|
774
|
-
const modelProvider = inferProviderFromModel(model);
|
|
775
|
-
if (modelProvider && modelProvider !== provider) {
|
|
776
|
-
throw new VisualAIConfigError(
|
|
777
|
-
`Model "${model}" appears to be a ${modelProvider} model, but provider is "${provider}". Either change the provider or use a ${provider}-compatible model.`
|
|
778
|
-
);
|
|
779
|
-
}
|
|
780
758
|
return {
|
|
781
759
|
provider,
|
|
782
760
|
apiKey: config.apiKey,
|
|
@@ -815,6 +793,14 @@ var PRICING_TABLE = {
|
|
|
815
793
|
inputPricePerToken: 1.75 / PER_MILLION,
|
|
816
794
|
outputPricePerToken: 14 / PER_MILLION
|
|
817
795
|
},
|
|
796
|
+
[`${Provider.OPENAI}:${Model.OpenAI.GPT_5_4_MINI}`]: {
|
|
797
|
+
inputPricePerToken: 0.75 / PER_MILLION,
|
|
798
|
+
outputPricePerToken: 4.5 / PER_MILLION
|
|
799
|
+
},
|
|
800
|
+
[`${Provider.OPENAI}:${Model.OpenAI.GPT_5_4_NANO}`]: {
|
|
801
|
+
inputPricePerToken: 0.2 / PER_MILLION,
|
|
802
|
+
outputPricePerToken: 1.25 / PER_MILLION
|
|
803
|
+
},
|
|
818
804
|
[`${Provider.OPENAI}:${Model.OpenAI.GPT_5_MINI}`]: {
|
|
819
805
|
inputPricePerToken: 0.25 / PER_MILLION,
|
|
820
806
|
outputPricePerToken: 2 / PER_MILLION
|
|
@@ -1397,7 +1383,6 @@ function assertVisualCompareResult(result, label) {
|
|
|
1397
1383
|
Provider,
|
|
1398
1384
|
StatementResultSchema,
|
|
1399
1385
|
UsageInfoSchema,
|
|
1400
|
-
VALID_PROVIDERS,
|
|
1401
1386
|
VisualAIAssertionError,
|
|
1402
1387
|
VisualAIAuthError,
|
|
1403
1388
|
VisualAIConfigError,
|