@contro1/claude-code 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hook.js +2 -2
- package/package.json +4 -2
- package/dist/centcomClient.d.ts +0 -33
- package/dist/centcomClient.js +0 -66
package/dist/hook.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { stdin, stdout, stderr } from "node:process";
|
|
3
|
-
import { CentcomClient } from "
|
|
3
|
+
import { CentcomClient } from "@contro1/sdk";
|
|
4
4
|
import { loadConfig } from "./config.js";
|
|
5
5
|
import { buildIdempotencyKey, formatRequest } from "./formatter.js";
|
|
6
6
|
let activeRequestId = null;
|
|
@@ -70,7 +70,7 @@ async function main() {
|
|
|
70
70
|
const client = new CentcomClient({
|
|
71
71
|
apiKey: config.apiKey,
|
|
72
72
|
baseUrl: config.baseUrl,
|
|
73
|
-
|
|
73
|
+
timeout: Math.min(config.timeoutMs, 30_000),
|
|
74
74
|
});
|
|
75
75
|
activeClient = client;
|
|
76
76
|
const formatted = formatRequest(input);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contro1/claude-code",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "CENTCOM approval hook for Claude Code PreToolUse",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/hook.js",
|
|
@@ -29,7 +29,9 @@
|
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
|
-
"dependencies": {
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@contro1/sdk": "^1.0.0"
|
|
34
|
+
},
|
|
33
35
|
"devDependencies": {
|
|
34
36
|
"@types/node": "^20.0.0",
|
|
35
37
|
"typescript": "^5.4.0"
|
package/dist/centcomClient.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
interface CentcomClientConfig {
|
|
2
|
-
apiKey: string;
|
|
3
|
-
baseUrl: string;
|
|
4
|
-
timeoutMs: number;
|
|
5
|
-
}
|
|
6
|
-
interface CreateRequestParams {
|
|
7
|
-
type: "approval" | "yes_no" | "free_text";
|
|
8
|
-
context: string;
|
|
9
|
-
question: string;
|
|
10
|
-
callback_url: string;
|
|
11
|
-
priority: "normal" | "urgent";
|
|
12
|
-
required_role?: string;
|
|
13
|
-
metadata?: Record<string, unknown>;
|
|
14
|
-
sla_minutes?: number;
|
|
15
|
-
idempotency_key?: string;
|
|
16
|
-
}
|
|
17
|
-
export interface CentcomRequest {
|
|
18
|
-
id: string;
|
|
19
|
-
state: string;
|
|
20
|
-
response?: Record<string, unknown> | null;
|
|
21
|
-
}
|
|
22
|
-
export declare class CentcomClient {
|
|
23
|
-
private readonly apiKey;
|
|
24
|
-
private readonly baseUrl;
|
|
25
|
-
private readonly timeoutMs;
|
|
26
|
-
constructor(config: CentcomClientConfig);
|
|
27
|
-
private request;
|
|
28
|
-
createRequest(params: CreateRequestParams): Promise<CentcomRequest>;
|
|
29
|
-
getRequest(requestId: string): Promise<CentcomRequest>;
|
|
30
|
-
cancelRequest(requestId: string): Promise<void>;
|
|
31
|
-
waitForResponse(requestId: string, intervalMs: number, timeoutMs: number): Promise<CentcomRequest>;
|
|
32
|
-
}
|
|
33
|
-
export {};
|
package/dist/centcomClient.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
export class CentcomClient {
|
|
2
|
-
apiKey;
|
|
3
|
-
baseUrl;
|
|
4
|
-
timeoutMs;
|
|
5
|
-
constructor(config) {
|
|
6
|
-
this.apiKey = config.apiKey;
|
|
7
|
-
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
8
|
-
this.timeoutMs = config.timeoutMs;
|
|
9
|
-
}
|
|
10
|
-
async request(method, path, body, extraHeaders) {
|
|
11
|
-
const controller = new AbortController();
|
|
12
|
-
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
13
|
-
try {
|
|
14
|
-
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
15
|
-
method,
|
|
16
|
-
headers: {
|
|
17
|
-
Authorization: `Bearer ${this.apiKey}`,
|
|
18
|
-
"Content-Type": "application/json",
|
|
19
|
-
...(extraHeaders ?? {}),
|
|
20
|
-
},
|
|
21
|
-
body: body ? JSON.stringify(body) : undefined,
|
|
22
|
-
signal: controller.signal,
|
|
23
|
-
});
|
|
24
|
-
const json = (await res.json());
|
|
25
|
-
if (!res.ok) {
|
|
26
|
-
throw new Error(json.message || `HTTP ${res.status}`);
|
|
27
|
-
}
|
|
28
|
-
return json;
|
|
29
|
-
}
|
|
30
|
-
finally {
|
|
31
|
-
clearTimeout(timeout);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
async createRequest(params) {
|
|
35
|
-
const { idempotency_key, ...body } = params;
|
|
36
|
-
const headers = {};
|
|
37
|
-
if (idempotency_key)
|
|
38
|
-
headers["Idempotency-Key"] = idempotency_key;
|
|
39
|
-
return this.request("POST", "/requests", body, headers);
|
|
40
|
-
}
|
|
41
|
-
async getRequest(requestId) {
|
|
42
|
-
return this.request("GET", `/requests/${requestId}`);
|
|
43
|
-
}
|
|
44
|
-
async cancelRequest(requestId) {
|
|
45
|
-
await this.request("DELETE", `/requests/${requestId}`);
|
|
46
|
-
}
|
|
47
|
-
async waitForResponse(requestId, intervalMs, timeoutMs) {
|
|
48
|
-
const deadline = Date.now() + timeoutMs;
|
|
49
|
-
const terminal = new Set([
|
|
50
|
-
"answered",
|
|
51
|
-
"callback_pending",
|
|
52
|
-
"callback_delivered",
|
|
53
|
-
"callback_failed",
|
|
54
|
-
"closed",
|
|
55
|
-
"expired",
|
|
56
|
-
"cancelled",
|
|
57
|
-
]);
|
|
58
|
-
while (Date.now() < deadline) {
|
|
59
|
-
const req = await this.getRequest(requestId);
|
|
60
|
-
if (terminal.has(req.state))
|
|
61
|
-
return req;
|
|
62
|
-
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
63
|
-
}
|
|
64
|
-
throw new Error(`Timeout waiting for response on request ${requestId}`);
|
|
65
|
-
}
|
|
66
|
-
}
|