@onklave/agent-cli 0.1.40 → 0.1.42
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/main.js +46 -12
- package/package.json +1 -1
package/main.js
CHANGED
|
@@ -127,6 +127,7 @@ var CredentialStore = class {
|
|
|
127
127
|
|
|
128
128
|
// _apps/@onklave/agent-cli/src/services/auth.service.ts
|
|
129
129
|
var DEFAULT_PLATFORM_URL = "https://api.onklave.app";
|
|
130
|
+
var DEFAULT_COMMS_URL = "wss://comms.onklave.app";
|
|
130
131
|
var AuthService = class {
|
|
131
132
|
constructor() {
|
|
132
133
|
this.store = new CredentialStore();
|
|
@@ -147,6 +148,7 @@ var AuthService = class {
|
|
|
147
148
|
...existing,
|
|
148
149
|
token,
|
|
149
150
|
platformUrl: metadata?.platformUrl ?? existing?.platformUrl ?? DEFAULT_PLATFORM_URL,
|
|
151
|
+
commsUrl: metadata?.commsUrl ?? existing?.commsUrl,
|
|
150
152
|
userId: metadata?.userId ?? existing?.userId,
|
|
151
153
|
orgId: metadata?.orgId ?? existing?.orgId,
|
|
152
154
|
expiresAt: metadata?.expiresAt ?? existing?.expiresAt
|
|
@@ -206,6 +208,15 @@ var AuthService = class {
|
|
|
206
208
|
const creds = await this.getCredentials();
|
|
207
209
|
return creds?.platformUrl ?? DEFAULT_PLATFORM_URL;
|
|
208
210
|
}
|
|
211
|
+
/*
|
|
212
|
+
* Get the comms (Socket.IO) URL from credentials or fallback to default.
|
|
213
|
+
* Resolved separately from the platform URL because comms is reached on a
|
|
214
|
+
* dedicated host, not through the gateway.
|
|
215
|
+
*/
|
|
216
|
+
async getCommsUrl() {
|
|
217
|
+
const creds = await this.getCredentials();
|
|
218
|
+
return creds?.commsUrl ?? DEFAULT_COMMS_URL;
|
|
219
|
+
}
|
|
209
220
|
};
|
|
210
221
|
|
|
211
222
|
// _apps/@onklave/agent-cli/src/utils.ts
|
|
@@ -257,10 +268,11 @@ async function loginCommand(args) {
|
|
|
257
268
|
const authService = new AuthService();
|
|
258
269
|
const token = flags["token"];
|
|
259
270
|
const platformUrl = flags["platform-url"];
|
|
271
|
+
const commsUrl = flags["comms-url"];
|
|
260
272
|
if (typeof token !== "string" || !token) {
|
|
261
273
|
console.log("Onklave Agent CLI \u2014 Login\n");
|
|
262
274
|
console.log(
|
|
263
|
-
"Usage: onklave login --token <token> [--platform-url <url>]\n"
|
|
275
|
+
"Usage: onklave login --token <token> [--platform-url <url>] [--comms-url <url>]\n"
|
|
264
276
|
);
|
|
265
277
|
console.log("To obtain a token:");
|
|
266
278
|
console.log(
|
|
@@ -277,6 +289,9 @@ async function loginCommand(args) {
|
|
|
277
289
|
if (typeof platformUrl === "string") {
|
|
278
290
|
metadata.platformUrl = platformUrl;
|
|
279
291
|
}
|
|
292
|
+
if (typeof commsUrl === "string") {
|
|
293
|
+
metadata.commsUrl = commsUrl;
|
|
294
|
+
}
|
|
280
295
|
try {
|
|
281
296
|
await authService.saveToken(token, metadata);
|
|
282
297
|
console.log("Successfully authenticated with Onklave platform.");
|
|
@@ -284,6 +299,9 @@ async function loginCommand(args) {
|
|
|
284
299
|
if (typeof platformUrl === "string") {
|
|
285
300
|
console.log(`Platform URL: ${platformUrl}`);
|
|
286
301
|
}
|
|
302
|
+
if (typeof commsUrl === "string") {
|
|
303
|
+
console.log(`Comms URL: ${commsUrl}`);
|
|
304
|
+
}
|
|
287
305
|
} catch (err) {
|
|
288
306
|
console.error(`Login failed: ${err.message}`);
|
|
289
307
|
process.exitCode = 1;
|
|
@@ -319,6 +337,7 @@ async function whoamiCommand() {
|
|
|
319
337
|
const isValid = await authService.isAuthenticated();
|
|
320
338
|
console.log("Onklave Agent CLI \u2014 Identity\n");
|
|
321
339
|
console.log(` Platform URL: ${creds.platformUrl}`);
|
|
340
|
+
console.log(` Comms URL: ${await authService.getCommsUrl()}`);
|
|
322
341
|
console.log(` User ID: ${creds.userId ?? "(not set)"}`);
|
|
323
342
|
console.log(` Org ID: ${creds.orgId ?? "(not set)"}`);
|
|
324
343
|
console.log(` Machine ID: ${creds.machineId ?? "(not registered)"}`);
|
|
@@ -354,6 +373,7 @@ var ConfigResolver = class {
|
|
|
354
373
|
headless: false,
|
|
355
374
|
dryRun: false,
|
|
356
375
|
apiKey: null,
|
|
376
|
+
oauthToken: null,
|
|
357
377
|
apiEndpoint: DEFAULT_PLATFORM_URL2,
|
|
358
378
|
platformUrl: DEFAULT_PLATFORM_URL2,
|
|
359
379
|
orgId: null,
|
|
@@ -417,6 +437,8 @@ var ConfigResolver = class {
|
|
|
417
437
|
fromEnv.orgId = process.env["ONKLAVE_ORG_ID"];
|
|
418
438
|
if (process.env["ANTHROPIC_API_KEY"])
|
|
419
439
|
fromEnv.apiKey = process.env["ANTHROPIC_API_KEY"];
|
|
440
|
+
if (process.env["CLAUDE_CODE_OAUTH_TOKEN"])
|
|
441
|
+
fromEnv.oauthToken = process.env["CLAUDE_CODE_OAUTH_TOKEN"];
|
|
420
442
|
const fromFlags = {};
|
|
421
443
|
if (typeof flags["task"] === "string") fromFlags.task = flags["task"];
|
|
422
444
|
if (typeof flags["context"] === "string")
|
|
@@ -545,6 +567,7 @@ var ConfigResolver = class {
|
|
|
545
567
|
};
|
|
546
568
|
|
|
547
569
|
// _apps/@onklave/agent-cli/src/services/platform-client.ts
|
|
570
|
+
var GATEWAY_SERVICE_PREFIX = "/agent-orchestration";
|
|
548
571
|
var PlatformClient = class {
|
|
549
572
|
constructor(baseUrl, token) {
|
|
550
573
|
this.baseUrl = baseUrl;
|
|
@@ -713,7 +736,7 @@ var PlatformClient = class {
|
|
|
713
736
|
* Make an authenticated HTTP request to the platform.
|
|
714
737
|
*/
|
|
715
738
|
async request(method, path8, body, extraHeaders) {
|
|
716
|
-
const url = `${this.baseUrl}${path8}`;
|
|
739
|
+
const url = `${this.baseUrl}${GATEWAY_SERVICE_PREFIX}${path8}`;
|
|
717
740
|
const headers = {
|
|
718
741
|
Authorization: `Bearer ${this.token}`,
|
|
719
742
|
"Content-Type": "application/json",
|
|
@@ -762,13 +785,15 @@ var CommsClient = class {
|
|
|
762
785
|
}
|
|
763
786
|
/*
|
|
764
787
|
* Connect to the Onklave comms service via Socket.IO.
|
|
788
|
+
* `commsUrl` is the comms service host (e.g. wss://comms.onklave.app) — NOT
|
|
789
|
+
* the gateway/platform URL; comms is reached on its own dedicated ingress.
|
|
765
790
|
* Pass `machineId` so the server can route inbound runner events
|
|
766
791
|
* (e.g. `assignment:claim-available`) to this specific runner.
|
|
767
792
|
*/
|
|
768
|
-
async connect(
|
|
793
|
+
async connect(commsUrl, token, extra) {
|
|
769
794
|
return new Promise((resolve3, reject) => {
|
|
770
|
-
const
|
|
771
|
-
this.socket = io(`${
|
|
795
|
+
const baseUrl = commsUrl.replace(/\/+$/, "");
|
|
796
|
+
this.socket = io(`${baseUrl}/agent-cli`, {
|
|
772
797
|
auth: {
|
|
773
798
|
token,
|
|
774
799
|
machineId: extra?.machineId,
|
|
@@ -911,7 +936,10 @@ var SessionManager = class {
|
|
|
911
936
|
args.push("--append-system-prompt", config.systemPromptAppend);
|
|
912
937
|
}
|
|
913
938
|
const env = { ...process.env };
|
|
914
|
-
if (config.
|
|
939
|
+
if (config.oauthToken) {
|
|
940
|
+
env["CLAUDE_CODE_OAUTH_TOKEN"] = config.oauthToken;
|
|
941
|
+
delete env["ANTHROPIC_API_KEY"];
|
|
942
|
+
} else if (config.apiKey) {
|
|
915
943
|
env["ANTHROPIC_API_KEY"] = config.apiKey;
|
|
916
944
|
}
|
|
917
945
|
const child = spawn("claude", args, {
|
|
@@ -1381,7 +1409,7 @@ var HeartbeatService = class {
|
|
|
1381
1409
|
};
|
|
1382
1410
|
try {
|
|
1383
1411
|
const response = await fetch(
|
|
1384
|
-
`${this.opts.platformUrl}/api/v1/runner/heartbeat`,
|
|
1412
|
+
`${this.opts.platformUrl}/agent-orchestration/api/v1/runner/heartbeat`,
|
|
1385
1413
|
{
|
|
1386
1414
|
method: "POST",
|
|
1387
1415
|
headers: {
|
|
@@ -2031,7 +2059,7 @@ async function runCommand(args) {
|
|
|
2031
2059
|
const auditStreamer = new AuditStreamer(commsClient);
|
|
2032
2060
|
try {
|
|
2033
2061
|
console.log("Connecting to Onklave comms service...");
|
|
2034
|
-
await commsClient.connect(
|
|
2062
|
+
await commsClient.connect(await authService.getCommsUrl(), creds.token, {
|
|
2035
2063
|
machineId: creds.machineId,
|
|
2036
2064
|
deviceToken: creds.deviceToken,
|
|
2037
2065
|
orgId: creds.orgId
|
|
@@ -2097,6 +2125,7 @@ async function runCommand(args) {
|
|
|
2097
2125
|
deniedTools: resolvedConfig.deniedTools,
|
|
2098
2126
|
addDirs,
|
|
2099
2127
|
apiKey: resolvedConfig.apiKey,
|
|
2128
|
+
oauthToken: resolvedConfig.oauthToken,
|
|
2100
2129
|
headless: resolvedConfig.headless,
|
|
2101
2130
|
platformUrl: resolvedConfig.platformUrl,
|
|
2102
2131
|
orgId: resolvedConfig.orgId,
|
|
@@ -2688,7 +2717,7 @@ async function checkWebSocket() {
|
|
|
2688
2717
|
}
|
|
2689
2718
|
const commsClient = new CommsClient();
|
|
2690
2719
|
try {
|
|
2691
|
-
await commsClient.connect(
|
|
2720
|
+
await commsClient.connect(await authService.getCommsUrl(), creds.token);
|
|
2692
2721
|
commsClient.disconnect();
|
|
2693
2722
|
return {
|
|
2694
2723
|
name: "WebSocket",
|
|
@@ -3004,7 +3033,7 @@ var DaemonCommsService = class {
|
|
|
3004
3033
|
let attempt = 0;
|
|
3005
3034
|
while (!this.stopRequested) {
|
|
3006
3035
|
try {
|
|
3007
|
-
await this.client.connect(this.opts.
|
|
3036
|
+
await this.client.connect(this.opts.commsUrl, this.opts.token, {
|
|
3008
3037
|
machineId: this.opts.machineId,
|
|
3009
3038
|
deviceToken: this.opts.deviceToken,
|
|
3010
3039
|
orgId: this.opts.orgId
|
|
@@ -3408,7 +3437,7 @@ var PlatformBrokerClient = class {
|
|
|
3408
3437
|
);
|
|
3409
3438
|
}
|
|
3410
3439
|
async request(method, path8, body) {
|
|
3411
|
-
const url = `${this.baseUrl}${path8}`;
|
|
3440
|
+
const url = `${this.baseUrl}/agent-orchestration${path8}`;
|
|
3412
3441
|
const response = await fetch(url, {
|
|
3413
3442
|
method,
|
|
3414
3443
|
headers: {
|
|
@@ -3513,6 +3542,9 @@ var WorkItemRunner = class {
|
|
|
3513
3542
|
deniedTools: [],
|
|
3514
3543
|
addDirs,
|
|
3515
3544
|
apiKey: null,
|
|
3545
|
+
// Honour a Claude Pro/Max subscription token if the runner was started
|
|
3546
|
+
// with one; otherwise Claude Code falls back to ambient ANTHROPIC_API_KEY.
|
|
3547
|
+
oauthToken: process.env["CLAUDE_CODE_OAUTH_TOKEN"] ?? null,
|
|
3516
3548
|
headless: true,
|
|
3517
3549
|
platformUrl: "",
|
|
3518
3550
|
orgId: null,
|
|
@@ -3685,6 +3717,7 @@ var DaemonSpawner = class {
|
|
|
3685
3717
|
allowedTools: [],
|
|
3686
3718
|
deniedTools: [],
|
|
3687
3719
|
apiKey: req.apiKey ?? null,
|
|
3720
|
+
oauthToken: process.env["CLAUDE_CODE_OAUTH_TOKEN"] ?? null,
|
|
3688
3721
|
headless: true,
|
|
3689
3722
|
platformUrl: this.platformUrl,
|
|
3690
3723
|
orgId: req.orgId,
|
|
@@ -4221,8 +4254,9 @@ async function daemonStart() {
|
|
|
4221
4254
|
creds.machineId
|
|
4222
4255
|
);
|
|
4223
4256
|
const platformUrl = await authService.getPlatformUrl();
|
|
4257
|
+
const commsUrl = await authService.getCommsUrl();
|
|
4224
4258
|
const comms = new DaemonCommsService({
|
|
4225
|
-
|
|
4259
|
+
commsUrl,
|
|
4226
4260
|
token: creds.token,
|
|
4227
4261
|
machineId: creds.machineId,
|
|
4228
4262
|
deviceToken: creds.deviceToken,
|