@alva-ai/toolkit 0.16.0 → 0.16.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.d.ts CHANGED
@@ -194,6 +194,13 @@ interface CronjobCreateRequest {
194
194
  * A string: SA ids are snowflake int64s that overflow JS number precision.
195
195
  */
196
196
  run_as_user_id?: string;
197
+ /**
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.
202
+ */
203
+ end_at?: string;
197
204
  }
198
205
  interface Cronjob {
199
206
  id: number;
@@ -210,6 +217,11 @@ interface Cronjob {
210
217
  * A string: snowflake int64 ids overflow JS number precision.
211
218
  */
212
219
  run_as_user_id: string;
220
+ /**
221
+ * Lifetime ceiling (RFC3339), or null/omitted when the cronjob has no expiry.
222
+ * Set by `alva loop create`; unset for feeds and other crons.
223
+ */
224
+ end_at?: string | null;
213
225
  created_at: string;
214
226
  updated_at: string;
215
227
  }
package/dist/cli.js CHANGED
@@ -9704,7 +9704,8 @@ var DeployResource = class {
9704
9704
  args: params.args,
9705
9705
  push_notify: params.push_notify,
9706
9706
  max_heap_size_mb: params.max_heap_size_mb,
9707
- run_as_user_id: params.run_as_user_id
9707
+ run_as_user_id: params.run_as_user_id,
9708
+ end_at: params.end_at
9708
9709
  }
9709
9710
  });
9710
9711
  }
@@ -13650,7 +13651,7 @@ import * as fs2 from "fs";
13650
13651
  import * as os2 from "os";
13651
13652
  import * as fsPromises2 from "fs/promises";
13652
13653
  import { Agent, setGlobalDispatcher } from "undici";
13653
- var CLI_VERSION = true ? "0.16.0" : "dev";
13654
+ var CLI_VERSION = true ? "0.16.1-beta.0" : "dev";
13654
13655
  var DEFAULT_RUN_TIMEOUT_MS = 6e5;
13655
13656
  var RUN_TIMEOUT_ENV = "ALVA_RUN_TIMEOUT_MS";
13656
13657
  var configuredRunFetchTimeoutMs;
@@ -13680,6 +13681,7 @@ Commands:
13680
13681
  fs Filesystem operations (read, write, stat, readdir, mkdir, remove, rename, copy, symlink, readlink, chmod, grant, revoke)
13681
13682
  run Execute code in the Alva runtime
13682
13683
  deploy Cronjob management (create, list, get, update, delete, pause, resume, runs, run-logs)
13684
+ loop Self-scheduled in-channel goal loops (create)
13683
13685
  service-account Restricted run-as identities (create, list, delete, grant, revoke)
13684
13686
  release Feed and playbook releases (feed, playbook-draft, playbook)
13685
13687
  lint Design-system lint (playbook)
@@ -14024,6 +14026,30 @@ Build-time verify (fire once, then poll until your run completes):
14024
14026
  STATUS=$(echo "$ROW" | jq -r .status)
14025
14027
  [ "$STATUS" = completed ] || alva deploy run-logs --id 42 \\
14026
14028
  --run-id "$(echo "$ROW" | jq -r .id)"`,
14029
+ loop: `Usage: alva loop <subcommand> [options]
14030
+
14031
+ Create a self-scheduled, in-channel goal loop: a cronjob that each tick runs
14032
+ 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.
14037
+
14038
+ Subcommands:
14039
+ create Create a loop (seeds the shared loop-runner + a cronjob)
14040
+
14041
+ Create flags:
14042
+ --goal <text> Instruction run each tick (required)
14043
+ --cron <expression> Cron schedule (required, e.g. "0 * * * *")
14044
+ --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
14047
+ --name <name> Cronjob name (default: derived from --goal;
14048
+ 1-63 lowercase alphanumeric/hyphens)
14049
+
14050
+ 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`,
14027
14053
  "service-account": `Usage: alva service-account <subcommand> [options]
14028
14054
 
14029
14055
  Manage restricted run-as identities. A service account executes a UDF or
@@ -15153,6 +15179,40 @@ function parseCreditsDurationMs(value) {
15153
15179
  }
15154
15180
  return durationMs;
15155
15181
  }
15182
+ var LOOP_RUNNER_PATH = "~/loops/_runner/index.js";
15183
+ var LOOP_RUNNER_SRC = [
15184
+ "const { loop } = require('@alva/loop');",
15185
+ "const { goal, channelId } = require('env').args;",
15186
+ "loop(goal, channelId ? { channelId } : {});",
15187
+ ""
15188
+ ].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);
15193
+ if (!match) {
15194
+ throw new CliUsageError(
15195
+ `--expires-in must be a positive duration like 30m, 24h, 7d, or 'never', got '${value}'`,
15196
+ command.split(" ")[0]
15197
+ );
15198
+ }
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)) {
15203
+ throw new CliUsageError(
15204
+ `--expires-in is too large, got '${value}'`,
15205
+ command.split(" ")[0]
15206
+ );
15207
+ }
15208
+ return new Date(Date.now() + durationMs).toISOString();
15209
+ }
15210
+ function loopCronjobName(flags, goal) {
15211
+ if (flags["name"] !== void 0) return flags["name"];
15212
+ const base = goal.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
15213
+ const slug = (base ? `loop-${base}` : "loop").slice(0, 63).replace(/-+$/g, "");
15214
+ return slug || "loop";
15215
+ }
15156
15216
  function parseCreditsItemsParams(flags) {
15157
15217
  const command = "credits items";
15158
15218
  const hasToday = boolFlag(flags["today"]) === true;
@@ -15607,6 +15667,38 @@ async function dispatch(client, args, meta, deps) {
15607
15667
  );
15608
15668
  }
15609
15669
  }
15670
+ case "loop": {
15671
+ if (!subcommand)
15672
+ throw new CliUsageError("Missing subcommand for loop", "loop");
15673
+ switch (subcommand) {
15674
+ case "create": {
15675
+ const goal = requireFlag(flags, "goal", "loop create");
15676
+ const cron = requireFlag(flags, "cron", "loop create");
15677
+ const channelId = flags["channel-id"];
15678
+ const endAt = parseExpiresInToEndAt(
15679
+ flags["expires-in"],
15680
+ "loop create"
15681
+ );
15682
+ await client.fs.write({
15683
+ path: LOOP_RUNNER_PATH,
15684
+ data: LOOP_RUNNER_SRC,
15685
+ mkdir_parents: true
15686
+ });
15687
+ return client.deploy.create({
15688
+ name: loopCronjobName(flags, goal),
15689
+ path: LOOP_RUNNER_PATH,
15690
+ cron_expression: cron,
15691
+ args: channelId ? { goal, channelId } : { goal },
15692
+ end_at: endAt
15693
+ });
15694
+ }
15695
+ default:
15696
+ throw new CliUsageError(
15697
+ `Unknown subcommand: loop ${subcommand}`,
15698
+ "loop"
15699
+ );
15700
+ }
15701
+ }
15610
15702
  case "service-account": {
15611
15703
  if (!subcommand)
15612
15704
  throw new CliUsageError(