@alva-ai/toolkit 0.12.0 → 0.12.1-beta.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/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 = 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 textContent(node) {
2080
+ function textContent2(node) {
2081
2081
  if (Array.isArray(node))
2082
- return node.map(textContent).join("");
2082
+ return node.map(textContent2).join("");
2083
2083
  if ((0, domhandler_1.hasChildren)(node) && !(0, domhandler_1.isComment)(node)) {
2084
- return textContent(node.children);
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);
@@ -9416,8 +9417,26 @@ __export(lint_exports, {
9416
9417
  lintBeforeRelease: () => lintBeforeRelease
9417
9418
  });
9418
9419
  import * as fs from "fs";
9420
+ function textContent(result, path) {
9421
+ if (typeof result === "string") return result;
9422
+ if (result instanceof ArrayBuffer) {
9423
+ return new TextDecoder("utf-8").decode(result);
9424
+ }
9425
+ throw new Error(
9426
+ `Cannot lint ${path}: expected text content, got ${typeof result}.`
9427
+ );
9428
+ }
9429
+ async function readPlaybookHtml(opts) {
9430
+ if (opts.client) {
9431
+ return textContent(
9432
+ await opts.client.fs.read({ path: opts.file }),
9433
+ opts.file
9434
+ );
9435
+ }
9436
+ return fs.readFileSync(opts.file, "utf8");
9437
+ }
9419
9438
  async function handleLintPlaybook(opts) {
9420
- const html = fs.readFileSync(opts.file, "utf8");
9439
+ const html = await readPlaybookHtml(opts);
9421
9440
  const contract = opts.contractYaml ? loadContract(opts.contractYaml) : await loadActiveDesignSystem();
9422
9441
  const report = lint(html, contract);
9423
9442
  const output = formatReport(report, opts.format ?? "human");
@@ -9431,15 +9450,7 @@ async function lintBeforeRelease(opts) {
9431
9450
  const result = await opts.client.fs.read({
9432
9451
  path: `~/playbooks/${opts.playbookName}/index.html`
9433
9452
  });
9434
- if (typeof result === "string") {
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
- }
9453
+ html = textContent(result, `~/playbooks/${opts.playbookName}/index.html`);
9443
9454
  }
9444
9455
  const contract = opts.contractYaml ? loadContract(opts.contractYaml) : await loadActiveDesignSystem();
9445
9456
  const report = lint(html, contract);
@@ -9474,11 +9485,13 @@ var init_lint2 = __esm({
9474
9485
  var AlvaError = class extends Error {
9475
9486
  code;
9476
9487
  status;
9477
- constructor(code, message, status) {
9488
+ details;
9489
+ constructor(code, message, status, details) {
9478
9490
  super(message);
9479
9491
  this.name = "AlvaError";
9480
9492
  this.code = code;
9481
9493
  this.status = status;
9494
+ this.details = details;
9482
9495
  }
9483
9496
  };
9484
9497
  var CliUsageError = class extends Error {
@@ -9491,6 +9504,45 @@ var CliUsageError = class extends Error {
9491
9504
  };
9492
9505
 
9493
9506
  // src/resources/fs.ts
9507
+ function isValidUtf8(bytes) {
9508
+ let i = 0;
9509
+ while (i < bytes.length) {
9510
+ const byte = bytes[i];
9511
+ if (byte <= 127) {
9512
+ i += 1;
9513
+ continue;
9514
+ }
9515
+ let needed = 0;
9516
+ let minCodePoint = 0;
9517
+ let codePoint = 0;
9518
+ if (byte >= 194 && byte <= 223) {
9519
+ needed = 1;
9520
+ minCodePoint = 128;
9521
+ codePoint = byte & 31;
9522
+ } else if (byte >= 224 && byte <= 239) {
9523
+ needed = 2;
9524
+ minCodePoint = 2048;
9525
+ codePoint = byte & 15;
9526
+ } else if (byte >= 240 && byte <= 244) {
9527
+ needed = 3;
9528
+ minCodePoint = 65536;
9529
+ codePoint = byte & 7;
9530
+ } else {
9531
+ return false;
9532
+ }
9533
+ if (i + needed >= bytes.length) return false;
9534
+ for (let j = 1; j <= needed; j += 1) {
9535
+ const next = bytes[i + j];
9536
+ if ((next & 192) !== 128) return false;
9537
+ codePoint = codePoint << 6 | next & 63;
9538
+ }
9539
+ if (codePoint < minCodePoint || codePoint > 1114111 || codePoint >= 55296 && codePoint <= 57343) {
9540
+ return false;
9541
+ }
9542
+ i += needed + 1;
9543
+ }
9544
+ return true;
9545
+ }
9494
9546
  var FsResource = class {
9495
9547
  constructor(client) {
9496
9548
  this.client = client;
@@ -9502,15 +9554,14 @@ var FsResource = class {
9502
9554
  query: { path: params.path, offset: params.offset, size: params.size }
9503
9555
  });
9504
9556
  if (!(result instanceof ArrayBuffer)) return result;
9557
+ if (!isValidUtf8(new Uint8Array(result))) {
9558
+ return result;
9559
+ }
9560
+ const text = new TextDecoder("utf-8").decode(result);
9505
9561
  try {
9506
- const text = new TextDecoder("utf-8", { fatal: true }).decode(result);
9507
- try {
9508
- return JSON.parse(text);
9509
- } catch {
9510
- return text;
9511
- }
9562
+ return JSON.parse(text);
9512
9563
  } catch {
9513
- return result;
9564
+ return text;
9514
9565
  }
9515
9566
  }
9516
9567
  /** Write file using JSON body (Mode 2). For text content. */
@@ -9629,7 +9680,8 @@ var RunResource = class {
9629
9680
  working_dir: params.working_dir,
9630
9681
  args: params.args,
9631
9682
  max_heap_size_mb: params.max_heap_size_mb
9632
- }
9683
+ },
9684
+ timeoutMs: params.timeout_ms
9633
9685
  });
9634
9686
  }
9635
9687
  };
@@ -11964,6 +12016,62 @@ function parseResultPayload(result) {
11964
12016
  // src/client.ts
11965
12017
  var DEFAULT_BASE_URL = "https://api-llm.prd.alva.ai";
11966
12018
  var DEFAULT_ARRAYS_BASE_URL = "https://data-tools.prd.space.id";
12019
+ function isRecord(value) {
12020
+ return typeof value === "object" && value !== null;
12021
+ }
12022
+ function stringField(value, field) {
12023
+ if (!isRecord(value)) return void 0;
12024
+ const fieldValue = value[field];
12025
+ return typeof fieldValue === "string" && fieldValue ? fieldValue : void 0;
12026
+ }
12027
+ function describeCause(cause) {
12028
+ if (cause === void 0 || cause === null) {
12029
+ return {};
12030
+ }
12031
+ const details = {};
12032
+ if (cause instanceof Error) {
12033
+ if (cause.name) details.name = cause.name;
12034
+ if (cause.message) details.message = cause.message;
12035
+ const code = stringField(cause, "code");
12036
+ if (code) details.code = code;
12037
+ } else if (isRecord(cause)) {
12038
+ const code = stringField(cause, "code");
12039
+ const name = stringField(cause, "name");
12040
+ const message = stringField(cause, "message");
12041
+ if (code) details.code = code;
12042
+ if (name) details.name = name;
12043
+ if (message) details.message = message;
12044
+ } else {
12045
+ details.message = String(cause);
12046
+ }
12047
+ const parts = [details.code, details.name, details.message].filter(
12048
+ (part) => Boolean(part)
12049
+ );
12050
+ return {
12051
+ message: parts.length > 0 ? parts.join(": ") : void 0,
12052
+ details: Object.keys(details).length > 0 ? details : void 0
12053
+ };
12054
+ }
12055
+ function describeFetchFailure(err) {
12056
+ const message = err instanceof Error && err.message ? err.message : "Network request failed";
12057
+ const details = {};
12058
+ if (err instanceof Error) {
12059
+ details.name = err.name;
12060
+ details.message = err.message;
12061
+ } else {
12062
+ details.message = String(err);
12063
+ }
12064
+ const { message: causeMessage, details: causeDetails } = describeCause(
12065
+ isRecord(err) ? err.cause : void 0
12066
+ );
12067
+ if (causeDetails) {
12068
+ details.cause = causeDetails;
12069
+ }
12070
+ return {
12071
+ message: causeMessage ? `${message}; cause: ${causeMessage}` : message,
12072
+ details
12073
+ };
12074
+ }
11967
12075
  var AlvaClient = class {
11968
12076
  baseUrl;
11969
12077
  arraysBaseUrl;
@@ -11973,6 +12081,16 @@ var AlvaClient = class {
11973
12081
  gaClientId;
11974
12082
  gaSessionId;
11975
12083
  utmParams;
12084
+ signal;
12085
+ /**
12086
+ * Alva chat session that owns work produced through this client (playbooks,
12087
+ * feeds, uploaded files). Forwarded as `X-Alva-Origin-Session-Id` so the
12088
+ * backend can attribute created artifacts to the originating session. This
12089
+ * is a request-context hint, NOT auth — the backend still verifies the
12090
+ * session belongs to the authenticated user before honoring it. Distinct
12091
+ * from `gaSessionId` (browser analytics).
12092
+ */
12093
+ originSessionId;
11976
12094
  _fs;
11977
12095
  _run;
11978
12096
  _deploy;
@@ -12005,6 +12123,8 @@ var AlvaClient = class {
12005
12123
  this.gaClientId = config.gaClientId;
12006
12124
  this.gaSessionId = config.gaSessionId;
12007
12125
  this.utmParams = config.utmParams;
12126
+ this.signal = config.signal;
12127
+ this.originSessionId = config.originSessionId;
12008
12128
  }
12009
12129
  get fs() {
12010
12130
  return this._fs ??= new FsResource(this);
@@ -12119,6 +12239,9 @@ var AlvaClient = class {
12119
12239
  if (this.utmParams) {
12120
12240
  headers["X-Alva-UTM-Params"] = this.utmParams;
12121
12241
  }
12242
+ if (this.originSessionId && !options?.noAuth) {
12243
+ headers["X-Alva-Origin-Session-Id"] = this.originSessionId;
12244
+ }
12122
12245
  let fetchBody;
12123
12246
  if (options?.rawBody !== void 0) {
12124
12247
  headers["Content-Type"] = "application/octet-stream";
@@ -12131,21 +12254,89 @@ var AlvaClient = class {
12131
12254
  fetchBody = JSON.stringify(options.body);
12132
12255
  }
12133
12256
  let response;
12257
+ const timeoutMs = options?.timeoutMs;
12258
+ const externalSignal = options?.signal ?? this.signal;
12259
+ if (externalSignal?.aborted) {
12260
+ throw new AlvaError(
12261
+ "NETWORK_ABORTED",
12262
+ `Request aborted while calling ${method} ${path}`,
12263
+ 0,
12264
+ {
12265
+ method,
12266
+ path
12267
+ }
12268
+ );
12269
+ }
12270
+ const controller = timeoutMs !== void 0 ? new AbortController() : void 0;
12271
+ let didTimeout = false;
12272
+ let timeoutId;
12273
+ let abortListener;
12274
+ if (controller && timeoutMs !== void 0) {
12275
+ if (externalSignal) {
12276
+ abortListener = () => controller.abort(externalSignal.reason);
12277
+ externalSignal.addEventListener("abort", abortListener, { once: true });
12278
+ }
12279
+ timeoutId = setTimeout(() => {
12280
+ didTimeout = true;
12281
+ controller.abort(
12282
+ new Error(
12283
+ `Request timed out after ${timeoutMs}ms while calling ${method} ${path}`
12284
+ )
12285
+ );
12286
+ }, timeoutMs);
12287
+ }
12288
+ const fetchInit = {
12289
+ method,
12290
+ headers,
12291
+ body: fetchBody,
12292
+ signal: controller?.signal ?? externalSignal
12293
+ };
12294
+ if (timeoutMs !== void 0) {
12295
+ fetchInit.timeout = timeoutMs;
12296
+ }
12134
12297
  try {
12135
- response = await fetch(url, {
12298
+ response = await fetch(url, fetchInit);
12299
+ } catch (err) {
12300
+ if (externalSignal?.aborted && !didTimeout) {
12301
+ throw new AlvaError(
12302
+ "NETWORK_ABORTED",
12303
+ `Request aborted while calling ${method} ${path}`,
12304
+ 0,
12305
+ {
12306
+ method,
12307
+ path
12308
+ }
12309
+ );
12310
+ }
12311
+ if (didTimeout) {
12312
+ throw new AlvaError(
12313
+ "NETWORK_TIMEOUT",
12314
+ `Request timed out after ${timeoutMs}ms while calling ${method} ${path}`,
12315
+ 0,
12316
+ { method, path, timeout_ms: timeoutMs }
12317
+ );
12318
+ }
12319
+ const failure = describeFetchFailure(err);
12320
+ throw new AlvaError("NETWORK_ERROR", failure.message, 0, {
12136
12321
  method,
12137
- headers,
12138
- body: fetchBody
12322
+ path,
12323
+ ...failure.details
12139
12324
  });
12140
- } catch (err) {
12141
- throw new AlvaError(
12142
- "NETWORK_ERROR",
12143
- err instanceof Error ? err.message : "Network request failed",
12144
- 0
12145
- );
12325
+ } finally {
12326
+ if (abortListener && externalSignal) {
12327
+ externalSignal.removeEventListener("abort", abortListener);
12328
+ }
12329
+ if (timeoutId !== void 0) {
12330
+ clearTimeout(timeoutId);
12331
+ }
12146
12332
  }
12147
12333
  if (!response.ok) {
12148
- const bodyText = await response.text().catch(() => "");
12334
+ let bodyText = "";
12335
+ try {
12336
+ bodyText = await Promise.resolve(response.text());
12337
+ } catch {
12338
+ bodyText = "";
12339
+ }
12149
12340
  const contentType2 = response.headers.get("content-type") ?? "";
12150
12341
  if (contentType2.includes("application/json") && bodyText) {
12151
12342
  try {
@@ -12263,6 +12454,7 @@ function loadConfig(deps) {
12263
12454
  const gaClientIdEnv = env.ALVA_GA_CLIENT_ID;
12264
12455
  const gaSessionIdEnv = env.ALVA_GA_SESSION_ID;
12265
12456
  const utmParamsEnv = env.ALVA_UTM_PARAMS;
12457
+ const originSessionIdEnv = env.ALVA_SESSION_ID;
12266
12458
  let fileProfile = {};
12267
12459
  const path = configPath({ env, homedir: homedir3 });
12268
12460
  try {
@@ -12286,7 +12478,8 @@ function loadConfig(deps) {
12286
12478
  profile: profileName,
12287
12479
  gaClientId: gaClientIdEnv,
12288
12480
  gaSessionId: gaSessionIdEnv,
12289
- utmParams: utmParamsEnv
12481
+ utmParams: utmParamsEnv,
12482
+ originSessionId: originSessionIdEnv
12290
12483
  };
12291
12484
  }
12292
12485
 
@@ -12928,7 +13121,11 @@ function formatPlaybookSkillFile(file) {
12928
13121
  import * as fs2 from "fs";
12929
13122
  import * as os2 from "os";
12930
13123
  import * as fsPromises2 from "fs/promises";
12931
- var CLI_VERSION = true ? "0.12.0" : "dev";
13124
+ import { Agent, setGlobalDispatcher } from "undici";
13125
+ var CLI_VERSION = true ? "0.12.1-beta.0" : "dev";
13126
+ var DEFAULT_RUN_TIMEOUT_MS = 6e5;
13127
+ var RUN_TIMEOUT_ENV = "ALVA_RUN_TIMEOUT_MS";
13128
+ var configuredRunFetchTimeoutMs;
12932
13129
  function isVersionOlderThan(a, b) {
12933
13130
  const parse4 = (v) => {
12934
13131
  if (!v) return null;
@@ -13152,6 +13349,7 @@ Options:
13152
13349
  --working-dir <dir> Working directory for require() (inline code only)
13153
13350
  --args <json> JSON object passed to require("env").args
13154
13351
  --max-heap-size-mb <mb> Override the V8 heap limit in MB (1-2048, default 256)
13352
+ --timeout-ms <ms> Client HTTP timeout for /api/v1/run (default: ${DEFAULT_RUN_TIMEOUT_MS}; env: ${RUN_TIMEOUT_ENV})
13155
13353
 
13156
13354
  At least one of --code, --local-file, or --entry-path is required.
13157
13355
  These three options are mutually exclusive.
@@ -13183,7 +13381,8 @@ Examples:
13183
13381
  alva run --entry-path "~/feeds/my-feed/v1/src/index.js"
13184
13382
  alva run --entry-path "~/tasks/analyze/src/index.js" --args '{"symbol":"NVDA","limit":50}'
13185
13383
  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`,
13384
+ alva run --entry-path "~/tasks/heavy/src/index.js" --max-heap-size-mb 1024
13385
+ alva run --entry-path "~/feeds/slow/v1/src/index.js" --timeout-ms 900000`,
13187
13386
  deploy: `Usage: alva deploy <subcommand> [options]
13188
13387
 
13189
13388
  Manage scheduled cronjobs that run your scripts on a cron schedule.
@@ -14034,6 +14233,45 @@ function optionalBoundedIntegerFlag(flags, name, command, min, max) {
14034
14233
  }
14035
14234
  return n;
14036
14235
  }
14236
+ function parsePositiveIntegerValue(val, label, command) {
14237
+ const n = Number(val);
14238
+ if (!/^[1-9]\d*$/.test(val) || !Number.isSafeInteger(n)) {
14239
+ const group = command.split(" ")[0];
14240
+ throw new CliUsageError(
14241
+ `${label} must be a positive integer for '${command}', got '${val}'`,
14242
+ group
14243
+ );
14244
+ }
14245
+ return n;
14246
+ }
14247
+ function runtimeEnv(deps) {
14248
+ return deps?.env ?? process.env;
14249
+ }
14250
+ function runTimeoutMs(flags, deps) {
14251
+ if (flags["timeout-ms"] !== void 0) {
14252
+ return parsePositiveIntegerValue(
14253
+ flags["timeout-ms"],
14254
+ "--timeout-ms",
14255
+ "run"
14256
+ );
14257
+ }
14258
+ const envValue = runtimeEnv(deps)[RUN_TIMEOUT_ENV];
14259
+ if (envValue !== void 0 && envValue !== "") {
14260
+ return parsePositiveIntegerValue(envValue, RUN_TIMEOUT_ENV, "run");
14261
+ }
14262
+ return DEFAULT_RUN_TIMEOUT_MS;
14263
+ }
14264
+ function configureRunFetchTimeout(timeoutMs, deps) {
14265
+ if (deps?.mode === "jagent") return;
14266
+ if (configuredRunFetchTimeoutMs === timeoutMs) return;
14267
+ setGlobalDispatcher(
14268
+ new Agent({
14269
+ headersTimeout: timeoutMs,
14270
+ bodyTimeout: timeoutMs
14271
+ })
14272
+ );
14273
+ configuredRunFetchTimeoutMs = timeoutMs;
14274
+ }
14037
14275
  function requireGroupSubscriptionTargetType(flags, command) {
14038
14276
  const val = requireFlag(flags, "target-type", command).trim().toLowerCase();
14039
14277
  if (val === "feed" || val === "playbook") return val;
@@ -14110,7 +14348,7 @@ function jsonRequiredFlag(flags, name, command) {
14110
14348
  );
14111
14349
  }
14112
14350
  }
14113
- function jsonSchemaStringFlag(flags, command) {
14351
+ function jsonSchemaStringFlag(flags, command, deps) {
14114
14352
  const inlineSchema = flags["params-schema"];
14115
14353
  const schemaFile = flags["params-schema-file"];
14116
14354
  if (inlineSchema !== void 0 && schemaFile !== void 0) {
@@ -14119,7 +14357,7 @@ function jsonSchemaStringFlag(flags, command) {
14119
14357
  command.split(" ")[0]
14120
14358
  );
14121
14359
  }
14122
- const raw = schemaFile !== void 0 ? fs2.readFileSync(schemaFile, "utf-8") : inlineSchema;
14360
+ const raw = schemaFile !== void 0 ? readLocalTextFile(schemaFile, command, "params-schema-file", deps) : inlineSchema;
14123
14361
  if (raw === void 0) return void 0;
14124
14362
  try {
14125
14363
  JSON.parse(raw);
@@ -14132,7 +14370,30 @@ function jsonSchemaStringFlag(flags, command) {
14132
14370
  }
14133
14371
  return raw;
14134
14372
  }
14135
- async function dispatch(client, args, meta) {
14373
+ function localFileUnsupported(command, flag) {
14374
+ return new CliUsageError(
14375
+ `--${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}'.`,
14376
+ command.split(" ")[0]
14377
+ );
14378
+ }
14379
+ function assertLocalFileAvailable(command, flag, deps) {
14380
+ if (deps?.mode === "jagent") {
14381
+ throw localFileUnsupported(command, flag);
14382
+ }
14383
+ }
14384
+ function readLocalTextFile(path, command, flag, deps) {
14385
+ assertLocalFileAvailable(command, flag, deps);
14386
+ return fs2.readFileSync(path, "utf-8");
14387
+ }
14388
+ function readLocalFileBytes(path, command, flag, deps) {
14389
+ assertLocalFileAvailable(command, flag, deps);
14390
+ return fs2.readFileSync(path);
14391
+ }
14392
+ function writeLocalFileBytes(path, data, command, flag, deps) {
14393
+ assertLocalFileAvailable(command, flag, deps);
14394
+ fs2.writeFileSync(path, data);
14395
+ }
14396
+ async function dispatch(client, args, meta, deps) {
14136
14397
  const group = args[0];
14137
14398
  if (!group || group === "--help" || group === "-h") {
14138
14399
  return { _help: true, text: HELP_TEXT };
@@ -14194,7 +14455,12 @@ async function dispatch(client, args, meta) {
14194
14455
  });
14195
14456
  case "write":
14196
14457
  if (flags["file"]) {
14197
- const fileData = fs2.readFileSync(flags["file"]);
14458
+ const fileData = readLocalFileBytes(
14459
+ flags["file"],
14460
+ "fs write",
14461
+ "file",
14462
+ deps
14463
+ );
14198
14464
  return client.fs.rawWrite({
14199
14465
  path: requireFlag(flags, "path", "fs write"),
14200
14466
  body: fileData,
@@ -14276,8 +14542,15 @@ async function dispatch(client, args, meta) {
14276
14542
  }
14277
14543
  let code = flags["code"];
14278
14544
  if (flags["local-file"]) {
14279
- code = fs2.readFileSync(flags["local-file"], "utf-8");
14545
+ code = readLocalTextFile(
14546
+ flags["local-file"],
14547
+ "run",
14548
+ "local-file",
14549
+ deps
14550
+ );
14280
14551
  }
14552
+ const timeout_ms = runTimeoutMs(flags, deps);
14553
+ configureRunFetchTimeout(timeout_ms, deps);
14281
14554
  return client.run.execute({
14282
14555
  code,
14283
14556
  entry_path: flags["entry-path"],
@@ -14289,7 +14562,8 @@ async function dispatch(client, args, meta) {
14289
14562
  "run",
14290
14563
  1,
14291
14564
  2048
14292
- )
14565
+ ),
14566
+ timeout_ms
14293
14567
  });
14294
14568
  }
14295
14569
  case "deploy": {
@@ -14355,7 +14629,7 @@ async function dispatch(client, args, meta) {
14355
14629
  return client.deploy.listRuns({
14356
14630
  cronjob_id: requireNumericFlag(flags, "id", "deploy runs"),
14357
14631
  first: num(flags["first"]),
14358
- cursor: num(flags["cursor"])
14632
+ cursor: flags["cursor"]
14359
14633
  });
14360
14634
  case "run-logs":
14361
14635
  return client.deploy.getRunLogs({
@@ -14512,7 +14786,11 @@ async function dispatch(client, args, meta) {
14512
14786
  "entry-script-path",
14513
14787
  "functions register"
14514
14788
  ),
14515
- params_schema: jsonSchemaStringFlag(flags, "functions register"),
14789
+ params_schema: jsonSchemaStringFlag(
14790
+ flags,
14791
+ "functions register",
14792
+ deps
14793
+ ),
14516
14794
  allow_charges: boolFlag(flags["allow-charges"])
14517
14795
  });
14518
14796
  case "list":
@@ -14605,7 +14883,7 @@ async function dispatch(client, args, meta) {
14605
14883
  });
14606
14884
  if (lintReport.summary.warnings > 0) {
14607
14885
  const { formatReport: formatReport2 } = await Promise.resolve().then(() => (init_report(), report_exports));
14608
- process.stderr.write(
14886
+ (deps?.stderr ?? process.stderr).write(
14609
14887
  "design lint warnings:\n" + formatReport2(lintReport, "human") + "\n"
14610
14888
  );
14611
14889
  }
@@ -14647,7 +14925,15 @@ async function dispatch(client, args, meta) {
14647
14925
  }
14648
14926
  const format = formatFlag ?? "human";
14649
14927
  const { handleLintPlaybook: handleLintPlaybook2 } = await Promise.resolve().then(() => (init_lint2(), lint_exports));
14650
- const { exitCode, output } = await handleLintPlaybook2({ file, format });
14928
+ const { exitCode, output } = await handleLintPlaybook2({
14929
+ file,
14930
+ format,
14931
+ client: deps?.mode === "jagent" ? client : void 0
14932
+ });
14933
+ if (deps?.mode === "jagent") {
14934
+ if (exitCode !== 0) throw new Error(output);
14935
+ return output;
14936
+ }
14651
14937
  process.stdout.write(output + (output.endsWith("\n") ? "" : "\n"));
14652
14938
  if (exitCode !== 0) process.exit(exitCode);
14653
14939
  return void 0;
@@ -15108,6 +15394,7 @@ async function dispatch(client, args, meta) {
15108
15394
  }
15109
15395
  case "screenshot": {
15110
15396
  const outFile = requireFlag(flags, "out", "screenshot");
15397
+ assertLocalFileAvailable("screenshot", "out", deps);
15111
15398
  const compressQuality = flags["compress-quality"];
15112
15399
  const compressMaxWidth = flags["compress-max-width"];
15113
15400
  const result = await client.screenshot.capture({
@@ -15125,7 +15412,13 @@ async function dispatch(client, args, meta) {
15125
15412
  "screenshot"
15126
15413
  );
15127
15414
  }
15128
- fs2.writeFileSync(outFile, buf);
15415
+ writeLocalFileBytes(
15416
+ outFile,
15417
+ new Uint8Array(buf),
15418
+ "screenshot",
15419
+ "out",
15420
+ deps
15421
+ );
15129
15422
  return { written: outFile, bytes: buf.length };
15130
15423
  }
15131
15424
  case "portfolio": {
@@ -15354,7 +15647,8 @@ async function main() {
15354
15647
  arraysBaseUrl: config.arraysBaseUrl,
15355
15648
  gaClientId: config.gaClientId,
15356
15649
  gaSessionId: config.gaSessionId,
15357
- utmParams: config.utmParams
15650
+ utmParams: config.utmParams,
15651
+ originSessionId: config.originSessionId
15358
15652
  });
15359
15653
  const cleanArgs = stripGlobalFlags(rawArgs);
15360
15654
  const result = await dispatch(client, cleanArgs, {
@@ -15397,7 +15691,8 @@ ${help}
15397
15691
  const error = {
15398
15692
  code: err.code,
15399
15693
  message: err.message,
15400
- status: err.status
15694
+ status: err.status,
15695
+ ...err.details !== void 0 ? { details: err.details } : {}
15401
15696
  };
15402
15697
  process.stderr.write(`${JSON.stringify({ error }, null, 2)}
15403
15698
  `);
@@ -15415,7 +15710,9 @@ if (isDirectRun) {
15415
15710
  main();
15416
15711
  }
15417
15712
  export {
15713
+ BOOLEAN_FLAGS,
15418
15714
  CLI_VERSION,
15715
+ DEFAULT_RUN_TIMEOUT_MS,
15419
15716
  dispatch,
15420
15717
  handleConfigure,
15421
15718
  isVersionOlderThan,