@alva-ai/toolkit 0.16.1-beta.0 → 0.16.1-beta.1

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.d.ts CHANGED
@@ -15,9 +15,14 @@ interface AlvaClientConfig {
15
15
  interface UserProfile {
16
16
  id: string;
17
17
  username: string;
18
- subscription_tier: 'free' | 'pro';
19
- telegram_username: string | null;
20
- slack_username: string | null;
18
+ subscription_tier: 'free' | 'pro' | 'max';
19
+ telegram_username: string;
20
+ discord_username: string;
21
+ slack_username: string;
22
+ whatsapp_username: string;
23
+ imessage_username: string;
24
+ active_channel: string;
25
+ toolkit_min_version: string;
21
26
  /** Caller's alfs home directory, e.g. `/alva/home/<username>`. */
22
27
  home_path: string;
23
28
  }
@@ -194,13 +199,14 @@ interface CronjobCreateRequest {
194
199
  * A string: SA ids are snowflake int64s that overflow JS number precision.
195
200
  */
196
201
  run_as_user_id?: string;
202
+ /** Inclusive RFC3339 lower bound. Omitted means start now (server clock). */
203
+ start_at?: string;
197
204
  /**
198
- * Lifetime ceiling (RFC3339 timestamp). Once now >= end_at the runner
199
- * self-terminates the cronjob before running (backend#1799). Omitted ⇒ no
200
- * expiry. The `alva loop create` sugar sets this to now + (expires_in ?? 7d);
201
- * feeds and other crons leave it unset.
205
+ * Exclusive RFC3339 upper bound. A run is admitted only while now < end_at.
202
206
  */
203
207
  end_at?: string;
208
+ /** Maximum number of admitted runs. */
209
+ max_runs?: number;
204
210
  }
205
211
  interface Cronjob {
206
212
  id: number;
@@ -217,11 +223,17 @@ interface Cronjob {
217
223
  * A string: snowflake int64 ids overflow JS number precision.
218
224
  */
219
225
  run_as_user_id: string;
226
+ /** Inclusive eligibility lower bound, resolved by the server on create. */
227
+ start_at?: string | null;
220
228
  /**
221
229
  * Lifetime ceiling (RFC3339), or null/omitted when the cronjob has no expiry.
222
230
  * Set by `alva loop create`; unset for feeds and other crons.
223
231
  */
224
232
  end_at?: string | null;
233
+ /** Maximum admitted runs, or null when unbounded by count. */
234
+ max_runs?: number | null;
235
+ /** Number of runs admitted so far. */
236
+ run_count: number;
225
237
  created_at: string;
226
238
  updated_at: string;
227
239
  }
@@ -282,6 +294,22 @@ interface CronjobRunsListResponse {
282
294
  stats?: CronjobRunStats;
283
295
  next_cursor?: number;
284
296
  }
297
+ interface CronjobRunStatusParams {
298
+ cronjob_id: number;
299
+ workflow_run_id: string;
300
+ }
301
+ interface CronjobRunStatusResponse {
302
+ workflow_run_id: string;
303
+ /**
304
+ * PENDING means no cronjob_runs row exists yet. It is not falsifiable:
305
+ * a mistyped workflow_run_id, a workflow_run_id from another cronjob, or
306
+ * a workflow that failed before persistence can remain PENDING forever.
307
+ * DISPATCHED and RUNNING mean an in-flight row exists. Pollers must stop
308
+ * on their own deadline if the run never reaches a terminal state.
309
+ */
310
+ state: 'PENDING' | 'DISPATCHED' | 'RUNNING' | 'COMPLETED' | 'FAILED' | 'SKIPPED' | 'UNSPECIFIED' | string;
311
+ run?: CronjobRun;
312
+ }
285
313
  interface CronjobRunLogsResponse {
286
314
  logs: string;
287
315
  }
@@ -289,8 +317,9 @@ interface CronjobTriggerResponse {
289
317
  /**
290
318
  * Hatchet workflow run id at enqueue. Async — the persisted
291
319
  * `cronjob_runs` row appears only after the worker finishes the run.
292
- * Callers verify completion by polling `deploy.listRuns({cronjob_id})`
293
- * and matching `runs[].workflow_run_id` against this value.
320
+ * Callers verify completion by polling
321
+ * `deploy.getRunStatus({cronjob_id, workflow_run_id})` with their own
322
+ * timeout/deadline.
294
323
  */
295
324
  workflow_run_id: string;
296
325
  }
@@ -790,8 +819,8 @@ interface PushSubscription {
790
819
  */
791
820
  kind?: 'PLAYBOOK_ALERTS' | 'FEED_ALERT' | 'UNSPECIFIED' | string;
792
821
  /**
793
- * Whether the caller also FOLLOWS the target playbook — the social
794
- * relation, distinct from this alert row. Always false for FEED targets.
822
+ * Legacy social playbook-follow signal. Do not use this to decide whether
823
+ * alert delivery is enabled; use kind + target_status instead.
795
824
  */
796
825
  following?: boolean;
797
826
  /**
@@ -1045,9 +1074,10 @@ declare class DeployResource {
1045
1074
  /**
1046
1075
  * Fire the cronjob workflow once, immediately, bypassing the schedule.
1047
1076
  * Async — returns the Hatchet workflow run id at enqueue. The
1048
- * `cronjob_runs` row appears only after the worker finishes the run;
1049
- * callers verify completion by polling `listRuns({cronjob_id})` and
1050
- * matching `runs[].workflow_run_id` against the returned id.
1077
+ * `cronjob_runs` row can appear as DISPATCHED/RUNNING before it reaches a
1078
+ * terminal status; callers verify completion by polling
1079
+ * `getRunStatus({cronjob_id, workflow_run_id})` with their own
1080
+ * timeout/deadline.
1051
1081
  *
1052
1082
  * Surfaces backend status as HTTP errors (handled by AlvaClient):
1053
1083
  * - 404 not found / cross-user
@@ -1058,6 +1088,7 @@ declare class DeployResource {
1058
1088
  id: number;
1059
1089
  }): Promise<CronjobTriggerResponse>;
1060
1090
  listRuns(params: CronjobRunsListParams): Promise<CronjobRunsListResponse>;
1091
+ getRunStatus(params: CronjobRunStatusParams): Promise<CronjobRunStatusResponse>;
1061
1092
  getRunLogs(params: {
1062
1093
  cronjob_id: number;
1063
1094
  run_id: number;
package/dist/cli.js CHANGED
@@ -9705,7 +9705,9 @@ var DeployResource = class {
9705
9705
  push_notify: params.push_notify,
9706
9706
  max_heap_size_mb: params.max_heap_size_mb,
9707
9707
  run_as_user_id: params.run_as_user_id,
9708
- end_at: params.end_at
9708
+ start_at: params.start_at,
9709
+ end_at: params.end_at,
9710
+ max_runs: params.max_runs
9709
9711
  }
9710
9712
  });
9711
9713
  }
@@ -9750,9 +9752,10 @@ var DeployResource = class {
9750
9752
  /**
9751
9753
  * Fire the cronjob workflow once, immediately, bypassing the schedule.
9752
9754
  * Async — returns the Hatchet workflow run id at enqueue. The
9753
- * `cronjob_runs` row appears only after the worker finishes the run;
9754
- * callers verify completion by polling `listRuns({cronjob_id})` and
9755
- * matching `runs[].workflow_run_id` against the returned id.
9755
+ * `cronjob_runs` row can appear as DISPATCHED/RUNNING before it reaches a
9756
+ * terminal status; callers verify completion by polling
9757
+ * `getRunStatus({cronjob_id, workflow_run_id})` with their own
9758
+ * timeout/deadline.
9756
9759
  *
9757
9760
  * Surfaces backend status as HTTP errors (handled by AlvaClient):
9758
9761
  * - 404 not found / cross-user
@@ -9776,6 +9779,13 @@ var DeployResource = class {
9776
9779
  }
9777
9780
  );
9778
9781
  }
9782
+ async getRunStatus(params) {
9783
+ this.client._requireAuth();
9784
+ return this.client._request(
9785
+ "GET",
9786
+ `/api/v1/deploy/cronjob/${params.cronjob_id}/runs/by-workflow/${encodeURIComponent(params.workflow_run_id)}`
9787
+ );
9788
+ }
9779
9789
  async getRunLogs(params) {
9780
9790
  this.client._requireAuth();
9781
9791
  return this.client._request(
@@ -13651,7 +13661,7 @@ import * as fs2 from "fs";
13651
13661
  import * as os2 from "os";
13652
13662
  import * as fsPromises2 from "fs/promises";
13653
13663
  import { Agent, setGlobalDispatcher } from "undici";
13654
- var CLI_VERSION = true ? "0.16.1-beta.0" : "dev";
13664
+ var CLI_VERSION = true ? "0.16.1-beta.1" : "dev";
13655
13665
  var DEFAULT_RUN_TIMEOUT_MS = 6e5;
13656
13666
  var RUN_TIMEOUT_ENV = "ALVA_RUN_TIMEOUT_MS";
13657
13667
  var configuredRunFetchTimeoutMs;
@@ -13796,9 +13806,13 @@ Subcommands:
13796
13806
  Response fields:
13797
13807
  id User ID
13798
13808
  username Username (used in ALFS paths and playbook URLs)
13799
- subscription_tier "free" or "pro" \u2014 determines release flow and feature gates
13800
- telegram_username Telegram username if connected, null otherwise
13801
- slack_username Slack display name if connected, null otherwise
13809
+ subscription_tier "free", "pro", or "max" \u2014 determines release flow and feature gates
13810
+ telegram_username Telegram display name if connected, empty otherwise
13811
+ discord_username Discord display name if connected, empty otherwise
13812
+ slack_username Slack display name if connected, empty otherwise
13813
+ whatsapp_username WhatsApp display name if connected, empty otherwise
13814
+ imessage_username iMessage display name if connected, empty otherwise
13815
+ active_channel Currently selected IM delivery channel
13802
13816
 
13803
13817
  Examples:
13804
13818
  alva user me`,
@@ -13959,8 +13973,9 @@ Subcommands:
13959
13973
  pause Pause a running cronjob
13960
13974
  resume Resume a paused cronjob
13961
13975
  trigger Fire the cronjob once, immediately, bypassing the schedule
13962
- (returns workflow_run_id; poll 'runs' to verify completion)
13976
+ (returns workflow_run_id; poll 'run-status' with a timeout)
13963
13977
  runs List runs for a cronjob (cursor-paginated)
13978
+ run-status Get one triggered run's pollable status by workflow_run_id
13964
13979
  run-logs Get stdout/stderr logs for a single cronjob run
13965
13980
 
13966
13981
  Create/Update flags:
@@ -13989,6 +14004,10 @@ Runs flags:
13989
14004
  --first <n> Max results per page
13990
14005
  --cursor <cursor> Pagination cursor from previous response
13991
14006
 
14007
+ Run-status flags:
14008
+ --id <id> Cronjob ID (required)
14009
+ --workflow-run-id <id> Workflow run ID returned by deploy trigger
14010
+
13992
14011
  Run-logs flags:
13993
14012
  --id <id> Cronjob ID (required)
13994
14013
  --run-id <id> Run ID (required)
@@ -14015,25 +14034,29 @@ Examples:
14015
14034
  alva deploy delete --id 42
14016
14035
  alva deploy runs --id 42
14017
14036
  alva deploy runs --id 42 --first 10
14037
+ alva deploy run-status --id 42 --workflow-run-id hatchet-run-id
14018
14038
  alva deploy run-logs --id 42 --run-id 123
14019
14039
 
14020
- Build-time verify (fire once, then poll until your run completes):
14040
+ Build-time verify (fire once, then poll up to 5 minutes):
14021
14041
  WF=$(alva deploy trigger --id 42 | jq -r .workflow_run_id)
14022
- while ! ROW=$(alva deploy runs --id 42 --first 5 \\
14023
- | jq -e ".runs[] | select(.workflow_run_id==\\"$WF\\")"); do
14042
+ for _ in {1..60}; do
14043
+ STATUS_JSON=$(alva deploy run-status --id 42 --workflow-run-id "$WF")
14044
+ STATE=$(echo "$STATUS_JSON" | jq -r .state)
14045
+ case "$STATE" in PENDING|DISPATCHED|RUNNING) ;; *) break ;; esac
14024
14046
  sleep 5
14025
14047
  done
14026
- STATUS=$(echo "$ROW" | jq -r .status)
14027
- [ "$STATUS" = completed ] || alva deploy run-logs --id 42 \\
14028
- --run-id "$(echo "$ROW" | jq -r .id)"`,
14048
+ case "$STATE" in
14049
+ PENDING|DISPATCHED|RUNNING) echo "Timed out waiting for run completion" >&2; exit 1 ;;
14050
+ esac
14051
+ [ "$STATE" = COMPLETED ] || alva deploy run-logs --id 42 \\
14052
+ --run-id "$(echo "$STATUS_JSON" | jq -r .run.id)"`,
14029
14053
  loop: `Usage: alva loop <subcommand> [options]
14030
14054
 
14031
- Create a self-scheduled, in-channel goal loop: a cronjob that each tick runs
14055
+ Create a bounded, self-scheduled in-channel goal loop: a cronjob that each tick runs
14032
14056
  one fire-and-forget agent turn on a channel's stable main session (via the
14033
- @alva/loop SDK), continuing that channel's conversation toward a goal. Every
14034
- loop gets a lifetime ceiling (default 7 days) so a self-scheduled loop always
14035
- terminates. Sugar over 'alva deploy create' \u2014 it seeds a shared loop-runner
14036
- script and packs the goal/channel into the cronjob's args.
14057
+ @alva/loop SDK), continuing that channel's conversation toward a goal. Sugar
14058
+ over 'alva deploy create' \u2014 it seeds a shared loop-runner script and packs the
14059
+ goal/channel into the cronjob's args.
14037
14060
 
14038
14061
  Subcommands:
14039
14062
  create Create a loop (seeds the shared loop-runner + a cronjob)
@@ -14042,14 +14065,18 @@ Create flags:
14042
14065
  --goal <text> Instruction run each tick (required)
14043
14066
  --cron <expression> Cron schedule (required, e.g. "0 * * * *")
14044
14067
  --channel-id <id> Target channel id. Omit \u21D2 your DM/agent channel
14045
- --expires-in <dur> Lifetime: 30m | 24h | 7d, or 'never' (unbounded \u2014
14046
- discouraged). Default: 7d
14068
+ --start <time> First eligible time: 'now' (default) or RFC3339
14069
+ --until <time> Exclusive RFC3339 cutoff
14070
+ --runs <count> Maximum admitted runs after --start
14047
14071
  --name <name> Cronjob name (default: derived from --goal;
14048
14072
  1-63 lowercase alphanumeric/hyphens)
14049
14073
 
14074
+ At least one of --until or --runs is required. RFC3339 timestamps must include
14075
+ a timezone (Z or \xB1HH:MM).
14076
+
14050
14077
  Examples:
14051
- alva loop create --channel-id 7284... --goal "watch NVDA pre-market, alert on setup" --cron "0 * * * *"
14052
- alva loop create --goal "summarize my unread channels" --cron "0 8 * * *" --expires-in 30d`,
14078
+ alva loop create --channel-id 7284... --goal "watch NVDA pre-market, alert on setup" --cron "*/5 * * * *" --until "2026-07-15T09:30:00-04:00"
14079
+ alva loop create --goal "check the next 12 intervals" --cron "0 * * * *" --start now --runs 12`,
14053
14080
  "service-account": `Usage: alva service-account <subcommand> [options]
14054
14081
 
14055
14082
  Manage restricted run-as identities. A service account executes a UDF or
@@ -14651,7 +14678,6 @@ Follows flags:
14651
14678
 
14652
14679
  List response notes:
14653
14680
  items[].kind PLAYBOOK_ALERTS (playbook-level wildcard) | FEED_ALERT
14654
- items[].following Whether the caller also FOLLOWS the playbook
14655
14681
  items[].target_status ACTIVE | TARGET_DELETED (ghost \u2014 clear via
14656
14682
  unsubscribe --playbook-ids/--feed-ids) | PAUSED
14657
14683
  items[].playbook {owner_username, name, display_name} for PLAYBOOK rows
@@ -15186,26 +15212,65 @@ var LOOP_RUNNER_SRC = [
15186
15212
  "loop(goal, channelId ? { channelId } : {});",
15187
15213
  ""
15188
15214
  ].join("\n");
15189
- function parseExpiresInToEndAt(value, command) {
15190
- const raw = (value ?? "7d").trim().toLowerCase();
15191
- if (raw === "never") return void 0;
15192
- const match = /^([1-9]\d*)([mhd])$/.exec(raw);
15215
+ function parseLoopTimestamp(value, flag) {
15216
+ const raw = value.trim();
15217
+ const match = /^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:[zZ]|([+-])(\d{2}):(\d{2}))$/.exec(
15218
+ raw
15219
+ );
15193
15220
  if (!match) {
15194
15221
  throw new CliUsageError(
15195
- `--expires-in must be a positive duration like 30m, 24h, 7d, or 'never', got '${value}'`,
15196
- command.split(" ")[0]
15222
+ `--${flag} must be an RFC3339 timestamp with a timezone (Z or \xB1HH:MM), got '${value}'`,
15223
+ "loop"
15197
15224
  );
15198
15225
  }
15199
- const amount = Number(match[1]);
15200
- const unit = match[2];
15201
- const durationMs = amount * (unit === "m" ? 6e4 : unit === "h" ? 36e5 : 864e5);
15202
- if (!Number.isSafeInteger(durationMs)) {
15226
+ const year = Number(match[1]);
15227
+ const month = Number(match[2]);
15228
+ const day = Number(match[3]);
15229
+ const hour = Number(match[4]);
15230
+ const minute = Number(match[5]);
15231
+ const second = Number(match[6]);
15232
+ const offsetHour = Number(match[8] ?? 0);
15233
+ const offsetMinute = Number(match[9] ?? 0);
15234
+ const leapYear = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
15235
+ const monthDays = [
15236
+ 31,
15237
+ leapYear ? 29 : 28,
15238
+ 31,
15239
+ 30,
15240
+ 31,
15241
+ 30,
15242
+ 31,
15243
+ 31,
15244
+ 30,
15245
+ 31,
15246
+ 30,
15247
+ 31
15248
+ ];
15249
+ if (month < 1 || month > 12 || day < 1 || day > monthDays[month - 1] || hour > 23 || minute > 59 || second > 59 || offsetHour > 23 || offsetMinute > 59) {
15203
15250
  throw new CliUsageError(
15204
- `--expires-in is too large, got '${value}'`,
15205
- command.split(" ")[0]
15251
+ `--${flag} must be a valid RFC3339 timestamp, got '${value}'`,
15252
+ "loop"
15253
+ );
15254
+ }
15255
+ const timestamp = Date.parse(raw);
15256
+ if (!Number.isFinite(timestamp)) {
15257
+ throw new CliUsageError(
15258
+ `--${flag} must be a valid RFC3339 timestamp, got '${value}'`,
15259
+ "loop"
15206
15260
  );
15207
15261
  }
15208
- return new Date(Date.now() + durationMs).toISOString();
15262
+ return new Date(timestamp).toISOString();
15263
+ }
15264
+ function parseLoopRuns(value) {
15265
+ if (value === void 0) return void 0;
15266
+ if (!/^[1-9]\d*$/.test(value)) {
15267
+ throw new CliUsageError("--runs must be a positive integer", "loop");
15268
+ }
15269
+ const runs = Number(value);
15270
+ if (!Number.isSafeInteger(runs) || runs > 2147483647) {
15271
+ throw new CliUsageError("--runs is too large", "loop");
15272
+ }
15273
+ return runs;
15209
15274
  }
15210
15275
  function loopCronjobName(flags, goal) {
15211
15276
  if (flags["name"] !== void 0) return flags["name"];
@@ -15655,6 +15720,15 @@ async function dispatch(client, args, meta, deps) {
15655
15720
  first: num(flags["first"]),
15656
15721
  cursor: flags["cursor"]
15657
15722
  });
15723
+ case "run-status":
15724
+ return client.deploy.getRunStatus({
15725
+ cronjob_id: requireNumericFlag(flags, "id", "deploy run-status"),
15726
+ workflow_run_id: requireFlag(
15727
+ flags,
15728
+ "workflow-run-id",
15729
+ "deploy run-status"
15730
+ )
15731
+ });
15658
15732
  case "run-logs":
15659
15733
  return client.deploy.getRunLogs({
15660
15734
  cronjob_id: requireNumericFlag(flags, "id", "deploy run-logs"),
@@ -15672,13 +15746,31 @@ async function dispatch(client, args, meta, deps) {
15672
15746
  throw new CliUsageError("Missing subcommand for loop", "loop");
15673
15747
  switch (subcommand) {
15674
15748
  case "create": {
15749
+ if (flags["expires-in"] !== void 0) {
15750
+ throw new CliUsageError(
15751
+ "Unknown flag --expires-in; use --until and/or --runs",
15752
+ "loop"
15753
+ );
15754
+ }
15675
15755
  const goal = requireFlag(flags, "goal", "loop create");
15676
15756
  const cron = requireFlag(flags, "cron", "loop create");
15677
15757
  const channelId = flags["channel-id"];
15678
- const endAt = parseExpiresInToEndAt(
15679
- flags["expires-in"],
15680
- "loop create"
15681
- );
15758
+ const startRaw = (flags["start"] ?? "now").trim();
15759
+ const startAt = startRaw.toLowerCase() === "now" ? void 0 : parseLoopTimestamp(startRaw, "start");
15760
+ const endAt = flags["until"] ? parseLoopTimestamp(flags["until"], "until") : void 0;
15761
+ const maxRuns = parseLoopRuns(flags["runs"]);
15762
+ if (endAt === void 0 && maxRuns === void 0) {
15763
+ throw new CliUsageError(
15764
+ "loop create requires at least one of --until or --runs",
15765
+ "loop"
15766
+ );
15767
+ }
15768
+ if (startAt !== void 0 && endAt !== void 0 && endAt <= startAt) {
15769
+ throw new CliUsageError(
15770
+ "--until must be later than --start",
15771
+ "loop"
15772
+ );
15773
+ }
15682
15774
  await client.fs.write({
15683
15775
  path: LOOP_RUNNER_PATH,
15684
15776
  data: LOOP_RUNNER_SRC,
@@ -15689,7 +15781,9 @@ async function dispatch(client, args, meta, deps) {
15689
15781
  path: LOOP_RUNNER_PATH,
15690
15782
  cron_expression: cron,
15691
15783
  args: channelId ? { goal, channelId } : { goal },
15692
- end_at: endAt
15784
+ start_at: startAt,
15785
+ end_at: endAt,
15786
+ max_runs: maxRuns
15693
15787
  });
15694
15788
  }
15695
15789
  default: