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.
- package/dist/{chunk-LGX52ZEL.js → chunk-3ZVL7ZFC.js} +53 -8
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -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.
|
|
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:
|
|
5695
|
-
const payload = line.slice(
|
|
5696
|
-
if (payload === "
|
|
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
|
|
5703
|
-
|
|
5704
|
-
|
|
5705
|
-
|
|
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
package/dist/index.js
CHANGED