agentaudit 3.13.8 → 3.13.10

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 (2) hide show
  1. package/cli.mjs +36 -3
  2. package/package.json +1 -1
package/cli.mjs CHANGED
@@ -2875,6 +2875,39 @@ async function safeJsonParse(res, llmConfig) {
2875
2875
  }
2876
2876
  }
2877
2877
 
2878
+ function getMaxOutputTokens(model) {
2879
+ // Known max_completion_tokens from provider docs (2026-02)
2880
+ // Array (not object) to guarantee match order — specific keys before generic ones
2881
+ const limits = [
2882
+ // Anthropic (specific versions first, then generic)
2883
+ ['claude-haiku-4-5', 8192], ['claude-3-haiku', 4096], ['claude-3-5-haiku', 8192],
2884
+ ['claude-sonnet-4-6', 64000], ['claude-sonnet-4-5', 16384], ['claude-3-5-sonnet', 8192], ['claude-sonnet-4', 16384],
2885
+ ['claude-opus-4-6', 32768], ['claude-opus-4', 32768],
2886
+ // Google Gemini
2887
+ ['gemini-3', 65536], ['gemini-2.5', 65536], ['gemini-2.0', 65536],
2888
+ // Qwen (OpenRouter)
2889
+ ['qwen3.5', 65536], ['qwen3', 32768], ['qwen2.5', 32768],
2890
+ // xAI
2891
+ ['grok-4', 32768], ['grok-3', 16384],
2892
+ // OpenAI
2893
+ ['gpt-4.1', 32768], ['gpt-4o', 16384], ['gpt-4-turbo', 4096], ['o3', 100000], ['o4-mini', 100000],
2894
+ // DeepSeek (8K standard mode — thinking mode allows 64K but we use standard)
2895
+ ['deepseek', 8192],
2896
+ // Mistral
2897
+ ['mistral-large', 32768], ['mistral-medium', 32768], ['mistral-small', 32768],
2898
+ // Meta Llama (served by Groq 32K, Together, Fireworks, Cerebras)
2899
+ ['llama-3.3', 32768], ['llama-v3p3', 32768], ['llama-3.1', 32768], ['llama-v3p1', 32768],
2900
+ ['llama-4', 32768], ['llama-3', 16384],
2901
+ // Zhipu / z.ai
2902
+ ['glm-4', 16384], ['glm-3', 8192],
2903
+ ];
2904
+ const m = (model || '').toLowerCase();
2905
+ for (const [key, val] of limits) {
2906
+ if (m.includes(key)) return val;
2907
+ }
2908
+ return 8192; // conservative fallback — safe for all providers
2909
+ }
2910
+
2878
2911
  async function callLlm(llmConfig, systemPrompt, userMessage) {
2879
2912
  const apiKey = process.env[llmConfig.key];
2880
2913
  if (!apiKey) return { error: `Missing API key: ${llmConfig.key}` };
@@ -2896,7 +2929,7 @@ async function callLlm(llmConfig, systemPrompt, userMessage) {
2896
2929
  const res = await fetch(llmConfig.url, {
2897
2930
  method: 'POST',
2898
2931
  headers: { 'x-api-key': apiKey, 'anthropic-version': '2023-06-01', 'content-type': 'application/json' },
2899
- body: JSON.stringify({ model: llmConfig.model, max_tokens: 32768, system: systemPrompt, messages: [{ role: 'user', content: userMessage }] }),
2932
+ body: JSON.stringify({ model: llmConfig.model, max_tokens: getMaxOutputTokens(llmConfig.model), system: systemPrompt, messages: [{ role: 'user', content: userMessage }] }),
2900
2933
  signal: AbortSignal.timeout(180_000),
2901
2934
  });
2902
2935
  data = await safeJsonParse(res, llmConfig);
@@ -2928,7 +2961,7 @@ async function callLlm(llmConfig, systemPrompt, userMessage) {
2928
2961
  body: JSON.stringify({
2929
2962
  systemInstruction: { parts: [{ text: systemPrompt }] },
2930
2963
  contents: [{ role: 'user', parts: [{ text: userMessage }] }],
2931
- generationConfig: { maxOutputTokens: 65536, responseMimeType: 'application/json', thinkingConfig: { thinkingBudget: 8192 } },
2964
+ generationConfig: { maxOutputTokens: getMaxOutputTokens(llmConfig.model), responseMimeType: 'application/json', thinkingConfig: { thinkingBudget: 8192 } },
2932
2965
  }),
2933
2966
  signal: AbortSignal.timeout(180_000),
2934
2967
  });
@@ -2957,7 +2990,7 @@ async function callLlm(llmConfig, systemPrompt, userMessage) {
2957
2990
  const res = await fetch(llmConfig.url, {
2958
2991
  method: 'POST',
2959
2992
  headers,
2960
- body: JSON.stringify({ model: llmConfig.model, max_tokens: 32768, messages: [{ role: 'system', content: systemPrompt }, { role: 'user', content: userMessage }] }),
2993
+ body: JSON.stringify({ model: llmConfig.model, max_tokens: getMaxOutputTokens(llmConfig.model), messages: [{ role: 'system', content: systemPrompt }, { role: 'user', content: userMessage }] }),
2961
2994
  signal: AbortSignal.timeout(180_000),
2962
2995
  });
2963
2996
  data = await safeJsonParse(res, llmConfig);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentaudit",
3
- "version": "3.13.8",
3
+ "version": "3.13.10",
4
4
  "description": "Security scanner for AI agent packages — CLI + MCP server",
5
5
  "type": "module",
6
6
  "bin": {