@alva-ai/toolkit 0.25.1 → 0.26.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.
@@ -2043,6 +2043,69 @@ declare class MarketsResource {
2043
2043
  private graphql;
2044
2044
  }
2045
2045
 
2046
+ type AgentScheduleStatus = 'active' | 'paused' | 'completed' | 'failed';
2047
+ type AgentScheduleFailureCode = 'target_invalid' | 'delivery_exhausted' | 'payload_conflict';
2048
+ type AgentScheduleRule = {
2049
+ kind: 'at';
2050
+ timestamp: string;
2051
+ } | {
2052
+ kind: 'every';
2053
+ interval: string;
2054
+ } | {
2055
+ kind: 'cron';
2056
+ expression: string;
2057
+ timezone: string;
2058
+ };
2059
+ interface AgentScheduleBounds {
2060
+ startsAt?: string;
2061
+ until?: string;
2062
+ maxOccurrences?: number;
2063
+ }
2064
+ interface AgentSchedule {
2065
+ name: string;
2066
+ rule: AgentScheduleRule;
2067
+ bounds: AgentScheduleBounds;
2068
+ text: string;
2069
+ status: AgentScheduleStatus;
2070
+ failure?: {
2071
+ code: AgentScheduleFailureCode;
2072
+ at?: string;
2073
+ };
2074
+ occurrencesUsed: number;
2075
+ nextFireAt?: string;
2076
+ createdAt: string;
2077
+ updatedAt: string;
2078
+ }
2079
+ interface PutAgentScheduleParams {
2080
+ channelId: string | number;
2081
+ name: string;
2082
+ rule: AgentScheduleRule | {
2083
+ kind: 'after';
2084
+ duration: string;
2085
+ };
2086
+ bounds?: AgentScheduleBounds;
2087
+ text: string;
2088
+ }
2089
+ interface ManageAgentScheduleParams {
2090
+ channelId: string | number;
2091
+ name: string;
2092
+ }
2093
+ declare class SchedulesResource {
2094
+ private client;
2095
+ constructor(client: AlvaClient);
2096
+ list(params: {
2097
+ channelId: string | number;
2098
+ }): Promise<AgentSchedule[]>;
2099
+ put(params: PutAgentScheduleParams): Promise<AgentSchedule>;
2100
+ pause(params: ManageAgentScheduleParams): Promise<AgentSchedule>;
2101
+ resume(params: ManageAgentScheduleParams): Promise<AgentSchedule>;
2102
+ delete(params: ManageAgentScheduleParams): Promise<void>;
2103
+ /** Resolve the authenticated viewer's unique Agent Channel for CLI defaults. */
2104
+ agentChannelId(): Promise<string>;
2105
+ private manage;
2106
+ private graphql;
2107
+ }
2108
+
2046
2109
  interface RequestOptions {
2047
2110
  query?: Record<string, unknown>;
2048
2111
  body?: unknown;
@@ -2108,6 +2171,7 @@ declare class AlvaClient {
2108
2171
  private _functions?;
2109
2172
  private _credits?;
2110
2173
  private _markets?;
2174
+ private _schedules?;
2111
2175
  constructor(config: AlvaClientConfig);
2112
2176
  get fs(): FsResource;
2113
2177
  get run(): RunResource;
@@ -2137,6 +2201,7 @@ declare class AlvaClient {
2137
2201
  get functions(): FunctionsResource;
2138
2202
  get credits(): CreditsResource;
2139
2203
  get markets(): MarketsResource;
2204
+ get schedules(): SchedulesResource;
2140
2205
  _requireAuth(): void;
2141
2206
  _request(method: string, path: string, options?: RequestOptions): Promise<unknown>;
2142
2207
  }
package/dist/dispatch.js CHANGED
@@ -6853,19 +6853,25 @@ var COMMAND_DEFINITIONS = [
6853
6853
  values: ["id", "workflow-run-id"]
6854
6854
  }),
6855
6855
  command("deploy run-logs", { values: ["id", "run-id"] }),
6856
- command("loop create", {
6856
+ command("schedule list", { values: ["channel-id"] }),
6857
+ command("schedule put", {
6857
6858
  values: [
6858
- "goal",
6859
- "cron",
6860
6859
  "channel-id",
6861
- "start",
6862
- "until",
6863
- "runs",
6864
6860
  "name",
6865
- // Retained so the handler can emit the existing migration guidance.
6866
- "expires-in"
6861
+ "message",
6862
+ "at",
6863
+ "after",
6864
+ "every",
6865
+ "cron",
6866
+ "timezone",
6867
+ "starts-at",
6868
+ "until",
6869
+ "max-occurrences"
6867
6870
  ]
6868
6871
  }),
6872
+ command("schedule pause", { values: ["channel-id", "name"] }),
6873
+ command("schedule resume", { values: ["channel-id", "name"] }),
6874
+ command("schedule delete", { values: ["channel-id", "name"] }),
6869
6875
  command("service-account create", { values: ["name"] }),
6870
6876
  command("service-account list"),
6871
6877
  command("service-account delete", { values: ["id"] }),
@@ -10930,7 +10936,7 @@ function validateSerializedArgs(raw) {
10930
10936
  }
10931
10937
 
10932
10938
  // src/cli/dispatch.ts
10933
- var CLI_VERSION = true ? "0.25.1" : "dev";
10939
+ var CLI_VERSION = true ? "0.26.0" : "dev";
10934
10940
  var DEFAULT_RUN_TIMEOUT_MS = 6e5;
10935
10941
  var RUN_TIMEOUT_ENV = "ALVA_RUN_TIMEOUT_MS";
10936
10942
  var GLOBAL_VALUE_FLAGS = Object.entries(GLOBAL_FLAG_DEFINITIONS).filter(([, kind]) => kind === "value").map(([name]) => `--${name}`);
@@ -11290,36 +11296,35 @@ Build-time verify (fire once, then poll up to 5 minutes):
11290
11296
  esac
11291
11297
  [ "$STATE" = COMPLETED ] || alva deploy run-logs --id 42 \\
11292
11298
  --run-id "$(echo "$STATUS_JSON" | jq -r .run.id)"`,
11293
- loop: `Usage: alva loop <subcommand> [options]
11299
+ schedule: `Usage: alva schedule <subcommand> [options]
11294
11300
 
11295
- Create a bounded, self-scheduled goal loop in an Alva channel. Each tick runs
11296
- one fire-and-forget agent turn on the Alva channel's stable main
11297
- session (via the @alva/loop SDK), continuing that conversation toward a goal. Creation
11298
- seeds a shared runner, creates its cronjob, and registers the cronjob as an
11299
- Automation without starting an extra publish-time run.
11301
+ Manage named future and recurring work for an Alva Channel Agent.
11300
11302
 
11301
11303
  Subcommands:
11302
- create Create a loop and its visible Automation
11304
+ list List schedules
11305
+ put Create or replace a schedule by name
11306
+ pause Pause a schedule
11307
+ resume Resume a schedule
11308
+ delete Delete a schedule
11303
11309
 
11304
- Create flags:
11305
- --goal <text> Instruction run each tick (required)
11306
- --cron <expression> Cron schedule (required, e.g. "0 * * * *")
11307
- --channel-id <id> Target Alva channel ID. Omit \u21D2 your default
11308
- Alva agent channel
11309
- --start <time> First eligible time: 'now' (default) or RFC3339
11310
- --until <time> Exclusive RFC3339 cutoff
11311
- --runs <count> Maximum admitted runs after --start
11312
- --name <name> Cronjob name (default: derived from --goal;
11313
- 1-63 lowercase alphanumeric/hyphens)
11314
-
11315
- At least one of --until or --runs is required. RFC3339 timestamps must include
11316
- a timezone (Z or \xB1HH:MM). The result includes automation_id and cronjob_id.
11317
- Use 'alva automation inspect/stop/resume/delete --id <automation_id>' for
11318
- lifecycle management; deletion also removes the Automation's producer cronjob.
11310
+ Common flags:
11311
+ --channel-id <id> Target Channel; omit for your Agent Channel
11312
+ --name <name> Stable schedule name
11313
+
11314
+ Put flags:
11315
+ --message <text> Agent instruction delivered at each occurrence
11316
+ Choose exactly one: --after <ISO duration>, --at <RFC3339>,
11317
+ --every <ISO duration>, or --cron <five fields>
11318
+ --timezone <IANA> Required with --cron
11319
+ --starts-at <RFC3339> Inclusive recurrence lower bound
11320
+ --until <RFC3339> Exclusive recurrence upper bound
11321
+ --max-occurrences <n> Positive recurrence count bound
11319
11322
 
11320
11323
  Examples:
11321
- alva loop create --channel-id 7284... --goal "watch NVDA pre-market, alert on setup" --cron "*/5 * * * *" --until "2026-07-15T09:30:00-04:00"
11322
- alva loop create --goal "check the next 12 intervals" --cron "0 * * * *" --start now --runs 12`,
11324
+ alva schedule put --name review --message "Review status" --after PT30M
11325
+ alva schedule put --name market-open --message "Review the open" --cron "30 9 * * 1-5" --timezone America/New_York
11326
+ alva schedule list
11327
+ alva schedule pause --name market-open`,
11323
11328
  "service-account": `Usage: alva service-account <subcommand> [options]
11324
11329
 
11325
11330
  Manage restricted run-as identities. A service account executes a UDF or
@@ -12547,84 +12552,69 @@ function parseCreditsDurationMs(value) {
12547
12552
  }
12548
12553
  return durationMs;
12549
12554
  }
12550
- var LOOP_RUNNER_PATH = "~/loops/_runner/index.js";
12551
- var LOOP_RUNNER_SRC = [
12552
- "const { loop } = require('@alva/loop');",
12553
- "const { goal, channelId } = require('env').args;",
12554
- "loop(goal, channelId ? { channelId } : {});",
12555
- ""
12556
- ].join("\n");
12557
- function parseLoopTimestamp(value, flag) {
12558
- const raw = value.trim();
12559
- const match = /^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:[zZ]|([+-])(\d{2}):(\d{2}))$/.exec(
12560
- raw
12555
+ async function scheduleChannelId(client, flags) {
12556
+ return flags["channel-id"] ?? client.schedules.agentChannelId();
12557
+ }
12558
+ function scheduleRuleFromFlags(flags) {
12559
+ const selected = ["after", "at", "every", "cron"].filter(
12560
+ (flag) => flags[flag] !== void 0
12561
12561
  );
12562
- if (!match) {
12562
+ if (selected.length !== 1) {
12563
12563
  throw new CliUsageError(
12564
- `--${flag} must be an RFC3339 timestamp with a timezone (Z or \xB1HH:MM), got '${value}'`,
12565
- "loop"
12564
+ "schedule put requires exactly one of --after, --at, --every, or --cron",
12565
+ "schedule"
12566
12566
  );
12567
12567
  }
12568
- const year = Number(match[1]);
12569
- const month = Number(match[2]);
12570
- const day = Number(match[3]);
12571
- const hour = Number(match[4]);
12572
- const minute = Number(match[5]);
12573
- const second = Number(match[6]);
12574
- const offsetHour = Number(match[8] ?? 0);
12575
- const offsetMinute = Number(match[9] ?? 0);
12576
- const leapYear = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
12577
- const monthDays = [
12578
- 31,
12579
- leapYear ? 29 : 28,
12580
- 31,
12581
- 30,
12582
- 31,
12583
- 30,
12584
- 31,
12585
- 31,
12586
- 30,
12587
- 31,
12588
- 30,
12589
- 31
12590
- ];
12591
- if (month < 1 || month > 12 || day < 1 || day > monthDays[month - 1] || hour > 23 || minute > 59 || second > 59 || offsetHour > 23 || offsetMinute > 59) {
12568
+ if (selected[0] !== "cron" && flags["timezone"] !== void 0) {
12569
+ throw new CliUsageError("--timezone is only valid with --cron", "schedule");
12570
+ }
12571
+ switch (selected[0]) {
12572
+ case "after":
12573
+ return { kind: "after", duration: flags["after"] };
12574
+ case "at":
12575
+ return {
12576
+ kind: "at",
12577
+ timestamp: parseScheduleTimestamp(flags["at"], "at")
12578
+ };
12579
+ case "every":
12580
+ return { kind: "every", interval: flags["every"] };
12581
+ default:
12582
+ return {
12583
+ kind: "cron",
12584
+ expression: flags["cron"],
12585
+ timezone: requireFlag(flags, "timezone", "schedule put")
12586
+ };
12587
+ }
12588
+ }
12589
+ function parseScheduleTimestamp(value, flag) {
12590
+ const raw = value.trim();
12591
+ const match = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:Z|[+-](\d{2}):(\d{2}))$/i.exec(
12592
+ raw
12593
+ );
12594
+ if (!match) {
12592
12595
  throw new CliUsageError(
12593
- `--${flag} must be a valid RFC3339 timestamp, got '${value}'`,
12594
- "loop"
12596
+ `--${flag} must be an RFC3339 timestamp with a timezone`,
12597
+ "schedule"
12595
12598
  );
12596
12599
  }
12597
- const timestamp = Date.parse(raw);
12598
- if (!Number.isFinite(timestamp)) {
12600
+ const [year, month, day, hour, minute, second] = match.slice(1, 7).map(Number);
12601
+ const offsetHour = Number(match[7] ?? 0);
12602
+ const offsetMinute = Number(match[8] ?? 0);
12603
+ const daysInMonth = new Date(Date.UTC(year, month, 0)).getUTCDate();
12604
+ const parsed = Date.parse(raw);
12605
+ if (!Number.isFinite(parsed) || year < 1 || year > 9999 || month < 1 || month > 12 || day < 1 || day > daysInMonth || hour > 23 || minute > 59 || second > 59 || offsetHour > 23 || offsetMinute > 59) {
12599
12606
  throw new CliUsageError(
12600
- `--${flag} must be a valid RFC3339 timestamp, got '${value}'`,
12601
- "loop"
12607
+ `--${flag} must be a valid RFC3339 timestamp with a timezone`,
12608
+ "schedule"
12602
12609
  );
12603
12610
  }
12604
- return new Date(timestamp).toISOString();
12605
- }
12606
- function parseLoopRuns(value) {
12607
- if (value === void 0) return void 0;
12608
- if (!/^[1-9]\d*$/.test(value)) {
12609
- throw new CliUsageError("--runs must be a positive integer", "loop");
12610
- }
12611
- const runs = Number(value);
12612
- if (!Number.isSafeInteger(runs) || runs > 2147483647) {
12613
- throw new CliUsageError("--runs is too large", "loop");
12614
- }
12615
- return runs;
12616
- }
12617
- function loopCronjobName(flags, goal) {
12618
- if (flags["name"] !== void 0) return flags["name"];
12619
- const base = goal.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
12620
- const slug = (base ? `loop-${base}` : "loop").slice(0, 63).replace(/-+$/g, "");
12621
- return slug || "loop";
12611
+ return new Date(parsed).toISOString().replace(".000Z", "Z");
12622
12612
  }
12623
- function loopAutomationDescription(goal) {
12624
- const prefix = "Channel loop: ";
12625
- const maxDescriptionRunes = 4096;
12626
- const availableGoalRunes = maxDescriptionRunes - Array.from(prefix).length;
12627
- return prefix + Array.from(goal).slice(0, availableGoalRunes).join("");
12613
+ function scheduleBoundsFromFlags(flags) {
12614
+ const startsAt = flags["starts-at"] !== void 0 ? parseScheduleTimestamp(flags["starts-at"], "starts-at") : void 0;
12615
+ const until = flags["until"] !== void 0 ? parseScheduleTimestamp(flags["until"], "until") : void 0;
12616
+ const maxOccurrences = flags["max-occurrences"] !== void 0 ? requirePositiveIntegerFlag(flags, "max-occurrences", "schedule put") : void 0;
12617
+ return startsAt !== void 0 || until !== void 0 || maxOccurrences !== void 0 ? { startsAt, until, maxOccurrences } : void 0;
12628
12618
  }
12629
12619
  function parseCreditsItemsParams(flags) {
12630
12620
  const command2 = "credits items";
@@ -13148,83 +13138,64 @@ async function executeParsedCommand(client, parsedCommand, meta, deps) {
13148
13138
  );
13149
13139
  }
13150
13140
  }
13151
- case "loop": {
13152
- if (!subcommand)
13153
- throw new CliUsageError("Missing subcommand for loop", "loop");
13141
+ case "schedule": {
13142
+ if (!subcommand) {
13143
+ throw new CliUsageError("Missing subcommand for schedule", "schedule");
13144
+ }
13154
13145
  switch (subcommand) {
13155
- case "create": {
13156
- if (flags["expires-in"] !== void 0) {
13157
- throw new CliUsageError(
13158
- "Unknown flag --expires-in; use --until and/or --runs",
13159
- "loop"
13160
- );
13161
- }
13162
- const goal = requireFlag(flags, "goal", "loop create");
13163
- const cron = requireFlag(flags, "cron", "loop create");
13164
- const channelId = flags["channel-id"];
13165
- const startRaw = (flags["start"] ?? "now").trim();
13166
- const startAt = startRaw.toLowerCase() === "now" ? void 0 : parseLoopTimestamp(startRaw, "start");
13167
- const endAt = flags["until"] ? parseLoopTimestamp(flags["until"], "until") : void 0;
13168
- const maxRuns = parseLoopRuns(flags["runs"]);
13169
- if (endAt === void 0 && maxRuns === void 0) {
13170
- throw new CliUsageError(
13171
- "loop create requires at least one of --until or --runs",
13172
- "loop"
13173
- );
13174
- }
13175
- if (startAt !== void 0 && endAt !== void 0 && endAt <= startAt) {
13146
+ case "list": {
13147
+ const channelId = await scheduleChannelId(client, flags);
13148
+ return client.schedules.list({ channelId });
13149
+ }
13150
+ case "put": {
13151
+ const rule = scheduleRuleFromFlags(flags);
13152
+ const bounds = scheduleBoundsFromFlags(flags);
13153
+ if ((rule.kind === "at" || rule.kind === "after") && bounds !== void 0) {
13176
13154
  throw new CliUsageError(
13177
- "--until must be later than --start",
13178
- "loop"
13155
+ `${rule.kind} does not accept recurring bounds`,
13156
+ "schedule"
13179
13157
  );
13180
13158
  }
13181
- const name = loopCronjobName(flags, goal);
13182
- await client.fs.write({
13183
- path: LOOP_RUNNER_PATH,
13184
- data: LOOP_RUNNER_SRC,
13185
- mkdir_parents: true
13186
- });
13187
- const cronjob = await client.deploy.create({
13159
+ const name = requireFlag(flags, "name", "schedule put");
13160
+ const text = requireFlag(flags, "message", "schedule put");
13161
+ const channelId = await scheduleChannelId(client, flags);
13162
+ return client.schedules.put({
13163
+ channelId,
13188
13164
  name,
13189
- path: LOOP_RUNNER_PATH,
13190
- cron_expression: cron,
13191
- args: channelId ? { goal, channelId } : { goal },
13192
- start_at: startAt,
13193
- end_at: endAt,
13194
- max_runs: maxRuns
13165
+ text,
13166
+ rule,
13167
+ bounds
13195
13168
  });
13196
- try {
13197
- const automation = await client.automation.publish({
13198
- name,
13199
- version: "1.0.0",
13200
- cronjob_id: cronjob.id,
13201
- description: loopAutomationDescription(goal),
13202
- skip_auto_trigger: true
13203
- });
13204
- return {
13205
- name,
13206
- automation_id: String(automation.feed_id),
13207
- cronjob_id: cronjob.id
13208
- };
13209
- } catch (publishError) {
13210
- const publishMessage = publishError instanceof Error ? publishError.message : String(publishError);
13211
- try {
13212
- await client.deploy.delete({ id: cronjob.id });
13213
- } catch (rollbackError) {
13214
- const rollbackMessage = rollbackError instanceof Error ? rollbackError.message : String(rollbackError);
13215
- throw new Error(
13216
- `failed to publish loop "${name}" as an automation after creating cronjob ${cronjob.id}: ${publishMessage}; automatic rollback failed: ${rollbackMessage}; cronjob ${cronjob.id} may still exist; run \`alva deploy delete --id ${cronjob.id}\``
13217
- );
13218
- }
13219
- throw new Error(
13220
- `failed to publish loop "${name}" as an automation; rolled back cronjob ${cronjob.id}: ${publishMessage}`
13221
- );
13222
- }
13169
+ }
13170
+ case "pause": {
13171
+ const name = requireFlag(flags, "name", "schedule pause");
13172
+ const channelId = await scheduleChannelId(client, flags);
13173
+ return client.schedules.pause({
13174
+ channelId,
13175
+ name
13176
+ });
13177
+ }
13178
+ case "resume": {
13179
+ const name = requireFlag(flags, "name", "schedule resume");
13180
+ const channelId = await scheduleChannelId(client, flags);
13181
+ return client.schedules.resume({
13182
+ channelId,
13183
+ name
13184
+ });
13185
+ }
13186
+ case "delete": {
13187
+ const name = requireFlag(flags, "name", "schedule delete");
13188
+ const channelId = await scheduleChannelId(client, flags);
13189
+ await client.schedules.delete({
13190
+ channelId,
13191
+ name
13192
+ });
13193
+ return { deleted: true };
13223
13194
  }
13224
13195
  default:
13225
13196
  throw new CliUsageError(
13226
- `Unknown subcommand: loop ${subcommand}`,
13227
- "loop"
13197
+ `Unknown subcommand: schedule ${subcommand}`,
13198
+ "schedule"
13228
13199
  );
13229
13200
  }
13230
13201
  }