@alva-ai/toolkit 0.11.3-beta.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);
@@ -7761,7 +7762,7 @@ body {
7761
7762
  .markdown-container code {
7762
7763
  display: inline-block;
7763
7764
  vertical-align: middle;
7764
- box-shadow: inset 0 0 0 1px var(--line-l07);
7765
+ box-shadow: inset 0 0 0 0.5px var(--line-l12);
7765
7766
  font-size: 12px;
7766
7767
  line-height: 20px;
7767
7768
  letter-spacing: 0.12px;
@@ -7769,7 +7770,8 @@ body {
7769
7770
  margin: 0 var(--spacing-xxs);
7770
7771
  }
7771
7772
  .markdown-container pre {
7772
- border: 1px solid var(--line-l07);
7773
+ border: 0.5px solid var(--line-l12);
7774
+ border-radius: var(--radius-ct-s);
7773
7775
  font-size: 12px;
7774
7776
  line-height: 20px;
7775
7777
  letter-spacing: 0.12px;
@@ -9415,8 +9417,26 @@ __export(lint_exports, {
9415
9417
  lintBeforeRelease: () => lintBeforeRelease
9416
9418
  });
9417
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
+ }
9418
9438
  async function handleLintPlaybook(opts) {
9419
- const html = fs.readFileSync(opts.file, "utf8");
9439
+ const html = await readPlaybookHtml(opts);
9420
9440
  const contract = opts.contractYaml ? loadContract(opts.contractYaml) : await loadActiveDesignSystem();
9421
9441
  const report = lint(html, contract);
9422
9442
  const output = formatReport(report, opts.format ?? "human");
@@ -9430,15 +9450,7 @@ async function lintBeforeRelease(opts) {
9430
9450
  const result = await opts.client.fs.read({
9431
9451
  path: `~/playbooks/${opts.playbookName}/index.html`
9432
9452
  });
9433
- if (typeof result === "string") {
9434
- html = result;
9435
- } else if (result instanceof ArrayBuffer) {
9436
- html = new TextDecoder("utf-8").decode(result);
9437
- } else {
9438
- throw new Error(
9439
- `Cannot lint ~/playbooks/${opts.playbookName}/index.html: expected text content, got ${typeof result}.`
9440
- );
9441
- }
9453
+ html = textContent(result, `~/playbooks/${opts.playbookName}/index.html`);
9442
9454
  }
9443
9455
  const contract = opts.contractYaml ? loadContract(opts.contractYaml) : await loadActiveDesignSystem();
9444
9456
  const report = lint(html, contract);
@@ -9473,11 +9485,13 @@ var init_lint2 = __esm({
9473
9485
  var AlvaError = class extends Error {
9474
9486
  code;
9475
9487
  status;
9476
- constructor(code, message, status) {
9488
+ details;
9489
+ constructor(code, message, status, details) {
9477
9490
  super(message);
9478
9491
  this.name = "AlvaError";
9479
9492
  this.code = code;
9480
9493
  this.status = status;
9494
+ this.details = details;
9481
9495
  }
9482
9496
  };
9483
9497
  var CliUsageError = class extends Error {
@@ -9490,6 +9504,45 @@ var CliUsageError = class extends Error {
9490
9504
  };
9491
9505
 
9492
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
+ }
9493
9546
  var FsResource = class {
9494
9547
  constructor(client) {
9495
9548
  this.client = client;
@@ -9501,15 +9554,14 @@ var FsResource = class {
9501
9554
  query: { path: params.path, offset: params.offset, size: params.size }
9502
9555
  });
9503
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);
9504
9561
  try {
9505
- const text = new TextDecoder("utf-8", { fatal: true }).decode(result);
9506
- try {
9507
- return JSON.parse(text);
9508
- } catch {
9509
- return text;
9510
- }
9562
+ return JSON.parse(text);
9511
9563
  } catch {
9512
- return result;
9564
+ return text;
9513
9565
  }
9514
9566
  }
9515
9567
  /** Write file using JSON body (Mode 2). For text content. */
@@ -9628,7 +9680,8 @@ var RunResource = class {
9628
9680
  working_dir: params.working_dir,
9629
9681
  args: params.args,
9630
9682
  max_heap_size_mb: params.max_heap_size_mb
9631
- }
9683
+ },
9684
+ timeoutMs: params.timeout_ms
9632
9685
  });
9633
9686
  }
9634
9687
  };
@@ -9843,6 +9896,69 @@ var PlaybooksResource = class {
9843
9896
  this.client = client;
9844
9897
  }
9845
9898
  client;
9899
+ /**
9900
+ * Resolve playbook ids to named, addressable records (mono-meta#584 A2).
9901
+ * Visibility-gated server-side; ids the caller cannot see — and DELETED
9902
+ * playbook ids — return no row. Treat a missing id as "deleted or not
9903
+ * visible" (the subscriptions list's `target_status` distinguishes ghosts).
9904
+ * Ids are strings (snowflake-safe). Max 100 per call.
9905
+ *
9906
+ * Auth is optional (like `trending`): with an API key, private/paid
9907
+ * visibility is evaluated for the caller; without one, only public
9908
+ * playbooks resolve. The server decides — no client-side gate.
9909
+ */
9910
+ async getByIds(ids) {
9911
+ return await this.client._request("GET", "/api/v1/playbooks", {
9912
+ query: { ids: ids.join(",") }
9913
+ });
9914
+ }
9915
+ /**
9916
+ * List a user's playbooks by owner username (mono-meta#584 C10).
9917
+ * Visibility-gated: another user's private playbooks are omitted.
9918
+ * Auth is optional (like `trending`); without credentials only public
9919
+ * playbooks are listed.
9920
+ */
9921
+ async listByOwner(params) {
9922
+ const query = { owner: params.owner };
9923
+ if (params.limit !== void 0 && params.limit > 0) {
9924
+ query.limit = String(params.limit);
9925
+ }
9926
+ if (params.cursor) query.cursor = params.cursor;
9927
+ return await this.client._request("GET", "/api/v1/playbooks", {
9928
+ query
9929
+ });
9930
+ }
9931
+ /**
9932
+ * Get one playbook by numeric id or by "owner/name" ref. Returns null when
9933
+ * not found / not visible / deleted.
9934
+ */
9935
+ async get(params) {
9936
+ if (params.id) {
9937
+ const resp = await this.getByIds([params.id]);
9938
+ return resp.items[0] ?? null;
9939
+ }
9940
+ if (params.ref) {
9941
+ const slash = params.ref.indexOf("/");
9942
+ if (slash <= 0 || slash === params.ref.length - 1) {
9943
+ throw new AlvaError(
9944
+ "INVALID_ARGUMENT",
9945
+ `Invalid ref "${params.ref}". Expected "owner/name".`,
9946
+ 400
9947
+ );
9948
+ }
9949
+ const owner = params.ref.slice(0, slash);
9950
+ const name = params.ref.slice(slash + 1);
9951
+ let cursor;
9952
+ for (; ; ) {
9953
+ const page = await this.listByOwner({ owner, cursor, limit: 100 });
9954
+ const hit = page.items.find((item) => item.name === name);
9955
+ if (hit) return hit;
9956
+ if (!page.has_next || !page.next_cursor) return null;
9957
+ cursor = page.next_cursor;
9958
+ }
9959
+ }
9960
+ throw new AlvaError("INVALID_ARGUMENT", "id or ref is required", 400);
9961
+ }
9846
9962
  /**
9847
9963
  * List trending / searchable playbooks. Auth is optional: when the client
9848
9964
  * has an API key it is forwarded, otherwise this uses the public surface.
@@ -11628,6 +11744,42 @@ var SubscriptionsResource = class {
11628
11744
  query
11629
11745
  });
11630
11746
  }
11747
+ /**
11748
+ * List the playbooks the caller FOLLOWS (the social relation — the UI's
11749
+ * "Subscribed Playbooks"). Rows carry the playbook identity; follows of
11750
+ * deleted playbooks are filtered server-side. Cursor-paginated.
11751
+ */
11752
+ async follows(params = {}) {
11753
+ this.client._requireAuth();
11754
+ const query = {};
11755
+ if (params.limit !== void 0 && params.limit > 0) {
11756
+ query.limit = String(params.limit);
11757
+ }
11758
+ if (params.cursor) query.cursor = params.cursor;
11759
+ return this.client._request("GET", "/api/v1/me/follows", {
11760
+ query
11761
+ });
11762
+ }
11763
+ /**
11764
+ * Disable alerts for many playbook/feed targets BY TARGET ID in one
11765
+ * idempotent call (max 100 ids). Ids are strings (snowflake-safe). Works
11766
+ * for ghost rows (deleted targets) because no name resolution happens —
11767
+ * the per-id results report `INVALID_ID` for malformed entries while
11768
+ * valid ones proceed. Safe to re-run: already-gone rows are no-ops.
11769
+ */
11770
+ async unsubscribeBatch(params) {
11771
+ this.client._requireAuth();
11772
+ return this.client._request(
11773
+ "POST",
11774
+ "/api/v1/subscriptions/unsubscribe-batch",
11775
+ {
11776
+ body: {
11777
+ playbook_ids: params.playbookIds ?? [],
11778
+ feed_ids: params.feedIds ?? []
11779
+ }
11780
+ }
11781
+ );
11782
+ }
11631
11783
  };
11632
11784
 
11633
11785
  // src/resources/channelGroupSubscriptions.ts
@@ -11864,6 +12016,62 @@ function parseResultPayload(result) {
11864
12016
  // src/client.ts
11865
12017
  var DEFAULT_BASE_URL = "https://api-llm.prd.alva.ai";
11866
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
+ }
11867
12075
  var AlvaClient = class {
11868
12076
  baseUrl;
11869
12077
  arraysBaseUrl;
@@ -11873,6 +12081,16 @@ var AlvaClient = class {
11873
12081
  gaClientId;
11874
12082
  gaSessionId;
11875
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;
11876
12094
  _fs;
11877
12095
  _run;
11878
12096
  _deploy;
@@ -11905,6 +12123,8 @@ var AlvaClient = class {
11905
12123
  this.gaClientId = config.gaClientId;
11906
12124
  this.gaSessionId = config.gaSessionId;
11907
12125
  this.utmParams = config.utmParams;
12126
+ this.signal = config.signal;
12127
+ this.originSessionId = config.originSessionId;
11908
12128
  }
11909
12129
  get fs() {
11910
12130
  return this._fs ??= new FsResource(this);
@@ -12019,6 +12239,9 @@ var AlvaClient = class {
12019
12239
  if (this.utmParams) {
12020
12240
  headers["X-Alva-UTM-Params"] = this.utmParams;
12021
12241
  }
12242
+ if (this.originSessionId && !options?.noAuth) {
12243
+ headers["X-Alva-Origin-Session-Id"] = this.originSessionId;
12244
+ }
12022
12245
  let fetchBody;
12023
12246
  if (options?.rawBody !== void 0) {
12024
12247
  headers["Content-Type"] = "application/octet-stream";
@@ -12031,21 +12254,89 @@ var AlvaClient = class {
12031
12254
  fetchBody = JSON.stringify(options.body);
12032
12255
  }
12033
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
+ }
12034
12297
  try {
12035
- 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, {
12036
12321
  method,
12037
- headers,
12038
- body: fetchBody
12322
+ path,
12323
+ ...failure.details
12039
12324
  });
12040
- } catch (err) {
12041
- throw new AlvaError(
12042
- "NETWORK_ERROR",
12043
- err instanceof Error ? err.message : "Network request failed",
12044
- 0
12045
- );
12325
+ } finally {
12326
+ if (abortListener && externalSignal) {
12327
+ externalSignal.removeEventListener("abort", abortListener);
12328
+ }
12329
+ if (timeoutId !== void 0) {
12330
+ clearTimeout(timeoutId);
12331
+ }
12046
12332
  }
12047
12333
  if (!response.ok) {
12048
- const bodyText = await response.text().catch(() => "");
12334
+ let bodyText = "";
12335
+ try {
12336
+ bodyText = await Promise.resolve(response.text());
12337
+ } catch {
12338
+ bodyText = "";
12339
+ }
12049
12340
  const contentType2 = response.headers.get("content-type") ?? "";
12050
12341
  if (contentType2.includes("application/json") && bodyText) {
12051
12342
  try {
@@ -12163,6 +12454,7 @@ function loadConfig(deps) {
12163
12454
  const gaClientIdEnv = env.ALVA_GA_CLIENT_ID;
12164
12455
  const gaSessionIdEnv = env.ALVA_GA_SESSION_ID;
12165
12456
  const utmParamsEnv = env.ALVA_UTM_PARAMS;
12457
+ const originSessionIdEnv = env.ALVA_SESSION_ID;
12166
12458
  let fileProfile = {};
12167
12459
  const path = configPath({ env, homedir: homedir3 });
12168
12460
  try {
@@ -12186,7 +12478,8 @@ function loadConfig(deps) {
12186
12478
  profile: profileName,
12187
12479
  gaClientId: gaClientIdEnv,
12188
12480
  gaSessionId: gaSessionIdEnv,
12189
- utmParams: utmParamsEnv
12481
+ utmParams: utmParamsEnv,
12482
+ originSessionId: originSessionIdEnv
12190
12483
  };
12191
12484
  }
12192
12485
 
@@ -12828,7 +13121,11 @@ function formatPlaybookSkillFile(file) {
12828
13121
  import * as fs2 from "fs";
12829
13122
  import * as os2 from "os";
12830
13123
  import * as fsPromises2 from "fs/promises";
12831
- var CLI_VERSION = true ? "0.11.3-beta.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;
12832
13129
  function isVersionOlderThan(a, b) {
12833
13130
  const parse4 = (v) => {
12834
13131
  if (!v) return null;
@@ -12858,7 +13155,7 @@ Commands:
12858
13155
  release Feed and playbook releases (feed, playbook-draft, playbook)
12859
13156
  lint Design-system lint (playbook)
12860
13157
  feed Feed lifecycle management (delete)
12861
- playbooks Playbook discovery (trending) and visibility
13158
+ playbooks Playbook discovery (trending, get, list) and visibility
12862
13159
  functions Playbook UDF function management (register, list, delete, invoke, allowance)
12863
13160
  secrets Secret management (create, list, get, update, delete)
12864
13161
  sdk SDK documentation (doc, partitions, partition-summary)
@@ -12868,7 +13165,7 @@ Commands:
12868
13165
  notification-history Notification delivery history (list-playbook, list-feed)
12869
13166
  notification-preferences Notification preferences (list, enable-session-completed, disable-session-completed)
12870
13167
  feedback Submit user-confirmed Alva platform feedback (submit)
12871
- subscriptions Subscribe to playbooks/feeds (subscribe-playbook, unsubscribe-playbook, subscribe-feed, unsubscribe-feed, list)
13168
+ subscriptions Follows + push alerts (subscribe-playbook, unsubscribe-playbook, subscribe-feed, unsubscribe-feed, unsubscribe, list, follows)
12872
13169
  channel Channel group operations (group-subscriptions context, list, subscribe, unsubscribe)
12873
13170
  remix Save playbook remix lineage
12874
13171
  portfolio Connected-account portfolio (accounts, summary, activities)
@@ -13052,6 +13349,7 @@ Options:
13052
13349
  --working-dir <dir> Working directory for require() (inline code only)
13053
13350
  --args <json> JSON object passed to require("env").args
13054
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})
13055
13353
 
13056
13354
  At least one of --code, --local-file, or --entry-path is required.
13057
13355
  These three options are mutually exclusive.
@@ -13083,7 +13381,8 @@ Examples:
13083
13381
  alva run --entry-path "~/feeds/my-feed/v1/src/index.js"
13084
13382
  alva run --entry-path "~/tasks/analyze/src/index.js" --args '{"symbol":"NVDA","limit":50}'
13085
13383
  alva run --local-file ./my-script.js --args '{"symbol":"BTC"}'
13086
- 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`,
13087
13386
  deploy: `Usage: alva deploy <subcommand> [options]
13088
13387
 
13089
13388
  Manage scheduled cronjobs that run your scripts on a cron schedule.
@@ -13185,12 +13484,25 @@ Examples:
13185
13484
  alva feed delete --id 42`,
13186
13485
  playbooks: `Usage: alva playbooks <subcommand> [options]
13187
13486
 
13188
- Find public playbooks with an agent-friendly response shape.
13487
+ Find and resolve playbooks with an agent-friendly response shape.
13189
13488
 
13190
13489
  Subcommands:
13191
13490
  trending List trending playbooks
13491
+ get Resolve playbooks by id(s) or "owner/name" ref
13492
+ list List a user's playbooks by owner username
13192
13493
  set-visibility Set a playbook's visibility (requires auth)
13193
13494
 
13495
+ Get flags:
13496
+ --id <n> Single numeric playbook id
13497
+ --ids <a,b> Comma-separated ids (max 100); ids you cannot see
13498
+ \u2014 and DELETED playbooks \u2014 return no row
13499
+ --ref <owner/name> Resolve by handle
13500
+
13501
+ List flags:
13502
+ --owner <username> Owner username (required)
13503
+ --limit <n> Max results per page
13504
+ --cursor <cursor> Pagination cursor from previous response
13505
+
13194
13506
  Trending flags:
13195
13507
  --keyword <text> Search text
13196
13508
  --tags <a,b> Comma-separated tags
@@ -13220,7 +13532,9 @@ Notes:
13220
13532
 
13221
13533
  Examples:
13222
13534
  alva playbooks trending --keyword scanner --tags macro,ai --sort recent --limit 5
13223
- alva playbooks trending --tag btc --cursor abc
13535
+ alva playbooks get --ids 8009,8010
13536
+ alva playbooks get --ref alice/btc-dashboard
13537
+ alva playbooks list --owner alice
13224
13538
  alva playbooks set-visibility --name my-scanner --visibility private
13225
13539
  alva playbooks set-visibility --name my-scanner --visibility public`,
13226
13540
  functions: `Usage: alva functions <subcommand> [options]
@@ -13556,33 +13870,63 @@ Examples:
13556
13870
  alva feedback submit --summary "bad quote data" --category data_quality`,
13557
13871
  subscriptions: `Usage: alva subscriptions <subcommand> [options]
13558
13872
 
13559
- Subscribe to playbooks and feeds.
13873
+ Three DISTINCT concepts share the word "subscribe" in the product:
13874
+ - FOLLOW \u2014 the social relation (the UI's "Subscribed Playbooks").
13875
+ Enumerate with: alva subscriptions follows
13876
+ - ALERTS \u2014 push/notification opt-ins (what list returns).
13877
+ - PURCHASE \u2014 paid playbook access / the SaaS plan. NOT this command.
13878
+
13879
+ Operations:
13560
13880
  - subscribe-playbook is a CASCADE: follows the playbook AND enables alerts
13561
13881
  on all its push-enabled automations (one call). unsubscribe-playbook
13562
- reverses both (unfollow + disable all of its alerts).
13882
+ reverses both and reports exactly what it changed
13883
+ ({unfollowed, wildcard_disabled}).
13563
13884
  - subscribe-feed / unsubscribe-feed toggle ONE feed's alert (a single
13564
13885
  automation) without touching the playbook follow.
13886
+ - unsubscribe disables alerts BY TARGET ID \u2014 bulk, idempotent, and the
13887
+ only way to clear ghost rows whose playbook/feed was deleted
13888
+ (name-addressed unsubscribe 404s on deleted targets).
13565
13889
 
13566
13890
  Subcommands:
13567
13891
  subscribe-playbook Subscribe a playbook (follow + enable all its alerts)
13568
13892
  unsubscribe-playbook Unsubscribe a playbook (unfollow + disable its alerts)
13569
13893
  subscribe-feed Enable alerts for a single feed
13570
13894
  unsubscribe-feed Disable alerts for a single feed
13571
- list List the caller's active subscriptions
13895
+ unsubscribe Bulk disable alerts by target id (handles ghosts)
13896
+ list List the caller's active alert subscriptions
13897
+ follows List the playbooks the caller follows
13572
13898
 
13573
- Subscribe/unsubscribe flags (playbook + feed):
13899
+ Subscribe/unsubscribe flags (playbook + feed, name-addressed):
13574
13900
  --username <user> Owner's username (required)
13575
13901
  --name <name> URL-safe playbook or feed name (required)
13576
13902
 
13903
+ Unsubscribe (by id) flags:
13904
+ --playbook-ids <a,b> Comma-separated playbook target ids
13905
+ --feed-ids <a,b> Comma-separated feed target ids
13906
+ (at least one of the two; max 100 ids total)
13907
+
13577
13908
  List flags:
13578
- --first <n> Optional page size
13909
+ --first <n> Optional page size (response carries total_count \u2014
13910
+ when items < total_count, keep paginating)
13911
+ --cursor <token> Optional cursor from the previous page
13912
+
13913
+ Follows flags:
13914
+ --limit <n> Optional page size
13579
13915
  --cursor <token> Optional cursor from the previous page
13580
13916
 
13917
+ List response notes:
13918
+ items[].kind PLAYBOOK_ALERTS (playbook-level wildcard) | FEED_ALERT
13919
+ items[].following Whether the caller also FOLLOWS the playbook
13920
+ items[].target_status ACTIVE | TARGET_DELETED (ghost \u2014 clear via
13921
+ unsubscribe --playbook-ids/--feed-ids) | PAUSED
13922
+ items[].playbook {owner_username, name, display_name} for PLAYBOOK rows
13923
+
13581
13924
  Examples:
13582
13925
  alva subscriptions subscribe-playbook --username alice --name btc-dashboard
13583
13926
  alva subscriptions subscribe-feed --username alice --name btc-ema-cross
13584
- alva subscriptions unsubscribe-feed --username alice --name btc-ema-cross
13585
- alva subscriptions list --first 20`,
13927
+ alva subscriptions unsubscribe --playbook-ids 8009,8010 --feed-ids 13292
13928
+ alva subscriptions list --first 200
13929
+ alva subscriptions follows`,
13586
13930
  channel: `Usage: alva channel group-subscriptions <subcommand> [options]
13587
13931
 
13588
13932
  Manage push notifications delivered into the external group chat attached
@@ -13889,6 +14233,45 @@ function optionalBoundedIntegerFlag(flags, name, command, min, max) {
13889
14233
  }
13890
14234
  return n;
13891
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
+ }
13892
14275
  function requireGroupSubscriptionTargetType(flags, command) {
13893
14276
  const val = requireFlag(flags, "target-type", command).trim().toLowerCase();
13894
14277
  if (val === "feed" || val === "playbook") return val;
@@ -13965,7 +14348,7 @@ function jsonRequiredFlag(flags, name, command) {
13965
14348
  );
13966
14349
  }
13967
14350
  }
13968
- function jsonSchemaStringFlag(flags, command) {
14351
+ function jsonSchemaStringFlag(flags, command, deps) {
13969
14352
  const inlineSchema = flags["params-schema"];
13970
14353
  const schemaFile = flags["params-schema-file"];
13971
14354
  if (inlineSchema !== void 0 && schemaFile !== void 0) {
@@ -13974,7 +14357,7 @@ function jsonSchemaStringFlag(flags, command) {
13974
14357
  command.split(" ")[0]
13975
14358
  );
13976
14359
  }
13977
- 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;
13978
14361
  if (raw === void 0) return void 0;
13979
14362
  try {
13980
14363
  JSON.parse(raw);
@@ -13987,7 +14370,30 @@ function jsonSchemaStringFlag(flags, command) {
13987
14370
  }
13988
14371
  return raw;
13989
14372
  }
13990
- 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) {
13991
14397
  const group = args[0];
13992
14398
  if (!group || group === "--help" || group === "-h") {
13993
14399
  return { _help: true, text: HELP_TEXT };
@@ -14049,7 +14455,12 @@ async function dispatch(client, args, meta) {
14049
14455
  });
14050
14456
  case "write":
14051
14457
  if (flags["file"]) {
14052
- const fileData = fs2.readFileSync(flags["file"]);
14458
+ const fileData = readLocalFileBytes(
14459
+ flags["file"],
14460
+ "fs write",
14461
+ "file",
14462
+ deps
14463
+ );
14053
14464
  return client.fs.rawWrite({
14054
14465
  path: requireFlag(flags, "path", "fs write"),
14055
14466
  body: fileData,
@@ -14131,8 +14542,15 @@ async function dispatch(client, args, meta) {
14131
14542
  }
14132
14543
  let code = flags["code"];
14133
14544
  if (flags["local-file"]) {
14134
- code = fs2.readFileSync(flags["local-file"], "utf-8");
14545
+ code = readLocalTextFile(
14546
+ flags["local-file"],
14547
+ "run",
14548
+ "local-file",
14549
+ deps
14550
+ );
14135
14551
  }
14552
+ const timeout_ms = runTimeoutMs(flags, deps);
14553
+ configureRunFetchTimeout(timeout_ms, deps);
14136
14554
  return client.run.execute({
14137
14555
  code,
14138
14556
  entry_path: flags["entry-path"],
@@ -14144,7 +14562,8 @@ async function dispatch(client, args, meta) {
14144
14562
  "run",
14145
14563
  1,
14146
14564
  2048
14147
- )
14565
+ ),
14566
+ timeout_ms
14148
14567
  });
14149
14568
  }
14150
14569
  case "deploy": {
@@ -14210,7 +14629,7 @@ async function dispatch(client, args, meta) {
14210
14629
  return client.deploy.listRuns({
14211
14630
  cronjob_id: requireNumericFlag(flags, "id", "deploy runs"),
14212
14631
  first: num(flags["first"]),
14213
- cursor: num(flags["cursor"])
14632
+ cursor: flags["cursor"]
14214
14633
  });
14215
14634
  case "run-logs":
14216
14635
  return client.deploy.getRunLogs({
@@ -14270,6 +14689,28 @@ async function dispatch(client, args, meta) {
14270
14689
  requireFlag(flags, "visibility", "playbooks set-visibility")
14271
14690
  )
14272
14691
  });
14692
+ case "get": {
14693
+ const ids = csvList(flags["ids"]);
14694
+ if (ids && ids.length > 0) {
14695
+ return client.playbooks.getByIds(ids);
14696
+ }
14697
+ if (flags["id"]) {
14698
+ return client.playbooks.get({ id: flags["id"] });
14699
+ }
14700
+ if (flags["ref"]) {
14701
+ return client.playbooks.get({ ref: flags["ref"] });
14702
+ }
14703
+ throw new CliUsageError(
14704
+ "--id, --ids or --ref is required",
14705
+ "playbooks"
14706
+ );
14707
+ }
14708
+ case "list":
14709
+ return client.playbooks.listByOwner({
14710
+ owner: requireFlag(flags, "owner", "playbooks list"),
14711
+ limit: num(flags["limit"]),
14712
+ cursor: flags["cursor"]
14713
+ });
14273
14714
  default:
14274
14715
  throw new CliUsageError(
14275
14716
  `Unknown subcommand: playbooks ${subcommand}`,
@@ -14345,7 +14786,11 @@ async function dispatch(client, args, meta) {
14345
14786
  "entry-script-path",
14346
14787
  "functions register"
14347
14788
  ),
14348
- params_schema: jsonSchemaStringFlag(flags, "functions register"),
14789
+ params_schema: jsonSchemaStringFlag(
14790
+ flags,
14791
+ "functions register",
14792
+ deps
14793
+ ),
14349
14794
  allow_charges: boolFlag(flags["allow-charges"])
14350
14795
  });
14351
14796
  case "list":
@@ -14438,7 +14883,7 @@ async function dispatch(client, args, meta) {
14438
14883
  });
14439
14884
  if (lintReport.summary.warnings > 0) {
14440
14885
  const { formatReport: formatReport2 } = await Promise.resolve().then(() => (init_report(), report_exports));
14441
- process.stderr.write(
14886
+ (deps?.stderr ?? process.stderr).write(
14442
14887
  "design lint warnings:\n" + formatReport2(lintReport, "human") + "\n"
14443
14888
  );
14444
14889
  }
@@ -14480,7 +14925,15 @@ async function dispatch(client, args, meta) {
14480
14925
  }
14481
14926
  const format = formatFlag ?? "human";
14482
14927
  const { handleLintPlaybook: handleLintPlaybook2 } = await Promise.resolve().then(() => (init_lint2(), lint_exports));
14483
- 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
+ }
14484
14937
  process.stdout.write(output + (output.endsWith("\n") ? "" : "\n"));
14485
14938
  if (exitCode !== 0) process.exit(exitCode);
14486
14939
  return void 0;
@@ -14807,6 +15260,25 @@ async function dispatch(client, args, meta) {
14807
15260
  first: num(flags["first"]),
14808
15261
  cursor: flags["cursor"]
14809
15262
  });
15263
+ case "follows":
15264
+ return client.subscriptions.follows({
15265
+ limit: num(flags["limit"]),
15266
+ cursor: flags["cursor"]
15267
+ });
15268
+ case "unsubscribe": {
15269
+ const playbookIds = csvList(flags["playbook-ids"]) ?? [];
15270
+ const feedIds = csvList(flags["feed-ids"]) ?? [];
15271
+ if (playbookIds.length === 0 && feedIds.length === 0) {
15272
+ throw new CliUsageError(
15273
+ "--playbook-ids or --feed-ids is required",
15274
+ "subscriptions"
15275
+ );
15276
+ }
15277
+ return client.subscriptions.unsubscribeBatch({
15278
+ playbookIds,
15279
+ feedIds
15280
+ });
15281
+ }
14810
15282
  default:
14811
15283
  throw new CliUsageError(
14812
15284
  `Unknown subcommand: subscriptions ${subcommand}`,
@@ -14922,6 +15394,7 @@ async function dispatch(client, args, meta) {
14922
15394
  }
14923
15395
  case "screenshot": {
14924
15396
  const outFile = requireFlag(flags, "out", "screenshot");
15397
+ assertLocalFileAvailable("screenshot", "out", deps);
14925
15398
  const compressQuality = flags["compress-quality"];
14926
15399
  const compressMaxWidth = flags["compress-max-width"];
14927
15400
  const result = await client.screenshot.capture({
@@ -14939,7 +15412,13 @@ async function dispatch(client, args, meta) {
14939
15412
  "screenshot"
14940
15413
  );
14941
15414
  }
14942
- fs2.writeFileSync(outFile, buf);
15415
+ writeLocalFileBytes(
15416
+ outFile,
15417
+ new Uint8Array(buf),
15418
+ "screenshot",
15419
+ "out",
15420
+ deps
15421
+ );
14943
15422
  return { written: outFile, bytes: buf.length };
14944
15423
  }
14945
15424
  case "portfolio": {
@@ -15168,7 +15647,8 @@ async function main() {
15168
15647
  arraysBaseUrl: config.arraysBaseUrl,
15169
15648
  gaClientId: config.gaClientId,
15170
15649
  gaSessionId: config.gaSessionId,
15171
- utmParams: config.utmParams
15650
+ utmParams: config.utmParams,
15651
+ originSessionId: config.originSessionId
15172
15652
  });
15173
15653
  const cleanArgs = stripGlobalFlags(rawArgs);
15174
15654
  const result = await dispatch(client, cleanArgs, {
@@ -15211,7 +15691,8 @@ ${help}
15211
15691
  const error = {
15212
15692
  code: err.code,
15213
15693
  message: err.message,
15214
- status: err.status
15694
+ status: err.status,
15695
+ ...err.details !== void 0 ? { details: err.details } : {}
15215
15696
  };
15216
15697
  process.stderr.write(`${JSON.stringify({ error }, null, 2)}
15217
15698
  `);
@@ -15229,7 +15710,9 @@ if (isDirectRun) {
15229
15710
  main();
15230
15711
  }
15231
15712
  export {
15713
+ BOOLEAN_FLAGS,
15232
15714
  CLI_VERSION,
15715
+ DEFAULT_RUN_TIMEOUT_MS,
15233
15716
  dispatch,
15234
15717
  handleConfigure,
15235
15718
  isVersionOlderThan,