@mapick/cost-firewall 0.1.1 → 0.2.1
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/breaker.d.ts +3 -0
- package/dist/breaker.d.ts.map +1 -1
- package/dist/breaker.js +8 -1
- package/dist/breaker.js.map +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +88 -16
- package/dist/cli/index.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +2 -0
- package/dist/config.js.map +1 -1
- package/dist/dashboard/html.d.ts.map +1 -1
- package/dist/dashboard/html.js +82 -38
- package/dist/dashboard/html.js.map +1 -1
- package/dist/dashboard/index.d.ts.map +1 -1
- package/dist/dashboard/index.js +2 -0
- package/dist/dashboard/index.js.map +1 -1
- package/dist/hooks/before-agent-reply.d.ts +9 -0
- package/dist/hooks/before-agent-reply.d.ts.map +1 -1
- package/dist/hooks/before-agent-reply.js +42 -6
- package/dist/hooks/before-agent-reply.js.map +1 -1
- package/dist/hooks/before-model-resolve.d.ts +20 -0
- package/dist/hooks/before-model-resolve.d.ts.map +1 -0
- package/dist/hooks/before-model-resolve.js +33 -0
- package/dist/hooks/before-model-resolve.js.map +1 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +6 -2
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/model-call.d.ts.map +1 -1
- package/dist/hooks/model-call.js +14 -1
- package/dist/hooks/model-call.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/pricing.d.ts +2 -4
- package/dist/pricing.d.ts.map +1 -1
- package/dist/pricing.js +2 -29
- package/dist/pricing.js.map +1 -1
- package/dist/provider/index.d.ts.map +1 -1
- package/dist/provider/index.js +5 -8
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/stream.d.ts +2 -7
- package/dist/provider/stream.d.ts.map +1 -1
- package/dist/provider/stream.js +1 -119
- package/dist/provider/stream.js.map +1 -1
- package/dist/provider/synthetic.d.ts.map +1 -1
- package/dist/provider/synthetic.js +10 -1
- package/dist/provider/synthetic.js.map +1 -1
- package/dist/provider/upstream/anthropic.d.ts +1 -1
- package/dist/provider/upstream/anthropic.d.ts.map +1 -1
- package/dist/provider/upstream/anthropic.js +12 -4
- package/dist/provider/upstream/anthropic.js.map +1 -1
- package/dist/provider/upstream/openai.d.ts +1 -1
- package/dist/provider/upstream/openai.d.ts.map +1 -1
- package/dist/provider/upstream/openai.js +2 -3
- package/dist/provider/upstream/openai.js.map +1 -1
- package/dist/source.js +3 -3
- package/dist/source.js.map +1 -1
- package/dist/state.js +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/openclaw.plugin.json +49 -13
- package/package.json +1 -1
|
@@ -6,6 +6,13 @@
|
|
|
6
6
|
* - Daily Budget blocking
|
|
7
7
|
* - Source Cooldown blocking
|
|
8
8
|
*/
|
|
9
|
+
// Test block flag — set by llm_input hook when user types 'block test'
|
|
10
|
+
export let testBlockRequested = null;
|
|
11
|
+
// Prevent re-triggering from conversation history containing "block test"
|
|
12
|
+
let testBlockProcessed = false;
|
|
13
|
+
export function clearTestBlock() {
|
|
14
|
+
testBlockRequested = null;
|
|
15
|
+
}
|
|
9
16
|
export function createBeforeAgentReplyHandler(state, store) {
|
|
10
17
|
return async function handleBeforeAgentReply(event, ctx) {
|
|
11
18
|
const source = event.agentId ?? event.sessionKey ?? "unknown";
|
|
@@ -20,12 +27,12 @@ export function createBeforeAgentReplyHandler(state, store) {
|
|
|
20
27
|
});
|
|
21
28
|
state.globalStats.todayBlocked++;
|
|
22
29
|
const messages = {
|
|
23
|
-
emergency_stop: "
|
|
24
|
-
daily_token_limit:
|
|
25
|
-
source_cooldown:
|
|
26
|
-
consecutive_failures: "
|
|
27
|
-
token_velocity: "
|
|
28
|
-
call_frequency: "
|
|
30
|
+
emergency_stop: "🛑 Emergency stop activated. All AI calls are blocked. Use `openclaw firewall resume` to restore.",
|
|
31
|
+
daily_token_limit: `⛔ Daily token limit reached. Today's AI usage has exceeded the limit. Use \`openclaw firewall status\` to check usage or \`openclaw firewall budget reset\` to remove the limit.`,
|
|
32
|
+
source_cooldown: `🔥 Breaker tripped — source is in cooldown for ${state.breaker.getCooldownRemaining(source)}ms. Wait for cooldown or use \`openclaw firewall reset "${source}"\` to clear.`,
|
|
33
|
+
consecutive_failures: `⚠️ Source "${source}" blocked: ${state.config.breaker?.consecutiveFailures ?? 3} consecutive failures triggered breaker. Use \`openclaw firewall reset "${source}"\` to clear.`,
|
|
34
|
+
token_velocity: `⚡ Source "${source}" blocked: token rate exceeded ${state.config.breaker?.tokenVelocityThreshold?.toLocaleString() ?? "limit"} tokens/${state.config.breaker?.tokenVelocityWindowSec ?? 60}s. Use \`openclaw firewall reset "${source}"\` to clear.`,
|
|
35
|
+
call_frequency: `📞 Source "${source}" blocked: call frequency exceeded ${state.config.breaker?.callFrequencyThreshold ?? 30} calls/${state.config.breaker?.callFrequencyWindowSec ?? 60}s. Use \`openclaw firewall reset "${source}"\` to clear.`,
|
|
29
36
|
};
|
|
30
37
|
return {
|
|
31
38
|
handled: true,
|
|
@@ -36,7 +43,36 @@ export function createBeforeAgentReplyHandler(state, store) {
|
|
|
36
43
|
reason: result.reason,
|
|
37
44
|
};
|
|
38
45
|
}
|
|
46
|
+
// Test block trigger
|
|
47
|
+
if (testBlockRequested) {
|
|
48
|
+
const src = testBlockRequested.source || "unknown";
|
|
49
|
+
testBlockRequested = null;
|
|
50
|
+
store.append({ type: "blocked", source: src, reason: "test_block", layer: "hook" });
|
|
51
|
+
state.globalStats.todayBlocked++;
|
|
52
|
+
return {
|
|
53
|
+
handled: true,
|
|
54
|
+
reply: {
|
|
55
|
+
text: `🧪 Block test triggered successfully for source "${src}". The firewall is working. Use \`openclaw firewall status\` to verify the blocked count increased.`,
|
|
56
|
+
isError: true,
|
|
57
|
+
},
|
|
58
|
+
reason: "test_block",
|
|
59
|
+
};
|
|
60
|
+
}
|
|
39
61
|
return undefined;
|
|
40
62
|
};
|
|
41
63
|
}
|
|
64
|
+
/** Handle llm_input — check for test block trigger phrase */
|
|
65
|
+
export function createTestBlockDetector(store) {
|
|
66
|
+
return function detectTestBlock(event, _ctx) {
|
|
67
|
+
const prompt = event.prompt ?? "";
|
|
68
|
+
if (prompt.includes("阻断测试") || prompt.includes("block test") || prompt.includes("test block")) {
|
|
69
|
+
// Only trigger once per gateway process to avoid re-triggering from history
|
|
70
|
+
if (testBlockProcessed)
|
|
71
|
+
return;
|
|
72
|
+
testBlockProcessed = true;
|
|
73
|
+
testBlockRequested = { source: event.provider ?? "chat" };
|
|
74
|
+
store.append({ type: "test_block_triggered", reason: "user requested block test" });
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
42
78
|
//# sourceMappingURL=before-agent-reply.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"before-agent-reply.js","sourceRoot":"","sources":["../../src/hooks/before-agent-reply.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"before-agent-reply.js","sourceRoot":"","sources":["../../src/hooks/before-agent-reply.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,uEAAuE;AACvE,MAAM,CAAC,IAAI,kBAAkB,GAA+B,IAAI,CAAC;AACjE,0EAA0E;AAC1E,IAAI,kBAAkB,GAAG,KAAK,CAAC;AAE/B,MAAM,UAAU,cAAc;IAC5B,kBAAkB,GAAG,IAAI,CAAC;AAC5B,CAAC;AAsBD,MAAM,UAAU,6BAA6B,CAC3C,KAAoB,EACpB,KAAiB;IAEjB,OAAO,KAAK,UAAU,sBAAsB,CAC1C,KAA4B,EAC5B,GAAwB;QAExB,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,UAAU,IAAI,SAAS,CAAC;QAE9D,mBAAmB;QACnB,MAAM,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAA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* Intercepts model resolution and rewrites non-mapick models to
|
|
5
|
+
* mapick/<provider>/<model>, making the Provider Layer transparent.
|
|
6
|
+
* Users keep their existing model config — no changes needed.
|
|
7
|
+
*/
|
|
8
|
+
import type { FirewallState } from "../state.js";
|
|
9
|
+
import type { EventStore } from "../store.js";
|
|
10
|
+
export interface BeforeModelResolveEvent {
|
|
11
|
+
provider: string;
|
|
12
|
+
model: string;
|
|
13
|
+
runId?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ModelResolveResult {
|
|
16
|
+
providerOverride?: string;
|
|
17
|
+
modelOverride?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function createBeforeModelResolveHandler(state: FirewallState, store: EventStore): (event: any, _ctx: any) => ModelResolveResult | undefined;
|
|
20
|
+
//# sourceMappingURL=before-model-resolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"before-model-resolve.d.ts","sourceRoot":"","sources":["../../src/hooks/before-model-resolve.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAG9C,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,kBAAkB;IACjC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,aAAa,EACpB,KAAK,EAAE,UAAU,IAGf,OAAO,GAAG,EACV,MAAM,GAAG,KACR,kBAAkB,GAAG,SAAS,CAuBlC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* before_model_resolve hook — transparent model routing through firewall
|
|
3
|
+
*
|
|
4
|
+
* Intercepts model resolution and rewrites non-mapick models to
|
|
5
|
+
* mapick/<provider>/<model>, making the Provider Layer transparent.
|
|
6
|
+
* Users keep their existing model config — no changes needed.
|
|
7
|
+
*/
|
|
8
|
+
import { isMapickModelRef } from "../provider/route.js";
|
|
9
|
+
export function createBeforeModelResolveHandler(state, store) {
|
|
10
|
+
return function handleBeforeModelResolve(event, _ctx) {
|
|
11
|
+
// Defensive: real OpenClaw events may have undefined model/provider
|
|
12
|
+
if (!event.model || !event.provider)
|
|
13
|
+
return undefined;
|
|
14
|
+
// Already using mapick/* — no rewrite needed
|
|
15
|
+
if (isMapickModelRef(event.model))
|
|
16
|
+
return undefined;
|
|
17
|
+
// Rewrite ALL calls to mapick/<provider>/<model>
|
|
18
|
+
// observe mode: routes through Provider Layer for tracking (no blocking)
|
|
19
|
+
// protect mode: routes through Provider Layer for tracking + blocking
|
|
20
|
+
const newModel = `mapick/${event.provider}/${event.model}`;
|
|
21
|
+
store.append({
|
|
22
|
+
type: "model_rewrite",
|
|
23
|
+
reason: "transparent_firewall_routing",
|
|
24
|
+
provider: event.provider,
|
|
25
|
+
model: event.model,
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
providerOverride: "mapick",
|
|
29
|
+
modelOverride: newModel,
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=before-model-resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"before-model-resolve.js","sourceRoot":"","sources":["../../src/hooks/before-model-resolve.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAaxD,MAAM,UAAU,+BAA+B,CAC7C,KAAoB,EACpB,KAAiB;IAEjB,OAAO,SAAS,wBAAwB,CACtC,KAAU,EACV,IAAS;QAET,oEAAoE;QACpE,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,QAAQ;YAAE,OAAO,SAAS,CAAC;QAEtD,6CAA6C;QAC7C,IAAI,gBAAgB,CAAC,KAAK,CAAC,KAAK,CAAC;YAAE,OAAO,SAAS,CAAC;QAEpD,iDAAiD;QACjD,yEAAyE;QACzE,sEAAsE;QACtE,MAAM,QAAQ,GAAG,UAAU,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAC3D,KAAK,CAAC,MAAM,CAAC;YACX,IAAI,EAAE,eAAe;YACrB,MAAM,EAAE,8BAA8B;YACtC,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB,CAAC,CAAC;QAEH,OAAO;YACL,gBAAgB,EAAE,QAAQ;YAC1B,aAAa,EAAE,QAAQ;SACxB,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAM9C,wBAAgB,aAAa,CAC3B,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,aAAa,EACpB,KAAK,EAAE,UAAU,GAChB,IAAI,CAcN"}
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hook registration entry point
|
|
3
3
|
*/
|
|
4
|
-
import { createBeforeAgentReplyHandler } from "./before-agent-reply.js";
|
|
4
|
+
import { createBeforeAgentReplyHandler, createTestBlockDetector } from "./before-agent-reply.js";
|
|
5
|
+
import { createBeforeModelResolveHandler } from "./before-model-resolve.js";
|
|
5
6
|
import { createModelCallStartedHandler, createModelCallEndedHandler } from "./model-call.js";
|
|
6
7
|
import { createAgentEndHandler } from "./agent-end.js";
|
|
7
8
|
export function registerHooks(api, state, store) {
|
|
8
9
|
api.on("before_agent_reply", createBeforeAgentReplyHandler(state, store));
|
|
10
|
+
api.on("before_model_resolve", createBeforeModelResolveHandler(state, store));
|
|
9
11
|
api.on("model_call_started", createModelCallStartedHandler(state, store));
|
|
10
12
|
api.on("model_call_ended", createModelCallEndedHandler(state, store));
|
|
11
13
|
api.on("agent_end", createAgentEndHandler(state, store));
|
|
14
|
+
// llm_input — test block detection (triggers on "block test" phrase)
|
|
15
|
+
api.on("llm_input", createTestBlockDetector(store));
|
|
12
16
|
if (state.config.privacy?.enableRawConversationHooks) {
|
|
13
|
-
//
|
|
17
|
+
// llm_output — opt-in only
|
|
14
18
|
// To be implemented in future versions
|
|
15
19
|
}
|
|
16
20
|
}
|
package/dist/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,6BAA6B,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,6BAA6B,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AACjG,OAAO,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,6BAA6B,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAC7F,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,MAAM,UAAU,aAAa,CAC3B,GAAQ,EACR,KAAoB,EACpB,KAAiB;IAEjB,GAAG,CAAC,EAAE,CAAC,oBAAoB,EAAE,6BAA6B,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IAC1E,GAAG,CAAC,EAAE,CAAC,sBAAsB,EAAE,+BAA+B,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IAC9E,GAAG,CAAC,EAAE,CAAC,oBAAoB,EAAE,6BAA6B,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IAC1E,GAAG,CAAC,EAAE,CAAC,kBAAkB,EAAE,2BAA2B,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IACtE,GAAG,CAAC,EAAE,CAAC,WAAW,EAAE,qBAAqB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IAEzD,qEAAqE;IACrE,GAAG,CAAC,EAAE,CAAC,WAAW,EAAE,uBAAuB,CAAC,KAAK,CAAC,CAAC,CAAC;IAEpD,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,0BAA0B,EAAE,CAAC;QACrD,2BAA2B;QAC3B,uCAAuC;IACzC,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-call.d.ts","sourceRoot":"","sources":["../../src/hooks/model-call.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"model-call.d.ts","sourceRoot":"","sources":["../../src/hooks/model-call.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAK9C,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,mBAAoB,SAAQ,qBAAqB;IAChE,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC;IAC/B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,SAAS,GAAG,mBAAmB,GAAG,kBAAkB,GAAG,YAAY,GAAG,SAAS,CAAC;IAC9F,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,KAAK,CAAC,EAAE;QACN,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;CACH;AAED,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,aAAa,EACpB,KAAK,EAAE,UAAU,IAGf,OAAO,qBAAqB,EAC5B,KAAK,GAAG,KACP,IAAI,CAyBR;AAED,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,aAAa,EACpB,KAAK,EAAE,UAAU,IAGf,OAAO,mBAAmB,EAC1B,KAAK,GAAG,KACP,IAAI,CAuGR"}
|
package/dist/hooks/model-call.js
CHANGED
|
@@ -8,9 +8,18 @@
|
|
|
8
8
|
* - Write event log
|
|
9
9
|
*/
|
|
10
10
|
import { sourceFromModelCall } from "../source.js";
|
|
11
|
+
import { testBlockRequested, clearTestBlock } from "./before-agent-reply.js";
|
|
11
12
|
export function createModelCallStartedHandler(state, store) {
|
|
12
13
|
return function handleModelCallStarted(event, ctx) {
|
|
13
14
|
const source = sourceFromModelCall(event, ctx);
|
|
15
|
+
// Test block detection: user typed "block test" → activate emergency stop now
|
|
16
|
+
if (testBlockRequested) {
|
|
17
|
+
const src = testBlockRequested.source || source;
|
|
18
|
+
clearTestBlock();
|
|
19
|
+
store.append({ type: "blocked", source: src, reason: "test_block", layer: "hook" });
|
|
20
|
+
state.globalStats.todayBlocked++;
|
|
21
|
+
state.setEmergencyStop(true);
|
|
22
|
+
}
|
|
14
23
|
const run = state.getOrCreateRun(event.runId, source, event.sessionId, event.sessionKey);
|
|
15
24
|
state.addCallToRun(event.runId, event.callId, {
|
|
16
25
|
callId: event.callId,
|
|
@@ -55,7 +64,11 @@ export function createModelCallEndedHandler(state, store) {
|
|
|
55
64
|
state.breaker.recordSuccess(source);
|
|
56
65
|
}
|
|
57
66
|
state.updateRunCost(event.runId, estimatedTokens);
|
|
58
|
-
|
|
67
|
+
// Provider layer tracks tokens for mapick/* calls — skip to avoid double-counting
|
|
68
|
+
// Uses model prefix check (more reliable than provider field)
|
|
69
|
+
if (!event.model?.startsWith("mapick/")) {
|
|
70
|
+
state.updateSourceStats(source, estimatedTokens);
|
|
71
|
+
}
|
|
59
72
|
// Token velocity + call frequency + zero output detection
|
|
60
73
|
if (event.outcome === "completed") {
|
|
61
74
|
state.breaker.recordTokens(source, estimatedTokens);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-call.js","sourceRoot":"","sources":["../../src/hooks/model-call.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"model-call.js","sourceRoot":"","sources":["../../src/hooks/model-call.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,kB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,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -13,7 +13,7 @@ import { detectConfigRisks } from "./config-warn.js";
|
|
|
13
13
|
export default {
|
|
14
14
|
id: PLUGIN_ID,
|
|
15
15
|
name: PLUGIN_NAME,
|
|
16
|
-
version: "0.1
|
|
16
|
+
version: "0.2.1",
|
|
17
17
|
register(api) {
|
|
18
18
|
const config = api.config?.plugins?.entries?.[PLUGIN_ID]?.config ?? {};
|
|
19
19
|
const state = new FirewallState(config);
|
package/dist/pricing.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* OpenRouter: pass-through pricing (inherits upstream provider pricing)
|
|
2
|
+
* Token estimation — estimates token count from usage or response bytes.
|
|
5
3
|
*/
|
|
6
4
|
export interface TokenUsage {
|
|
7
5
|
prompt_tokens?: number;
|
|
8
6
|
completion_tokens?: number;
|
|
9
7
|
}
|
|
10
|
-
export declare function
|
|
8
|
+
export declare function estimateTokens(usage: TokenUsage | null | undefined, provider: string, model: string, responseStreamBytes?: number): number;
|
|
11
9
|
export declare function getProviderModelKey(provider: string, model: string): string;
|
|
12
10
|
//# sourceMappingURL=pricing.d.ts.map
|
package/dist/pricing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pricing.d.ts","sourceRoot":"","sources":["../src/pricing.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"pricing.d.ts","sourceRoot":"","sources":["../src/pricing.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,UAAU;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,UAAU,GAAG,IAAI,GAAG,SAAS,EACpC,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,mBAAmB,CAAC,EAAE,MAAM,GAC3B,MAAM,CAUR;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAE3E"}
|
package/dist/pricing.js
CHANGED
|
@@ -1,34 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* OpenRouter: pass-through pricing (inherits upstream provider pricing)
|
|
2
|
+
* Token estimation — estimates token count from usage or response bytes.
|
|
5
3
|
*/
|
|
6
|
-
|
|
7
|
-
const PRICING = {
|
|
8
|
-
openai: {
|
|
9
|
-
"gpt-4o": { input: 2.5, output: 10 },
|
|
10
|
-
"gpt-4o-mini": { input: 0.15, output: 0.6 },
|
|
11
|
-
"gpt-4-turbo": { input: 10, output: 30 },
|
|
12
|
-
"gpt-3.5-turbo": { input: 0.5, output: 1.5 },
|
|
13
|
-
},
|
|
14
|
-
anthropic: {
|
|
15
|
-
"claude-sonnet-4-6": { input: 3, output: 15 },
|
|
16
|
-
"claude-sonnet-4-20250514": { input: 3, output: 15 },
|
|
17
|
-
"claude-sonnet-4-5": { input: 3, output: 15 },
|
|
18
|
-
"claude-haiku-3-5": { input: 0.8, output: 4 },
|
|
19
|
-
},
|
|
20
|
-
openrouter: {}, // pass-through pricing
|
|
21
|
-
deepseek: {
|
|
22
|
-
"deepseek-chat": { input: 0.28, output: 0.42 },
|
|
23
|
-
"deepseek-reasoner": { input: 0.55, output: 2.19 },
|
|
24
|
-
},
|
|
25
|
-
qwen: {
|
|
26
|
-
"qwen3-plus": { input: 0.5, output: 2 },
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
// Fallback: estimate by response bytes (assuming 1 token ≈ 4 bytes, $3/1M tokens)
|
|
30
|
-
const FALLBACK_COST_PER_BYTE = 3 / 1_000_000 / 4;
|
|
31
|
-
export function estimateCost(usage, provider, model, responseStreamBytes) {
|
|
4
|
+
export function estimateTokens(usage, provider, model, responseStreamBytes) {
|
|
32
5
|
if (usage?.prompt_tokens || usage?.completion_tokens) {
|
|
33
6
|
return (usage.prompt_tokens ?? 0) + (usage.completion_tokens ?? 0);
|
|
34
7
|
}
|
package/dist/pricing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pricing.js","sourceRoot":"","sources":["../src/pricing.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"pricing.js","sourceRoot":"","sources":["../src/pricing.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,MAAM,UAAU,cAAc,CAC5B,KAAoC,EACpC,QAAgB,EAChB,KAAa,EACb,mBAA4B;IAE5B,IAAI,KAAK,EAAE,aAAa,IAAI,KAAK,EAAE,iBAAiB,EAAE,CAAC;QACrD,OAAO,CAAC,KAAK,CAAC,aAAa,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,iBAAiB,IAAI,CAAC,CAAC,CAAC;IACrE,CAAC;IAED,IAAI,mBAAmB,EAAE,CAAC;QACxB,OAAO,mBAAmB,CAAC;IAC7B,CAAC;IAED,OAAO,CAAC,CAAC;AACX,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,QAAgB,EAAE,KAAa;IACjE,OAAO,GAAG,QAAQ,IAAI,KAAK,EAAE,CAAC;AAChC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/provider/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAoB9C,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,aAAa,EACpB,KAAK,EAAE,UAAU,GAChB,IAAI,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/provider/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAoB9C,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,aAAa,EACpB,KAAK,EAAE,UAAU,GAChB,IAAI,CAoGN"}
|
package/dist/provider/index.js
CHANGED
|
@@ -19,7 +19,7 @@ import { resolveUpstreamAuth } from "./auth.js";
|
|
|
19
19
|
import { createBlockedStream } from "./synthetic.js";
|
|
20
20
|
import { streamOpenAi, getOpenAiBaseUrl } from "./upstream/openai.js";
|
|
21
21
|
import { streamAnthropic } from "./upstream/anthropic.js";
|
|
22
|
-
import {
|
|
22
|
+
import { estimateTokens } from "../pricing.js";
|
|
23
23
|
function categorizeError(err) {
|
|
24
24
|
const m = err?.message ?? String(err);
|
|
25
25
|
if (m.includes("timeout") || m.includes("ETIMEDOUT"))
|
|
@@ -80,7 +80,6 @@ export function registerProvider(api, state, store) {
|
|
|
80
80
|
};
|
|
81
81
|
},
|
|
82
82
|
createStreamFn() {
|
|
83
|
-
const self = this;
|
|
84
83
|
return async function* stream(model, context, options) {
|
|
85
84
|
// model may come from ctx, use catalog + resolveDynamicModel provided model
|
|
86
85
|
const modelId = typeof model === "string" ? model : model?.id ?? "";
|
|
@@ -109,13 +108,14 @@ export function registerProvider(api, state, store) {
|
|
|
109
108
|
}
|
|
110
109
|
// Resolve upstream auth
|
|
111
110
|
const auth = await resolveUpstreamAuth(api, route.upstream, route.model);
|
|
111
|
+
const timeout = state.config.upstreamTimeoutMs ?? 30_000;
|
|
112
112
|
let inputTokens = 0;
|
|
113
113
|
let outputTokens = 0;
|
|
114
114
|
let responseStreamBytes = 0;
|
|
115
115
|
try {
|
|
116
116
|
const s = route.upstream === "anthropic"
|
|
117
|
-
? streamAnthropic({ apiKey: auth.apiKey, model: route.model, messages: context?.messages ?? [], ...options })
|
|
118
|
-
: streamOpenAi({ baseUrl: getOpenAiBaseUrl(route.upstream), apiKey: auth.apiKey, model: route.model, messages: context?.messages ?? [], ...options });
|
|
117
|
+
? streamAnthropic({ apiKey: auth.apiKey, model: route.model, messages: context?.messages ?? [], ...options }, timeout)
|
|
118
|
+
: streamOpenAi({ baseUrl: getOpenAiBaseUrl(route.upstream), apiKey: auth.apiKey, model: route.model, messages: context?.messages ?? [], ...options }, timeout);
|
|
119
119
|
for await (const chunk of s) {
|
|
120
120
|
responseStreamBytes += JSON.stringify(chunk).length;
|
|
121
121
|
if (chunk.usage) {
|
|
@@ -124,14 +124,11 @@ export function registerProvider(api, state, store) {
|
|
|
124
124
|
}
|
|
125
125
|
yield chunk;
|
|
126
126
|
}
|
|
127
|
-
const cost =
|
|
128
|
-
store.append({ type: "model_call_ended", provider: route.upstream, model: route.model, outcome: "completed", estimatedCost: cost });
|
|
127
|
+
const cost = estimateTokens({ prompt_tokens: inputTokens, completion_tokens: outputTokens }, route.upstream, route.model, responseStreamBytes);
|
|
129
128
|
state.updateSourceStats(src, cost);
|
|
130
129
|
state.breaker.recordSuccess(src);
|
|
131
130
|
}
|
|
132
131
|
catch (err) {
|
|
133
|
-
const msg = err?.message ?? String(err);
|
|
134
|
-
store.append({ type: "model_call_ended", provider: route.upstream, model: route.model, outcome: "error", failureKind: categorizeError(err), reason: msg.slice(0, 200) });
|
|
135
132
|
state.breaker.recordFailure(src);
|
|
136
133
|
throw err;
|
|
137
134
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/provider/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAA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AAI,KAAK,CAAC,KAAK,EAAE,CAAC;4BAAC,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC,aAAa,IAAI,WAAW,CAAC;4BAAC,YAAY,GAAG,KAAK,CAAC,KAAK,CAAC,iBAAiB,IAAI,YAAY,CAAC;wBAAC,CAAC;wBAC1I,MAAM,KAAK,CAAC;oBACd,CAAC;oBAED,MAAM,IAAI,GAAG,cAAc,CAAC,EAAE,aAAa,EAAE,WAAW,EAAE,iBAAiB,EAAE,YAAY,EAAE,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC;oBAC/I,KAAK,CAAC,iBAAiB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;oBACnC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;gBACnC,CAAC;gBAAC,OAAO,GAAQ,EAAE,CAAC;oBAClB,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;oBACjC,MAAM,GAAG,CAAC;gBACZ,CAAC;YACH,CAAC,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* createStreamFn
|
|
3
|
-
*
|
|
4
|
-
* Core: precheck before real upstream request is sent
|
|
5
|
-
* SDK convention: createStreamFn(ctx) => async function*(model, context, options)
|
|
2
|
+
* stream.ts — removed. Provider Layer uses inline createStreamFn in provider/index.ts.
|
|
6
3
|
*/
|
|
7
|
-
|
|
8
|
-
import type { EventStore } from "../store.js";
|
|
9
|
-
export declare function createStreamFn(state: FirewallState, store: EventStore, api: any): (ctx: any) => (model: string, context: any, options: any) => AsyncGenerator<any, void, any>;
|
|
4
|
+
export {};
|
|
10
5
|
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/provider/stream.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/provider/stream.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,CAAC"}
|
package/dist/provider/stream.js
CHANGED
|
@@ -1,120 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* createStreamFn implementation
|
|
3
|
-
*
|
|
4
|
-
* Core: precheck before real upstream request is sent
|
|
5
|
-
* SDK convention: createStreamFn(ctx) => async function*(model, context, options)
|
|
6
|
-
*/
|
|
7
|
-
import { parseMapickModelRef } from "./route.js";
|
|
8
|
-
import { resolveUpstreamAuth } from "./auth.js";
|
|
9
|
-
import { createBlockedStream } from "./synthetic.js";
|
|
10
|
-
import { streamOpenAi, getOpenAiBaseUrl } from "./upstream/openai.js";
|
|
11
|
-
import { streamAnthropic } from "./upstream/anthropic.js";
|
|
12
|
-
import { sourceFromProviderContext } from "../source.js";
|
|
13
|
-
import { estimateCost } from "../pricing.js";
|
|
14
|
-
export function createStreamFn(state, store, api) {
|
|
15
|
-
// Return createStreamFn matching SDK signature
|
|
16
|
-
// OpenClaw calls createStreamFn(ctx), returns async generator function
|
|
17
|
-
return function (ctx) {
|
|
18
|
-
return async function* stream(model, context, options) {
|
|
19
|
-
const route = parseMapickModelRef(model);
|
|
20
|
-
if (!route) {
|
|
21
|
-
throw new Error(`Invalid Mapick model reference: ${model}`);
|
|
22
|
-
}
|
|
23
|
-
const source = sourceFromProviderContext({ ...context, ...ctx }, route);
|
|
24
|
-
// Precheck
|
|
25
|
-
const result = state.precheck(source);
|
|
26
|
-
if (!result.allow) {
|
|
27
|
-
store.append({
|
|
28
|
-
type: "blocked",
|
|
29
|
-
source,
|
|
30
|
-
provider: route.upstream,
|
|
31
|
-
model: route.model,
|
|
32
|
-
reason: result.reason,
|
|
33
|
-
layer: result.layer,
|
|
34
|
-
});
|
|
35
|
-
state.globalStats.todayBlocked++;
|
|
36
|
-
state.globalStats.todaySavedEstimate += estimateCost(null, route.upstream, route.model);
|
|
37
|
-
yield* createBlockedStream({
|
|
38
|
-
provider: route.upstream,
|
|
39
|
-
model: route.model,
|
|
40
|
-
reason: result.reason,
|
|
41
|
-
format: route.upstream === "anthropic" ? "anthropic" : "openai",
|
|
42
|
-
});
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
// Get upstream auth
|
|
46
|
-
const auth = await resolveUpstreamAuth(api, route.upstream, route.model);
|
|
47
|
-
// Call upstream
|
|
48
|
-
let inputTokens = 0;
|
|
49
|
-
let outputTokens = 0;
|
|
50
|
-
let responseStreamBytes = 0;
|
|
51
|
-
try {
|
|
52
|
-
let upstreamStream;
|
|
53
|
-
if (route.upstream === "anthropic") {
|
|
54
|
-
upstreamStream = streamAnthropic({
|
|
55
|
-
apiKey: auth.apiKey,
|
|
56
|
-
model: route.model,
|
|
57
|
-
messages: context.messages ?? [],
|
|
58
|
-
...options,
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
upstreamStream = streamOpenAi({
|
|
63
|
-
baseUrl: getOpenAiBaseUrl(route.upstream),
|
|
64
|
-
apiKey: auth.apiKey,
|
|
65
|
-
model: route.model,
|
|
66
|
-
messages: context.messages ?? [],
|
|
67
|
-
...options,
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
for await (const chunk of upstreamStream) {
|
|
71
|
-
responseStreamBytes += JSON.stringify(chunk).length;
|
|
72
|
-
if (chunk.usage) {
|
|
73
|
-
inputTokens = chunk.usage.prompt_tokens ?? inputTokens;
|
|
74
|
-
outputTokens = chunk.usage.completion_tokens ?? outputTokens;
|
|
75
|
-
}
|
|
76
|
-
yield chunk;
|
|
77
|
-
}
|
|
78
|
-
const cost = estimateCost({ prompt_tokens: inputTokens, completion_tokens: outputTokens }, route.upstream, route.model, responseStreamBytes);
|
|
79
|
-
store.append({
|
|
80
|
-
type: "model_call_ended",
|
|
81
|
-
source,
|
|
82
|
-
provider: route.upstream,
|
|
83
|
-
model: route.model,
|
|
84
|
-
outcome: "completed",
|
|
85
|
-
estimatedCost: cost,
|
|
86
|
-
});
|
|
87
|
-
state.updateSourceStats(source, cost);
|
|
88
|
-
state.breaker.recordSuccess(source);
|
|
89
|
-
}
|
|
90
|
-
catch (err) {
|
|
91
|
-
store.append({
|
|
92
|
-
type: "model_call_ended",
|
|
93
|
-
source,
|
|
94
|
-
provider: route.upstream,
|
|
95
|
-
model: route.model,
|
|
96
|
-
outcome: "error",
|
|
97
|
-
failureKind: categorizeError(err),
|
|
98
|
-
});
|
|
99
|
-
state.breaker.recordFailure(source);
|
|
100
|
-
throw err;
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
function categorizeError(err) {
|
|
106
|
-
if (err.message.includes("timeout"))
|
|
107
|
-
return "timeout";
|
|
108
|
-
if (err.message.includes("ECONNRESET"))
|
|
109
|
-
return "connection_reset";
|
|
110
|
-
if (err.message.includes("ECONNREFUSED"))
|
|
111
|
-
return "connection_closed";
|
|
112
|
-
if (err.message.includes("401"))
|
|
113
|
-
return "auth_error";
|
|
114
|
-
if (err.message.includes("429"))
|
|
115
|
-
return "rate_limit";
|
|
116
|
-
if (err.message.includes("5"))
|
|
117
|
-
return "server_error";
|
|
118
|
-
return "unknown";
|
|
119
|
-
}
|
|
1
|
+
export {};
|
|
120
2
|
//# sourceMappingURL=stream.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/provider/stream.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/provider/stream.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"synthetic.d.ts","sourceRoot":"","sources":["../../src/provider/synthetic.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAC;CACjC;AAED,wBAAuB,mBAAmB,CACxC,OAAO,EAAE,oBAAoB,GAC5B,cAAc,CAAC,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"synthetic.d.ts","sourceRoot":"","sources":["../../src/provider/synthetic.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAC;CACjC;AAED,wBAAuB,mBAAmB,CACxC,OAAO,EAAE,oBAAoB,GAC5B,cAAc,CAAC,GAAG,CAAC,CAiErB"}
|
|
@@ -5,7 +5,16 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export async function* createBlockedStream(options) {
|
|
7
7
|
const { provider, model, reason, format = "openai" } = options;
|
|
8
|
-
const
|
|
8
|
+
const hints = {
|
|
9
|
+
emergency_stop: `🛑 Emergency stop. Use \`openclaw firewall resume\`.`,
|
|
10
|
+
daily_token_limit: `⛔ Token limit reached. Use \`openclaw firewall budget reset\`.`,
|
|
11
|
+
consecutive_failures: `⚠️ Consecutive failures. Use \`openclaw firewall reset ${provider}\` to clear.`,
|
|
12
|
+
token_velocity: `⚡ Token velocity exceeded. Cooldown active.`,
|
|
13
|
+
call_frequency: `📞 Call frequency exceeded. Cooldown active.`,
|
|
14
|
+
source_cooldown: `🔥 Source in cooldown. Wait or reset.`,
|
|
15
|
+
};
|
|
16
|
+
const hint = hints[reason] ?? `Blocked: ${reason}`;
|
|
17
|
+
const message = `Mapick Firewall — ${hint}`;
|
|
9
18
|
if (format === "anthropic") {
|
|
10
19
|
yield {
|
|
11
20
|
type: "message_start",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"synthetic.js","sourceRoot":"","sources":["../../src/provider/synthetic.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,mBAAmB,CACxC,OAA6B;IAE7B,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC/D,MAAM,
|
|
1
|
+
{"version":3,"file":"synthetic.js","sourceRoot":"","sources":["../../src/provider/synthetic.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,mBAAmB,CACxC,OAA6B;IAE7B,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC/D,MAAM,KAAK,GAA2B;QACpC,cAAc,EAAE,sDAAsD;QACtE,iBAAiB,EAAE,gEAAgE;QACnF,oBAAoB,EAAE,0DAA0D,QAAQ,cAAc;QACtG,cAAc,EAAE,6CAA6C;QAC7D,cAAc,EAAE,8CAA8C;QAC9D,eAAe,EAAE,uCAAuC;KACzD,CAAC;IACF,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,YAAY,MAAM,EAAE,CAAC;IACnD,MAAM,OAAO,GAAG,qBAAqB,IAAI,EAAE,CAAC;IAE5C,IAAI,MAAM,KAAK,WAAW,EAAE,CAAC;QAC3B,MAAM;YACJ,IAAI,EAAE,eAAe;YACrB,OAAO,EAAE;gBACP,EAAE,EAAE,cAAc,IAAI,CAAC,GAAG,EAAE,EAAE;gBAC9B,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,WAAW;gBACjB,OAAO,EAAE,EAAE;gBACX,KAAK,EAAE,gBAAgB;gBACvB,WAAW,EAAE,UAAU;gBACvB,KAAK,EAAE,EAAE,YAAY,EAAE,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE;aAC7C;SACF,CAAC;QAEF,MAAM;YACJ,IAAI,EAAE,qBAAqB;YAC3B,KAAK,EAAE,CAAC;YACR,aAAa,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE;SAC1C,CAAC;QAEF,MAAM;YACJ,IAAI,EAAE,qBAAqB;YAC3B,KAAK,EAAE,CAAC;YACR,KAAK,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE;SAC7C,CAAC;QAEF,MAAM;YACJ,IAAI,EAAE,oBAAoB;YAC1B,KAAK,EAAE,CAAC;SACT,CAAC;QAEF,MAAM;YACJ,IAAI,EAAE,eAAe;YACrB,KAAK,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE;YAClC,KAAK,EAAE,EAAE,aAAa,EAAE,CAAC,EAAE;SAC5B,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,MAAM;YACJ,EAAE,EAAE,mBAAmB,IAAI,CAAC,GAAG,EAAE,EAAE;YACnC,MAAM,EAAE,uBAAuB;YAC/B,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;YACtC,KAAK,EAAE,gBAAgB;YACvB,OAAO,EAAE;gBACP;oBACE,KAAK,EAAE,CAAC;oBACR,KAAK,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE;oBAC9C,aAAa,EAAE,MAAM;iBACtB;aACF;YACD,KAAK,EAAE,EAAE,aAAa,EAAE,CAAC,EAAE,iBAAiB,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE;SACnE,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -9,5 +9,5 @@ export interface AnthropicStreamOptions {
|
|
|
9
9
|
stream?: boolean;
|
|
10
10
|
[key: string]: any;
|
|
11
11
|
}
|
|
12
|
-
export declare function streamAnthropic(options: AnthropicStreamOptions): AsyncGenerator<any>;
|
|
12
|
+
export declare function streamAnthropic(options: AnthropicStreamOptions, timeoutMs?: number): AsyncGenerator<any>;
|
|
13
13
|
//# sourceMappingURL=anthropic.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../src/provider/upstream/anthropic.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,GAAG,EAAE,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,wBAAuB,eAAe,CACpC,OAAO,EAAE,sBAAsB,
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../src/provider/upstream/anthropic.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,GAAG,EAAE,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,wBAAuB,eAAe,CACpC,OAAO,EAAE,sBAAsB,EAC/B,SAAS,GAAE,MAAe,GACzB,cAAc,CAAC,GAAG,CAAC,CAuErB"}
|