@shieldaai/security-watch 0.0.0-stage → 1.0.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/CHANGELOG.md +170 -0
- package/CONTRIBUTING.md +92 -0
- package/LICENSE +202 -0
- package/README.md +394 -2
- package/SECURITY.md +62 -0
- package/dist/assessment.d.ts +16 -0
- package/dist/assessment.js +569 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +1105 -0
- package/dist/config.d.ts +302 -0
- package/dist/config.js +381 -0
- package/dist/coverage.d.ts +4 -0
- package/dist/coverage.js +11 -0
- package/dist/cve-now.d.ts +35 -0
- package/dist/cve-now.js +1002 -0
- package/dist/cvss4.d.ts +3 -0
- package/dist/cvss4.js +39 -0
- package/dist/delivery.d.ts +58 -0
- package/dist/delivery.js +687 -0
- package/dist/ecosystems.d.ts +48 -0
- package/dist/ecosystems.js +332 -0
- package/dist/engine.d.ts +80 -0
- package/dist/engine.js +388 -0
- package/dist/everyday-words.d.ts +11 -0
- package/dist/everyday-words.js +256 -0
- package/dist/health.d.ts +24 -0
- package/dist/health.js +122 -0
- package/dist/heartbeat.d.ts +13 -0
- package/dist/heartbeat.js +74 -0
- package/dist/http.d.ts +15 -0
- package/dist/http.js +280 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +23 -0
- package/dist/inventory-evidence.d.ts +10 -0
- package/dist/inventory-evidence.js +206 -0
- package/dist/inventory.d.ts +276 -0
- package/dist/inventory.js +336 -0
- package/dist/lock.d.ts +3 -0
- package/dist/lock.js +112 -0
- package/dist/maintenance.d.ts +48 -0
- package/dist/maintenance.js +295 -0
- package/dist/matching.d.ts +29 -0
- package/dist/matching.js +537 -0
- package/dist/models.d.ts +33 -0
- package/dist/models.js +932 -0
- package/dist/operations.d.ts +17 -0
- package/dist/operations.js +117 -0
- package/dist/pilot-cases.d.ts +171 -0
- package/dist/pilot-cases.js +330 -0
- package/dist/pilot-input.d.ts +16 -0
- package/dist/pilot-input.js +125 -0
- package/dist/pilot-recall.d.ts +166 -0
- package/dist/pilot-recall.js +231 -0
- package/dist/pilot-report.d.ts +113 -0
- package/dist/pilot-report.js +279 -0
- package/dist/pilot-responses.d.ts +111 -0
- package/dist/pilot-responses.js +159 -0
- package/dist/providers.d.ts +209 -0
- package/dist/providers.js +459 -0
- package/dist/python-version.d.ts +3 -0
- package/dist/python-version.js +30 -0
- package/dist/rehearsal.d.ts +440 -0
- package/dist/rehearsal.js +372 -0
- package/dist/sbom.d.ts +13 -0
- package/dist/sbom.js +193 -0
- package/dist/setup.d.ts +113 -0
- package/dist/setup.js +100 -0
- package/dist/source-error.d.ts +38 -0
- package/dist/source-error.js +71 -0
- package/dist/sources.d.ts +3 -0
- package/dist/sources.js +1725 -0
- package/dist/store.d.ts +96 -0
- package/dist/store.js +953 -0
- package/dist/types.d.ts +404 -0
- package/dist/types.js +1 -0
- package/dist/util.d.ts +29 -0
- package/dist/util.js +94 -0
- package/dist/vendor/cvss4-reference.d.ts +2 -0
- package/dist/vendor/cvss4-reference.js +789 -0
- package/dist/vendor-sources.d.ts +24 -0
- package/dist/vendor-sources.js +56 -0
- package/dist/word-filter.d.ts +3 -0
- package/dist/word-filter.js +3291 -0
- package/docs/alert-outcome-evaluation.md +150 -0
- package/docs/compatibility.md +35 -0
- package/docs/configuration.md +666 -0
- package/docs/cvss-v4-support.md +41 -0
- package/docs/offline-advisory-preview.md +114 -0
- package/docs/offline-rehearsal.md +44 -0
- package/docs/pilot-cases.md +58 -0
- package/docs/pilot-recall.md +124 -0
- package/docs/pilot-report.md +52 -0
- package/docs/validation/alert-outcome-evaluation-2026-11-05.json +2935 -0
- package/docs/validation/cvss-v4-reference-parity-2026-11-05.json +93 -0
- package/docs/validation/rehearsal-accepted-2026-11-05.json +175 -0
- package/docs/validation/rehearsal-unknown-2026-11-05.json +175 -0
- package/docs/vendor/cvss-v4-LICENSE.txt +22 -0
- package/docs/vendor/cvss-v4-provenance.json +38 -0
- package/examples/advisories.json +17 -0
- package/examples/agent-advisories-2026.json +145 -0
- package/examples/agent-advisory-cases-2026.json +397 -0
- package/examples/common-systems.yaml +243 -0
- package/examples/libraries.example.txt +18 -0
- package/examples/libraries.example.yaml +40 -0
- package/examples/library-watch.example.yaml +27 -0
- package/examples/offline-advisory-preview.mjs +42 -0
- package/examples/rehearsal.json +75 -0
- package/examples/security-watch.example.yaml +86 -0
- package/examples/systems.example.yaml +35 -0
- package/package.json +85 -4
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import type { ModelSpec } from './types.js';
|
|
2
|
+
export type OutputFormat = 'auto' | 'json_schema' | 'json_object' | 'prompt';
|
|
3
|
+
export type ProviderProtocol = 'openai-responses' | 'openai-chat' | 'anthropic' | 'gemini' | 'cohere' | 'perplexity';
|
|
4
|
+
export interface ProviderDefinition {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
protocol: ProviderProtocol;
|
|
8
|
+
endpoint?: string;
|
|
9
|
+
apiKeyEnv: string;
|
|
10
|
+
defaultFormat: Exclude<OutputFormat, 'auto'>;
|
|
11
|
+
documentationUrl: string;
|
|
12
|
+
local?: boolean;
|
|
13
|
+
tokenParameter?: 'max_tokens' | 'max_completion_tokens';
|
|
14
|
+
formats?: readonly Exclude<OutputFormat, 'auto'>[];
|
|
15
|
+
}
|
|
16
|
+
declare const catalog: readonly [{
|
|
17
|
+
readonly id: 'openai';
|
|
18
|
+
readonly name: 'OpenAI';
|
|
19
|
+
readonly protocol: 'openai-responses';
|
|
20
|
+
readonly endpoint: 'https://api.openai.com/v1/responses';
|
|
21
|
+
readonly apiKeyEnv: 'OPENAI_API_KEY';
|
|
22
|
+
readonly defaultFormat: 'json_schema';
|
|
23
|
+
readonly documentationUrl: 'https://developers.openai.com/api/reference/resources/responses/methods/create';
|
|
24
|
+
}, {
|
|
25
|
+
readonly id: 'azure-openai';
|
|
26
|
+
readonly name: 'Azure OpenAI';
|
|
27
|
+
readonly protocol: 'openai-responses';
|
|
28
|
+
readonly apiKeyEnv: 'AZURE_OPENAI_API_KEY';
|
|
29
|
+
readonly defaultFormat: 'json_schema';
|
|
30
|
+
readonly documentationUrl: 'https://learn.microsoft.com/en-us/rest/api/aifoundry/azureopenai/responses';
|
|
31
|
+
}, {
|
|
32
|
+
readonly id: 'anthropic';
|
|
33
|
+
readonly name: 'Anthropic';
|
|
34
|
+
readonly protocol: 'anthropic';
|
|
35
|
+
readonly endpoint: 'https://api.anthropic.com/v1/messages';
|
|
36
|
+
readonly apiKeyEnv: 'ANTHROPIC_API_KEY';
|
|
37
|
+
readonly defaultFormat: 'json_schema';
|
|
38
|
+
readonly formats: readonly ["json_schema", "prompt"];
|
|
39
|
+
readonly documentationUrl: 'https://platform.claude.com/docs/en/build-with-claude/structured-outputs';
|
|
40
|
+
}, {
|
|
41
|
+
readonly id: 'gemini';
|
|
42
|
+
readonly name: 'Google Gemini';
|
|
43
|
+
readonly protocol: 'gemini';
|
|
44
|
+
readonly endpoint: 'https://generativelanguage.googleapis.com/v1beta/models/{model}:generateContent';
|
|
45
|
+
readonly apiKeyEnv: 'GEMINI_API_KEY';
|
|
46
|
+
readonly defaultFormat: 'json_schema';
|
|
47
|
+
readonly documentationUrl: 'https://ai.google.dev/api/generate-content';
|
|
48
|
+
}, {
|
|
49
|
+
readonly id: 'cohere';
|
|
50
|
+
readonly name: 'Cohere';
|
|
51
|
+
readonly protocol: 'cohere';
|
|
52
|
+
readonly endpoint: 'https://api.cohere.com/v2/chat';
|
|
53
|
+
readonly apiKeyEnv: 'COHERE_API_KEY';
|
|
54
|
+
readonly defaultFormat: 'json_schema';
|
|
55
|
+
readonly documentationUrl: 'https://docs.cohere.com/v2/reference/chat';
|
|
56
|
+
}, {
|
|
57
|
+
readonly id: 'groq';
|
|
58
|
+
readonly name: 'Groq';
|
|
59
|
+
readonly protocol: 'openai-chat';
|
|
60
|
+
readonly endpoint: 'https://api.groq.com/openai/v1/chat/completions';
|
|
61
|
+
readonly apiKeyEnv: 'GROQ_API_KEY';
|
|
62
|
+
readonly defaultFormat: 'json_object';
|
|
63
|
+
readonly tokenParameter: 'max_completion_tokens';
|
|
64
|
+
readonly documentationUrl: 'https://console.groq.com/docs/api-reference';
|
|
65
|
+
}, {
|
|
66
|
+
readonly id: 'deepseek';
|
|
67
|
+
readonly name: 'DeepSeek';
|
|
68
|
+
readonly protocol: 'openai-chat';
|
|
69
|
+
readonly endpoint: 'https://api.deepseek.com/chat/completions';
|
|
70
|
+
readonly apiKeyEnv: 'DEEPSEEK_API_KEY';
|
|
71
|
+
readonly defaultFormat: 'json_object';
|
|
72
|
+
readonly formats: readonly ["json_object", "prompt"];
|
|
73
|
+
readonly documentationUrl: 'https://api-docs.deepseek.com/api/create-chat-completion/';
|
|
74
|
+
}, {
|
|
75
|
+
readonly id: 'xai';
|
|
76
|
+
readonly name: 'xAI';
|
|
77
|
+
readonly protocol: 'openai-responses';
|
|
78
|
+
readonly endpoint: 'https://api.x.ai/v1/responses';
|
|
79
|
+
readonly apiKeyEnv: 'XAI_API_KEY';
|
|
80
|
+
readonly defaultFormat: 'json_schema';
|
|
81
|
+
readonly documentationUrl: 'https://docs.x.ai/developers/model-capabilities/text/structured-outputs';
|
|
82
|
+
}, {
|
|
83
|
+
readonly id: 'mistral';
|
|
84
|
+
readonly name: 'Mistral';
|
|
85
|
+
readonly protocol: 'openai-chat';
|
|
86
|
+
readonly endpoint: 'https://api.mistral.ai/v1/chat/completions';
|
|
87
|
+
readonly apiKeyEnv: 'MISTRAL_API_KEY';
|
|
88
|
+
readonly defaultFormat: 'json_schema';
|
|
89
|
+
readonly documentationUrl: 'https://docs.mistral.ai/api';
|
|
90
|
+
}, {
|
|
91
|
+
readonly id: 'together';
|
|
92
|
+
readonly name: 'Together AI';
|
|
93
|
+
readonly protocol: 'openai-chat';
|
|
94
|
+
readonly endpoint: 'https://api.together.ai/v1/chat/completions';
|
|
95
|
+
readonly apiKeyEnv: 'TOGETHER_API_KEY';
|
|
96
|
+
readonly defaultFormat: 'json_object';
|
|
97
|
+
readonly documentationUrl: 'https://docs.together.ai/reference/chat-completions';
|
|
98
|
+
}, {
|
|
99
|
+
readonly id: 'fireworks';
|
|
100
|
+
readonly name: 'Fireworks AI';
|
|
101
|
+
readonly protocol: 'openai-chat';
|
|
102
|
+
readonly endpoint: 'https://api.fireworks.ai/inference/v1/chat/completions';
|
|
103
|
+
readonly apiKeyEnv: 'FIREWORKS_API_KEY';
|
|
104
|
+
readonly defaultFormat: 'json_object';
|
|
105
|
+
readonly documentationUrl: 'https://docs.fireworks.ai/api-reference/post-chatcompletions';
|
|
106
|
+
}, {
|
|
107
|
+
readonly id: 'openrouter';
|
|
108
|
+
readonly name: 'OpenRouter';
|
|
109
|
+
readonly protocol: 'openai-chat';
|
|
110
|
+
readonly endpoint: 'https://openrouter.ai/api/v1/chat/completions';
|
|
111
|
+
readonly apiKeyEnv: 'OPENROUTER_API_KEY';
|
|
112
|
+
readonly defaultFormat: 'json_object';
|
|
113
|
+
readonly documentationUrl: 'https://openrouter.ai/docs/guides/features/structured-outputs';
|
|
114
|
+
}, {
|
|
115
|
+
readonly id: 'cerebras';
|
|
116
|
+
readonly name: 'Cerebras';
|
|
117
|
+
readonly protocol: 'openai-chat';
|
|
118
|
+
readonly endpoint: 'https://api.cerebras.ai/v1/chat/completions';
|
|
119
|
+
readonly apiKeyEnv: 'CEREBRAS_API_KEY';
|
|
120
|
+
readonly defaultFormat: 'json_object';
|
|
121
|
+
readonly tokenParameter: 'max_completion_tokens';
|
|
122
|
+
readonly documentationUrl: 'https://inference-docs.cerebras.ai/api-reference/chat-completions';
|
|
123
|
+
}, {
|
|
124
|
+
readonly id: 'nvidia';
|
|
125
|
+
readonly name: 'NVIDIA NIM';
|
|
126
|
+
readonly protocol: 'openai-chat';
|
|
127
|
+
readonly endpoint: 'https://integrate.api.nvidia.com/v1/chat/completions';
|
|
128
|
+
readonly apiKeyEnv: 'NVIDIA_API_KEY';
|
|
129
|
+
readonly defaultFormat: 'prompt';
|
|
130
|
+
readonly documentationUrl: 'https://docs.api.nvidia.com/nim/reference/openai-gpt-oss-120b-infer';
|
|
131
|
+
}, {
|
|
132
|
+
readonly id: 'sambanova';
|
|
133
|
+
readonly name: 'SambaNova';
|
|
134
|
+
readonly protocol: 'openai-chat';
|
|
135
|
+
readonly endpoint: 'https://api.sambanova.ai/v1/chat/completions';
|
|
136
|
+
readonly apiKeyEnv: 'SAMBANOVA_API_KEY';
|
|
137
|
+
readonly defaultFormat: 'json_object';
|
|
138
|
+
readonly documentationUrl: 'https://raw.githubusercontent.com/sambanova/sambanova-inference-api-spec/refs/heads/main/openapi.documented.json';
|
|
139
|
+
}, {
|
|
140
|
+
readonly id: 'huggingface';
|
|
141
|
+
readonly name: 'Hugging Face Inference Providers';
|
|
142
|
+
readonly protocol: 'openai-chat';
|
|
143
|
+
readonly endpoint: 'https://router.huggingface.co/v1/chat/completions';
|
|
144
|
+
readonly apiKeyEnv: 'HF_TOKEN';
|
|
145
|
+
readonly defaultFormat: 'prompt';
|
|
146
|
+
readonly documentationUrl: 'https://huggingface.co/docs/inference-providers/en/tasks/chat-completion';
|
|
147
|
+
}, {
|
|
148
|
+
readonly id: 'perplexity';
|
|
149
|
+
readonly name: 'Perplexity Agent API';
|
|
150
|
+
readonly protocol: 'perplexity';
|
|
151
|
+
readonly endpoint: 'https://api.perplexity.ai/v1/agent';
|
|
152
|
+
readonly apiKeyEnv: 'PERPLEXITY_API_KEY';
|
|
153
|
+
readonly defaultFormat: 'json_schema';
|
|
154
|
+
readonly formats: readonly ["json_schema", "prompt"];
|
|
155
|
+
readonly documentationUrl: 'https://docs.perplexity.ai/api-reference/agent-post';
|
|
156
|
+
}, {
|
|
157
|
+
readonly id: 'openai-compatible';
|
|
158
|
+
readonly name: 'OpenAI-compatible endpoint';
|
|
159
|
+
readonly protocol: 'openai-chat';
|
|
160
|
+
readonly apiKeyEnv: 'OPENAI_API_KEY';
|
|
161
|
+
readonly defaultFormat: 'json_schema';
|
|
162
|
+
readonly documentationUrl: 'https://developers.openai.com/api/reference/resources/chat/subresources/completions/methods/create';
|
|
163
|
+
}, {
|
|
164
|
+
readonly id: 'ollama';
|
|
165
|
+
readonly name: 'Ollama local server';
|
|
166
|
+
readonly protocol: 'openai-chat';
|
|
167
|
+
readonly apiKeyEnv: 'OLLAMA_API_KEY';
|
|
168
|
+
readonly defaultFormat: 'json_schema';
|
|
169
|
+
readonly local: true;
|
|
170
|
+
readonly documentationUrl: 'https://docs.ollama.com/api/openai-compatibility';
|
|
171
|
+
}, {
|
|
172
|
+
readonly id: 'lmstudio';
|
|
173
|
+
readonly name: 'LM Studio local server';
|
|
174
|
+
readonly protocol: 'openai-chat';
|
|
175
|
+
readonly apiKeyEnv: 'LM_STUDIO_API_KEY';
|
|
176
|
+
readonly defaultFormat: 'json_schema';
|
|
177
|
+
readonly local: true;
|
|
178
|
+
readonly documentationUrl: 'https://lmstudio.ai/docs/developer/openai-compat/structured-output';
|
|
179
|
+
}, {
|
|
180
|
+
readonly id: 'vllm';
|
|
181
|
+
readonly name: 'vLLM server';
|
|
182
|
+
readonly protocol: 'openai-chat';
|
|
183
|
+
readonly apiKeyEnv: 'VLLM_API_KEY';
|
|
184
|
+
readonly defaultFormat: 'json_schema';
|
|
185
|
+
readonly local: true;
|
|
186
|
+
readonly documentationUrl: 'https://docs.vllm.ai/en/latest/features/structured_outputs/';
|
|
187
|
+
}, {
|
|
188
|
+
readonly id: 'litellm';
|
|
189
|
+
readonly name: 'LiteLLM gateway';
|
|
190
|
+
readonly protocol: 'openai-chat';
|
|
191
|
+
readonly apiKeyEnv: 'LITELLM_API_KEY';
|
|
192
|
+
readonly defaultFormat: 'json_object';
|
|
193
|
+
readonly local: true;
|
|
194
|
+
readonly documentationUrl: 'https://docs.litellm.ai/docs/completion/json_mode';
|
|
195
|
+
}];
|
|
196
|
+
export type ModelProvider = (typeof catalog)[number]['id'];
|
|
197
|
+
export declare const PROVIDERS: readonly Readonly<ProviderDefinition>[];
|
|
198
|
+
export declare const PROVIDER_IDS: readonly ("anthropic" | "azure-openai" | "cerebras" | "cohere" | "deepseek" | "fireworks" | "gemini" | "groq" | "huggingface" | "litellm" | "lmstudio" | "mistral" | "nvidia" | "ollama" | "openai" | "openai-compatible" | "openrouter" | "perplexity" | "sambanova" | "together" | "vllm" | "xai")[];
|
|
199
|
+
export declare function providerDefinition(id: string): Readonly<ProviderDefinition>;
|
|
200
|
+
export declare function allowsMissingKey(spec: ModelSpec): boolean;
|
|
201
|
+
export declare function modelOutputFormat(spec: ModelSpec): Exclude<OutputFormat, 'auto'>;
|
|
202
|
+
export declare function modelEndpoint(spec: ModelSpec): string;
|
|
203
|
+
export declare function buildModelRequest(spec: ModelSpec, token: string | undefined, instruction: string, input: string, schema: unknown, maxOutput: number): {
|
|
204
|
+
url: string;
|
|
205
|
+
headers: Record<string, string>;
|
|
206
|
+
body: Record<string, unknown>;
|
|
207
|
+
};
|
|
208
|
+
export declare function parseModelResponse(spec: ModelSpec, value: unknown): string;
|
|
209
|
+
export {};
|
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
const catalog = [
|
|
3
|
+
{
|
|
4
|
+
id: 'openai',
|
|
5
|
+
name: 'OpenAI',
|
|
6
|
+
protocol: 'openai-responses',
|
|
7
|
+
endpoint: 'https://api.openai.com/v1/responses',
|
|
8
|
+
apiKeyEnv: 'OPENAI_API_KEY',
|
|
9
|
+
defaultFormat: 'json_schema',
|
|
10
|
+
documentationUrl: 'https://developers.openai.com/api/reference/resources/responses/methods/create',
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
id: 'azure-openai',
|
|
14
|
+
name: 'Azure OpenAI',
|
|
15
|
+
protocol: 'openai-responses',
|
|
16
|
+
apiKeyEnv: 'AZURE_OPENAI_API_KEY',
|
|
17
|
+
defaultFormat: 'json_schema',
|
|
18
|
+
documentationUrl: 'https://learn.microsoft.com/en-us/rest/api/aifoundry/azureopenai/responses',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
id: 'anthropic',
|
|
22
|
+
name: 'Anthropic',
|
|
23
|
+
protocol: 'anthropic',
|
|
24
|
+
endpoint: 'https://api.anthropic.com/v1/messages',
|
|
25
|
+
apiKeyEnv: 'ANTHROPIC_API_KEY',
|
|
26
|
+
defaultFormat: 'json_schema',
|
|
27
|
+
formats: ['json_schema', 'prompt'],
|
|
28
|
+
documentationUrl: 'https://platform.claude.com/docs/en/build-with-claude/structured-outputs',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: 'gemini',
|
|
32
|
+
name: 'Google Gemini',
|
|
33
|
+
protocol: 'gemini',
|
|
34
|
+
endpoint: 'https://generativelanguage.googleapis.com/v1beta/models/{model}:generateContent',
|
|
35
|
+
apiKeyEnv: 'GEMINI_API_KEY',
|
|
36
|
+
defaultFormat: 'json_schema',
|
|
37
|
+
documentationUrl: 'https://ai.google.dev/api/generate-content',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
id: 'cohere',
|
|
41
|
+
name: 'Cohere',
|
|
42
|
+
protocol: 'cohere',
|
|
43
|
+
endpoint: 'https://api.cohere.com/v2/chat',
|
|
44
|
+
apiKeyEnv: 'COHERE_API_KEY',
|
|
45
|
+
defaultFormat: 'json_schema',
|
|
46
|
+
documentationUrl: 'https://docs.cohere.com/v2/reference/chat',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
id: 'groq',
|
|
50
|
+
name: 'Groq',
|
|
51
|
+
protocol: 'openai-chat',
|
|
52
|
+
endpoint: 'https://api.groq.com/openai/v1/chat/completions',
|
|
53
|
+
apiKeyEnv: 'GROQ_API_KEY',
|
|
54
|
+
defaultFormat: 'json_object',
|
|
55
|
+
tokenParameter: 'max_completion_tokens',
|
|
56
|
+
documentationUrl: 'https://console.groq.com/docs/api-reference',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
id: 'deepseek',
|
|
60
|
+
name: 'DeepSeek',
|
|
61
|
+
protocol: 'openai-chat',
|
|
62
|
+
endpoint: 'https://api.deepseek.com/chat/completions',
|
|
63
|
+
apiKeyEnv: 'DEEPSEEK_API_KEY',
|
|
64
|
+
defaultFormat: 'json_object',
|
|
65
|
+
formats: ['json_object', 'prompt'],
|
|
66
|
+
documentationUrl: 'https://api-docs.deepseek.com/api/create-chat-completion/',
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
id: 'xai',
|
|
70
|
+
name: 'xAI',
|
|
71
|
+
protocol: 'openai-responses',
|
|
72
|
+
endpoint: 'https://api.x.ai/v1/responses',
|
|
73
|
+
apiKeyEnv: 'XAI_API_KEY',
|
|
74
|
+
defaultFormat: 'json_schema',
|
|
75
|
+
documentationUrl: 'https://docs.x.ai/developers/model-capabilities/text/structured-outputs',
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
id: 'mistral',
|
|
79
|
+
name: 'Mistral',
|
|
80
|
+
protocol: 'openai-chat',
|
|
81
|
+
endpoint: 'https://api.mistral.ai/v1/chat/completions',
|
|
82
|
+
apiKeyEnv: 'MISTRAL_API_KEY',
|
|
83
|
+
defaultFormat: 'json_schema',
|
|
84
|
+
documentationUrl: 'https://docs.mistral.ai/api',
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
id: 'together',
|
|
88
|
+
name: 'Together AI',
|
|
89
|
+
protocol: 'openai-chat',
|
|
90
|
+
endpoint: 'https://api.together.ai/v1/chat/completions',
|
|
91
|
+
apiKeyEnv: 'TOGETHER_API_KEY',
|
|
92
|
+
defaultFormat: 'json_object',
|
|
93
|
+
documentationUrl: 'https://docs.together.ai/reference/chat-completions',
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: 'fireworks',
|
|
97
|
+
name: 'Fireworks AI',
|
|
98
|
+
protocol: 'openai-chat',
|
|
99
|
+
endpoint: 'https://api.fireworks.ai/inference/v1/chat/completions',
|
|
100
|
+
apiKeyEnv: 'FIREWORKS_API_KEY',
|
|
101
|
+
defaultFormat: 'json_object',
|
|
102
|
+
documentationUrl: 'https://docs.fireworks.ai/api-reference/post-chatcompletions',
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
id: 'openrouter',
|
|
106
|
+
name: 'OpenRouter',
|
|
107
|
+
protocol: 'openai-chat',
|
|
108
|
+
endpoint: 'https://openrouter.ai/api/v1/chat/completions',
|
|
109
|
+
apiKeyEnv: 'OPENROUTER_API_KEY',
|
|
110
|
+
defaultFormat: 'json_object',
|
|
111
|
+
documentationUrl: 'https://openrouter.ai/docs/guides/features/structured-outputs',
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
id: 'cerebras',
|
|
115
|
+
name: 'Cerebras',
|
|
116
|
+
protocol: 'openai-chat',
|
|
117
|
+
endpoint: 'https://api.cerebras.ai/v1/chat/completions',
|
|
118
|
+
apiKeyEnv: 'CEREBRAS_API_KEY',
|
|
119
|
+
defaultFormat: 'json_object',
|
|
120
|
+
tokenParameter: 'max_completion_tokens',
|
|
121
|
+
documentationUrl: 'https://inference-docs.cerebras.ai/api-reference/chat-completions',
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
id: 'nvidia',
|
|
125
|
+
name: 'NVIDIA NIM',
|
|
126
|
+
protocol: 'openai-chat',
|
|
127
|
+
endpoint: 'https://integrate.api.nvidia.com/v1/chat/completions',
|
|
128
|
+
apiKeyEnv: 'NVIDIA_API_KEY',
|
|
129
|
+
defaultFormat: 'prompt',
|
|
130
|
+
documentationUrl: 'https://docs.api.nvidia.com/nim/reference/openai-gpt-oss-120b-infer',
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
id: 'sambanova',
|
|
134
|
+
name: 'SambaNova',
|
|
135
|
+
protocol: 'openai-chat',
|
|
136
|
+
endpoint: 'https://api.sambanova.ai/v1/chat/completions',
|
|
137
|
+
apiKeyEnv: 'SAMBANOVA_API_KEY',
|
|
138
|
+
defaultFormat: 'json_object',
|
|
139
|
+
documentationUrl: 'https://raw.githubusercontent.com/sambanova/sambanova-inference-api-spec/refs/heads/main/openapi.documented.json',
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
id: 'huggingface',
|
|
143
|
+
name: 'Hugging Face Inference Providers',
|
|
144
|
+
protocol: 'openai-chat',
|
|
145
|
+
endpoint: 'https://router.huggingface.co/v1/chat/completions',
|
|
146
|
+
apiKeyEnv: 'HF_TOKEN',
|
|
147
|
+
defaultFormat: 'prompt',
|
|
148
|
+
documentationUrl: 'https://huggingface.co/docs/inference-providers/en/tasks/chat-completion',
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
id: 'perplexity',
|
|
152
|
+
name: 'Perplexity Agent API',
|
|
153
|
+
protocol: 'perplexity',
|
|
154
|
+
endpoint: 'https://api.perplexity.ai/v1/agent',
|
|
155
|
+
apiKeyEnv: 'PERPLEXITY_API_KEY',
|
|
156
|
+
defaultFormat: 'json_schema',
|
|
157
|
+
formats: ['json_schema', 'prompt'],
|
|
158
|
+
documentationUrl: 'https://docs.perplexity.ai/api-reference/agent-post',
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
id: 'openai-compatible',
|
|
162
|
+
name: 'OpenAI-compatible endpoint',
|
|
163
|
+
protocol: 'openai-chat',
|
|
164
|
+
apiKeyEnv: 'OPENAI_API_KEY',
|
|
165
|
+
defaultFormat: 'json_schema',
|
|
166
|
+
documentationUrl: 'https://developers.openai.com/api/reference/resources/chat/subresources/completions/methods/create',
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
id: 'ollama',
|
|
170
|
+
name: 'Ollama local server',
|
|
171
|
+
protocol: 'openai-chat',
|
|
172
|
+
apiKeyEnv: 'OLLAMA_API_KEY',
|
|
173
|
+
defaultFormat: 'json_schema',
|
|
174
|
+
local: true,
|
|
175
|
+
documentationUrl: 'https://docs.ollama.com/api/openai-compatibility',
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
id: 'lmstudio',
|
|
179
|
+
name: 'LM Studio local server',
|
|
180
|
+
protocol: 'openai-chat',
|
|
181
|
+
apiKeyEnv: 'LM_STUDIO_API_KEY',
|
|
182
|
+
defaultFormat: 'json_schema',
|
|
183
|
+
local: true,
|
|
184
|
+
documentationUrl: 'https://lmstudio.ai/docs/developer/openai-compat/structured-output',
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
id: 'vllm',
|
|
188
|
+
name: 'vLLM server',
|
|
189
|
+
protocol: 'openai-chat',
|
|
190
|
+
apiKeyEnv: 'VLLM_API_KEY',
|
|
191
|
+
defaultFormat: 'json_schema',
|
|
192
|
+
local: true,
|
|
193
|
+
documentationUrl: 'https://docs.vllm.ai/en/latest/features/structured_outputs/',
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
id: 'litellm',
|
|
197
|
+
name: 'LiteLLM gateway',
|
|
198
|
+
protocol: 'openai-chat',
|
|
199
|
+
apiKeyEnv: 'LITELLM_API_KEY',
|
|
200
|
+
defaultFormat: 'json_object',
|
|
201
|
+
local: true,
|
|
202
|
+
documentationUrl: 'https://docs.litellm.ai/docs/completion/json_mode',
|
|
203
|
+
},
|
|
204
|
+
];
|
|
205
|
+
export const PROVIDERS = Object.freeze(catalog.map((entry) => Object.freeze({
|
|
206
|
+
...entry,
|
|
207
|
+
...('formats' in entry ? { formats: Object.freeze([...entry.formats]) } : {}),
|
|
208
|
+
})));
|
|
209
|
+
export const PROVIDER_IDS = Object.freeze(catalog.map((entry) => entry.id));
|
|
210
|
+
export function providerDefinition(id) {
|
|
211
|
+
const definition = PROVIDERS.find((entry) => entry.id === id);
|
|
212
|
+
if (!definition)
|
|
213
|
+
throw new Error('MODEL_PROVIDER_UNKNOWN');
|
|
214
|
+
return definition;
|
|
215
|
+
}
|
|
216
|
+
export function allowsMissingKey(spec) {
|
|
217
|
+
return Boolean(spec.allow_private_endpoint &&
|
|
218
|
+
(spec.provider === 'openai-compatible' || providerDefinition(spec.provider).local));
|
|
219
|
+
}
|
|
220
|
+
export function modelOutputFormat(spec) {
|
|
221
|
+
const definition = providerDefinition(spec.provider);
|
|
222
|
+
const format = !spec.output_format || spec.output_format === 'auto' ? definition.defaultFormat : spec.output_format;
|
|
223
|
+
if (definition.formats && !definition.formats.includes(format))
|
|
224
|
+
throw new Error('MODEL_OUTPUT_FORMAT_UNSUPPORTED');
|
|
225
|
+
return format;
|
|
226
|
+
}
|
|
227
|
+
export function modelEndpoint(spec) {
|
|
228
|
+
if (spec.endpoint)
|
|
229
|
+
return spec.endpoint;
|
|
230
|
+
const definition = providerDefinition(spec.provider);
|
|
231
|
+
if (!definition.endpoint)
|
|
232
|
+
throw new Error('MODEL_ENDPOINT_MISSING');
|
|
233
|
+
if (definition.protocol !== 'gemini')
|
|
234
|
+
return definition.endpoint;
|
|
235
|
+
const model = spec.model.replace(/^models\//, '');
|
|
236
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(model))
|
|
237
|
+
throw new Error('MODEL_ID_INVALID');
|
|
238
|
+
return definition.endpoint.replace('{model}', encodeURIComponent(model));
|
|
239
|
+
}
|
|
240
|
+
export function buildModelRequest(spec, token, instruction, input, schema, maxOutput) {
|
|
241
|
+
const definition = providerDefinition(spec.provider);
|
|
242
|
+
if (!token && !allowsMissingKey(spec))
|
|
243
|
+
throw new Error('MODEL_CREDENTIAL_MISSING');
|
|
244
|
+
const url = modelEndpoint(spec);
|
|
245
|
+
const format = modelOutputFormat(spec);
|
|
246
|
+
const headers = { 'content-type': 'application/json' };
|
|
247
|
+
const guidance = instruction + `\nReturn only JSON matching this JSON schema: ${JSON.stringify(schema)}`;
|
|
248
|
+
if (definition.protocol === 'anthropic') {
|
|
249
|
+
headers['x-api-key'] = token;
|
|
250
|
+
headers['anthropic-version'] = '2023-06-01';
|
|
251
|
+
return {
|
|
252
|
+
url,
|
|
253
|
+
headers,
|
|
254
|
+
body: {
|
|
255
|
+
model: spec.model,
|
|
256
|
+
max_tokens: maxOutput,
|
|
257
|
+
system: guidance,
|
|
258
|
+
messages: [{ role: 'user', content: input }],
|
|
259
|
+
...(format === 'json_schema' ? { output_config: { format: { type: 'json_schema', schema } } } : {}),
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
if (definition.protocol === 'gemini') {
|
|
264
|
+
headers['x-goog-api-key'] = token;
|
|
265
|
+
return {
|
|
266
|
+
url,
|
|
267
|
+
headers,
|
|
268
|
+
body: {
|
|
269
|
+
systemInstruction: { parts: [{ text: guidance }] },
|
|
270
|
+
contents: [{ role: 'user', parts: [{ text: input }] }],
|
|
271
|
+
generationConfig: {
|
|
272
|
+
maxOutputTokens: maxOutput,
|
|
273
|
+
candidateCount: 1,
|
|
274
|
+
...(format === 'prompt'
|
|
275
|
+
? {}
|
|
276
|
+
: {
|
|
277
|
+
responseFormat: {
|
|
278
|
+
text: { mimeType: 'APPLICATION_JSON', ...(format === 'json_schema' ? { schema } : {}) },
|
|
279
|
+
},
|
|
280
|
+
}),
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
if (token) {
|
|
286
|
+
if (spec.provider === 'azure-openai')
|
|
287
|
+
headers['api-key'] = token;
|
|
288
|
+
else
|
|
289
|
+
headers.authorization = `Bearer ${token}`;
|
|
290
|
+
}
|
|
291
|
+
if (definition.protocol === 'openai-responses' || definition.protocol === 'perplexity') {
|
|
292
|
+
const body = {
|
|
293
|
+
model: spec.model,
|
|
294
|
+
instructions: guidance,
|
|
295
|
+
input,
|
|
296
|
+
store: false,
|
|
297
|
+
background: false,
|
|
298
|
+
max_output_tokens: maxOutput,
|
|
299
|
+
};
|
|
300
|
+
if (definition.protocol === 'perplexity') {
|
|
301
|
+
Object.assign(body, { tools: [], tool_choice: 'none', max_steps: 1, stream: false });
|
|
302
|
+
if (format === 'json_schema')
|
|
303
|
+
body.response_format = { type: 'json_schema', json_schema: { name: 'securityassessment', schema } };
|
|
304
|
+
}
|
|
305
|
+
else if (format !== 'prompt') {
|
|
306
|
+
body.text = {
|
|
307
|
+
format: format === 'json_schema'
|
|
308
|
+
? { type: 'json_schema', name: 'security_assessment', strict: true, schema }
|
|
309
|
+
: { type: 'json_object' },
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
return { url, headers, body };
|
|
313
|
+
}
|
|
314
|
+
const body = {
|
|
315
|
+
model: spec.model,
|
|
316
|
+
[definition.tokenParameter ?? 'max_tokens']: maxOutput,
|
|
317
|
+
stream: false,
|
|
318
|
+
messages: [
|
|
319
|
+
{ role: 'system', content: guidance },
|
|
320
|
+
{ role: 'user', content: input },
|
|
321
|
+
],
|
|
322
|
+
};
|
|
323
|
+
if (format !== 'prompt') {
|
|
324
|
+
body.response_format =
|
|
325
|
+
definition.protocol === 'cohere'
|
|
326
|
+
? { type: 'json_object', ...(format === 'json_schema' ? { schema } : {}) }
|
|
327
|
+
: format === 'json_schema'
|
|
328
|
+
? { type: 'json_schema', json_schema: { name: 'security_assessment', strict: true, schema } }
|
|
329
|
+
: { type: 'json_object' };
|
|
330
|
+
}
|
|
331
|
+
if (spec.provider === 'openrouter' && format !== 'prompt')
|
|
332
|
+
body.provider = { require_parameters: true };
|
|
333
|
+
return { url, headers, body };
|
|
334
|
+
}
|
|
335
|
+
const recordSchema = z.record(z.string(), z.unknown());
|
|
336
|
+
const textBlocks = z.array(z.object({ type: z.string(), text: z.string().optional() }));
|
|
337
|
+
function responseText(text) {
|
|
338
|
+
if (!text.trim())
|
|
339
|
+
throw new Error('MODEL_EMPTY_OUTPUT');
|
|
340
|
+
return text;
|
|
341
|
+
}
|
|
342
|
+
export function parseModelResponse(spec, value) {
|
|
343
|
+
const protocol = providerDefinition(spec.provider).protocol;
|
|
344
|
+
const record = recordSchema.parse(value);
|
|
345
|
+
if (record.error)
|
|
346
|
+
throw new Error('MODEL_PROVIDER_ERROR');
|
|
347
|
+
if (protocol === 'openai-responses' || protocol === 'perplexity') {
|
|
348
|
+
if (record.status !== 'completed')
|
|
349
|
+
throw new Error('MODEL_INCOMPLETE');
|
|
350
|
+
const output = z
|
|
351
|
+
.array(z.object({ type: z.string(), status: z.string().optional(), content: textBlocks.optional() }))
|
|
352
|
+
.parse(record.output);
|
|
353
|
+
if (output.some((item) => item.content?.some((part) => part.type === 'refusal')))
|
|
354
|
+
throw new Error('MODEL_REFUSAL');
|
|
355
|
+
if (output.some((item) => !['message', 'reasoning'].includes(item.type)))
|
|
356
|
+
throw new Error('MODEL_UNEXPECTED_TOOL');
|
|
357
|
+
if (output.some((item) => item.status && item.status !== 'completed'))
|
|
358
|
+
throw new Error('MODEL_INCOMPLETE');
|
|
359
|
+
return responseText(output
|
|
360
|
+
.filter((item) => item.type === 'message')
|
|
361
|
+
.flatMap((item) => item.content ?? [])
|
|
362
|
+
.filter((part) => part.type === 'output_text')
|
|
363
|
+
.map((part) => part.text ?? '')
|
|
364
|
+
.join(''));
|
|
365
|
+
}
|
|
366
|
+
if (protocol === 'gemini') {
|
|
367
|
+
const feedback = record.promptFeedback === undefined ? undefined : recordSchema.parse(record.promptFeedback);
|
|
368
|
+
if (feedback?.blockReason)
|
|
369
|
+
throw new Error('MODEL_REFUSAL');
|
|
370
|
+
const candidates = z
|
|
371
|
+
.array(z.object({
|
|
372
|
+
finishReason: z.string(),
|
|
373
|
+
content: z.object({
|
|
374
|
+
parts: z.array(z.object({
|
|
375
|
+
text: z.string().optional(),
|
|
376
|
+
thought: z.boolean().optional(),
|
|
377
|
+
functionCall: z.unknown().optional(),
|
|
378
|
+
functionResponse: z.unknown().optional(),
|
|
379
|
+
executableCode: z.unknown().optional(),
|
|
380
|
+
codeExecutionResult: z.unknown().optional(),
|
|
381
|
+
toolCall: z.unknown().optional(),
|
|
382
|
+
toolResponse: z.unknown().optional(),
|
|
383
|
+
})),
|
|
384
|
+
}),
|
|
385
|
+
safetyRatings: z.array(z.object({ blocked: z.boolean().optional() })).optional(),
|
|
386
|
+
}))
|
|
387
|
+
.length(1)
|
|
388
|
+
.parse(record.candidates);
|
|
389
|
+
const candidate = candidates[0];
|
|
390
|
+
if (candidate.safetyRatings?.some((rating) => rating.blocked) ||
|
|
391
|
+
['SAFETY', 'RECITATION', 'BLOCKLIST', 'PROHIBITED_CONTENT', 'SPII', 'IMAGE_SAFETY'].includes(candidate.finishReason))
|
|
392
|
+
throw new Error('MODEL_REFUSAL');
|
|
393
|
+
if (candidate.finishReason !== 'STOP')
|
|
394
|
+
throw new Error('MODEL_INCOMPLETE');
|
|
395
|
+
if (candidate.content.parts.some((part) => [
|
|
396
|
+
part.functionCall,
|
|
397
|
+
part.functionResponse,
|
|
398
|
+
part.executableCode,
|
|
399
|
+
part.codeExecutionResult,
|
|
400
|
+
part.toolCall,
|
|
401
|
+
part.toolResponse,
|
|
402
|
+
].some((value) => value !== undefined)))
|
|
403
|
+
throw new Error('MODEL_UNEXPECTED_TOOL');
|
|
404
|
+
return responseText(candidate.content.parts
|
|
405
|
+
.filter((part) => !part.thought)
|
|
406
|
+
.map((part) => part.text ?? '')
|
|
407
|
+
.join(''));
|
|
408
|
+
}
|
|
409
|
+
if (protocol === 'anthropic') {
|
|
410
|
+
if (record.stop_reason === 'refusal')
|
|
411
|
+
throw new Error('MODEL_REFUSAL');
|
|
412
|
+
if (record.stop_reason !== 'end_turn')
|
|
413
|
+
throw new Error('MODEL_INCOMPLETE');
|
|
414
|
+
const content = textBlocks.parse(record.content);
|
|
415
|
+
if (content.some((part) => !['text', 'thinking', 'redacted_thinking'].includes(part.type)))
|
|
416
|
+
throw new Error('MODEL_UNEXPECTED_TOOL');
|
|
417
|
+
return responseText(content
|
|
418
|
+
.filter((part) => part.type === 'text')
|
|
419
|
+
.map((part) => part.text ?? '')
|
|
420
|
+
.join(''));
|
|
421
|
+
}
|
|
422
|
+
if (protocol === 'cohere') {
|
|
423
|
+
if (record.finish_reason !== 'COMPLETE')
|
|
424
|
+
throw new Error('MODEL_INCOMPLETE');
|
|
425
|
+
const message = z
|
|
426
|
+
.object({ content: textBlocks, tool_calls: z.array(z.unknown()).optional() })
|
|
427
|
+
.parse(record.message);
|
|
428
|
+
if (message.tool_calls?.length)
|
|
429
|
+
throw new Error('MODEL_UNEXPECTED_TOOL');
|
|
430
|
+
if (message.content.some((part) => part.type === 'refusal'))
|
|
431
|
+
throw new Error('MODEL_REFUSAL');
|
|
432
|
+
if (message.content.some((part) => part.type !== 'text'))
|
|
433
|
+
throw new Error('MODEL_UNEXPECTED_TOOL');
|
|
434
|
+
return responseText(message.content
|
|
435
|
+
.filter((part) => part.type === 'text')
|
|
436
|
+
.map((part) => part.text ?? '')
|
|
437
|
+
.join(''));
|
|
438
|
+
}
|
|
439
|
+
const choices = z
|
|
440
|
+
.array(z.object({
|
|
441
|
+
finish_reason: z.string(),
|
|
442
|
+
message: z.object({
|
|
443
|
+
content: z.string(),
|
|
444
|
+
refusal: z.string().nullable().optional(),
|
|
445
|
+
tool_calls: z.array(z.unknown()).optional(),
|
|
446
|
+
function_call: z.unknown().optional(),
|
|
447
|
+
}),
|
|
448
|
+
}))
|
|
449
|
+
.length(1)
|
|
450
|
+
.parse(record.choices);
|
|
451
|
+
const choice = choices[0];
|
|
452
|
+
if (choice.message.refusal || choice.finish_reason === 'content_filter')
|
|
453
|
+
throw new Error('MODEL_REFUSAL');
|
|
454
|
+
if (choice.finish_reason !== 'stop')
|
|
455
|
+
throw new Error('MODEL_INCOMPLETE');
|
|
456
|
+
if (choice.message.tool_calls?.length || choice.message.function_call)
|
|
457
|
+
throw new Error('MODEL_UNEXPECTED_TOOL');
|
|
458
|
+
return responseText(choice.message.content);
|
|
459
|
+
}
|