@premai/api-sdk 1.0.51 → 1.0.53
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/cli-claude.mjs +24 -19
- package/dist/cli.mjs +17 -6
- package/dist/index.cjs +17 -6
- package/dist/index.mjs +17 -6
- package/package.json +1 -1
package/dist/cli-claude.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/launcher/claude-code.ts
|
|
4
|
+
import { spawn as spawn2, spawnSync } from "node:child_process";
|
|
4
5
|
import { existsSync as existsSync3, mkdirSync as mkdirSync3, writeFileSync as writeFileSync2 } from "node:fs";
|
|
5
6
|
import path from "node:path";
|
|
6
7
|
import { config } from "dotenv";
|
|
@@ -241,6 +242,10 @@ function interactivePickModel(models) {
|
|
|
241
242
|
});
|
|
242
243
|
}
|
|
243
244
|
|
|
245
|
+
// src/launcher/proxy-subprocess.ts
|
|
246
|
+
import { spawn } from "node:child_process";
|
|
247
|
+
import { openSync } from "node:fs";
|
|
248
|
+
|
|
244
249
|
// src/utils/debug.ts
|
|
245
250
|
import { existsSync, mkdirSync } from "node:fs";
|
|
246
251
|
import { dirname } from "node:path";
|
|
@@ -346,7 +351,7 @@ function isProcessAlive(pid) {
|
|
|
346
351
|
|
|
347
352
|
// src/launcher/proxy-subprocess.ts
|
|
348
353
|
function resolveCliScript() {
|
|
349
|
-
return new URL(import.meta.resolve(import.meta.url.endsWith(".ts") ? "../cli" : "./cli")).pathname;
|
|
354
|
+
return new URL(import.meta.resolve(import.meta.url.endsWith(".ts") ? "../cli.ts" : "./cli.mjs")).pathname;
|
|
350
355
|
}
|
|
351
356
|
async function postShutdown(host, port, token, timeoutMs = 5000) {
|
|
352
357
|
try {
|
|
@@ -434,19 +439,26 @@ async function ensureProxyRunning(config) {
|
|
|
434
439
|
...config.attest === false ? ["--no-attest"] : []
|
|
435
440
|
];
|
|
436
441
|
logger.debug("spawning proxy", { spawnArgs });
|
|
437
|
-
const
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
442
|
+
const logFd = defaultLogFile ? openSync(defaultLogFile, "a") : null;
|
|
443
|
+
const child = spawn(spawnArgs[0], spawnArgs.slice(1), {
|
|
444
|
+
stdio: ["ignore", logFd ?? "ignore", logFd ?? "ignore"],
|
|
445
|
+
detached: true,
|
|
441
446
|
env: {
|
|
442
447
|
...process.env,
|
|
443
448
|
CONFIDENTIAL_PROXY_DAEMON_CHILD: "1",
|
|
444
449
|
CONFIDENTIAL_PROXY_SHUTDOWN_TOKEN: token
|
|
445
450
|
}
|
|
446
451
|
});
|
|
452
|
+
const exited = new Promise((resolve, reject) => {
|
|
453
|
+
child.on("exit", (code) => resolve(code ?? 0));
|
|
454
|
+
child.on("error", (err) => {
|
|
455
|
+
logger.debug("proxy spawn error", { error: String(err) });
|
|
456
|
+
reject(err);
|
|
457
|
+
});
|
|
458
|
+
});
|
|
447
459
|
logger.debug("proxy spawned", { pid: child.pid });
|
|
448
460
|
logger.debug("polling for readiness");
|
|
449
|
-
const startupCrash =
|
|
461
|
+
const startupCrash = exited.then((exitCode) => {
|
|
450
462
|
logger.debug("proxy exited during startup", { exitCode });
|
|
451
463
|
throw new Error(`Proxy process exited during startup with code ${exitCode}. Run with CONFIDENTIAL_PROXY_LOG_LEVEL=debug to capture logs.`);
|
|
452
464
|
});
|
|
@@ -458,7 +470,7 @@ async function ensureProxyRunning(config) {
|
|
|
458
470
|
}
|
|
459
471
|
logger.debug("proxy is ready");
|
|
460
472
|
const whenCrashed = new Promise((_, reject) => {
|
|
461
|
-
|
|
473
|
+
exited.then((exitCode) => {
|
|
462
474
|
logger.debug("proxy exited", { exitCode });
|
|
463
475
|
reject(new Error(`Proxy process exited unexpectedly with code ${exitCode}`));
|
|
464
476
|
});
|
|
@@ -623,11 +635,7 @@ async function pickModel(models) {
|
|
|
623
635
|
return found;
|
|
624
636
|
}
|
|
625
637
|
function detectCommand(command, args = ["--version"]) {
|
|
626
|
-
|
|
627
|
-
stdout: "ignore",
|
|
628
|
-
stderr: "ignore"
|
|
629
|
-
});
|
|
630
|
-
return result.exitCode === 0;
|
|
638
|
+
return spawnSync(command, args).status === 0;
|
|
631
639
|
}
|
|
632
640
|
function detectClaude() {
|
|
633
641
|
return detectCommand("claude");
|
|
@@ -653,15 +661,12 @@ function buildClaudeEnv(baseUrl, model, apiKey) {
|
|
|
653
661
|
function spawnClaude(baseUrl, model, apiKey, forwardedArgs) {
|
|
654
662
|
const env = buildClaudeEnv(baseUrl, model, apiKey);
|
|
655
663
|
return new Promise((resolve, reject) => {
|
|
656
|
-
const child =
|
|
657
|
-
|
|
658
|
-
stdout: "inherit",
|
|
659
|
-
stderr: "inherit",
|
|
664
|
+
const child = spawn2("claude", forwardedArgs, {
|
|
665
|
+
stdio: "inherit",
|
|
660
666
|
env
|
|
661
667
|
});
|
|
662
|
-
child.
|
|
663
|
-
|
|
664
|
-
}).catch(reject);
|
|
668
|
+
child.on("exit", (code) => resolve(code ?? 0));
|
|
669
|
+
child.on("error", reject);
|
|
665
670
|
});
|
|
666
671
|
}
|
|
667
672
|
async function runClaudeCode(forwardedArgs = []) {
|
package/dist/cli.mjs
CHANGED
|
@@ -2741,7 +2741,7 @@ function setLogLevel(level2) {
|
|
|
2741
2741
|
});
|
|
2742
2742
|
}
|
|
2743
2743
|
// package.json
|
|
2744
|
-
var version = "1.0.
|
|
2744
|
+
var version = "1.0.52";
|
|
2745
2745
|
|
|
2746
2746
|
// src/server/route-prefix.ts
|
|
2747
2747
|
function normalizeRoutePrefix(raw) {
|
|
@@ -3108,6 +3108,10 @@ function createDrainingServer(app, port, host, opts = {}) {
|
|
|
3108
3108
|
});
|
|
3109
3109
|
});
|
|
3110
3110
|
}
|
|
3111
|
+
// src/server/start.ts
|
|
3112
|
+
import { spawn } from "node:child_process";
|
|
3113
|
+
import { openSync } from "node:fs";
|
|
3114
|
+
|
|
3111
3115
|
// src/utils/poll-ready.ts
|
|
3112
3116
|
async function isProxyRoot(baseUrl) {
|
|
3113
3117
|
try {
|
|
@@ -3349,19 +3353,26 @@ async function runDaemonParent(opts) {
|
|
|
3349
3353
|
const scriptPath = process.argv[1];
|
|
3350
3354
|
const args = [scriptPath, ...process.argv.slice(2)];
|
|
3351
3355
|
logger.debug("daemon re-exec", { execPath: process.execPath, args });
|
|
3352
|
-
const
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
+
const logFd = logFile ? openSync(logFile, "a") : null;
|
|
3357
|
+
const child = spawn(process.execPath, args, {
|
|
3358
|
+
stdio: ["ignore", logFd ?? "ignore", logFd ?? "ignore"],
|
|
3359
|
+
detached: true,
|
|
3356
3360
|
env: {
|
|
3357
3361
|
...process.env,
|
|
3358
3362
|
[DAEMON_CHILD_ENV]: "1",
|
|
3359
3363
|
[SHUTDOWN_TOKEN_ENV]: token
|
|
3360
3364
|
}
|
|
3361
3365
|
});
|
|
3366
|
+
const exited = new Promise((resolve, reject) => {
|
|
3367
|
+
child.on("exit", (code) => resolve(code ?? 0));
|
|
3368
|
+
child.on("error", (err) => {
|
|
3369
|
+
logger.debug("daemon child spawn error", { error: String(err) });
|
|
3370
|
+
reject(err);
|
|
3371
|
+
});
|
|
3372
|
+
});
|
|
3362
3373
|
logger.debug("daemon child spawned", { pid: child.pid, stateFilePath });
|
|
3363
3374
|
const baseUrl = `http://${serverHost}:${serverPort}`;
|
|
3364
|
-
const startupCrash =
|
|
3375
|
+
const startupCrash = exited.then((code) => {
|
|
3365
3376
|
throw new Error(`Proxy exited during startup with code ${code}. Run with CONFIDENTIAL_PROXY_LOG_LEVEL=debug to capture logs.`);
|
|
3366
3377
|
});
|
|
3367
3378
|
let started = false;
|
package/dist/index.cjs
CHANGED
|
@@ -2847,7 +2847,7 @@ var logger = import_winston.default.createLogger({
|
|
|
2847
2847
|
transports: [fileTransport, consoleTransport]
|
|
2848
2848
|
});
|
|
2849
2849
|
// package.json
|
|
2850
|
-
var version = "1.0.
|
|
2850
|
+
var version = "1.0.52";
|
|
2851
2851
|
|
|
2852
2852
|
// src/server/route-prefix.ts
|
|
2853
2853
|
function normalizeRoutePrefix(raw) {
|
|
@@ -3214,6 +3214,10 @@ function createDrainingServer(app, port, host, opts = {}) {
|
|
|
3214
3214
|
});
|
|
3215
3215
|
});
|
|
3216
3216
|
}
|
|
3217
|
+
// src/server/start.ts
|
|
3218
|
+
var import_node_child_process = require("node:child_process");
|
|
3219
|
+
var import_node_fs3 = require("node:fs");
|
|
3220
|
+
|
|
3217
3221
|
// src/utils/poll-ready.ts
|
|
3218
3222
|
async function isProxyRoot(baseUrl) {
|
|
3219
3223
|
try {
|
|
@@ -3437,19 +3441,26 @@ async function runDaemonParent(opts) {
|
|
|
3437
3441
|
const scriptPath = process.argv[1];
|
|
3438
3442
|
const args = [scriptPath, ...process.argv.slice(2)];
|
|
3439
3443
|
logger.debug("daemon re-exec", { execPath: process.execPath, args });
|
|
3440
|
-
const
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
+
const logFd = logFile ? import_node_fs3.openSync(logFile, "a") : null;
|
|
3445
|
+
const child = import_node_child_process.spawn(process.execPath, args, {
|
|
3446
|
+
stdio: ["ignore", logFd ?? "ignore", logFd ?? "ignore"],
|
|
3447
|
+
detached: true,
|
|
3444
3448
|
env: {
|
|
3445
3449
|
...process.env,
|
|
3446
3450
|
[DAEMON_CHILD_ENV]: "1",
|
|
3447
3451
|
[SHUTDOWN_TOKEN_ENV]: token
|
|
3448
3452
|
}
|
|
3449
3453
|
});
|
|
3454
|
+
const exited = new Promise((resolve, reject) => {
|
|
3455
|
+
child.on("exit", (code) => resolve(code ?? 0));
|
|
3456
|
+
child.on("error", (err) => {
|
|
3457
|
+
logger.debug("daemon child spawn error", { error: String(err) });
|
|
3458
|
+
reject(err);
|
|
3459
|
+
});
|
|
3460
|
+
});
|
|
3450
3461
|
logger.debug("daemon child spawned", { pid: child.pid, stateFilePath });
|
|
3451
3462
|
const baseUrl = `http://${serverHost}:${serverPort}`;
|
|
3452
|
-
const startupCrash =
|
|
3463
|
+
const startupCrash = exited.then((code) => {
|
|
3453
3464
|
throw new Error(`Proxy exited during startup with code ${code}. Run with CONFIDENTIAL_PROXY_LOG_LEVEL=debug to capture logs.`);
|
|
3454
3465
|
});
|
|
3455
3466
|
let started = false;
|
package/dist/index.mjs
CHANGED
|
@@ -2767,7 +2767,7 @@ var logger = winston.createLogger({
|
|
|
2767
2767
|
transports: [fileTransport, consoleTransport]
|
|
2768
2768
|
});
|
|
2769
2769
|
// package.json
|
|
2770
|
-
var version = "1.0.
|
|
2770
|
+
var version = "1.0.52";
|
|
2771
2771
|
|
|
2772
2772
|
// src/server/route-prefix.ts
|
|
2773
2773
|
function normalizeRoutePrefix(raw) {
|
|
@@ -3134,6 +3134,10 @@ function createDrainingServer(app, port, host, opts = {}) {
|
|
|
3134
3134
|
});
|
|
3135
3135
|
});
|
|
3136
3136
|
}
|
|
3137
|
+
// src/server/start.ts
|
|
3138
|
+
import { spawn } from "node:child_process";
|
|
3139
|
+
import { openSync } from "node:fs";
|
|
3140
|
+
|
|
3137
3141
|
// src/utils/poll-ready.ts
|
|
3138
3142
|
async function isProxyRoot(baseUrl) {
|
|
3139
3143
|
try {
|
|
@@ -3363,19 +3367,26 @@ async function runDaemonParent(opts) {
|
|
|
3363
3367
|
const scriptPath = process.argv[1];
|
|
3364
3368
|
const args = [scriptPath, ...process.argv.slice(2)];
|
|
3365
3369
|
logger.debug("daemon re-exec", { execPath: process.execPath, args });
|
|
3366
|
-
const
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
+
const logFd = logFile ? openSync(logFile, "a") : null;
|
|
3371
|
+
const child = spawn(process.execPath, args, {
|
|
3372
|
+
stdio: ["ignore", logFd ?? "ignore", logFd ?? "ignore"],
|
|
3373
|
+
detached: true,
|
|
3370
3374
|
env: {
|
|
3371
3375
|
...process.env,
|
|
3372
3376
|
[DAEMON_CHILD_ENV]: "1",
|
|
3373
3377
|
[SHUTDOWN_TOKEN_ENV]: token
|
|
3374
3378
|
}
|
|
3375
3379
|
});
|
|
3380
|
+
const exited = new Promise((resolve, reject) => {
|
|
3381
|
+
child.on("exit", (code) => resolve(code ?? 0));
|
|
3382
|
+
child.on("error", (err) => {
|
|
3383
|
+
logger.debug("daemon child spawn error", { error: String(err) });
|
|
3384
|
+
reject(err);
|
|
3385
|
+
});
|
|
3386
|
+
});
|
|
3376
3387
|
logger.debug("daemon child spawned", { pid: child.pid, stateFilePath });
|
|
3377
3388
|
const baseUrl = `http://${serverHost}:${serverPort}`;
|
|
3378
|
-
const startupCrash =
|
|
3389
|
+
const startupCrash = exited.then((code) => {
|
|
3379
3390
|
throw new Error(`Proxy exited during startup with code ${code}. Run with CONFIDENTIAL_PROXY_LOG_LEVEL=debug to capture logs.`);
|
|
3380
3391
|
});
|
|
3381
3392
|
let started = false;
|