@intutic/clawde 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -0
- package/dist/budget-checker.d.ts +11 -0
- package/dist/budget-checker.d.ts.map +1 -0
- package/dist/budget-checker.js +53 -0
- package/dist/budget-checker.js.map +1 -0
- package/dist/circuit-breaker.d.ts +7 -0
- package/dist/circuit-breaker.d.ts.map +1 -0
- package/dist/circuit-breaker.js +62 -0
- package/dist/circuit-breaker.js.map +1 -0
- package/dist/client.d.ts +20 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +138 -0
- package/dist/client.js.map +1 -0
- package/dist/context-resolver.d.ts +3 -0
- package/dist/context-resolver.d.ts.map +1 -0
- package/dist/context-resolver.js +39 -0
- package/dist/context-resolver.js.map +1 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +34 -0
- package/dist/errors.js.map +1 -0
- package/dist/event-emitter.d.ts +8 -0
- package/dist/event-emitter.d.ts.map +1 -0
- package/dist/event-emitter.js +18 -0
- package/dist/event-emitter.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/schema-enforcer.d.ts +4 -0
- package/dist/schema-enforcer.d.ts.map +1 -0
- package/dist/schema-enforcer.js +84 -0
- package/dist/schema-enforcer.js.map +1 -0
- package/dist/types.d.ts +71 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +23 -0
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# @intutic/clawde
|
|
2
|
+
|
|
3
|
+
Programmatic client SDK for intercepting, wrapping, and enforcing policies on AI coding agent scripts.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @intutic/clawde
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Context Resolution:** Automatically detects current Git branch, PR, CI variables, and parses sync-daemon configurations (`~/.intutic/config.json`).
|
|
14
|
+
- **Pre-flight Budget Gating:** Checks remaining session spend limits before calling LLM endpoints.
|
|
15
|
+
- **Circuit Breaker:** Wraps tasks with strict fallback parameters to isolate execution failures.
|
|
16
|
+
- **Schema Normalization:** Intercepts and translates Anthropic payloads to OpenAI structures.
|
|
17
|
+
- **Policy Callbacks:** Simple event subscriptions for policy execution events (e.g. `hijack`, `kill`).
|
|
18
|
+
|
|
19
|
+
## License
|
|
20
|
+
|
|
21
|
+
MIT
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BudgetCheckResult } from './types';
|
|
2
|
+
export declare class BudgetChecker {
|
|
3
|
+
private cache;
|
|
4
|
+
private cacheTtl;
|
|
5
|
+
private baseUrl;
|
|
6
|
+
private apiKey;
|
|
7
|
+
constructor(baseUrl: string, apiKey: string);
|
|
8
|
+
checkBudget(model: string, estimatedTokens: number): Promise<BudgetCheckResult>;
|
|
9
|
+
updateCachedBudget(model: string, estimatedTokens: number, remainingUsd: number, allowed: boolean): void;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=budget-checker.d.ts.map
|
|
@@ -0,0 +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;AAQ3C,qBAAa,aAAa;IACxB,OAAO,CAAC,KAAK,CAAgC;IAC7C,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,MAAM,CAAQ;gBAEV,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAK9B,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAmCrF,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;CAOzG"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BudgetChecker = void 0;
|
|
4
|
+
const errors_1 = require("./errors");
|
|
5
|
+
class BudgetChecker {
|
|
6
|
+
cache = new Map();
|
|
7
|
+
cacheTtl = 30000; // 30s TTL
|
|
8
|
+
baseUrl;
|
|
9
|
+
apiKey;
|
|
10
|
+
constructor(baseUrl, apiKey) {
|
|
11
|
+
this.baseUrl = baseUrl;
|
|
12
|
+
this.apiKey = apiKey;
|
|
13
|
+
}
|
|
14
|
+
async checkBudget(model, estimatedTokens) {
|
|
15
|
+
const cacheKey = `${model}:${estimatedTokens}`;
|
|
16
|
+
const now = Date.now();
|
|
17
|
+
const cached = this.cache.get(cacheKey);
|
|
18
|
+
if (cached && now - cached.timestamp < this.cacheTtl) {
|
|
19
|
+
return cached.result;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const url = new URL(`${this.baseUrl}/v1/budget/check`);
|
|
23
|
+
url.searchParams.append('model', model);
|
|
24
|
+
url.searchParams.append('estimated_tokens', String(estimatedTokens));
|
|
25
|
+
const response = await fetch(url.toString(), {
|
|
26
|
+
method: 'GET',
|
|
27
|
+
headers: {
|
|
28
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
29
|
+
'Accept': 'application/json',
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
if (!response.ok) {
|
|
33
|
+
throw new Error(`Budget check failed with status: ${response.status}`);
|
|
34
|
+
}
|
|
35
|
+
const result = (await response.json());
|
|
36
|
+
this.cache.set(cacheKey, { result, timestamp: now });
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
throw new errors_1.ClawdeConnectionError(`Could not reach budget check endpoint: ${err.message}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Helper to manually update/pre-populate budget cache from response headers
|
|
44
|
+
updateCachedBudget(model, estimatedTokens, remainingUsd, allowed) {
|
|
45
|
+
const cacheKey = `${model}:${estimatedTokens}`;
|
|
46
|
+
this.cache.set(cacheKey, {
|
|
47
|
+
result: { allowed, remaining_usd: remainingUsd },
|
|
48
|
+
timestamp: Date.now(),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.BudgetChecker = BudgetChecker;
|
|
53
|
+
//# sourceMappingURL=budget-checker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"budget-checker.js","sourceRoot":"","sources":["../src/budget-checker.ts"],"names":[],"mappings":";;;AACA,qCAAgD;AAOhD,MAAa,aAAa;IAChB,KAAK,GAAG,IAAI,GAAG,EAAsB,CAAA;IACrC,QAAQ,GAAG,KAAK,CAAA,CAAC,UAAU;IAC3B,OAAO,CAAQ;IACf,MAAM,CAAQ;IAEtB,YAAY,OAAe,EAAE,MAAc;QACzC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAEM,KAAK,CAAC,WAAW,CAAC,KAAa,EAAE,eAAuB;QAC7D,MAAM,QAAQ,GAAG,GAAG,KAAK,IAAI,eAAe,EAAE,CAAA;QAC9C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACtB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QAEvC,IAAI,MAAM,IAAI,GAAG,GAAG,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;YACrD,OAAO,MAAM,CAAC,MAAM,CAAA;QACtB,CAAC;QAED,IAAI,CAAC;YACH,MAAM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I,CAAC,GAAG,EAAE;SACtB,CAAC,CAAA;IACJ,CAAC;CACF;AArDD,sCAqDC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CircuitBreakerOptions } from './types';
|
|
2
|
+
export declare class CircuitBreaker {
|
|
3
|
+
private client;
|
|
4
|
+
constructor(client: any);
|
|
5
|
+
wrap<T>(toolName: string, options?: CircuitBreakerOptions): (fn: () => Promise<T>) => Promise<T>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=circuit-breaker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;CAoDxC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CircuitBreaker = void 0;
|
|
4
|
+
const errors_1 = require("./errors");
|
|
5
|
+
class CircuitBreaker {
|
|
6
|
+
client;
|
|
7
|
+
constructor(client) {
|
|
8
|
+
this.client = client;
|
|
9
|
+
}
|
|
10
|
+
wrap(toolName, options = {}) {
|
|
11
|
+
const failOpen = options.failOpen ?? false;
|
|
12
|
+
return async (fn) => {
|
|
13
|
+
// 1. Pre-Check: Context & pre-flight budget validation
|
|
14
|
+
try {
|
|
15
|
+
const context = await this.client.resolveContext();
|
|
16
|
+
// If maxCostUsd is specified, check against current budget limit or remaining
|
|
17
|
+
if (options.maxCostUsd !== undefined) {
|
|
18
|
+
// Pre-flight check
|
|
19
|
+
const budget = await this.client.checkBudget('default', 1);
|
|
20
|
+
if (!budget.allowed) {
|
|
21
|
+
throw new errors_1.ClawdeVerdictError('kill', `Circuit breaker tripped for tool '${toolName}': budget exceeded. Remaining: $${budget.remaining_usd}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
if (!failOpen) {
|
|
27
|
+
throw err;
|
|
28
|
+
}
|
|
29
|
+
// If failOpen is true, we log the error and continue execution
|
|
30
|
+
if (process.env.INTUTIC_DEBUG === 'true') {
|
|
31
|
+
console.warn(`[Clawde SDK] Circuit breaker pre-check failed (failing open): ${err.message}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// 2. Execute the function
|
|
35
|
+
try {
|
|
36
|
+
const result = await fn();
|
|
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;
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
if (err instanceof errors_1.ClawdeVerdictError && !failOpen) {
|
|
48
|
+
throw err;
|
|
49
|
+
}
|
|
50
|
+
if (!failOpen) {
|
|
51
|
+
throw err;
|
|
52
|
+
}
|
|
53
|
+
if (process.env.INTUTIC_DEBUG === 'true') {
|
|
54
|
+
console.warn(`[Clawde SDK] Circuit breaker execution failed (failing open): ${err.message}`);
|
|
55
|
+
}
|
|
56
|
+
return null; // Fail open returns null or empty
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.CircuitBreaker = CircuitBreaker;
|
|
62
|
+
//# sourceMappingURL=circuit-bre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AE,EAAE,CAAA;gBAEzB,sFAAsF;gBACtF,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;oBACzC,MAAM,GAAG,GAAG,MAAa,CAAA;oBACzB,IAAI,GAAG,CAAC,OAAO,KAAK,MAAM,EAAE,CAAC;wBAC3B,MAAM,IAAI,2BAAkB,CAAC,MAAM,EAAE,wDAAwD,CAAC,CAAA;oBAChG,CAAC;gBACH,CAAC;gBAED,OAAO,MAAM,CAAC;YAChB,CAAC;YAAC,OAAO,GAAQ,EAAE,CAAC;gBAClB,IAAI,GAAG,YAAY,2BAAkB,IAAI,CAAC,QAAQ,EAAE,CAAC;oBACnD,MAAM,GAAG,CAAA;gBACX,CAAC;gBACD,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;AA9DD,wCA8DC"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ClawdeClientOptions, ChatParams, ChatResponse, ResolvedContext, BudgetCheckResult, EventCallback, CircuitBreakerOptions } from './types';
|
|
2
|
+
export declare class ClawdeClient {
|
|
3
|
+
private apiKey;
|
|
4
|
+
private baseUrl;
|
|
5
|
+
private provider?;
|
|
6
|
+
private autoContext;
|
|
7
|
+
private timeout;
|
|
8
|
+
private retries;
|
|
9
|
+
private budgetChecker;
|
|
10
|
+
private circuitBreakerWrapper;
|
|
11
|
+
private eventEmitter;
|
|
12
|
+
constructor(options: ClawdeClientOptions);
|
|
13
|
+
on(event: 'hijack' | 'enhance' | 'kill' | 'bypass', callback: EventCallback): void;
|
|
14
|
+
off(event: string, callback: EventCallback): void;
|
|
15
|
+
checkBudget(model: string, estimatedTokens: number): Promise<BudgetCheckResult>;
|
|
16
|
+
resolveContext(): Promise<ResolvedContext>;
|
|
17
|
+
circuitBreaker<T>(toolName: string, options?: CircuitBreakerOptions): (fn: () => Promise<T>) => Promise<T>;
|
|
18
|
+
chat(params: ChatParams): Promise<ChatResponse>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +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,EACtB,MAAM,SAAS,CAAA;AAQhB,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,QAAQ,CAAC,CAAmC;IACpD,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,OAAO,CAAQ;IAEvB,OAAO,CAAC,aAAa,CAAe;IACpC,OAAO,CAAC,qBAAqB,CAAgB;IAC7C,OAAO,CAAC,YAAY,CAAoB;gBAE5B,OAAO,EAAE,mBAAmB;IAiBjC,EAAE,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI;IAIlF,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;IAK1B,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;CAoG7D"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClawdeClient = void 0;
|
|
4
|
+
const errors_1 = require("./errors");
|
|
5
|
+
const schema_enforcer_1 = require("./schema-enforcer");
|
|
6
|
+
const context_resolver_1 = require("./context-resolver");
|
|
7
|
+
const budget_checker_1 = require("./budget-checker");
|
|
8
|
+
const circuit_breaker_1 = require("./circuit-breaker");
|
|
9
|
+
const event_emitter_1 = require("./event-emitter");
|
|
10
|
+
class ClawdeClient {
|
|
11
|
+
apiKey;
|
|
12
|
+
baseUrl;
|
|
13
|
+
provider;
|
|
14
|
+
autoContext;
|
|
15
|
+
timeout;
|
|
16
|
+
retries;
|
|
17
|
+
budgetChecker;
|
|
18
|
+
circuitBreakerWrapper;
|
|
19
|
+
eventEmitter;
|
|
20
|
+
constructor(options) {
|
|
21
|
+
if (!options.apiKey) {
|
|
22
|
+
throw new Error('API key is required to initialize ClawdeClient.');
|
|
23
|
+
}
|
|
24
|
+
this.apiKey = options.apiKey;
|
|
25
|
+
this.baseUrl = options.baseUrl || process.env.INTUTIC_BASE_URL || 'http://localhost:4000';
|
|
26
|
+
this.provider = options.provider;
|
|
27
|
+
this.autoContext = options.autoContext ?? true;
|
|
28
|
+
this.timeout = options.timeout ?? 30000;
|
|
29
|
+
this.retries = options.retries ?? 2;
|
|
30
|
+
this.budgetChecker = new budget_checker_1.BudgetChecker(this.baseUrl, this.apiKey);
|
|
31
|
+
this.circuitBreakerWrapper = new circuit_breaker_1.CircuitBreaker(this);
|
|
32
|
+
this.eventEmitter = new event_emitter_1.ClawdeEventEmitter();
|
|
33
|
+
}
|
|
34
|
+
// Event emitter delegates
|
|
35
|
+
on(event, callback) {
|
|
36
|
+
this.eventEmitter.on(event, callback);
|
|
37
|
+
}
|
|
38
|
+
off(event, callback) {
|
|
39
|
+
this.eventEmitter.off(event, callback);
|
|
40
|
+
}
|
|
41
|
+
// Budget checker delegate
|
|
42
|
+
async checkBudget(model, estimatedTokens) {
|
|
43
|
+
return this.budgetChecker.checkBudget(model, estimatedTokens);
|
|
44
|
+
}
|
|
45
|
+
// Context resolution delegate
|
|
46
|
+
async resolveContext() {
|
|
47
|
+
if (!this.autoContext) {
|
|
48
|
+
return {};
|
|
49
|
+
}
|
|
50
|
+
return (0, context_resolver_1.resolveContext)();
|
|
51
|
+
}
|
|
52
|
+
// Circuit breaker wrapper delegate
|
|
53
|
+
circuitBreaker(toolName, options = {}) {
|
|
54
|
+
return this.circuitBreakerWrapper.wrap(toolName, options);
|
|
55
|
+
}
|
|
56
|
+
// Chat completion endpoint wrapper
|
|
57
|
+
async chat(params) {
|
|
58
|
+
// 1. Resolve context
|
|
59
|
+
const context = await this.resolveContext();
|
|
60
|
+
// 2. Normalize payload based on provider
|
|
61
|
+
const requestPayload = (0, schema_enforcer_1.normalizeRequest)(params, this.provider);
|
|
62
|
+
// 3. Make the API request with headers
|
|
63
|
+
let lastError = null;
|
|
64
|
+
const maxAttempts = this.retries + 1;
|
|
65
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
66
|
+
const controller = new AbortController();
|
|
67
|
+
const timer = setTimeout(() => controller.abort(), this.timeout);
|
|
68
|
+
try {
|
|
69
|
+
const headers = {
|
|
70
|
+
'Content-Type': 'application/json',
|
|
71
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
72
|
+
'X-Intutic-Context': JSON.stringify(context),
|
|
73
|
+
};
|
|
74
|
+
if (params.max_cost_usd !== undefined) {
|
|
75
|
+
headers['X-Intutic-Cost-Limit'] = String(params.max_cost_usd);
|
|
76
|
+
}
|
|
77
|
+
if (params.sensitivity_tier !== undefined) {
|
|
78
|
+
headers['X-Intutic-Sensitivity'] = String(params.sensitivity_tier);
|
|
79
|
+
}
|
|
80
|
+
const response = await fetch(`${this.baseUrl}/v1/chat/completions`, {
|
|
81
|
+
method: 'POST',
|
|
82
|
+
headers,
|
|
83
|
+
body: JSON.stringify(requestPayload),
|
|
84
|
+
signal: controller.signal,
|
|
85
|
+
});
|
|
86
|
+
clearTimeout(timer);
|
|
87
|
+
if (!response.ok) {
|
|
88
|
+
throw new Error(`HTTP error ${response.status}: ${await response.text()}`);
|
|
89
|
+
}
|
|
90
|
+
const json = await response.json();
|
|
91
|
+
const normalized = (0, schema_enforcer_1.normalizeResponse)(json, this.provider);
|
|
92
|
+
// 4. Extract Intutic response headers
|
|
93
|
+
const verdictHeader = response.headers.get('x-intutic-verdict') || 'allow';
|
|
94
|
+
const budgetRemainingHeader = response.headers.get('x-intutic-budget-remaining');
|
|
95
|
+
const budgetPctHeader = response.headers.get('x-intutic-budget-pct');
|
|
96
|
+
normalized.verdict = verdictHeader;
|
|
97
|
+
if (budgetRemainingHeader) {
|
|
98
|
+
normalized.budgetRemainingUsd = parseFloat(budgetRemainingHeader);
|
|
99
|
+
}
|
|
100
|
+
if (budgetPctHeader) {
|
|
101
|
+
normalized.budgetPctUsed = parseFloat(budgetPctHeader);
|
|
102
|
+
}
|
|
103
|
+
// 5. Update local budget cache
|
|
104
|
+
if (normalized.budgetRemainingUsd !== undefined) {
|
|
105
|
+
this.budgetChecker.updateCachedBudget(params.model, params.messages.length, // approximation
|
|
106
|
+
normalized.budgetRemainingUsd, verdictHeader !== 'kill');
|
|
107
|
+
}
|
|
108
|
+
// 6. Trigger event emitters
|
|
109
|
+
if (normalized.verdict && normalized.verdict !== 'allow') {
|
|
110
|
+
this.eventEmitter.emit(normalized.verdict, normalized);
|
|
111
|
+
}
|
|
112
|
+
// 7. Policy enforcement
|
|
113
|
+
if (normalized.verdict === 'kill') {
|
|
114
|
+
throw new errors_1.ClawdeVerdictError('kill', 'Request blocked by policy (Verdict: KILL)');
|
|
115
|
+
}
|
|
116
|
+
return normalized;
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
clearTimeout(timer);
|
|
120
|
+
lastError = err;
|
|
121
|
+
if (err instanceof errors_1.ClawdeVerdictError) {
|
|
122
|
+
throw err; // Do not retry on explicit policy blocks
|
|
123
|
+
}
|
|
124
|
+
if (attempt < maxAttempts) {
|
|
125
|
+
if (process.env.INTUTIC_DEBUG === 'true') {
|
|
126
|
+
console.warn(`[Clawde SDK] Attempt ${attempt} failed, retrying... Error: ${err.message}`);
|
|
127
|
+
}
|
|
128
|
+
// backoff delay
|
|
129
|
+
await new Promise((resolve) => setTimeout(resolve, attempt * 100));
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
throw new errors_1.ClawdeConnectionError(`Request failed after ${maxAttempts} attempts. Last error: ${lastError.message}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
exports.ClawdeClient = ClawdeClient;
|
|
138
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AASA,qCAAoE;AACpE,uDAAuE;AACvE,yDAAmD;AACnD,qDAAgD;AAChD,uDAAkD;AAClD,mDAAoD;AAEpD,MAAa,YAAY;IACf,MAAM,CAAQ;IACd,OAAO,CAAQ;IACf,QAAQ,CAAoC;IAC5C,WAAW,CAAS;IACpB,OAAO,CAAQ;IACf,OAAO,CAAQ;IAEf,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,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AAC,OAAO,EAAE,CAAC,CAAA;IACnH,CAAC;CACF;AA/JD,oCA+JC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-resolver.d.ts","sourceRoot":"","sources":["../src/context-resolver.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAEzC,wBAAsB,cAAc,IAAI,OAAO,CAAC,eAAe,CAAC,CAgC/D"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveContext = resolveContext;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const os_1 = require("os");
|
|
7
|
+
async function resolveContext() {
|
|
8
|
+
const configPath = (0, path_1.join)((0, os_1.homedir)(), '.intutic', 'config.json');
|
|
9
|
+
// 1. Primary: Read from sync-daemon's config (written every 30s)
|
|
10
|
+
if ((0, fs_1.existsSync)(configPath)) {
|
|
11
|
+
try {
|
|
12
|
+
const config = JSON.parse((0, fs_1.readFileSync)(configPath, 'utf-8'));
|
|
13
|
+
return {
|
|
14
|
+
gitBranch: config.gitBranch,
|
|
15
|
+
jiraTicket: config.jiraTicket,
|
|
16
|
+
pagerdutyIncident: config.pagerdutyIncident,
|
|
17
|
+
ciPipeline: config.ciPipeline,
|
|
18
|
+
workingDirectory: config.workingDirectory || process.cwd(),
|
|
19
|
+
workspaceId: config.workspaceId,
|
|
20
|
+
sessionId: config.sessionId,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
// JSON parse failed or config locked, fallback to env vars
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
// 2. Fallback: Environment variables (if sync-daemon not running)
|
|
28
|
+
return {
|
|
29
|
+
workspaceId: process.env.INTUTIC_WORKSPACE_ID,
|
|
30
|
+
sessionId: process.env.INTUTIC_SESSION_ID,
|
|
31
|
+
gitBranch: process.env.GIT_BRANCH,
|
|
32
|
+
ciPipeline: process.env.GITHUB_RUN_ID
|
|
33
|
+
|| process.env.BUILDKITE_BUILD_ID
|
|
34
|
+
|| process.env.CIRCLE_BUILD_NUM,
|
|
35
|
+
pagerdutyIncident: process.env.PD_INCIDENT_ID,
|
|
36
|
+
workingDirectory: process.cwd(),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=context-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-resolver.js","sourceRoot":"","sources":["../src/context-resolver.ts"],"names":[],"mappings":";;AAKA,wCAgCC;AArCD,2BAA6C;AAC7C,+BAA2B;AAC3B,2BAA4B;AAGrB,KAAK,UAAU,cAAc;IAClC,MAAM,UAAU,GAAG,IAAA,WAAI,EAAC,IAAA,YAAO,GAAE,EAAE,UAAU,EAAE,aAAa,CAAC,CAAA;IAE7D,iEAAiE;IACjE,IAAI,IAAA,eAAU,EAAC,UAAU,CAAC,EAAE,CAAC;QAC3B,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAA,iBAAY,EAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAA;YAC5D,OAAO;gBACL,SAAS,EAAE,MAAM,CAAC,SAAS;gBAC3B,UAAU,EAAE,MAAM,CAAC,UAAU;gBAC7B,iBAAiB,EAAE,MAAM,CAAC,iBAAiB;gBAC3C,UAAU,EAAE,MAAM,CAAC,UAAU;gBAC7B,gBAAgB,EAAE,MAAM,CAAC,gBAAgB,IAAI,OAAO,CAAC,GAAG,EAAE;gBAC1D,WAAW,EAAE,MAAM,CAAC,WAAW;gBAC/B,SAAS,EAAE,MAAM,CAAC,SAAS;aAC5B,CAAA;QACH,CAAC;QAAC,MAAM,CAAC;YACP,2DAA2D;QAC7D,CAAC;IACH,CAAC;IAED,kEAAkE;IAClE,OAAO;QACL,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAoB;QAC7C,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,kBAAkB;QACzC,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,UAAU;QACjC,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa;eAChC,OAAO,CAAC,GAAG,CAAC,kBAAkB;eAC9B,OAAO,CAAC,GAAG,CAAC,gBAAgB;QACjC,iBAAiB,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc;QAC7C,gBAAgB,EAAE,OAAO,CAAC,GAAG,EAAE;KAChC,CAAA;AACH,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare class ClawdeError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
export declare class ClawdeConnectionError extends ClawdeError {
|
|
5
|
+
constructor(message: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class ClawdeBudgetExceededError extends ClawdeError {
|
|
8
|
+
constructor(message: string);
|
|
9
|
+
}
|
|
10
|
+
export declare class ClawdeVerdictError extends ClawdeError {
|
|
11
|
+
verdict: string;
|
|
12
|
+
constructor(verdict: string, message: string);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +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"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClawdeVerdictError = exports.ClawdeBudgetExceededError = exports.ClawdeConnectionError = exports.ClawdeError = void 0;
|
|
4
|
+
class ClawdeError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'ClawdeError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.ClawdeError = ClawdeError;
|
|
11
|
+
class ClawdeConnectionError extends ClawdeError {
|
|
12
|
+
constructor(message) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = 'ClawdeConnectionError';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.ClawdeConnectionError = ClawdeConnectionError;
|
|
18
|
+
class ClawdeBudgetExceededError extends ClawdeError {
|
|
19
|
+
constructor(message) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.name = 'ClawdeBudgetExceededError';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.ClawdeBudgetExceededError = ClawdeBudgetExceededError;
|
|
25
|
+
class ClawdeVerdictError extends ClawdeError {
|
|
26
|
+
verdict;
|
|
27
|
+
constructor(verdict, message) {
|
|
28
|
+
super(message);
|
|
29
|
+
this.name = 'ClawdeVerdictError';
|
|
30
|
+
this.verdict = verdict;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.ClawdeVerdictError = ClawdeVerdictError;
|
|
34
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA,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,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,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"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { EventCallback } from './types';
|
|
2
|
+
export declare class ClawdeEventEmitter {
|
|
3
|
+
private emitter;
|
|
4
|
+
on(event: 'hijack' | 'enhance' | 'kill' | 'bypass', callback: EventCallback): void;
|
|
5
|
+
off(event: string, callback: EventCallback): void;
|
|
6
|
+
emit(event: string, data: any): void;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=event-emitter.d.ts.map
|
|
@@ -0,0 +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;AAEvC,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,OAAO,CAAqB;IAE7B,EAAE,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI;IAIlF,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI;IAIjD,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,IAAI;CAG5C"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClawdeEventEmitter = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
class ClawdeEventEmitter {
|
|
6
|
+
emitter = new events_1.EventEmitter();
|
|
7
|
+
on(event, callback) {
|
|
8
|
+
this.emitter.on(event, callback);
|
|
9
|
+
}
|
|
10
|
+
off(event, callback) {
|
|
11
|
+
this.emitter.off(event, callback);
|
|
12
|
+
}
|
|
13
|
+
emit(event, data) {
|
|
14
|
+
this.emitter.emit(event, data);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.ClawdeEventEmitter = ClawdeEventEmitter;
|
|
18
|
+
//# sourceMappingURL=event-emitter.js.map
|
|
@@ -0,0 +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,KAA+C,EAAE,QAAuB;QAChF,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"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.normalizeResponse = exports.normalizeRequest = exports.resolveContext = exports.ClawdeClient = void 0;
|
|
18
|
+
var client_1 = require("./client");
|
|
19
|
+
Object.defineProperty(exports, "ClawdeClient", { enumerable: true, get: function () { return client_1.ClawdeClient; } });
|
|
20
|
+
__exportStar(require("./types"), exports);
|
|
21
|
+
__exportStar(require("./errors"), exports);
|
|
22
|
+
var context_resolver_1 = require("./context-resolver");
|
|
23
|
+
Object.defineProperty(exports, "resolveContext", { enumerable: true, get: function () { return context_resolver_1.resolveContext; } });
|
|
24
|
+
var schema_enforcer_1 = require("./schema-enforcer");
|
|
25
|
+
Object.defineProperty(exports, "normalizeRequest", { enumerable: true, get: function () { return schema_enforcer_1.normalizeRequest; } });
|
|
26
|
+
Object.defineProperty(exports, "normalizeResponse", { enumerable: true, get: function () { return schema_enforcer_1.normalizeResponse; } });
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mCAAuC;AAA9B,sGAAA,YAAY,OAAA;AACrB,0CAAuB;AACvB,2CAAwB;AACxB,uDAAmD;AAA1C,kHAAA,cAAc,OAAA;AACvB,qDAAuE;AAA9D,mHAAA,gBAAgB,OAAA;AAAE,oHAAA,iBAAiB,OAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ChatParams, ChatResponse } from './types';
|
|
2
|
+
export declare function normalizeRequest(params: ChatParams, provider?: string): any;
|
|
3
|
+
export declare function normalizeResponse(response: any, provider?: string): ChatResponse;
|
|
4
|
+
//# sourceMappingURL=schema-enforcer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-enforcer.d.ts","sourceRoot":"","sources":["../src/schema-enforcer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAElD,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,GAAG,CAuD3E;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,YAAY,CA+BhF"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeRequest = normalizeRequest;
|
|
4
|
+
exports.normalizeResponse = normalizeResponse;
|
|
5
|
+
function normalizeRequest(params, provider) {
|
|
6
|
+
if (!provider || provider === 'openai') {
|
|
7
|
+
return params;
|
|
8
|
+
}
|
|
9
|
+
if (provider === 'anthropic') {
|
|
10
|
+
// If request is formatted as OpenAI, but provider is Anthropic, translate it to Anthropic
|
|
11
|
+
// 1. Separate system message
|
|
12
|
+
let system = params.system || '';
|
|
13
|
+
const filteredMessages = params.messages.filter((msg) => {
|
|
14
|
+
if (msg.role === 'system') {
|
|
15
|
+
system = typeof msg.content === 'string' ? msg.content : JSON.stringify(msg.content);
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
});
|
|
20
|
+
const anthropicParams = {
|
|
21
|
+
model: params.model,
|
|
22
|
+
messages: filteredMessages.map((msg) => {
|
|
23
|
+
// Translate roles
|
|
24
|
+
let role = msg.role;
|
|
25
|
+
if (role === 'tool') {
|
|
26
|
+
role = 'user'; // Anthropic packages tool response in a user message block
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
role,
|
|
30
|
+
content: msg.content,
|
|
31
|
+
};
|
|
32
|
+
}),
|
|
33
|
+
max_tokens: params.max_tokens || params.max_tokens_to_sample || 1024,
|
|
34
|
+
temperature: params.temperature ?? 0.7,
|
|
35
|
+
};
|
|
36
|
+
if (system) {
|
|
37
|
+
anthropicParams.system = system;
|
|
38
|
+
}
|
|
39
|
+
if (params.tools) {
|
|
40
|
+
anthropicParams.tools = params.tools.map((tool) => {
|
|
41
|
+
if (tool.type === 'function') {
|
|
42
|
+
return {
|
|
43
|
+
name: tool.function.name,
|
|
44
|
+
description: tool.function.description,
|
|
45
|
+
input_schema: tool.function.parameters,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return tool;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return anthropicParams;
|
|
52
|
+
}
|
|
53
|
+
return params;
|
|
54
|
+
}
|
|
55
|
+
function normalizeResponse(response, provider) {
|
|
56
|
+
if (!provider || provider === 'openai') {
|
|
57
|
+
return response;
|
|
58
|
+
}
|
|
59
|
+
if (provider === 'anthropic') {
|
|
60
|
+
// Translate Anthropic message response back to OpenAI ChatResponse
|
|
61
|
+
const openAiChoice = {
|
|
62
|
+
index: 0,
|
|
63
|
+
message: {
|
|
64
|
+
role: 'assistant',
|
|
65
|
+
content: response.content?.[0]?.text || response.content || '',
|
|
66
|
+
},
|
|
67
|
+
finish_reason: response.stop_reason === 'end_turn' ? 'stop' : (response.stop_reason || 'stop'),
|
|
68
|
+
};
|
|
69
|
+
return {
|
|
70
|
+
id: response.id || `anthropic-${Date.now()}`,
|
|
71
|
+
object: 'chat.completion',
|
|
72
|
+
created: Math.floor(Date.now() / 1000),
|
|
73
|
+
model: response.model || 'unknown',
|
|
74
|
+
choices: [openAiChoice],
|
|
75
|
+
usage: response.usage ? {
|
|
76
|
+
prompt_tokens: response.usage.input_tokens,
|
|
77
|
+
completion_tokens: response.usage.output_tokens,
|
|
78
|
+
total_tokens: response.usage.input_tokens + response.usage.output_tokens,
|
|
79
|
+
} : undefined,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return response;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=schema-enforcer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-enforcer.js","sourceRoot":"","sources":["../src/schema-enforcer.ts"],"names":[],"mappings":";;AAEA,4CAuDC;AAED,8CA+BC;AAxFD,SAAgB,gBAAgB,CAAC,MAAkB,EAAE,QAAiB;IACpE,IAAI,CAAC,QAAQ,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACvC,OAAO,MAAM,CAAA;IACf,CAAC;IAED,IAAI,QAAQ,KAAK,WAAW,EAAE,CAAC;QAC7B,0FAA0F;QAC1F,6BAA6B;QAC7B,IAAI,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,CAAA;QAChC,MAAM,gBAAgB,GAAG,MAAM,CAA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AAC,aAAa;gBAC/C,YAAY,EAAE,QAAQ,CAAC,KAAK,CAAC,YAAY,GAAG,QAAQ,CAAC,KAAK,CAAC,aAAa;aACzE,CAAC,CAAC,CAAC,SAAS;SACd,CAAA;IACH,CAAC;IAED,OAAO,QAAwB,CAAA;AACjC,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export interface ClawdeClientOptions {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
provider?: 'openai' | 'anthropic' | 'google';
|
|
5
|
+
autoContext?: boolean;
|
|
6
|
+
timeout?: number;
|
|
7
|
+
retries?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface ChatMessage {
|
|
10
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
11
|
+
content: string | any[];
|
|
12
|
+
name?: string;
|
|
13
|
+
tool_calls?: any[];
|
|
14
|
+
tool_call_id?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ChatParams {
|
|
17
|
+
model: string;
|
|
18
|
+
messages: ChatMessage[];
|
|
19
|
+
temperature?: number;
|
|
20
|
+
max_tokens?: number;
|
|
21
|
+
stream?: boolean;
|
|
22
|
+
tools?: any[];
|
|
23
|
+
tool_choice?: any;
|
|
24
|
+
response_format?: any;
|
|
25
|
+
[key: string]: any;
|
|
26
|
+
}
|
|
27
|
+
export interface ChatResponse {
|
|
28
|
+
id: string;
|
|
29
|
+
object: string;
|
|
30
|
+
created: number;
|
|
31
|
+
model: string;
|
|
32
|
+
choices: {
|
|
33
|
+
index: number;
|
|
34
|
+
message: ChatMessage;
|
|
35
|
+
finish_reason: string;
|
|
36
|
+
}[];
|
|
37
|
+
usage?: {
|
|
38
|
+
prompt_tokens: number;
|
|
39
|
+
completion_tokens: number;
|
|
40
|
+
total_tokens: number;
|
|
41
|
+
};
|
|
42
|
+
verdict?: 'allow' | 'hijack' | 'enhance' | 'kill' | 'bypass';
|
|
43
|
+
budgetRemainingUsd?: number;
|
|
44
|
+
budgetPctUsed?: number;
|
|
45
|
+
}
|
|
46
|
+
export interface CircuitBreakerOptions {
|
|
47
|
+
maxCostUsd?: number;
|
|
48
|
+
sensitivityTier?: 'low' | 'medium' | 'high' | 'critical';
|
|
49
|
+
failOpen?: boolean;
|
|
50
|
+
}
|
|
51
|
+
export interface ResolvedContext {
|
|
52
|
+
workspaceId?: string;
|
|
53
|
+
sessionId?: string;
|
|
54
|
+
gitBranch?: string;
|
|
55
|
+
jiraTicket?: string;
|
|
56
|
+
pagerdutyIncident?: string;
|
|
57
|
+
ciPipeline?: string;
|
|
58
|
+
workingDirectory?: string;
|
|
59
|
+
}
|
|
60
|
+
export interface BudgetCheckResult {
|
|
61
|
+
allowed: boolean;
|
|
62
|
+
remaining_usd: number;
|
|
63
|
+
reason?: string;
|
|
64
|
+
}
|
|
65
|
+
export type EventCallback = (data: {
|
|
66
|
+
verdict: 'allow' | 'hijack' | 'enhance' | 'kill' | 'bypass';
|
|
67
|
+
budgetRemainingUsd?: number;
|
|
68
|
+
budgetPctUsed?: number;
|
|
69
|
+
[key: string]: any;
|
|
70
|
+
}) => void | Promise<void>;
|
|
71
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +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,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;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAA;IAC9C,OAAO,EAAE,M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AAO,CAAA;CACnB;AAED,MAAM,WAAW,eAAe;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAA;IAChB,aAAa,EAAE,MAAM,CAAA;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE;IACjC,OAAO,EAAE,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,CAAA;IAC3D,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACnB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@intutic/clawde",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"./dist"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc",
|
|
15
|
+
"test": "vitest run --passWithNoTests",
|
|
16
|
+
"typecheck": "tsc --noEmit"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"typescript": "^5.5",
|
|
21
|
+
"vitest": "^3"
|
|
22
|
+
}
|
|
23
|
+
}
|