@intutic/clawde 2.0.0 → 2.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 +6 -5
- package/dist/budget-checker.d.ts +0 -1
- package/dist/budget-checker.d.ts.map +1 -1
- package/dist/budget-checker.js +0 -8
- package/dist/budget-checker.js.map +1 -1
- package/dist/circuit-breaker.d.ts.map +1 -1
- package/dist/circuit-breaker.js +20 -30
- package/dist/circuit-breaker.js.map +1 -1
- package/dist/client.d.ts +11 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +70 -69
- package/dist/client.js.map +1 -1
- package/dist/errors.d.ts +14 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +19 -1
- package/dist/errors.js.map +1 -1
- package/dist/event-emitter.d.ts +2 -2
- package/dist/event-emitter.d.ts.map +1 -1
- package/dist/event-emitter.js.map +1 -1
- package/dist/refusals.d.ts +36 -0
- package/dist/refusals.d.ts.map +1 -0
- package/dist/refusals.js +69 -0
- package/dist/refusals.js.map +1 -0
- package/dist/types.d.ts +41 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,11 +10,12 @@ npm install @intutic/clawde
|
|
|
10
10
|
|
|
11
11
|
## Features
|
|
12
12
|
|
|
13
|
-
- **
|
|
14
|
-
- **
|
|
15
|
-
- **
|
|
16
|
-
- **
|
|
17
|
-
- **
|
|
13
|
+
- **Governed chat:** `chat()` sends a request through the proxy and resolves with `verdict: 'allow'`. A governance refusal (policy block, reask, loop run held for review, spend cap, DLP block) throws `ClawdeBlockedError` with the proxy's `verdict`, `code` and reason, and is never retried; transport failures and 5xx answers are retried.
|
|
14
|
+
- **Verdict Events:** `client.on('kill' | 'reask' | 'hold', ...)` fires on a refusal, before `chat()` throws. See the [SDK reference](https://docs.intutic.ai/reference/clawde-sdk#_5-verdicts-and-errors) for every refusal code.
|
|
15
|
+
- **Anthropic requests:** `provider: 'anthropic'` translates OpenAI-style parameters to an Anthropic Messages body, sends it to the proxy's `/v1/messages` route, and translates the reply back.
|
|
16
|
+
- **Budget Check:** `checkBudget()` reports whether the workspace has budget left, from the control plane's `GET /api/v1/budget`.
|
|
17
|
+
- **Circuit Breaker:** `client.circuitBreaker(toolName, options)(fn)` runs `fn`, after a workspace budget check when `requireBudget` is set, failing closed unless `failOpen` is set.
|
|
18
|
+
- **Context Resolution:** `resolveContext()` reads the sync daemon's `~/.intutic/config.json` (git branch, Jira ticket, PagerDuty incident, CI pipeline, workspace, session), falling back to environment variables.
|
|
18
19
|
- **Control-Plane Management (`ControlPlaneClient`):** Org signup, team/workspace creation, gateway registration and assignment, and provider-credential provisioning — the CLI's management surface, callable programmatically. See the [SDK reference](https://docs.intutic.ai/reference/clawde-sdk#control-plane-management-controlplaneclient).
|
|
19
20
|
|
|
20
21
|
## License
|
package/dist/budget-checker.d.ts
CHANGED
|
@@ -18,6 +18,5 @@ export declare class BudgetChecker {
|
|
|
18
18
|
* for API/cache-behavior compatibility with callers already using them.
|
|
19
19
|
*/
|
|
20
20
|
checkBudget(model: string, estimatedTokens: number): Promise<BudgetCheckResult>;
|
|
21
|
-
updateCachedBudget(model: string, estimatedTokens: number, remainingUsd: number, allowed: boolean): void;
|
|
22
21
|
}
|
|
23
22
|
//# sourceMappingURL=budget-checker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"budget-checker.d.ts","sourceRoot":"","sources":["../src/budget-checker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAc3C,qBAAa,aAAa;IACxB,OAAO,CAAC,KAAK,CAAgC;IAC7C,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,eAAe,CAAQ;IAC/B,OAAO,CAAC,MAAM,CAAQ;gBAEV,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAKnD;;;;;;;;;;;OAWG;IACU,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"budget-checker.d.ts","sourceRoot":"","sources":["../src/budget-checker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAc3C,qBAAa,aAAa;IACxB,OAAO,CAAC,KAAK,CAAgC;IAC7C,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,eAAe,CAAQ;IAC/B,OAAO,CAAC,MAAM,CAAQ;gBAEV,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAKnD;;;;;;;;;;;OAWG;IACU,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAoC7F"}
|
package/dist/budget-checker.js
CHANGED
|
@@ -56,14 +56,6 @@ class BudgetChecker {
|
|
|
56
56
|
throw new errors_1.ClawdeConnectionError(`Could not reach control-plane budget endpoint: ${err.message}`);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
// Helper to manually update/pre-populate budget cache from response headers
|
|
60
|
-
updateCachedBudget(model, estimatedTokens, remainingUsd, allowed) {
|
|
61
|
-
const cacheKey = `${model}:${estimatedTokens}`;
|
|
62
|
-
this.cache.set(cacheKey, {
|
|
63
|
-
result: { allowed, remaining_usd: remainingUsd },
|
|
64
|
-
timestamp: Date.now(),
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
59
|
}
|
|
68
60
|
exports.BudgetChecker = BudgetChecker;
|
|
69
61
|
//# sourceMappingURL=budget-checker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"budget-checker.js","sourceRoot":"","sources":["../src/budget-checker.ts"],"names":[],"mappings":";;;AACA,qCAAgD;AAahD,MAAa,aAAa;IAChB,KAAK,GAAG,IAAI,GAAG,EAAsB,CAAA;IACrC,QAAQ,GAAG,KAAK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1
|
+
{"version":3,"file":"circuit-breaker.d.ts","sourceRoot":"","sources":["../src/circuit-breaker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAG/C,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAK;gBAEP,MAAM,EAAE,GAAG;IAIhB,IAAI,CAAC,CAAC,EACX,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,qBAA0B,GAClC,CAAC,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC;CAwCxC"}
|
package/dist/circuit-breaker.js
CHANGED
|
@@ -10,43 +10,33 @@ class CircuitBreaker {
|
|
|
10
10
|
wrap(toolName, options = {}) {
|
|
11
11
|
const failOpen = options.failOpen ?? false;
|
|
12
12
|
return async (fn) => {
|
|
13
|
-
// 1. Pre-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
throw new errors_1.ClawdeVerdictError('kill', `Circuit breaker tripped for tool '${toolName}': budget exceeded. Remaining: $${budget.remaining_usd}`);
|
|
22
|
-
}
|
|
13
|
+
// 1. Pre-check: workspace budget, when asked for. `failOpen` covers a
|
|
14
|
+
// check that could not be made; a check that answered "no budget" is a
|
|
15
|
+
// verdict and refuses either way, or the breaker would let every call
|
|
16
|
+
// through exactly when the budget is gone.
|
|
17
|
+
if (options.requireBudget || options.maxCostUsd !== undefined) {
|
|
18
|
+
let budget = null;
|
|
19
|
+
try {
|
|
20
|
+
budget = await this.client.checkBudget('default', 1);
|
|
23
21
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
catch (err) {
|
|
23
|
+
if (!failOpen) {
|
|
24
|
+
throw err;
|
|
25
|
+
}
|
|
26
|
+
if (process.env.INTUTIC_DEBUG === 'true') {
|
|
27
|
+
console.warn(`[Clawde SDK] Circuit breaker pre-check failed (failing open): ${err.message}`);
|
|
28
|
+
}
|
|
28
29
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
console.warn(`[Clawde SDK] Circuit breaker pre-check failed (failing open): ${err.message}`);
|
|
30
|
+
if (budget && !budget.allowed) {
|
|
31
|
+
throw new errors_1.ClawdeVerdictError('kill', `Circuit breaker tripped for tool '${toolName}': budget exceeded. Remaining: $${budget.remaining_usd}`);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
// 2.
|
|
34
|
+
// 2. Run the function. A refusal from chat() arrives as a thrown
|
|
35
|
+
// ClawdeBlockedError, so fail-closed needs nothing beyond rethrowing.
|
|
35
36
|
try {
|
|
36
|
-
|
|
37
|
-
// 3. Post-Check: If the result is a ChatResponse (or has verdict headers), inspect it
|
|
38
|
-
if (result && typeof result === 'object') {
|
|
39
|
-
const res = result;
|
|
40
|
-
if (res.verdict === 'kill') {
|
|
41
|
-
throw new errors_1.ClawdeVerdictError('kill', `Execution blocked by governance policy (Verdict: KILL)`);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return result;
|
|
37
|
+
return await fn();
|
|
45
38
|
}
|
|
46
39
|
catch (err) {
|
|
47
|
-
if (err instanceof errors_1.ClawdeVerdictError && !failOpen) {
|
|
48
|
-
throw err;
|
|
49
|
-
}
|
|
50
40
|
if (!failOpen) {
|
|
51
41
|
throw err;
|
|
52
42
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"circuit-breaker.js","sourceRoot":"","sources":["../src/circuit-breaker.ts"],"names":[],"mappings":";;;AACA,qCAA6C;AAE7C,MAAa,cAAc;IACjB,MAAM,CAAK;IAEnB,YAAY,MAAW;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAEM,IAAI,CACT,QAAgB,EAChB,UAAiC,EAAE;QAEnC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,KAAK,CAAA;QAE1C,OAAO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EAAE,EAAE,CAAA;YACnB,CAAC;YAAC,OAAO,GAAQ,EAAE,CAAC;gBAClB,IAAI,CAAC,QAAQ,EAAE,CAAC;oBACd,MAAM,GAAG,CAAA;gBACX,CAAC;gBACD,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,KAAK,MAAM,EAAE,CAAC;oBACzC,OAAO,CAAC,IAAI,CAAC,iEAAiE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAA;gBAC9F,CAAC;gBACD,OAAO,IAAW,CAAA,CAAC,kCAAkC;YACvD,CAAC;QACH,CAAC,CAAA;IACH,CAAC;CACF;AAlDD,wCAkDC"}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ClawdeClientOptions, ChatParams, ChatResponse, ResolvedContext, BudgetCheckResult, EventCallback, CircuitBreakerOptions } from './types';
|
|
1
|
+
import { ClawdeClientOptions, ChatParams, ChatResponse, ResolvedContext, BudgetCheckResult, EventCallback, CircuitBreakerOptions, VerdictEvent } from './types';
|
|
2
2
|
export declare class ClawdeClient {
|
|
3
3
|
private apiKey;
|
|
4
4
|
private baseUrl;
|
|
@@ -13,11 +13,20 @@ export declare class ClawdeClient {
|
|
|
13
13
|
private circuitBreakerWrapper;
|
|
14
14
|
private eventEmitter;
|
|
15
15
|
constructor(options: ClawdeClientOptions);
|
|
16
|
-
on(event:
|
|
16
|
+
on(event: VerdictEvent, callback: EventCallback): void;
|
|
17
17
|
off(event: string, callback: EventCallback): void;
|
|
18
18
|
checkBudget(model: string, estimatedTokens: number): Promise<BudgetCheckResult>;
|
|
19
19
|
resolveContext(): Promise<ResolvedContext>;
|
|
20
20
|
circuitBreaker<T>(toolName: string, options?: CircuitBreakerOptions): (fn: () => Promise<T>) => Promise<T>;
|
|
21
|
+
/**
|
|
22
|
+
* Send a chat request through the proxy.
|
|
23
|
+
*
|
|
24
|
+
* Resolves with `verdict: 'allow'` when the proxy let the request through. A
|
|
25
|
+
* governance refusal, including one the proxy answers with a 200 and names in
|
|
26
|
+
* `x-intutic-refusal`, fires the matching event and rejects with
|
|
27
|
+
* `ClawdeBlockedError`, unretried. Transport failures, timeouts and 5xx
|
|
28
|
+
* answers are retried; anything else rejects with `ClawdeConnectionError`.
|
|
29
|
+
*/
|
|
21
30
|
chat(params: ChatParams): Promise<ChatResponse>;
|
|
22
31
|
}
|
|
23
32
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,qBAAqB,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,qBAAqB,EACrB,YAAY,EACb,MAAM,SAAS,CAAA;AAUhB,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,eAAe,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAC,CAAmC;IACpD,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,OAAO,CAAQ;IAEvB,wEAAwE;IACxE,OAAO,CAAC,QAAQ,CAAe;IAE/B,OAAO,CAAC,aAAa,CAAe;IACpC,OAAO,CAAC,qBAAqB,CAAgB;IAC7C,OAAO,CAAC,YAAY,CAAoB;gBAE5B,OAAO,EAAE,mBAAmB;IAuBjC,EAAE,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI;IAItD,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI;IAK3C,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAK/E,cAAc,IAAI,OAAO,CAAC,eAAe,CAAC;IAQhD,cAAc,CAAC,CAAC,EACrB,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,qBAA0B,GAClC,CAAC,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC;IAIvC;;;;;;;;OAQG;IACU,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;CA8E7D"}
|
package/dist/client.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ClawdeClient = void 0;
|
|
4
4
|
const errors_1 = require("./errors");
|
|
5
|
+
const refusals_1 = require("./refusals");
|
|
5
6
|
const schema_enforcer_1 = require("./schema-enforcer");
|
|
6
7
|
const context_resolver_1 = require("./context-resolver");
|
|
7
8
|
const budget_checker_1 = require("./budget-checker");
|
|
@@ -62,89 +63,89 @@ class ClawdeClient {
|
|
|
62
63
|
circuitBreaker(toolName, options = {}) {
|
|
63
64
|
return this.circuitBreakerWrapper.wrap(toolName, options);
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Send a chat request through the proxy.
|
|
68
|
+
*
|
|
69
|
+
* Resolves with `verdict: 'allow'` when the proxy let the request through. A
|
|
70
|
+
* governance refusal, including one the proxy answers with a 200 and names in
|
|
71
|
+
* `x-intutic-refusal`, fires the matching event and rejects with
|
|
72
|
+
* `ClawdeBlockedError`, unretried. Transport failures, timeouts and 5xx
|
|
73
|
+
* answers are retried; anything else rejects with `ClawdeConnectionError`.
|
|
74
|
+
*/
|
|
66
75
|
async chat(params) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
//
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
76
|
+
const anthropic = this.provider === 'anthropic';
|
|
77
|
+
// The proxy picks the wire format by route: an Anthropic Messages body
|
|
78
|
+
// sent to /v1/chat/completions is parsed as an OpenAI one.
|
|
79
|
+
const url = `${this.baseUrl}${anthropic ? '/v1/messages' : '/v1/chat/completions'}`;
|
|
80
|
+
const headers = {
|
|
81
|
+
'Content-Type': 'application/json',
|
|
82
|
+
...(anthropic
|
|
83
|
+
? { 'x-api-key': this.apiKey, 'anthropic-version': '2023-06-01' }
|
|
84
|
+
: { 'Authorization': `Bearer ${this.apiKey}` }),
|
|
85
|
+
// Without these the proxy sees graph_id == session_id, treats every
|
|
86
|
+
// request as a graph of one, and skips membership, fleet spend and
|
|
87
|
+
// node counting entirely.
|
|
88
|
+
...(0, graph_identity_1.identityHeaders)(this.identity),
|
|
89
|
+
};
|
|
90
|
+
const body = JSON.stringify((0, schema_enforcer_1.normalizeRequest)(params, this.provider));
|
|
91
|
+
let lastError = '';
|
|
73
92
|
const maxAttempts = this.retries + 1;
|
|
74
93
|
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
94
|
+
if (attempt > 1) {
|
|
95
|
+
if (process.env.INTUTIC_DEBUG === 'true') {
|
|
96
|
+
console.warn(`[Clawde SDK] Attempt ${attempt - 1} failed, retrying... Error: ${lastError}`);
|
|
97
|
+
}
|
|
98
|
+
await new Promise((resolve) => setTimeout(resolve, (attempt - 1) * 100));
|
|
99
|
+
}
|
|
75
100
|
const controller = new AbortController();
|
|
76
101
|
const timer = setTimeout(() => controller.abort(), this.timeout);
|
|
102
|
+
let status;
|
|
103
|
+
let text;
|
|
104
|
+
let refusedBy;
|
|
77
105
|
try {
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
headers['X-Intutic-Cost-Limit'] = String(params.max_cost_usd);
|
|
89
|
-
}
|
|
90
|
-
if (params.sensitivity_tier !== undefined) {
|
|
91
|
-
headers['X-Intutic-Sensitivity'] = String(params.sensitivity_tier);
|
|
92
|
-
}
|
|
93
|
-
const response = await fetch(`${this.baseUrl}/v1/chat/completions`, {
|
|
94
|
-
method: 'POST',
|
|
95
|
-
headers,
|
|
96
|
-
body: JSON.stringify(requestPayload),
|
|
97
|
-
signal: controller.signal,
|
|
98
|
-
});
|
|
106
|
+
const response = await fetch(url, { method: 'POST', headers, body, signal: controller.signal });
|
|
107
|
+
status = response.status;
|
|
108
|
+
refusedBy = response.headers.get(refusals_1.REFUSAL_HEADER);
|
|
109
|
+
text = await response.text();
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
lastError = err instanceof Error ? err.message : String(err);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
99
116
|
clearTimeout(timer);
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
// 4. Extract Intutic response headers
|
|
106
|
-
const verdictHeader = response.headers.get('x-intutic-verdict') || 'allow';
|
|
107
|
-
const budgetRemainingHeader = response.headers.get('x-intutic-budget-remaining');
|
|
108
|
-
const budgetPctHeader = response.headers.get('x-intutic-budget-pct');
|
|
109
|
-
normalized.verdict = verdictHeader;
|
|
110
|
-
if (budgetRemainingHeader) {
|
|
111
|
-
normalized.budgetRemainingUsd = parseFloat(budgetRemainingHeader);
|
|
112
|
-
}
|
|
113
|
-
if (budgetPctHeader) {
|
|
114
|
-
normalized.budgetPctUsed = parseFloat(budgetPctHeader);
|
|
115
|
-
}
|
|
116
|
-
// 5. Update local budget cache
|
|
117
|
-
if (normalized.budgetRemainingUsd !== undefined) {
|
|
118
|
-
this.budgetChecker.updateCachedBudget(params.model, params.messages.length, // approximation
|
|
119
|
-
normalized.budgetRemainingUsd, verdictHeader !== 'kill');
|
|
117
|
+
}
|
|
118
|
+
if (status >= 200 && status < 300) {
|
|
119
|
+
let json;
|
|
120
|
+
try {
|
|
121
|
+
json = JSON.parse(text);
|
|
120
122
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
this.eventEmitter.emit(normalized.verdict, normalized);
|
|
123
|
+
catch {
|
|
124
|
+
throw new errors_1.ClawdeConnectionError(`Proxy answered ${status} with a body that is not JSON: ${text}`);
|
|
124
125
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
const normalized = (0, schema_enforcer_1.normalizeResponse)(json, this.provider);
|
|
127
|
+
// A refusal answered as an assistant turn (the cost-prediction gate).
|
|
128
|
+
const content = normalized.choices?.[0]?.message?.content;
|
|
129
|
+
const answered = (0, refusals_1.headerRefusal)(refusedBy, typeof content === 'string' ? content : '');
|
|
130
|
+
if (answered) {
|
|
131
|
+
this.eventEmitter.emit(answered.verdict, { ...answered, status });
|
|
132
|
+
throw new errors_1.ClawdeBlockedError(answered.verdict, answered.code, status, answered.message);
|
|
128
133
|
}
|
|
134
|
+
normalized.verdict = 'allow';
|
|
129
135
|
return normalized;
|
|
130
136
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
throw err; // Do not retry on explicit policy blocks
|
|
136
|
-
}
|
|
137
|
-
if (attempt < maxAttempts) {
|
|
138
|
-
if (process.env.INTUTIC_DEBUG === 'true') {
|
|
139
|
-
console.warn(`[Clawde SDK] Attempt ${attempt} failed, retrying... Error: ${err.message}`);
|
|
140
|
-
}
|
|
141
|
-
// backoff delay
|
|
142
|
-
await new Promise((resolve) => setTimeout(resolve, attempt * 100));
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
137
|
+
const refusal = (0, refusals_1.parseRefusal)(status, text);
|
|
138
|
+
if (refusal) {
|
|
139
|
+
this.eventEmitter.emit(refusal.verdict, { ...refusal, status });
|
|
140
|
+
throw new errors_1.ClawdeBlockedError(refusal.verdict, refusal.code, status, refusal.message);
|
|
145
141
|
}
|
|
142
|
+
lastError = `HTTP error ${status}: ${text}`;
|
|
143
|
+
// A 4xx that is not a refusal (bad key, malformed body) fails the same
|
|
144
|
+
// way every time; only a 5xx is worth another attempt.
|
|
145
|
+
if (status < 500)
|
|
146
|
+
throw new errors_1.ClawdeConnectionError(lastError);
|
|
146
147
|
}
|
|
147
|
-
throw new errors_1.ClawdeConnectionError(`Request failed after ${maxAttempts} attempts. Last error: ${lastError
|
|
148
|
+
throw new errors_1.ClawdeConnectionError(`Request failed after ${maxAttempts} attempts. Last error: ${lastError}`);
|
|
148
149
|
}
|
|
149
150
|
}
|
|
150
151
|
exports.ClawdeClient = ClawdeClient;
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAUA,qCAAoE;AACpE,yCAAwE;AACxE,uDAAuE;AACvE,yDAAmD;AACnD,qDAAgD;AAChD,uDAAkD;AAClD,mDAAoD;AACpD,qDAAsF;AAEtF,MAAa,YAAY;IACf,MAAM,CAAQ;IACd,OAAO,CAAQ;IACf,eAAe,CAAQ;IACvB,QAAQ,CAAoC;IAC5C,WAAW,CAAS;IACpB,OAAO,CAAQ;IACf,OAAO,CAAQ;IAEvB,wEAAwE;IAChE,QAAQ,CAAe;IAEvB,aAAa,CAAe;IAC5B,qBAAqB,CAAgB;IACrC,YAAY,CAAoB;IAExC,YAAY,OAA4B;QACtC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAA;QACpE,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,uBAAuB,CAAA;QACz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O,CAAC,OAAO,CAAC,CAAA;YACtF,CAAC;YAED,SAAS,GAAG,cAAc,MAAM,KAAK,IAAI,EAAE,CAAA;YAC3C,uEAAuE;YACvE,uDAAuD;YACvD,IAAI,MAAM,GAAG,GAAG;gBAAE,MAAM,IAAI,8BAAqB,CAAC,SAAS,CAAC,CAAA;QAC9D,CAAC;QAED,MAAM,IAAI,8BAAqB,CAAC,wBAAwB,WAAW,0BAA0B,SAAS,EAAE,CAAC,CAAA;IAC3G,CAAC;CACF;AA3JD,oCA2JC"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,14 +1,28 @@
|
|
|
1
|
+
import type { RefusalVerdict } from './types';
|
|
1
2
|
export declare class ClawdeError extends Error {
|
|
2
3
|
constructor(message: string);
|
|
3
4
|
}
|
|
5
|
+
/** The proxy is unreachable, timed out, or answered with an error that is not a governance refusal. */
|
|
4
6
|
export declare class ClawdeConnectionError extends ClawdeError {
|
|
5
7
|
constructor(message: string);
|
|
6
8
|
}
|
|
7
9
|
export declare class ClawdeBudgetExceededError extends ClawdeError {
|
|
8
10
|
constructor(message: string);
|
|
9
11
|
}
|
|
12
|
+
/** A governance verdict stopped the call: a proxy refusal (`ClawdeBlockedError`) or the circuit breaker's budget check. */
|
|
10
13
|
export declare class ClawdeVerdictError extends ClawdeError {
|
|
11
14
|
verdict: string;
|
|
12
15
|
constructor(verdict: string, message: string);
|
|
13
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* The proxy refused the request: a policy block, a reask, a loop run held for
|
|
19
|
+
* review, a spend cap or a DLP block. Never retried — the same request would be
|
|
20
|
+
* refused again. `code` is the proxy's error code and `message` its reason.
|
|
21
|
+
*/
|
|
22
|
+
export declare class ClawdeBlockedError extends ClawdeVerdictError {
|
|
23
|
+
verdict: RefusalVerdict;
|
|
24
|
+
readonly code: string;
|
|
25
|
+
readonly status: number;
|
|
26
|
+
constructor(verdict: RefusalVerdict, code: string, status: number, message: string);
|
|
27
|
+
}
|
|
14
28
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,WAAY,SAAQ,KAAK;gBACxB,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,qBAAsB,SAAQ,WAAW;gBACxC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,yBAA0B,SAAQ,WAAW;gBAC5C,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,kBAAmB,SAAQ,WAAW;IAC1C,OAAO,EAAE,MAAM,CAAA;gBAEV,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAK7C"}
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,qBAAa,WAAY,SAAQ,KAAK;gBACxB,OAAO,EAAE,MAAM;CAI5B;AAED,uGAAuG;AACvG,qBAAa,qBAAsB,SAAQ,WAAW;gBACxC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,yBAA0B,SAAQ,WAAW;gBAC5C,OAAO,EAAE,MAAM;CAI5B;AAED,2HAA2H;AAC3H,qBAAa,kBAAmB,SAAQ,WAAW;IAC1C,OAAO,EAAE,MAAM,CAAA;gBAEV,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAK7C;AAED;;;;GAIG;AACH,qBAAa,kBAAmB,SAAQ,kBAAkB;IACzC,OAAO,EAAE,cAAc,CAAA;IACtC,SAAgB,IAAI,EAAE,MAAM,CAAA;IAC5B,SAAgB,MAAM,EAAE,MAAM,CAAA;gBAElB,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAMnF"}
|
package/dist/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ClawdeVerdictError = exports.ClawdeBudgetExceededError = exports.ClawdeConnectionError = exports.ClawdeError = void 0;
|
|
3
|
+
exports.ClawdeBlockedError = exports.ClawdeVerdictError = exports.ClawdeBudgetExceededError = exports.ClawdeConnectionError = exports.ClawdeError = void 0;
|
|
4
4
|
class ClawdeError extends Error {
|
|
5
5
|
constructor(message) {
|
|
6
6
|
super(message);
|
|
@@ -8,6 +8,7 @@ class ClawdeError extends Error {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
exports.ClawdeError = ClawdeError;
|
|
11
|
+
/** The proxy is unreachable, timed out, or answered with an error that is not a governance refusal. */
|
|
11
12
|
class ClawdeConnectionError extends ClawdeError {
|
|
12
13
|
constructor(message) {
|
|
13
14
|
super(message);
|
|
@@ -22,6 +23,7 @@ class ClawdeBudgetExceededError extends ClawdeError {
|
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
exports.ClawdeBudgetExceededError = ClawdeBudgetExceededError;
|
|
26
|
+
/** A governance verdict stopped the call: a proxy refusal (`ClawdeBlockedError`) or the circuit breaker's budget check. */
|
|
25
27
|
class ClawdeVerdictError extends ClawdeError {
|
|
26
28
|
verdict;
|
|
27
29
|
constructor(verdict, message) {
|
|
@@ -31,4 +33,20 @@ class ClawdeVerdictError extends ClawdeError {
|
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
exports.ClawdeVerdictError = ClawdeVerdictError;
|
|
36
|
+
/**
|
|
37
|
+
* The proxy refused the request: a policy block, a reask, a loop run held for
|
|
38
|
+
* review, a spend cap or a DLP block. Never retried — the same request would be
|
|
39
|
+
* refused again. `code` is the proxy's error code and `message` its reason.
|
|
40
|
+
*/
|
|
41
|
+
class ClawdeBlockedError extends ClawdeVerdictError {
|
|
42
|
+
code;
|
|
43
|
+
status;
|
|
44
|
+
constructor(verdict, code, status, message) {
|
|
45
|
+
super(verdict, message);
|
|
46
|
+
this.name = 'ClawdeBlockedError';
|
|
47
|
+
this.code = code;
|
|
48
|
+
this.status = status;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.ClawdeBlockedError = ClawdeBlockedError;
|
|
34
52
|
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAEA,MAAa,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,aAAa,CAAA;IAC3B,CAAC;CACF;AALD,kCAKC;AAED,uGAAuG;AACvG,MAAa,qBAAsB,SAAQ,WAAW;IACpD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAA;IACrC,CAAC;CACF;AALD,sDAKC;AAED,MAAa,yBAA0B,SAAQ,WAAW;IACxD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAA;IACzC,CAAC;CACF;AALD,8DAKC;AAED,2HAA2H;AAC3H,MAAa,kBAAmB,SAAQ,WAAW;IAC1C,OAAO,CAAQ;IAEtB,YAAY,OAAe,EAAE,OAAe;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAA;QAChC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;CACF;AARD,gDAQC;AAED;;;;GAIG;AACH,MAAa,kBAAmB,SAAQ,kBAAkB;IAExC,IAAI,CAAQ;IACZ,MAAM,CAAQ;IAE9B,YAAY,OAAuB,EAAE,IAAY,EAAE,MAAc,EAAE,OAAe;QAChF,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACvB,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAA;QAChC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;CACF;AAXD,gDAWC"}
|
package/dist/event-emitter.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { EventCallback } from './types';
|
|
1
|
+
import { EventCallback, VerdictEvent } from './types';
|
|
2
2
|
export declare class ClawdeEventEmitter {
|
|
3
3
|
private emitter;
|
|
4
|
-
on(event:
|
|
4
|
+
on(event: VerdictEvent, callback: EventCallback): void;
|
|
5
5
|
off(event: string, callback: EventCallback): void;
|
|
6
6
|
emit(event: string, data: any): void;
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-emitter.d.ts","sourceRoot":"","sources":["../src/event-emitter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"event-emitter.d.ts","sourceRoot":"","sources":["../src/event-emitter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAErD,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,OAAO,CAAqB;IAE7B,EAAE,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI;IAItD,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI;IAIjD,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,IAAI;CAG5C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-emitter.js","sourceRoot":"","sources":["../src/event-emitter.ts"],"names":[],"mappings":";;;AAAA,mCAAqC;AAGrC,MAAa,kBAAkB;IACrB,OAAO,GAAG,IAAI,qBAAY,EAAE,CAAA;IAE7B,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"event-emitter.js","sourceRoot":"","sources":["../src/event-emitter.ts"],"names":[],"mappings":";;;AAAA,mCAAqC;AAGrC,MAAa,kBAAkB;IACrB,OAAO,GAAG,IAAI,qBAAY,EAAE,CAAA;IAE7B,EAAE,CAAC,KAAmB,EAAE,QAAuB;QACpD,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;IAClC,CAAC;IAEM,GAAG,CAAC,KAAa,EAAE,QAAuB;QAC/C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;IACnC,CAAC;IAEM,IAAI,CAAC,KAAa,EAAE,IAAS;QAClC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;IAChC,CAAC;CACF;AAdD,gDAcC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { RefusalVerdict } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* The proxy's governance refusals: the `error.type` of its JSON error body
|
|
4
|
+
* (`{"error": {"type", "message"}}`, `json_error` in packages/proxy/src/proxy.rs),
|
|
5
|
+
* the status it always pairs that type with, and the verdict it represents.
|
|
6
|
+
*
|
|
7
|
+
* Matching on the pair rather than the status alone matters because the same
|
|
8
|
+
* statuses also carry errors that are not decisions: a provider's own 429 rate
|
|
9
|
+
* limit, a 403 for a key used against the wrong workspace, a 400 for a malformed
|
|
10
|
+
* body. Those are not refusals and must not be reported as one.
|
|
11
|
+
*
|
|
12
|
+
* `__tests__/refusals.test.ts` checks this table against proxy.rs, so a refusal
|
|
13
|
+
* the proxy adds or renames fails the build instead of silently turning back
|
|
14
|
+
* into a retried connection error.
|
|
15
|
+
*/
|
|
16
|
+
export declare const PROXY_REFUSALS: Readonly<Record<string, {
|
|
17
|
+
status: number;
|
|
18
|
+
verdict: RefusalVerdict;
|
|
19
|
+
}>>;
|
|
20
|
+
export interface ProxyRefusal {
|
|
21
|
+
verdict: RefusalVerdict;
|
|
22
|
+
code: string;
|
|
23
|
+
message: string;
|
|
24
|
+
}
|
|
25
|
+
/** The refusal an error response carries, or `null` when it is any other kind of failure. */
|
|
26
|
+
export declare function parseRefusal(status: number, body: string): ProxyRefusal | null;
|
|
27
|
+
/**
|
|
28
|
+
* The header the proxy sets on a 200 that is a refusal in the shape of an
|
|
29
|
+
* answer: the cost-prediction gate replies to a non-streaming request with an
|
|
30
|
+
* assistant turn explaining the estimate, so a chat client shows the reason.
|
|
31
|
+
* Its value is the refusal's code.
|
|
32
|
+
*/
|
|
33
|
+
export declare const REFUSAL_HEADER = "x-intutic-refusal";
|
|
34
|
+
/** The refusal a 2xx response names in `REFUSAL_HEADER`, or `null` for a real answer. */
|
|
35
|
+
export declare function headerRefusal(code: string | null, message: string): ProxyRefusal | null;
|
|
36
|
+
//# sourceMappingURL=refusals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refusals.d.ts","sourceRoot":"","sources":["../src/refusals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,cAAc,CAAA;CAAE,CAAC,CAUhG,CAAA;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,cAAc,CAAA;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,6FAA6F;AAC7F,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CAe9E;AAED;;;;;GAKG;AACH,eAAO,MAAM,cAAc,sBAAsB,CAAA;AAEjD,yFAAyF;AACzF,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CAQvF"}
|
package/dist/refusals.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REFUSAL_HEADER = exports.PROXY_REFUSALS = void 0;
|
|
4
|
+
exports.parseRefusal = parseRefusal;
|
|
5
|
+
exports.headerRefusal = headerRefusal;
|
|
6
|
+
/**
|
|
7
|
+
* The proxy's governance refusals: the `error.type` of its JSON error body
|
|
8
|
+
* (`{"error": {"type", "message"}}`, `json_error` in packages/proxy/src/proxy.rs),
|
|
9
|
+
* the status it always pairs that type with, and the verdict it represents.
|
|
10
|
+
*
|
|
11
|
+
* Matching on the pair rather than the status alone matters because the same
|
|
12
|
+
* statuses also carry errors that are not decisions: a provider's own 429 rate
|
|
13
|
+
* limit, a 403 for a key used against the wrong workspace, a 400 for a malformed
|
|
14
|
+
* body. Those are not refusals and must not be reported as one.
|
|
15
|
+
*
|
|
16
|
+
* `__tests__/refusals.test.ts` checks this table against proxy.rs, so a refusal
|
|
17
|
+
* the proxy adds or renames fails the build instead of silently turning back
|
|
18
|
+
* into a retried connection error.
|
|
19
|
+
*/
|
|
20
|
+
exports.PROXY_REFUSALS = {
|
|
21
|
+
policy_denied: { status: 403, verdict: 'kill' },
|
|
22
|
+
model_not_allowed: { status: 403, verdict: 'kill' },
|
|
23
|
+
LOOP_RUN_TERMINATED: { status: 403, verdict: 'kill' },
|
|
24
|
+
LOOP_RUN_PENDING_REVIEW: { status: 403, verdict: 'hold' },
|
|
25
|
+
policy_reask: { status: 409, verdict: 'reask' },
|
|
26
|
+
BUDGET_EXCEEDED: { status: 429, verdict: 'kill' },
|
|
27
|
+
OVERAGE_HARD_CAP_EXCEEDED: { status: 429, verdict: 'kill' },
|
|
28
|
+
COST_GATE_EXCEEDED: { status: 402, verdict: 'kill' },
|
|
29
|
+
dlp_policy_violation: { status: 400, verdict: 'kill' },
|
|
30
|
+
};
|
|
31
|
+
/** The refusal an error response carries, or `null` when it is any other kind of failure. */
|
|
32
|
+
function parseRefusal(status, body) {
|
|
33
|
+
let error;
|
|
34
|
+
try {
|
|
35
|
+
error = JSON.parse(body)?.error;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
if (!error || typeof error.type !== 'string')
|
|
41
|
+
return null;
|
|
42
|
+
const known = exports.PROXY_REFUSALS[error.type];
|
|
43
|
+
if (!known || known.status !== status)
|
|
44
|
+
return null;
|
|
45
|
+
return {
|
|
46
|
+
verdict: known.verdict,
|
|
47
|
+
code: error.type,
|
|
48
|
+
message: typeof error.message === 'string' ? error.message : error.type,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The header the proxy sets on a 200 that is a refusal in the shape of an
|
|
53
|
+
* answer: the cost-prediction gate replies to a non-streaming request with an
|
|
54
|
+
* assistant turn explaining the estimate, so a chat client shows the reason.
|
|
55
|
+
* Its value is the refusal's code.
|
|
56
|
+
*/
|
|
57
|
+
exports.REFUSAL_HEADER = 'x-intutic-refusal';
|
|
58
|
+
/** The refusal a 2xx response names in `REFUSAL_HEADER`, or `null` for a real answer. */
|
|
59
|
+
function headerRefusal(code, message) {
|
|
60
|
+
if (!code)
|
|
61
|
+
return null;
|
|
62
|
+
const known = exports.PROXY_REFUSALS[code];
|
|
63
|
+
return {
|
|
64
|
+
verdict: known?.verdict ?? 'kill',
|
|
65
|
+
code,
|
|
66
|
+
message: message || code,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=refusals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file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IAAI,KAAK,CAAC,MAAM,KAAK,MAAM;QAAE,OAAO,IAAI,CAAA;IAClD,OAAO;QACL,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,OAAO,EAAE,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI;KACxE,CAAA;AACH,CAAC;AAED;;;;;GAKG;AACU,QAAA,cAAc,GAAG,mBAAmB,CAAA;AAEjD,yFAAyF;AACzF,SAAgB,aAAa,CAAC,IAAmB,EAAE,OAAe;IAChE,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAA;IACtB,MAAM,KAAK,GAAG,sBAAc,CAAC,IAAI,CAAC,CAAA;IAClC,OAAO;QACL,OAAO,EAAE,KAAK,EAAE,OAAO,IAAI,MAAM;QACjC,IAAI;QACJ,OAAO,EAAE,OAAO,IAAI,IAAI;KACzB,CAAA;AACH,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -52,12 +52,43 @@ export interface ChatResponse {
|
|
|
52
52
|
completion_tokens: number;
|
|
53
53
|
total_tokens: number;
|
|
54
54
|
};
|
|
55
|
-
|
|
55
|
+
/** Always `allow`: a response only comes back when the proxy let the request through. */
|
|
56
|
+
verdict?: Verdict | LegacyVerdict;
|
|
57
|
+
/** @deprecated Never set: the proxy does not report budget on responses. Use `checkBudget()`. */
|
|
56
58
|
budgetRemainingUsd?: number;
|
|
59
|
+
/** @deprecated Never set: the proxy does not report budget on responses. Use `checkBudget()`. */
|
|
57
60
|
budgetPctUsed?: number;
|
|
58
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* A governance refusal the proxy answered with: `kill` blocks the request, `reask`
|
|
64
|
+
* refuses this attempt and tells the agent to revise it (it escalates to `kill`
|
|
65
|
+
* after repeated attempts), and `hold` pauses a loop run until a human reviews it.
|
|
66
|
+
*/
|
|
67
|
+
export type RefusalVerdict = 'kill' | 'reask' | 'hold';
|
|
68
|
+
/** What `chat()` can know about a request: it was let through, or refused. */
|
|
69
|
+
export type Verdict = 'allow' | RefusalVerdict;
|
|
70
|
+
/**
|
|
71
|
+
* @deprecated Never reported. The proxy applies these inside the response and
|
|
72
|
+
* does not tell the client, so no response carries them and no event fires for
|
|
73
|
+
* them. Still accepted so code written against 2.0 compiles; they will be
|
|
74
|
+
* removed in the next major version.
|
|
75
|
+
*/
|
|
76
|
+
export type LegacyVerdict = 'hijack' | 'enhance' | 'bypass';
|
|
77
|
+
/** Events `on()` accepts. */
|
|
78
|
+
export type VerdictEvent = RefusalVerdict | LegacyVerdict;
|
|
59
79
|
export interface CircuitBreakerOptions {
|
|
80
|
+
/**
|
|
81
|
+
* Run `checkBudget()` first and refuse to run the function when the workspace
|
|
82
|
+
* has no budget left. Default: false.
|
|
83
|
+
*/
|
|
84
|
+
requireBudget?: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* @deprecated Use `requireBudget: true`. Any value turns the workspace budget
|
|
87
|
+
* check on; the amount is not compared with anything, because nothing reports
|
|
88
|
+
* a call's cost before it is made.
|
|
89
|
+
*/
|
|
60
90
|
maxCostUsd?: number;
|
|
91
|
+
/** @deprecated Ignored: neither the SDK nor the proxy reads a sensitivity tier. */
|
|
61
92
|
sensitivityTier?: 'low' | 'medium' | 'high' | 'critical';
|
|
62
93
|
failOpen?: boolean;
|
|
63
94
|
}
|
|
@@ -75,11 +106,18 @@ export interface BudgetCheckResult {
|
|
|
75
106
|
remaining_usd: number;
|
|
76
107
|
reason?: string;
|
|
77
108
|
}
|
|
109
|
+
/** Called with the refusal before `chat()` throws it as a `ClawdeBlockedError`. */
|
|
78
110
|
export type EventCallback = (data: {
|
|
79
|
-
|
|
111
|
+
/** One of the `RefusalVerdict` values; typed wider so listeners written against 2.0 compile. */
|
|
112
|
+
verdict: Verdict | LegacyVerdict;
|
|
113
|
+
/** The proxy's error code, e.g. `policy_denied` or `OVERAGE_HARD_CAP_EXCEEDED`. */
|
|
114
|
+
code: string;
|
|
115
|
+
status: number;
|
|
116
|
+
message: string;
|
|
117
|
+
/** @deprecated Never set. */
|
|
80
118
|
budgetRemainingUsd?: number;
|
|
119
|
+
/** @deprecated Never set. */
|
|
81
120
|
budgetPctUsed?: number;
|
|
82
|
-
[key: string]: any;
|
|
83
121
|
}) => void | Promise<void>;
|
|
84
122
|
export interface ControlPlaneClientOptions {
|
|
85
123
|
apiKey: string;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,EAAE,QAAQ,GAAG,WAAW,GAAG,QAAQ,CAAA;IAC5C,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC,OAAO,kBAAkB,EAAE,aAAa,CAAC,CAAA;CAClE;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAA;IAC9C,OAAO,EAAE,MAAM,GAAG,GAAG,EAAE,CAAA;IACvB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,GAAG,EAAE,CAAA;IAClB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,WAAW,EAAE,CAAA;IACvB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,MA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