@alva-ai/toolkit 0.12.0 → 0.13.0
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 +24 -1
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/cli.d.ts +1607 -0
- package/dist/cli.js +442 -66
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +200 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -2
- package/dist/index.d.ts +26 -2
- package/dist/index.js +200 -20
- package/dist/index.js.map +1 -1
- package/package.json +6 -1
package/dist/cli.js
CHANGED
|
@@ -2053,7 +2053,7 @@ var require_stringify = __commonJS({
|
|
|
2053
2053
|
exports.getOuterHTML = getOuterHTML;
|
|
2054
2054
|
exports.getInnerHTML = getInnerHTML;
|
|
2055
2055
|
exports.getText = getText;
|
|
2056
|
-
exports.textContent =
|
|
2056
|
+
exports.textContent = textContent2;
|
|
2057
2057
|
exports.innerText = innerText;
|
|
2058
2058
|
var domhandler_1 = require_lib2();
|
|
2059
2059
|
var dom_serializer_1 = __importDefault(require_lib4());
|
|
@@ -2077,11 +2077,11 @@ var require_stringify = __commonJS({
|
|
|
2077
2077
|
return node.data;
|
|
2078
2078
|
return "";
|
|
2079
2079
|
}
|
|
2080
|
-
function
|
|
2080
|
+
function textContent2(node) {
|
|
2081
2081
|
if (Array.isArray(node))
|
|
2082
|
-
return node.map(
|
|
2082
|
+
return node.map(textContent2).join("");
|
|
2083
2083
|
if ((0, domhandler_1.hasChildren)(node) && !(0, domhandler_1.isComment)(node)) {
|
|
2084
|
-
return
|
|
2084
|
+
return textContent2(node.children);
|
|
2085
2085
|
}
|
|
2086
2086
|
if ((0, domhandler_1.isText)(node))
|
|
2087
2087
|
return node.data;
|
|
@@ -7342,6 +7342,7 @@ var init_fallback_bundle = __esm({
|
|
|
7342
7342
|
--chart-green2-main: #8fc13a;
|
|
7343
7343
|
--chart-green2-1: #5b8513;
|
|
7344
7344
|
--chart-green2-2: #c0d40f;
|
|
7345
|
+
--chart-cyan1-main: #49a3a6; /* same as --main-m1 */
|
|
7345
7346
|
--chart-cyan1-1: #117a7d;
|
|
7346
7347
|
--chart-cyan1-2: #77c9c2;
|
|
7347
7348
|
--chart-cyan2-main: #7cafad;
|
|
@@ -7448,7 +7449,7 @@ var init_fallback_bundle = __esm({
|
|
|
7448
7449
|
--line-l12: rgba(0, 0, 0, 0.12); /* Card Border */
|
|
7449
7450
|
--line-l2: rgba(0, 0, 0, 0.2); /* Popup/Dropdown Border */
|
|
7450
7451
|
--line-l3: rgba(0, 0, 0, 0.3); /* Button/Input/Select Border */
|
|
7451
|
-
--line-l9: rgba(0, 0, 0, 0.9);
|
|
7452
|
+
--line-l9: rgba(0, 0, 0, 0.9); /* Hover/Active Border */
|
|
7452
7453
|
|
|
7453
7454
|
/* Shadow */
|
|
7454
7455
|
--shadow-xs: 0 4px 15px 0 rgba(0, 0, 0, 0.05);
|
|
@@ -7549,7 +7550,6 @@ body {
|
|
|
7549
7550
|
width: 100%;
|
|
7550
7551
|
margin: 0 auto;
|
|
7551
7552
|
padding: var(--spacing-s) var(--spacing-xxl) var(--spacing-xxxxl);
|
|
7552
|
-
/* max-width: 2048px; */
|
|
7553
7553
|
}
|
|
7554
7554
|
|
|
7555
7555
|
@media (max-width: 768px) {
|
|
@@ -9416,8 +9416,26 @@ __export(lint_exports, {
|
|
|
9416
9416
|
lintBeforeRelease: () => lintBeforeRelease
|
|
9417
9417
|
});
|
|
9418
9418
|
import * as fs from "fs";
|
|
9419
|
+
function textContent(result, path) {
|
|
9420
|
+
if (typeof result === "string") return result;
|
|
9421
|
+
if (result instanceof ArrayBuffer) {
|
|
9422
|
+
return new TextDecoder("utf-8").decode(result);
|
|
9423
|
+
}
|
|
9424
|
+
throw new Error(
|
|
9425
|
+
`Cannot lint ${path}: expected text content, got ${typeof result}.`
|
|
9426
|
+
);
|
|
9427
|
+
}
|
|
9428
|
+
async function readPlaybookHtml(opts) {
|
|
9429
|
+
if (opts.client) {
|
|
9430
|
+
return textContent(
|
|
9431
|
+
await opts.client.fs.read({ path: opts.file }),
|
|
9432
|
+
opts.file
|
|
9433
|
+
);
|
|
9434
|
+
}
|
|
9435
|
+
return fs.readFileSync(opts.file, "utf8");
|
|
9436
|
+
}
|
|
9419
9437
|
async function handleLintPlaybook(opts) {
|
|
9420
|
-
const html =
|
|
9438
|
+
const html = await readPlaybookHtml(opts);
|
|
9421
9439
|
const contract = opts.contractYaml ? loadContract(opts.contractYaml) : await loadActiveDesignSystem();
|
|
9422
9440
|
const report = lint(html, contract);
|
|
9423
9441
|
const output = formatReport(report, opts.format ?? "human");
|
|
@@ -9431,15 +9449,7 @@ async function lintBeforeRelease(opts) {
|
|
|
9431
9449
|
const result = await opts.client.fs.read({
|
|
9432
9450
|
path: `~/playbooks/${opts.playbookName}/index.html`
|
|
9433
9451
|
});
|
|
9434
|
-
|
|
9435
|
-
html = result;
|
|
9436
|
-
} else if (result instanceof ArrayBuffer) {
|
|
9437
|
-
html = new TextDecoder("utf-8").decode(result);
|
|
9438
|
-
} else {
|
|
9439
|
-
throw new Error(
|
|
9440
|
-
`Cannot lint ~/playbooks/${opts.playbookName}/index.html: expected text content, got ${typeof result}.`
|
|
9441
|
-
);
|
|
9442
|
-
}
|
|
9452
|
+
html = textContent(result, `~/playbooks/${opts.playbookName}/index.html`);
|
|
9443
9453
|
}
|
|
9444
9454
|
const contract = opts.contractYaml ? loadContract(opts.contractYaml) : await loadActiveDesignSystem();
|
|
9445
9455
|
const report = lint(html, contract);
|
|
@@ -9474,11 +9484,13 @@ var init_lint2 = __esm({
|
|
|
9474
9484
|
var AlvaError = class extends Error {
|
|
9475
9485
|
code;
|
|
9476
9486
|
status;
|
|
9477
|
-
|
|
9487
|
+
details;
|
|
9488
|
+
constructor(code, message, status, details) {
|
|
9478
9489
|
super(message);
|
|
9479
9490
|
this.name = "AlvaError";
|
|
9480
9491
|
this.code = code;
|
|
9481
9492
|
this.status = status;
|
|
9493
|
+
this.details = details;
|
|
9482
9494
|
}
|
|
9483
9495
|
};
|
|
9484
9496
|
var CliUsageError = class extends Error {
|
|
@@ -9491,6 +9503,45 @@ var CliUsageError = class extends Error {
|
|
|
9491
9503
|
};
|
|
9492
9504
|
|
|
9493
9505
|
// src/resources/fs.ts
|
|
9506
|
+
function isValidUtf8(bytes) {
|
|
9507
|
+
let i = 0;
|
|
9508
|
+
while (i < bytes.length) {
|
|
9509
|
+
const byte = bytes[i];
|
|
9510
|
+
if (byte <= 127) {
|
|
9511
|
+
i += 1;
|
|
9512
|
+
continue;
|
|
9513
|
+
}
|
|
9514
|
+
let needed = 0;
|
|
9515
|
+
let minCodePoint = 0;
|
|
9516
|
+
let codePoint = 0;
|
|
9517
|
+
if (byte >= 194 && byte <= 223) {
|
|
9518
|
+
needed = 1;
|
|
9519
|
+
minCodePoint = 128;
|
|
9520
|
+
codePoint = byte & 31;
|
|
9521
|
+
} else if (byte >= 224 && byte <= 239) {
|
|
9522
|
+
needed = 2;
|
|
9523
|
+
minCodePoint = 2048;
|
|
9524
|
+
codePoint = byte & 15;
|
|
9525
|
+
} else if (byte >= 240 && byte <= 244) {
|
|
9526
|
+
needed = 3;
|
|
9527
|
+
minCodePoint = 65536;
|
|
9528
|
+
codePoint = byte & 7;
|
|
9529
|
+
} else {
|
|
9530
|
+
return false;
|
|
9531
|
+
}
|
|
9532
|
+
if (i + needed >= bytes.length) return false;
|
|
9533
|
+
for (let j = 1; j <= needed; j += 1) {
|
|
9534
|
+
const next = bytes[i + j];
|
|
9535
|
+
if ((next & 192) !== 128) return false;
|
|
9536
|
+
codePoint = codePoint << 6 | next & 63;
|
|
9537
|
+
}
|
|
9538
|
+
if (codePoint < minCodePoint || codePoint > 1114111 || codePoint >= 55296 && codePoint <= 57343) {
|
|
9539
|
+
return false;
|
|
9540
|
+
}
|
|
9541
|
+
i += needed + 1;
|
|
9542
|
+
}
|
|
9543
|
+
return true;
|
|
9544
|
+
}
|
|
9494
9545
|
var FsResource = class {
|
|
9495
9546
|
constructor(client) {
|
|
9496
9547
|
this.client = client;
|
|
@@ -9502,15 +9553,14 @@ var FsResource = class {
|
|
|
9502
9553
|
query: { path: params.path, offset: params.offset, size: params.size }
|
|
9503
9554
|
});
|
|
9504
9555
|
if (!(result instanceof ArrayBuffer)) return result;
|
|
9556
|
+
if (!isValidUtf8(new Uint8Array(result))) {
|
|
9557
|
+
return result;
|
|
9558
|
+
}
|
|
9559
|
+
const text = new TextDecoder("utf-8").decode(result);
|
|
9505
9560
|
try {
|
|
9506
|
-
|
|
9507
|
-
try {
|
|
9508
|
-
return JSON.parse(text);
|
|
9509
|
-
} catch {
|
|
9510
|
-
return text;
|
|
9511
|
-
}
|
|
9561
|
+
return JSON.parse(text);
|
|
9512
9562
|
} catch {
|
|
9513
|
-
return
|
|
9563
|
+
return text;
|
|
9514
9564
|
}
|
|
9515
9565
|
}
|
|
9516
9566
|
/** Write file using JSON body (Mode 2). For text content. */
|
|
@@ -9629,7 +9679,8 @@ var RunResource = class {
|
|
|
9629
9679
|
working_dir: params.working_dir,
|
|
9630
9680
|
args: params.args,
|
|
9631
9681
|
max_heap_size_mb: params.max_heap_size_mb
|
|
9632
|
-
}
|
|
9682
|
+
},
|
|
9683
|
+
timeoutMs: params.timeout_ms
|
|
9633
9684
|
});
|
|
9634
9685
|
}
|
|
9635
9686
|
};
|
|
@@ -11964,6 +12015,62 @@ function parseResultPayload(result) {
|
|
|
11964
12015
|
// src/client.ts
|
|
11965
12016
|
var DEFAULT_BASE_URL = "https://api-llm.prd.alva.ai";
|
|
11966
12017
|
var DEFAULT_ARRAYS_BASE_URL = "https://data-tools.prd.space.id";
|
|
12018
|
+
function isRecord(value) {
|
|
12019
|
+
return typeof value === "object" && value !== null;
|
|
12020
|
+
}
|
|
12021
|
+
function stringField(value, field) {
|
|
12022
|
+
if (!isRecord(value)) return void 0;
|
|
12023
|
+
const fieldValue = value[field];
|
|
12024
|
+
return typeof fieldValue === "string" && fieldValue ? fieldValue : void 0;
|
|
12025
|
+
}
|
|
12026
|
+
function describeCause(cause) {
|
|
12027
|
+
if (cause === void 0 || cause === null) {
|
|
12028
|
+
return {};
|
|
12029
|
+
}
|
|
12030
|
+
const details = {};
|
|
12031
|
+
if (cause instanceof Error) {
|
|
12032
|
+
if (cause.name) details.name = cause.name;
|
|
12033
|
+
if (cause.message) details.message = cause.message;
|
|
12034
|
+
const code = stringField(cause, "code");
|
|
12035
|
+
if (code) details.code = code;
|
|
12036
|
+
} else if (isRecord(cause)) {
|
|
12037
|
+
const code = stringField(cause, "code");
|
|
12038
|
+
const name = stringField(cause, "name");
|
|
12039
|
+
const message = stringField(cause, "message");
|
|
12040
|
+
if (code) details.code = code;
|
|
12041
|
+
if (name) details.name = name;
|
|
12042
|
+
if (message) details.message = message;
|
|
12043
|
+
} else {
|
|
12044
|
+
details.message = String(cause);
|
|
12045
|
+
}
|
|
12046
|
+
const parts = [details.code, details.name, details.message].filter(
|
|
12047
|
+
(part) => Boolean(part)
|
|
12048
|
+
);
|
|
12049
|
+
return {
|
|
12050
|
+
message: parts.length > 0 ? parts.join(": ") : void 0,
|
|
12051
|
+
details: Object.keys(details).length > 0 ? details : void 0
|
|
12052
|
+
};
|
|
12053
|
+
}
|
|
12054
|
+
function describeFetchFailure(err) {
|
|
12055
|
+
const message = err instanceof Error && err.message ? err.message : "Network request failed";
|
|
12056
|
+
const details = {};
|
|
12057
|
+
if (err instanceof Error) {
|
|
12058
|
+
details.name = err.name;
|
|
12059
|
+
details.message = err.message;
|
|
12060
|
+
} else {
|
|
12061
|
+
details.message = String(err);
|
|
12062
|
+
}
|
|
12063
|
+
const { message: causeMessage, details: causeDetails } = describeCause(
|
|
12064
|
+
isRecord(err) ? err.cause : void 0
|
|
12065
|
+
);
|
|
12066
|
+
if (causeDetails) {
|
|
12067
|
+
details.cause = causeDetails;
|
|
12068
|
+
}
|
|
12069
|
+
return {
|
|
12070
|
+
message: causeMessage ? `${message}; cause: ${causeMessage}` : message,
|
|
12071
|
+
details
|
|
12072
|
+
};
|
|
12073
|
+
}
|
|
11967
12074
|
var AlvaClient = class {
|
|
11968
12075
|
baseUrl;
|
|
11969
12076
|
arraysBaseUrl;
|
|
@@ -11973,6 +12080,16 @@ var AlvaClient = class {
|
|
|
11973
12080
|
gaClientId;
|
|
11974
12081
|
gaSessionId;
|
|
11975
12082
|
utmParams;
|
|
12083
|
+
signal;
|
|
12084
|
+
/**
|
|
12085
|
+
* Alva chat session that owns work produced through this client (playbooks,
|
|
12086
|
+
* feeds, uploaded files). Forwarded as `X-Alva-Origin-Session-Id` so the
|
|
12087
|
+
* backend can attribute created artifacts to the originating session. This
|
|
12088
|
+
* is a request-context hint, NOT auth — the backend still verifies the
|
|
12089
|
+
* session belongs to the authenticated user before honoring it. Distinct
|
|
12090
|
+
* from `gaSessionId` (browser analytics).
|
|
12091
|
+
*/
|
|
12092
|
+
originSessionId;
|
|
11976
12093
|
_fs;
|
|
11977
12094
|
_run;
|
|
11978
12095
|
_deploy;
|
|
@@ -12005,6 +12122,8 @@ var AlvaClient = class {
|
|
|
12005
12122
|
this.gaClientId = config.gaClientId;
|
|
12006
12123
|
this.gaSessionId = config.gaSessionId;
|
|
12007
12124
|
this.utmParams = config.utmParams;
|
|
12125
|
+
this.signal = config.signal;
|
|
12126
|
+
this.originSessionId = config.originSessionId;
|
|
12008
12127
|
}
|
|
12009
12128
|
get fs() {
|
|
12010
12129
|
return this._fs ??= new FsResource(this);
|
|
@@ -12119,6 +12238,9 @@ var AlvaClient = class {
|
|
|
12119
12238
|
if (this.utmParams) {
|
|
12120
12239
|
headers["X-Alva-UTM-Params"] = this.utmParams;
|
|
12121
12240
|
}
|
|
12241
|
+
if (this.originSessionId && !options?.noAuth) {
|
|
12242
|
+
headers["X-Alva-Origin-Session-Id"] = this.originSessionId;
|
|
12243
|
+
}
|
|
12122
12244
|
let fetchBody;
|
|
12123
12245
|
if (options?.rawBody !== void 0) {
|
|
12124
12246
|
headers["Content-Type"] = "application/octet-stream";
|
|
@@ -12131,21 +12253,89 @@ var AlvaClient = class {
|
|
|
12131
12253
|
fetchBody = JSON.stringify(options.body);
|
|
12132
12254
|
}
|
|
12133
12255
|
let response;
|
|
12256
|
+
const timeoutMs = options?.timeoutMs;
|
|
12257
|
+
const externalSignal = options?.signal ?? this.signal;
|
|
12258
|
+
if (externalSignal?.aborted) {
|
|
12259
|
+
throw new AlvaError(
|
|
12260
|
+
"NETWORK_ABORTED",
|
|
12261
|
+
`Request aborted while calling ${method} ${path}`,
|
|
12262
|
+
0,
|
|
12263
|
+
{
|
|
12264
|
+
method,
|
|
12265
|
+
path
|
|
12266
|
+
}
|
|
12267
|
+
);
|
|
12268
|
+
}
|
|
12269
|
+
const controller = timeoutMs !== void 0 ? new AbortController() : void 0;
|
|
12270
|
+
let didTimeout = false;
|
|
12271
|
+
let timeoutId;
|
|
12272
|
+
let abortListener;
|
|
12273
|
+
if (controller && timeoutMs !== void 0) {
|
|
12274
|
+
if (externalSignal) {
|
|
12275
|
+
abortListener = () => controller.abort(externalSignal.reason);
|
|
12276
|
+
externalSignal.addEventListener("abort", abortListener, { once: true });
|
|
12277
|
+
}
|
|
12278
|
+
timeoutId = setTimeout(() => {
|
|
12279
|
+
didTimeout = true;
|
|
12280
|
+
controller.abort(
|
|
12281
|
+
new Error(
|
|
12282
|
+
`Request timed out after ${timeoutMs}ms while calling ${method} ${path}`
|
|
12283
|
+
)
|
|
12284
|
+
);
|
|
12285
|
+
}, timeoutMs);
|
|
12286
|
+
}
|
|
12287
|
+
const fetchInit = {
|
|
12288
|
+
method,
|
|
12289
|
+
headers,
|
|
12290
|
+
body: fetchBody,
|
|
12291
|
+
signal: controller?.signal ?? externalSignal
|
|
12292
|
+
};
|
|
12293
|
+
if (timeoutMs !== void 0) {
|
|
12294
|
+
fetchInit.timeout = timeoutMs;
|
|
12295
|
+
}
|
|
12134
12296
|
try {
|
|
12135
|
-
response = await fetch(url,
|
|
12297
|
+
response = await fetch(url, fetchInit);
|
|
12298
|
+
} catch (err) {
|
|
12299
|
+
if (externalSignal?.aborted && !didTimeout) {
|
|
12300
|
+
throw new AlvaError(
|
|
12301
|
+
"NETWORK_ABORTED",
|
|
12302
|
+
`Request aborted while calling ${method} ${path}`,
|
|
12303
|
+
0,
|
|
12304
|
+
{
|
|
12305
|
+
method,
|
|
12306
|
+
path
|
|
12307
|
+
}
|
|
12308
|
+
);
|
|
12309
|
+
}
|
|
12310
|
+
if (didTimeout) {
|
|
12311
|
+
throw new AlvaError(
|
|
12312
|
+
"NETWORK_TIMEOUT",
|
|
12313
|
+
`Request timed out after ${timeoutMs}ms while calling ${method} ${path}`,
|
|
12314
|
+
0,
|
|
12315
|
+
{ method, path, timeout_ms: timeoutMs }
|
|
12316
|
+
);
|
|
12317
|
+
}
|
|
12318
|
+
const failure = describeFetchFailure(err);
|
|
12319
|
+
throw new AlvaError("NETWORK_ERROR", failure.message, 0, {
|
|
12136
12320
|
method,
|
|
12137
|
-
|
|
12138
|
-
|
|
12321
|
+
path,
|
|
12322
|
+
...failure.details
|
|
12139
12323
|
});
|
|
12140
|
-
}
|
|
12141
|
-
|
|
12142
|
-
"
|
|
12143
|
-
|
|
12144
|
-
|
|
12145
|
-
|
|
12324
|
+
} finally {
|
|
12325
|
+
if (abortListener && externalSignal) {
|
|
12326
|
+
externalSignal.removeEventListener("abort", abortListener);
|
|
12327
|
+
}
|
|
12328
|
+
if (timeoutId !== void 0) {
|
|
12329
|
+
clearTimeout(timeoutId);
|
|
12330
|
+
}
|
|
12146
12331
|
}
|
|
12147
12332
|
if (!response.ok) {
|
|
12148
|
-
|
|
12333
|
+
let bodyText = "";
|
|
12334
|
+
try {
|
|
12335
|
+
bodyText = await Promise.resolve(response.text());
|
|
12336
|
+
} catch {
|
|
12337
|
+
bodyText = "";
|
|
12338
|
+
}
|
|
12149
12339
|
const contentType2 = response.headers.get("content-type") ?? "";
|
|
12150
12340
|
if (contentType2.includes("application/json") && bodyText) {
|
|
12151
12341
|
try {
|
|
@@ -12263,6 +12453,7 @@ function loadConfig(deps) {
|
|
|
12263
12453
|
const gaClientIdEnv = env.ALVA_GA_CLIENT_ID;
|
|
12264
12454
|
const gaSessionIdEnv = env.ALVA_GA_SESSION_ID;
|
|
12265
12455
|
const utmParamsEnv = env.ALVA_UTM_PARAMS;
|
|
12456
|
+
const originSessionIdEnv = env.ALVA_SESSION_ID;
|
|
12266
12457
|
let fileProfile = {};
|
|
12267
12458
|
const path = configPath({ env, homedir: homedir3 });
|
|
12268
12459
|
try {
|
|
@@ -12286,7 +12477,8 @@ function loadConfig(deps) {
|
|
|
12286
12477
|
profile: profileName,
|
|
12287
12478
|
gaClientId: gaClientIdEnv,
|
|
12288
12479
|
gaSessionId: gaSessionIdEnv,
|
|
12289
|
-
utmParams: utmParamsEnv
|
|
12480
|
+
utmParams: utmParamsEnv,
|
|
12481
|
+
originSessionId: originSessionIdEnv
|
|
12290
12482
|
};
|
|
12291
12483
|
}
|
|
12292
12484
|
|
|
@@ -12928,7 +13120,11 @@ function formatPlaybookSkillFile(file) {
|
|
|
12928
13120
|
import * as fs2 from "fs";
|
|
12929
13121
|
import * as os2 from "os";
|
|
12930
13122
|
import * as fsPromises2 from "fs/promises";
|
|
12931
|
-
|
|
13123
|
+
import { Agent, setGlobalDispatcher } from "undici";
|
|
13124
|
+
var CLI_VERSION = true ? "0.13.0" : "dev";
|
|
13125
|
+
var DEFAULT_RUN_TIMEOUT_MS = 6e5;
|
|
13126
|
+
var RUN_TIMEOUT_ENV = "ALVA_RUN_TIMEOUT_MS";
|
|
13127
|
+
var configuredRunFetchTimeoutMs;
|
|
12932
13128
|
function isVersionOlderThan(a, b) {
|
|
12933
13129
|
const parse4 = (v) => {
|
|
12934
13130
|
if (!v) return null;
|
|
@@ -13152,6 +13348,7 @@ Options:
|
|
|
13152
13348
|
--working-dir <dir> Working directory for require() (inline code only)
|
|
13153
13349
|
--args <json> JSON object passed to require("env").args
|
|
13154
13350
|
--max-heap-size-mb <mb> Override the V8 heap limit in MB (1-2048, default 256)
|
|
13351
|
+
--timeout-ms <ms> Client HTTP timeout for /api/v1/run (default: ${DEFAULT_RUN_TIMEOUT_MS}; env: ${RUN_TIMEOUT_ENV})
|
|
13155
13352
|
|
|
13156
13353
|
At least one of --code, --local-file, or --entry-path is required.
|
|
13157
13354
|
These three options are mutually exclusive.
|
|
@@ -13183,7 +13380,8 @@ Examples:
|
|
|
13183
13380
|
alva run --entry-path "~/feeds/my-feed/v1/src/index.js"
|
|
13184
13381
|
alva run --entry-path "~/tasks/analyze/src/index.js" --args '{"symbol":"NVDA","limit":50}'
|
|
13185
13382
|
alva run --local-file ./my-script.js --args '{"symbol":"BTC"}'
|
|
13186
|
-
alva run --entry-path "~/tasks/heavy/src/index.js" --max-heap-size-mb 1024
|
|
13383
|
+
alva run --entry-path "~/tasks/heavy/src/index.js" --max-heap-size-mb 1024
|
|
13384
|
+
alva run --entry-path "~/feeds/slow/v1/src/index.js" --timeout-ms 900000`,
|
|
13187
13385
|
deploy: `Usage: alva deploy <subcommand> [options]
|
|
13188
13386
|
|
|
13189
13387
|
Manage scheduled cronjobs that run your scripts on a cron schedule.
|
|
@@ -13766,26 +13964,30 @@ Required:
|
|
|
13766
13964
|
|
|
13767
13965
|
Examples:
|
|
13768
13966
|
alva remix --child-username bob --child-name my-btc --parents '[{"username":"alice","name":"btc-signals"}]'`,
|
|
13769
|
-
screenshot: `Usage: alva screenshot --url <url> --out <file> [--selector <css>] [--xpath <xpath>] [--compress] [--compress-quality <n>] [--compress-max-width <px>]
|
|
13967
|
+
screenshot: `Usage: alva screenshot --url <url> (--base64 | --out <file>) [--selector <css>] [--xpath <xpath>] [--full] [--compress] [--compress-quality <n>] [--compress-max-width <px>]
|
|
13770
13968
|
|
|
13771
|
-
Capture a screenshot of an Alva page
|
|
13772
|
-
playbook rendering before release.
|
|
13969
|
+
Capture a screenshot of an Alva page. Choose exactly one output mode.
|
|
13773
13970
|
|
|
13774
13971
|
Required:
|
|
13775
13972
|
--url <url> URL or path to capture (e.g. /playbook/alice/dashboard)
|
|
13776
|
-
|
|
13973
|
+
|
|
13974
|
+
Output (choose one):
|
|
13975
|
+
--base64 Emit the image as base64 to stdout. Compresses by
|
|
13976
|
+
default (max-width 1280, quality 70) unless --full.
|
|
13977
|
+
--out <file> Write the image to a local file.
|
|
13777
13978
|
|
|
13778
13979
|
Optional:
|
|
13779
|
-
--selector <css>
|
|
13780
|
-
--xpath <xpath>
|
|
13781
|
-
--
|
|
13782
|
-
--compress-
|
|
13980
|
+
--selector <css> Capture a specific element by CSS selector
|
|
13981
|
+
--xpath <xpath> Capture a specific element by XPath
|
|
13982
|
+
--full (--base64) Return the raw image, no default compression
|
|
13983
|
+
--compress Re-encode the image to reduce file size
|
|
13984
|
+
--compress-quality <n> Compression quality 1-100
|
|
13783
13985
|
--compress-max-width <px> Downscale to at most this width in pixels
|
|
13784
13986
|
|
|
13785
13987
|
Examples:
|
|
13786
|
-
alva screenshot --url /playbook/alice/
|
|
13787
|
-
alva screenshot --url /playbook/alice/
|
|
13788
|
-
alva screenshot --url /playbook/alice/
|
|
13988
|
+
alva screenshot --url /playbook/alice/dashboard --base64
|
|
13989
|
+
alva screenshot --url /playbook/alice/dashboard --out dashboard.png
|
|
13990
|
+
alva screenshot --url /playbook/alice/dashboard --out chart.png --selector ".chart-container"`,
|
|
13789
13991
|
portfolio: `Usage: alva portfolio <subcommand> [options]
|
|
13790
13992
|
|
|
13791
13993
|
Read-only view of connected accounts across TREX and SnapTrade.
|
|
@@ -13938,7 +14140,9 @@ var BOOLEAN_FLAGS = /* @__PURE__ */ new Set([
|
|
|
13938
14140
|
"compress",
|
|
13939
14141
|
"bypass-lint",
|
|
13940
14142
|
"no-browser",
|
|
13941
|
-
"browser"
|
|
14143
|
+
"browser",
|
|
14144
|
+
"base64",
|
|
14145
|
+
"full"
|
|
13942
14146
|
]);
|
|
13943
14147
|
function parseFlags2(argv) {
|
|
13944
14148
|
const flags = {};
|
|
@@ -14034,6 +14238,45 @@ function optionalBoundedIntegerFlag(flags, name, command, min, max) {
|
|
|
14034
14238
|
}
|
|
14035
14239
|
return n;
|
|
14036
14240
|
}
|
|
14241
|
+
function parsePositiveIntegerValue(val, label, command) {
|
|
14242
|
+
const n = Number(val);
|
|
14243
|
+
if (!/^[1-9]\d*$/.test(val) || !Number.isSafeInteger(n)) {
|
|
14244
|
+
const group = command.split(" ")[0];
|
|
14245
|
+
throw new CliUsageError(
|
|
14246
|
+
`${label} must be a positive integer for '${command}', got '${val}'`,
|
|
14247
|
+
group
|
|
14248
|
+
);
|
|
14249
|
+
}
|
|
14250
|
+
return n;
|
|
14251
|
+
}
|
|
14252
|
+
function runtimeEnv(deps) {
|
|
14253
|
+
return deps?.env ?? process.env;
|
|
14254
|
+
}
|
|
14255
|
+
function runTimeoutMs(flags, deps) {
|
|
14256
|
+
if (flags["timeout-ms"] !== void 0) {
|
|
14257
|
+
return parsePositiveIntegerValue(
|
|
14258
|
+
flags["timeout-ms"],
|
|
14259
|
+
"--timeout-ms",
|
|
14260
|
+
"run"
|
|
14261
|
+
);
|
|
14262
|
+
}
|
|
14263
|
+
const envValue = runtimeEnv(deps)[RUN_TIMEOUT_ENV];
|
|
14264
|
+
if (envValue !== void 0 && envValue !== "") {
|
|
14265
|
+
return parsePositiveIntegerValue(envValue, RUN_TIMEOUT_ENV, "run");
|
|
14266
|
+
}
|
|
14267
|
+
return DEFAULT_RUN_TIMEOUT_MS;
|
|
14268
|
+
}
|
|
14269
|
+
function configureRunFetchTimeout(timeoutMs, deps) {
|
|
14270
|
+
if (deps?.mode === "jagent") return;
|
|
14271
|
+
if (configuredRunFetchTimeoutMs === timeoutMs) return;
|
|
14272
|
+
setGlobalDispatcher(
|
|
14273
|
+
new Agent({
|
|
14274
|
+
headersTimeout: timeoutMs,
|
|
14275
|
+
bodyTimeout: timeoutMs
|
|
14276
|
+
})
|
|
14277
|
+
);
|
|
14278
|
+
configuredRunFetchTimeoutMs = timeoutMs;
|
|
14279
|
+
}
|
|
14037
14280
|
function requireGroupSubscriptionTargetType(flags, command) {
|
|
14038
14281
|
const val = requireFlag(flags, "target-type", command).trim().toLowerCase();
|
|
14039
14282
|
if (val === "feed" || val === "playbook") return val;
|
|
@@ -14110,7 +14353,7 @@ function jsonRequiredFlag(flags, name, command) {
|
|
|
14110
14353
|
);
|
|
14111
14354
|
}
|
|
14112
14355
|
}
|
|
14113
|
-
function jsonSchemaStringFlag(flags, command) {
|
|
14356
|
+
function jsonSchemaStringFlag(flags, command, deps) {
|
|
14114
14357
|
const inlineSchema = flags["params-schema"];
|
|
14115
14358
|
const schemaFile = flags["params-schema-file"];
|
|
14116
14359
|
if (inlineSchema !== void 0 && schemaFile !== void 0) {
|
|
@@ -14119,7 +14362,7 @@ function jsonSchemaStringFlag(flags, command) {
|
|
|
14119
14362
|
command.split(" ")[0]
|
|
14120
14363
|
);
|
|
14121
14364
|
}
|
|
14122
|
-
const raw = schemaFile !== void 0 ?
|
|
14365
|
+
const raw = schemaFile !== void 0 ? readLocalTextFile(schemaFile, command, "params-schema-file", deps) : inlineSchema;
|
|
14123
14366
|
if (raw === void 0) return void 0;
|
|
14124
14367
|
try {
|
|
14125
14368
|
JSON.parse(raw);
|
|
@@ -14132,7 +14375,43 @@ function jsonSchemaStringFlag(flags, command) {
|
|
|
14132
14375
|
}
|
|
14133
14376
|
return raw;
|
|
14134
14377
|
}
|
|
14135
|
-
|
|
14378
|
+
function localFileUnsupported(command, flag) {
|
|
14379
|
+
return new CliUsageError(
|
|
14380
|
+
`--${flag} reads or writes a local file, which is unavailable in jagent. Use ALFS-native read/write/edit tools first, then pass ALFS paths or inline data to '${command}'.`,
|
|
14381
|
+
command.split(" ")[0]
|
|
14382
|
+
);
|
|
14383
|
+
}
|
|
14384
|
+
function assertLocalFileAvailable(command, flag, deps) {
|
|
14385
|
+
if (deps?.mode === "jagent") {
|
|
14386
|
+
throw localFileUnsupported(command, flag);
|
|
14387
|
+
}
|
|
14388
|
+
}
|
|
14389
|
+
function readLocalTextFile(path, command, flag, deps) {
|
|
14390
|
+
assertLocalFileAvailable(command, flag, deps);
|
|
14391
|
+
return fs2.readFileSync(path, "utf-8");
|
|
14392
|
+
}
|
|
14393
|
+
function readLocalFileBytes(path, command, flag, deps) {
|
|
14394
|
+
assertLocalFileAvailable(command, flag, deps);
|
|
14395
|
+
return fs2.readFileSync(path);
|
|
14396
|
+
}
|
|
14397
|
+
function sniffImageMime(bytes) {
|
|
14398
|
+
const b = bytes;
|
|
14399
|
+
if (b.length >= 4 && b[0] === 137 && b[1] === 80 && b[2] === 78 && b[3] === 71) {
|
|
14400
|
+
return "image/png";
|
|
14401
|
+
}
|
|
14402
|
+
if (b.length >= 3 && b[0] === 255 && b[1] === 216 && b[2] === 255) {
|
|
14403
|
+
return "image/jpeg";
|
|
14404
|
+
}
|
|
14405
|
+
if (b.length >= 12 && b[0] === 82 && b[1] === 73 && b[2] === 70 && b[3] === 70 && b[8] === 87 && b[9] === 69 && b[10] === 66 && b[11] === 80) {
|
|
14406
|
+
return "image/webp";
|
|
14407
|
+
}
|
|
14408
|
+
return "image/png";
|
|
14409
|
+
}
|
|
14410
|
+
function writeLocalFileBytes(path, data, command, flag, deps) {
|
|
14411
|
+
assertLocalFileAvailable(command, flag, deps);
|
|
14412
|
+
fs2.writeFileSync(path, data);
|
|
14413
|
+
}
|
|
14414
|
+
async function dispatch(client, args, meta, deps) {
|
|
14136
14415
|
const group = args[0];
|
|
14137
14416
|
if (!group || group === "--help" || group === "-h") {
|
|
14138
14417
|
return { _help: true, text: HELP_TEXT };
|
|
@@ -14194,7 +14473,12 @@ async function dispatch(client, args, meta) {
|
|
|
14194
14473
|
});
|
|
14195
14474
|
case "write":
|
|
14196
14475
|
if (flags["file"]) {
|
|
14197
|
-
const fileData =
|
|
14476
|
+
const fileData = readLocalFileBytes(
|
|
14477
|
+
flags["file"],
|
|
14478
|
+
"fs write",
|
|
14479
|
+
"file",
|
|
14480
|
+
deps
|
|
14481
|
+
);
|
|
14198
14482
|
return client.fs.rawWrite({
|
|
14199
14483
|
path: requireFlag(flags, "path", "fs write"),
|
|
14200
14484
|
body: fileData,
|
|
@@ -14276,8 +14560,15 @@ async function dispatch(client, args, meta) {
|
|
|
14276
14560
|
}
|
|
14277
14561
|
let code = flags["code"];
|
|
14278
14562
|
if (flags["local-file"]) {
|
|
14279
|
-
code =
|
|
14563
|
+
code = readLocalTextFile(
|
|
14564
|
+
flags["local-file"],
|
|
14565
|
+
"run",
|
|
14566
|
+
"local-file",
|
|
14567
|
+
deps
|
|
14568
|
+
);
|
|
14280
14569
|
}
|
|
14570
|
+
const timeout_ms = runTimeoutMs(flags, deps);
|
|
14571
|
+
configureRunFetchTimeout(timeout_ms, deps);
|
|
14281
14572
|
return client.run.execute({
|
|
14282
14573
|
code,
|
|
14283
14574
|
entry_path: flags["entry-path"],
|
|
@@ -14289,7 +14580,8 @@ async function dispatch(client, args, meta) {
|
|
|
14289
14580
|
"run",
|
|
14290
14581
|
1,
|
|
14291
14582
|
2048
|
|
14292
|
-
)
|
|
14583
|
+
),
|
|
14584
|
+
timeout_ms
|
|
14293
14585
|
});
|
|
14294
14586
|
}
|
|
14295
14587
|
case "deploy": {
|
|
@@ -14355,7 +14647,7 @@ async function dispatch(client, args, meta) {
|
|
|
14355
14647
|
return client.deploy.listRuns({
|
|
14356
14648
|
cronjob_id: requireNumericFlag(flags, "id", "deploy runs"),
|
|
14357
14649
|
first: num(flags["first"]),
|
|
14358
|
-
cursor:
|
|
14650
|
+
cursor: flags["cursor"]
|
|
14359
14651
|
});
|
|
14360
14652
|
case "run-logs":
|
|
14361
14653
|
return client.deploy.getRunLogs({
|
|
@@ -14512,7 +14804,11 @@ async function dispatch(client, args, meta) {
|
|
|
14512
14804
|
"entry-script-path",
|
|
14513
14805
|
"functions register"
|
|
14514
14806
|
),
|
|
14515
|
-
params_schema: jsonSchemaStringFlag(
|
|
14807
|
+
params_schema: jsonSchemaStringFlag(
|
|
14808
|
+
flags,
|
|
14809
|
+
"functions register",
|
|
14810
|
+
deps
|
|
14811
|
+
),
|
|
14516
14812
|
allow_charges: boolFlag(flags["allow-charges"])
|
|
14517
14813
|
});
|
|
14518
14814
|
case "list":
|
|
@@ -14605,7 +14901,7 @@ async function dispatch(client, args, meta) {
|
|
|
14605
14901
|
});
|
|
14606
14902
|
if (lintReport.summary.warnings > 0) {
|
|
14607
14903
|
const { formatReport: formatReport2 } = await Promise.resolve().then(() => (init_report(), report_exports));
|
|
14608
|
-
process.stderr.write(
|
|
14904
|
+
(deps?.stderr ?? process.stderr).write(
|
|
14609
14905
|
"design lint warnings:\n" + formatReport2(lintReport, "human") + "\n"
|
|
14610
14906
|
);
|
|
14611
14907
|
}
|
|
@@ -14647,7 +14943,15 @@ async function dispatch(client, args, meta) {
|
|
|
14647
14943
|
}
|
|
14648
14944
|
const format = formatFlag ?? "human";
|
|
14649
14945
|
const { handleLintPlaybook: handleLintPlaybook2 } = await Promise.resolve().then(() => (init_lint2(), lint_exports));
|
|
14650
|
-
const { exitCode, output } = await handleLintPlaybook2({
|
|
14946
|
+
const { exitCode, output } = await handleLintPlaybook2({
|
|
14947
|
+
file,
|
|
14948
|
+
format,
|
|
14949
|
+
client: deps?.mode === "jagent" ? client : void 0
|
|
14950
|
+
});
|
|
14951
|
+
if (deps?.mode === "jagent") {
|
|
14952
|
+
if (exitCode !== 0) throw new Error(output);
|
|
14953
|
+
return output;
|
|
14954
|
+
}
|
|
14651
14955
|
process.stdout.write(output + (output.endsWith("\n") ? "" : "\n"));
|
|
14652
14956
|
if (exitCode !== 0) process.exit(exitCode);
|
|
14653
14957
|
return void 0;
|
|
@@ -15107,13 +15411,70 @@ async function dispatch(client, args, meta) {
|
|
|
15107
15411
|
);
|
|
15108
15412
|
}
|
|
15109
15413
|
case "screenshot": {
|
|
15414
|
+
const hasOut = flags["out"] !== void 0;
|
|
15415
|
+
const wantBase64 = boolFlag(flags["base64"]) === true;
|
|
15416
|
+
if (hasOut && wantBase64) {
|
|
15417
|
+
throw new CliUsageError(
|
|
15418
|
+
"screenshot accepts only one of --out (local file) or --base64 (stdout); both were provided.",
|
|
15419
|
+
"screenshot"
|
|
15420
|
+
);
|
|
15421
|
+
}
|
|
15422
|
+
if (!hasOut && !wantBase64) {
|
|
15423
|
+
throw new CliUsageError(
|
|
15424
|
+
"one of --out/--base64 is required for screenshot",
|
|
15425
|
+
"screenshot"
|
|
15426
|
+
);
|
|
15427
|
+
}
|
|
15428
|
+
const url = requireFlag(flags, "url", "screenshot");
|
|
15429
|
+
const selector = flags["selector"];
|
|
15430
|
+
const xpath = flags["xpath"];
|
|
15431
|
+
if (wantBase64) {
|
|
15432
|
+
const full = boolFlag(flags["full"]) === true;
|
|
15433
|
+
const explicitQuality = flags["compress-quality"];
|
|
15434
|
+
const explicitMaxWidth = flags["compress-max-width"];
|
|
15435
|
+
const noCompress = full || boolFlag(flags["compress"]) === false;
|
|
15436
|
+
let compress;
|
|
15437
|
+
let compressQuality2;
|
|
15438
|
+
let compressMaxWidth2;
|
|
15439
|
+
if (noCompress) {
|
|
15440
|
+
compress = false;
|
|
15441
|
+
compressQuality2 = void 0;
|
|
15442
|
+
compressMaxWidth2 = void 0;
|
|
15443
|
+
} else {
|
|
15444
|
+
compress = true;
|
|
15445
|
+
compressQuality2 = explicitQuality !== void 0 ? Number(explicitQuality) : 70;
|
|
15446
|
+
compressMaxWidth2 = explicitMaxWidth !== void 0 ? Number(explicitMaxWidth) : 1280;
|
|
15447
|
+
}
|
|
15448
|
+
const result2 = await client.screenshot.capture({
|
|
15449
|
+
url,
|
|
15450
|
+
selector,
|
|
15451
|
+
xpath,
|
|
15452
|
+
compress,
|
|
15453
|
+
compressQuality: compressQuality2,
|
|
15454
|
+
compressMaxWidth: compressMaxWidth2
|
|
15455
|
+
});
|
|
15456
|
+
const buf2 = Buffer.from(result2);
|
|
15457
|
+
if (buf2.length === 0) {
|
|
15458
|
+
throw new CliUsageError(
|
|
15459
|
+
"Screenshot service returned empty response (0 bytes). The service may be overloaded \u2014 retry in a few seconds.",
|
|
15460
|
+
"screenshot"
|
|
15461
|
+
);
|
|
15462
|
+
}
|
|
15463
|
+
return {
|
|
15464
|
+
_image: true,
|
|
15465
|
+
mimeType: sniffImageMime(buf2),
|
|
15466
|
+
data: Buffer.from(buf2).toString("base64"),
|
|
15467
|
+
bytes: buf2.length
|
|
15468
|
+
};
|
|
15469
|
+
}
|
|
15110
15470
|
const outFile = requireFlag(flags, "out", "screenshot");
|
|
15471
|
+
assertLocalFileAvailable("screenshot", "out", deps);
|
|
15111
15472
|
const compressQuality = flags["compress-quality"];
|
|
15112
15473
|
const compressMaxWidth = flags["compress-max-width"];
|
|
15113
15474
|
const result = await client.screenshot.capture({
|
|
15114
|
-
url
|
|
15115
|
-
selector
|
|
15116
|
-
xpath
|
|
15475
|
+
url,
|
|
15476
|
+
selector,
|
|
15477
|
+
xpath,
|
|
15117
15478
|
compress: boolFlag(flags["compress"]),
|
|
15118
15479
|
compressQuality: compressQuality !== void 0 ? Number(compressQuality) : void 0,
|
|
15119
15480
|
compressMaxWidth: compressMaxWidth !== void 0 ? Number(compressMaxWidth) : void 0
|
|
@@ -15125,7 +15486,13 @@ async function dispatch(client, args, meta) {
|
|
|
15125
15486
|
"screenshot"
|
|
15126
15487
|
);
|
|
15127
15488
|
}
|
|
15128
|
-
|
|
15489
|
+
writeLocalFileBytes(
|
|
15490
|
+
outFile,
|
|
15491
|
+
new Uint8Array(buf),
|
|
15492
|
+
"screenshot",
|
|
15493
|
+
"out",
|
|
15494
|
+
deps
|
|
15495
|
+
);
|
|
15129
15496
|
return { written: outFile, bytes: buf.length };
|
|
15130
15497
|
}
|
|
15131
15498
|
case "portfolio": {
|
|
@@ -15354,7 +15721,8 @@ async function main() {
|
|
|
15354
15721
|
arraysBaseUrl: config.arraysBaseUrl,
|
|
15355
15722
|
gaClientId: config.gaClientId,
|
|
15356
15723
|
gaSessionId: config.gaSessionId,
|
|
15357
|
-
utmParams: config.utmParams
|
|
15724
|
+
utmParams: config.utmParams,
|
|
15725
|
+
originSessionId: config.originSessionId
|
|
15358
15726
|
});
|
|
15359
15727
|
const cleanArgs = stripGlobalFlags(rawArgs);
|
|
15360
15728
|
const result = await dispatch(client, cleanArgs, {
|
|
@@ -15373,6 +15741,11 @@ async function main() {
|
|
|
15373
15741
|
process.stdout.write(helpResult.text + "\n");
|
|
15374
15742
|
return;
|
|
15375
15743
|
}
|
|
15744
|
+
if (result && typeof result === "object" && result._image === true && typeof result.data === "string") {
|
|
15745
|
+
const imageResult = result;
|
|
15746
|
+
process.stdout.write(imageResult.data + "\n");
|
|
15747
|
+
return;
|
|
15748
|
+
}
|
|
15376
15749
|
if (result instanceof ArrayBuffer) {
|
|
15377
15750
|
process.stdout.write(Buffer.from(result));
|
|
15378
15751
|
return;
|
|
@@ -15397,7 +15770,8 @@ ${help}
|
|
|
15397
15770
|
const error = {
|
|
15398
15771
|
code: err.code,
|
|
15399
15772
|
message: err.message,
|
|
15400
|
-
status: err.status
|
|
15773
|
+
status: err.status,
|
|
15774
|
+
...err.details !== void 0 ? { details: err.details } : {}
|
|
15401
15775
|
};
|
|
15402
15776
|
process.stderr.write(`${JSON.stringify({ error }, null, 2)}
|
|
15403
15777
|
`);
|
|
@@ -15415,7 +15789,9 @@ if (isDirectRun) {
|
|
|
15415
15789
|
main();
|
|
15416
15790
|
}
|
|
15417
15791
|
export {
|
|
15792
|
+
BOOLEAN_FLAGS,
|
|
15418
15793
|
CLI_VERSION,
|
|
15794
|
+
DEFAULT_RUN_TIMEOUT_MS,
|
|
15419
15795
|
dispatch,
|
|
15420
15796
|
handleConfigure,
|
|
15421
15797
|
isVersionOlderThan,
|