@sickr/cli 0.9.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/dist/agentAuth.js +76 -0
- package/dist/auth.js +52 -0
- package/dist/cli.js +1109 -0
- package/dist/hookConfig.js +49 -0
- package/dist/live.js +392 -0
- package/dist/recorder.js +154 -0
- package/dist/redact.js +132 -0
- package/dist/render.js +528 -0
- package/dist/share.js +30 -0
- package/dist/ui.js +63 -0
- package/package.json +22 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync, mkdirSync, chmodSync, unlinkSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
export const AGENT_API_URL = (process.env.SICKR_API_URL ?? 'https://support-backend.sickr.ai').replace(/\/+$/, '');
|
|
5
|
+
function agentCredsPath() {
|
|
6
|
+
return join(homedir(), '.sickr', 'agent.json');
|
|
7
|
+
}
|
|
8
|
+
export function readAgentCredentials() {
|
|
9
|
+
try {
|
|
10
|
+
return JSON.parse(readFileSync(agentCredsPath(), 'utf8'));
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function writeAgentCredentials(c) {
|
|
17
|
+
const dir = join(homedir(), '.sickr');
|
|
18
|
+
mkdirSync(dir, { recursive: true });
|
|
19
|
+
const p = agentCredsPath();
|
|
20
|
+
writeFileSync(p, JSON.stringify(c, null, 2) + '\n');
|
|
21
|
+
try {
|
|
22
|
+
chmodSync(p, 0o600);
|
|
23
|
+
}
|
|
24
|
+
catch { /* Windows: skip */ }
|
|
25
|
+
}
|
|
26
|
+
export function clearAgentCredentials() {
|
|
27
|
+
try {
|
|
28
|
+
unlinkSync(agentCredsPath());
|
|
29
|
+
}
|
|
30
|
+
catch { /* none */ }
|
|
31
|
+
}
|
|
32
|
+
export async function startAgentConnect(apiUrl, agentId) {
|
|
33
|
+
const r = await fetch(`${apiUrl.replace(/\/+$/, '')}/agent-connect/start`, {
|
|
34
|
+
method: 'POST',
|
|
35
|
+
headers: { 'Content-Type': 'application/json' },
|
|
36
|
+
body: JSON.stringify({ agent_id: agentId }),
|
|
37
|
+
});
|
|
38
|
+
if (!r.ok)
|
|
39
|
+
throw new Error(`agent-connect/start failed: ${r.status}`);
|
|
40
|
+
return await r.json();
|
|
41
|
+
}
|
|
42
|
+
export async function pollAgentConnect(apiUrl, deviceCode) {
|
|
43
|
+
const r = await fetch(`${apiUrl.replace(/\/+$/, '')}/agent-connect/poll`, {
|
|
44
|
+
method: 'POST',
|
|
45
|
+
headers: { 'Content-Type': 'application/json' },
|
|
46
|
+
body: JSON.stringify({ device_code: deviceCode }),
|
|
47
|
+
});
|
|
48
|
+
if (!r.ok)
|
|
49
|
+
throw new Error(`agent-connect/poll failed: ${r.status}`);
|
|
50
|
+
return await r.json();
|
|
51
|
+
}
|
|
52
|
+
export async function fetchAgentStatus(c) {
|
|
53
|
+
const r = await fetch(`${c.api_url.replace(/\/+$/, '')}/agent/self/status`, {
|
|
54
|
+
headers: { Authorization: `Bearer ${c.api_key}` },
|
|
55
|
+
});
|
|
56
|
+
if (!r.ok)
|
|
57
|
+
throw new Error(`agent/self/status failed: ${r.status}`);
|
|
58
|
+
return await r.json();
|
|
59
|
+
}
|
|
60
|
+
export async function rotateAgentKey(c) {
|
|
61
|
+
const r = await fetch(`${c.api_url.replace(/\/+$/, '')}/agent/self/rotate`, {
|
|
62
|
+
method: 'POST',
|
|
63
|
+
headers: { Authorization: `Bearer ${c.api_key}` },
|
|
64
|
+
});
|
|
65
|
+
if (!r.ok)
|
|
66
|
+
throw new Error(`agent/self/rotate failed: ${r.status}`);
|
|
67
|
+
return await r.json();
|
|
68
|
+
}
|
|
69
|
+
export async function disconnectAgent(c) {
|
|
70
|
+
const r = await fetch(`${c.api_url.replace(/\/+$/, '')}/agent/self/disconnect`, {
|
|
71
|
+
method: 'POST',
|
|
72
|
+
headers: { Authorization: `Bearer ${c.api_key}` },
|
|
73
|
+
});
|
|
74
|
+
if (!r.ok)
|
|
75
|
+
throw new Error(`agent/self/disconnect failed: ${r.status}`);
|
|
76
|
+
}
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync, mkdirSync, chmodSync, unlinkSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
function credsPath() {
|
|
5
|
+
return join(homedir(), '.sickr', 'credentials.json');
|
|
6
|
+
}
|
|
7
|
+
export function readCredentials() {
|
|
8
|
+
try {
|
|
9
|
+
return JSON.parse(readFileSync(credsPath(), 'utf8'));
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function writeCredentials(c) {
|
|
16
|
+
const dir = join(homedir(), '.sickr');
|
|
17
|
+
mkdirSync(dir, { recursive: true });
|
|
18
|
+
const p = credsPath();
|
|
19
|
+
writeFileSync(p, JSON.stringify(c, null, 2) + '\n');
|
|
20
|
+
try {
|
|
21
|
+
chmodSync(p, 0o600);
|
|
22
|
+
}
|
|
23
|
+
catch { /* Windows: skip */ }
|
|
24
|
+
}
|
|
25
|
+
export function clearCredentials() {
|
|
26
|
+
try {
|
|
27
|
+
unlinkSync(credsPath());
|
|
28
|
+
}
|
|
29
|
+
catch { /* none */ }
|
|
30
|
+
}
|
|
31
|
+
/** Default to the production wedge worker; override with env for local dev. */
|
|
32
|
+
export const AUTH_ENDPOINT = process.env.SICKR_AUTH_ENDPOINT ?? 'https://sickr.ai/api';
|
|
33
|
+
export async function startDevice() {
|
|
34
|
+
const r = await fetch(`${AUTH_ENDPOINT}/auth/device/start`, { method: 'POST' });
|
|
35
|
+
if (!r.ok)
|
|
36
|
+
throw new Error(`device/start failed: ${r.status}`);
|
|
37
|
+
return await r.json();
|
|
38
|
+
}
|
|
39
|
+
export async function pollDevice(device_code) {
|
|
40
|
+
const r = await fetch(`${AUTH_ENDPOINT}/auth/device/poll`, {
|
|
41
|
+
method: 'POST',
|
|
42
|
+
headers: { 'Content-Type': 'application/json' },
|
|
43
|
+
body: JSON.stringify({ device_code }),
|
|
44
|
+
});
|
|
45
|
+
if (!r.ok)
|
|
46
|
+
throw new Error(`device/poll failed: ${r.status}`);
|
|
47
|
+
return await r.json();
|
|
48
|
+
}
|
|
49
|
+
/** Sleep that respects an AbortSignal if you ever need to cancel. */
|
|
50
|
+
export function sleep(ms) {
|
|
51
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
52
|
+
}
|