@mapick/cost-firewall 0.1.0 → 0.2.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/README.md +56 -68
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +25 -11
- 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/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 +30 -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/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/auth.d.ts.map +1 -1
- package/dist/provider/auth.js +11 -3
- package/dist/provider/auth.js.map +1 -1
- package/dist/provider/index.d.ts +8 -0
- package/dist/provider/index.d.ts.map +1 -1
- package/dist/provider/index.js +13 -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/store.d.ts +2 -3
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +6 -12
- package/dist/store.js.map +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 +5 -3
|
@@ -0,0 +1,20 @@
|
|
|
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 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: BeforeModelResolveEvent, _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,uBAAuB,EAC9B,MAAM,GAAG,KACR,kBAAkB,GAAG,SAAS,CAoBlC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
// Already using mapick/* — no rewrite needed
|
|
12
|
+
if (isMapickModelRef(event.model))
|
|
13
|
+
return undefined;
|
|
14
|
+
// Rewrite ALL calls to mapick/<provider>/<model>
|
|
15
|
+
// observe mode: routes through Provider Layer for tracking (no blocking)
|
|
16
|
+
// protect mode: routes through Provider Layer for tracking + blocking
|
|
17
|
+
const newModel = `mapick/${event.provider}/${event.model}`;
|
|
18
|
+
store.append({
|
|
19
|
+
type: "model_rewrite",
|
|
20
|
+
reason: "transparent_firewall_routing",
|
|
21
|
+
provider: event.provider,
|
|
22
|
+
model: event.model,
|
|
23
|
+
});
|
|
24
|
+
return {
|
|
25
|
+
providerOverride: "mapick",
|
|
26
|
+
modelOverride: newModel,
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# 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,KAA8B,EAC9B,IAAS;QAET,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/h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6B,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,kBAAkB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AA6B7E,MAAM,UAAU,6BAA6B,CAC3C,KAAoB,EACpB,KAAiB;IAEjB,OAAO,SAAS,sBAAsB,CACpC,KAA4B,EAC5B,GAAQ;QAER,MAAM,MAAM,GAAG,mBAAmB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAE/C,8EAA8E;QAC9E,IAAI,kBAAkB,EAAE,CAAC;YACvB,MAAM,GAAG,GAAG,kBAAkB,CAAC,MAAM,IAAI,MAAM,CAAC;YAChD,cAAc,EAAE,CAAC;YACjB,KAAK,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;YACpF,KAAK,CAAC,WAAW,CAAC,YAAY,EAAE,CAAC;YACjC,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC;QAED,MAAM,GAAG,GAAG,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;QAEzF,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,KAAK,EAA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AmB;gBACzB,KAAK,EAAE,KAAK,CAAC,KAAK;gBAClB,MAAM;gBACN,gBAAgB,EAAE,aAAa;aAChC,CAAC,CAAC;QACL,CAAC;QAED,KAAK,CAAC,MAAM,CAAC;YACX,IAAI,EAAE,kBAAkB;YACxB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,MAAM;YACN,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,aAAa,EAAE,eAAe;SAC/B,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
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":"auth.d.ts","sourceRoot":"","sources":["../../src/provider/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAWD,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,GAAG,EACR,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,UAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/provider/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAWD,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,GAAG,EACR,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,UAAU,CAAC,CA4CrB"}
|
package/dist/provider/auth.js
CHANGED
|
@@ -15,14 +15,22 @@ const ENV_VAR_MAP = {
|
|
|
15
15
|
qwen: "DASHSCOPE_API_KEY",
|
|
16
16
|
};
|
|
17
17
|
export async function resolveUpstreamAuth(api, upstream, model) {
|
|
18
|
+
// Helper: extract key from response (could be string or { apiKey, ... })
|
|
19
|
+
function extractKey(raw) {
|
|
20
|
+
if (!raw)
|
|
21
|
+
return undefined;
|
|
22
|
+
if (typeof raw === "string")
|
|
23
|
+
return raw;
|
|
24
|
+
return raw.apiKey ?? raw.key ?? raw.value ?? undefined;
|
|
25
|
+
}
|
|
18
26
|
// 1. Try SDK runtime auth
|
|
19
27
|
if (api.runtime?.modelAuth?.getApiKeyForModel) {
|
|
20
28
|
try {
|
|
21
|
-
const key = await api.runtime.modelAuth.getApiKeyForModel({
|
|
29
|
+
const key = extractKey(await api.runtime.modelAuth.getApiKeyForModel({
|
|
22
30
|
model: { provider: upstream, id: model },
|
|
23
31
|
cfg: api.config,
|
|
24
32
|
workspaceDir: api.workspaceDir,
|
|
25
|
-
});
|
|
33
|
+
}));
|
|
26
34
|
if (key)
|
|
27
35
|
return { apiKey: key };
|
|
28
36
|
}
|
|
@@ -30,7 +38,7 @@ export async function resolveUpstreamAuth(api, upstream, model) {
|
|
|
30
38
|
}
|
|
31
39
|
if (api.runtime?.modelAuth?.resolveApiKeyForProvider) {
|
|
32
40
|
try {
|
|
33
|
-
const key = await api.runtime.modelAuth.resolveApiKeyForProvider(upstream);
|
|
41
|
+
const key = extractKey(await api.runtime.modelAuth.resolveApiKeyForProvider(upstream));
|
|
34
42
|
if (key)
|
|
35
43
|
return { apiKey: key };
|
|
36
44
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/provider/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,oCAAoC;AACpC,MAAM,WAAW,GAA2B;IAC1C,MAAM,EAAE,gBAAgB;IACxB,SAAS,EAAE,mBAAmB;IAC9B,UAAU,EAAE,oBAAoB;IAChC,QAAQ,EAAE,kBAAkB;IAC5B,IAAI,EAAE,mBAAmB;CAC1B,CAAC;AAEF,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,GAAQ,EACR,QAAgB,EAChB,KAAa;IAEb,0BAA0B;IAC1B,IAAI,GAAG,CAAC,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,CAAC;QAC9C,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/provider/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,oCAAoC;AACpC,MAAM,WAAW,GAA2B;IAC1C,MAAM,EAAE,gBAAgB;IACxB,SAAS,EAAE,mBAAmB;IAC9B,UAAU,EAAE,oBAAoB;IAChC,QAAQ,EAAE,kBAAkB;IAC5B,IAAI,EAAE,mBAAmB;CAC1B,CAAC;AAEF,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,GAAQ,EACR,QAAgB,EAChB,KAAa;IAEb,yEAAyE;IACzE,SAAS,UAAU,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B,OAAO,EAAE,MAAM,EAAE,cAAc,CAAC,MAAM,EAAE,CAAC;IAC3C,CAAC;IAED,qCAAqC;IACrC,MAAM,MAAM,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;IACrC,IAAI,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;QAClC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM,CAAE,EAAE,CAAC;IAC1C,CAAC;IAED,MAAM,IAAI,KAAK,CACb,mDAAmD,QAAQ,KAAK;QAChE,8CAA8C,QAAQ,WAAW;QACjE,cAAc,WAAW,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,WAAW,EAAE,GAAG,UAAU,wBAAwB,CACnG,CAAC;AACJ,CAAC"}
|
package/dist/provider/index.d.ts
CHANGED
|
@@ -5,6 +5,14 @@
|
|
|
5
5
|
* - catalog: declare model catalog
|
|
6
6
|
* - resolveDynamicModel: dynamically accept any upstream model ID
|
|
7
7
|
* - createStreamFn: precheck + upstream forwarding
|
|
8
|
+
*
|
|
9
|
+
* @known-limitations
|
|
10
|
+
* - Message format: passes context.messages directly to upstream API.
|
|
11
|
+
* Works for plain text but tool calls, system prompts, cache headers,
|
|
12
|
+
* and reasoning payloads may need format conversion for Anthropic/OpenAI.
|
|
13
|
+
* - Provider contract: not yet validated against real OpenClaw gateway
|
|
14
|
+
* contract (createStreamFn invocation, synthetic stream handling, fallback
|
|
15
|
+
* routing). Works via runtime registration; end-to-end gateway test pending.
|
|
8
16
|
*/
|
|
9
17
|
import type { FirewallState } from "../state.js";
|
|
10
18
|
import type { EventStore } from "../store.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/provider/index.ts"],"names":[],"mappings":"AAAA
|
|
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
|
@@ -5,13 +5,21 @@
|
|
|
5
5
|
* - catalog: declare model catalog
|
|
6
6
|
* - resolveDynamicModel: dynamically accept any upstream model ID
|
|
7
7
|
* - createStreamFn: precheck + upstream forwarding
|
|
8
|
+
*
|
|
9
|
+
* @known-limitations
|
|
10
|
+
* - Message format: passes context.messages directly to upstream API.
|
|
11
|
+
* Works for plain text but tool calls, system prompts, cache headers,
|
|
12
|
+
* and reasoning payloads may need format conversion for Anthropic/OpenAI.
|
|
13
|
+
* - Provider contract: not yet validated against real OpenClaw gateway
|
|
14
|
+
* contract (createStreamFn invocation, synthetic stream handling, fallback
|
|
15
|
+
* routing). Works via runtime registration; end-to-end gateway test pending.
|
|
8
16
|
*/
|
|
9
17
|
import { parseMapickModelRef } from "./route.js";
|
|
10
18
|
import { resolveUpstreamAuth } from "./auth.js";
|
|
11
19
|
import { createBlockedStream } from "./synthetic.js";
|
|
12
20
|
import { streamOpenAi, getOpenAiBaseUrl } from "./upstream/openai.js";
|
|
13
21
|
import { streamAnthropic } from "./upstream/anthropic.js";
|
|
14
|
-
import {
|
|
22
|
+
import { estimateTokens } from "../pricing.js";
|
|
15
23
|
function categorizeError(err) {
|
|
16
24
|
const m = err?.message ?? String(err);
|
|
17
25
|
if (m.includes("timeout") || m.includes("ETIMEDOUT"))
|
|
@@ -72,7 +80,6 @@ export function registerProvider(api, state, store) {
|
|
|
72
80
|
};
|
|
73
81
|
},
|
|
74
82
|
createStreamFn() {
|
|
75
|
-
const self = this;
|
|
76
83
|
return async function* stream(model, context, options) {
|
|
77
84
|
// model may come from ctx, use catalog + resolveDynamicModel provided model
|
|
78
85
|
const modelId = typeof model === "string" ? model : model?.id ?? "";
|
|
@@ -101,13 +108,14 @@ export function registerProvider(api, state, store) {
|
|
|
101
108
|
}
|
|
102
109
|
// Resolve upstream auth
|
|
103
110
|
const auth = await resolveUpstreamAuth(api, route.upstream, route.model);
|
|
111
|
+
const timeout = state.config.upstreamTimeoutMs ?? 30_000;
|
|
104
112
|
let inputTokens = 0;
|
|
105
113
|
let outputTokens = 0;
|
|
106
114
|
let responseStreamBytes = 0;
|
|
107
115
|
try {
|
|
108
116
|
const s = route.upstream === "anthropic"
|
|
109
|
-
? streamAnthropic({ apiKey: auth.apiKey, model: route.model, messages: context?.messages ?? [], ...options })
|
|
110
|
-
: 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);
|
|
111
119
|
for await (const chunk of s) {
|
|
112
120
|
responseStreamBytes += JSON.stringify(chunk).length;
|
|
113
121
|
if (chunk.usage) {
|
|
@@ -116,14 +124,11 @@ export function registerProvider(api, state, store) {
|
|
|
116
124
|
}
|
|
117
125
|
yield chunk;
|
|
118
126
|
}
|
|
119
|
-
const cost =
|
|
120
|
-
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);
|
|
121
128
|
state.updateSourceStats(src, cost);
|
|
122
129
|
state.breaker.recordSuccess(src);
|
|
123
130
|
}
|
|
124
131
|
catch (err) {
|
|
125
|
-
const msg = err?.message ?? String(err);
|
|
126
|
-
store.append({ type: "model_call_ended", provider: route.upstream, model: route.model, outcome: "error", failureKind: categorizeError(err), reason: msg.slice(0, 200) });
|
|
127
132
|
state.breaker.recordFailure(src);
|
|
128
133
|
throw err;
|
|
129
134
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/provider/index.ts"],"names":[],"mappings":"AAAA
|
|
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,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,SAAS,eAAe,CAAC,GAAU;IACjC,MAAM,CAAC,GAAG,GAAG,EAAE,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC;IACtC,IAAI,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC;QAAE,OAAO,SAAS,CAAC;IACvE,IAAI,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,cAAc,CAAC;QAAE,OAAO,YAAY,CAAC;IACzE,IAAI,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,YAAY,CAAC;IACjE,IAAI,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC;QAAE,OAAO,eAAe,CAAC;IACzE,I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AC,EAAE,CAAC;wBAC5B,mBAAmB,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC;wBACpD,IAAI,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,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
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"}
|