shield-llm 0.6.1 → 0.6.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.
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __cjs_createRequire } from "module"; import { fileURLToPath as __cjs_fileURLToPath } from "url"; import { dirname as __cjs_dirname } from "path"; const __filename = __cjs_fileURLToPath(import.meta.url); const __dirname = __cjs_dirname(__filename); const require = __cjs_createRequire(import.meta.url);
2
2
 
3
3
  // package.json
4
- var version = "0.6.1";
4
+ var version = "0.6.2";
5
5
 
6
6
  // src/config/schema.ts
7
7
  import { z as z2 } from "zod";
@@ -328,6 +328,15 @@ var RATE_LIMIT_PATTERNS = [
328
328
  pattern: /\b(quota|usage cap)\b.*\b(exceeded|reached|exhausted|hit)\b/i,
329
329
  platform: "generic"
330
330
  },
331
+ {
332
+ // Credit-based exhaustion (e.g. ChatGot free tier replies "No credits
333
+ // left." for EVERY message once the per-device_id allowance runs out).
334
+ // Without this the scanner reads that as a normal answer and scores an
335
+ // out-of-credits bot as "secure" across the whole suite (false negatives),
336
+ // the same failure mode the soft-throttle classifier exists to prevent.
337
+ pattern: /\b(no|out of|insufficient|zero|0)\s+credits?\b|\bcredits?\s+(have\s+run\s+out|ran\s+out|run\s+out|exhausted|depleted|used\s+up)\b/i,
338
+ platform: "generic"
339
+ },
331
340
  {
332
341
  pattern: /\blimite de (requ[eê]tes|taux)\b.*\b(attendez|r[eé]essayez|d[eé]pass[eé]e)\b/i,
333
342
  platform: "generic"
@@ -5665,6 +5674,33 @@ async function readBodyWithLimit(response) {
5665
5674
  result += decoder.decode();
5666
5675
  return result;
5667
5676
  }
5677
+ function extractSseChunk(parsed) {
5678
+ const p = parsed;
5679
+ if ((p.type === "response.output_text.delta" || p.type === "text-delta") && typeof p.delta === "string") {
5680
+ return p.delta;
5681
+ }
5682
+ const parts = p.candidates?.[0]?.content?.parts;
5683
+ if (Array.isArray(parts)) {
5684
+ const joined = parts.map((part) => typeof part?.text === "string" ? part.text : "").join("");
5685
+ if (joined) return joined;
5686
+ }
5687
+ const candidate = (
5688
+ // {message:"…"} simple wrappers, OR Ollama native {message:{content:"…"}}
5689
+ (typeof p.message === "string" ? p.message : p.message?.content) ?? p.content ?? // {content:"…"}; LangServe /stream AIMessageChunk
5690
+ p.delta?.content ?? // top-level delta object {delta:{content}}
5691
+ p.delta?.text ?? // Anthropic content_block_delta (text_delta)
5692
+ p.delta?.message?.content?.text ?? // Cohere v2 content-delta
5693
+ p.text ?? // {text:"…"}
5694
+ p.choices?.[0]?.delta?.content ?? // OpenAI/Mistral/Ollama-compat chat chunk
5695
+ p.token?.text ?? // HF TGI /generate_stream
5696
+ p.response ?? // Ollama native /api/generate (top-level string)
5697
+ p.data?.message ?? // nested {data:{message}}
5698
+ p.data?.content ?? // nested {data:{content}} (ChatGot)
5699
+ p.data?.chunk?.content ?? // LangChain /stream_events on_chat_model_stream
5700
+ (typeof p.data === "string" ? p.data : void 0)
5701
+ );
5702
+ return typeof candidate === "string" ? candidate : void 0;
5703
+ }
5668
5704
  async function collectSSE(response) {
5669
5705
  if (!response.body) {
5670
5706
  throw new HttpTargetError("SSE response has no body", 0);
@@ -5691,18 +5727,27 @@ async function collectSSE(response) {
5691
5727
  const lines = buffer.split("\n");
5692
5728
  buffer = lines.pop();
5693
5729
  for (const line of lines) {
5694
- if (!line.startsWith("data: ")) continue;
5695
- const payload = line.slice(6).trim();
5696
- if (payload === "[DONE]" || payload === "") continue;
5730
+ if (!line.startsWith("data:")) continue;
5731
+ const payload = line.slice(5).trim();
5732
+ if (payload === "") continue;
5733
+ if (payload === "[DONE]") {
5734
+ await reader.cancel().catch(() => {
5735
+ });
5736
+ return result;
5737
+ }
5697
5738
  try {
5698
5739
  const parsed = JSON.parse(payload);
5699
5740
  if (typeof parsed === "string") {
5700
5741
  result += parsed;
5701
5742
  } else {
5702
- const chunk = parsed.message ?? parsed.content ?? parsed.delta?.content ?? parsed.text ?? parsed.choices?.[0]?.delta?.content ?? parsed.data?.message ?? // nested: {"data":{"message":"…"}} (e.g. ChatGot)
5703
- parsed.data?.content ?? parsed.data;
5704
- if (chunk != null) {
5705
- result += typeof chunk === "string" ? chunk : JSON.stringify(chunk);
5743
+ const chunk = extractSseChunk(parsed);
5744
+ if (chunk === "[DONE]") {
5745
+ await reader.cancel().catch(() => {
5746
+ });
5747
+ return result;
5748
+ }
5749
+ if (typeof chunk === "string") {
5750
+ result += chunk;
5706
5751
  }
5707
5752
  }
5708
5753
  } catch {
package/dist/cli.js CHANGED
@@ -29,7 +29,7 @@ import {
29
29
  resolveOfflinePosition,
30
30
  summarizeAttackErrors,
31
31
  version
32
- } from "./chunk-LGX52ZEL.js";
32
+ } from "./chunk-3ZVL7ZFC.js";
33
33
 
34
34
  // src/load-env.ts
35
35
  try {
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  generatePdf,
10
10
  loadConfig,
11
11
  loadSystemPrompt
12
- } from "./chunk-LGX52ZEL.js";
12
+ } from "./chunk-3ZVL7ZFC.js";
13
13
  export {
14
14
  ConfigError,
15
15
  ConfigSchema,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shield-llm",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "AI chatbot security scanner — automated red teaming for LLMs",
5
5
  "type": "module",
6
6
  "publishConfig": {