@wenathlan/extension 1.1.51 → 1.1.52

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/index.js CHANGED
@@ -4363,6 +4363,77 @@ var sessionmemory = class {
4363
4363
  }
4364
4364
  return history;
4365
4365
  }
4366
+ /** Stores one armed trigger rule with its workflow reference; re-arming the same id replaces the rule while the fire history survives. */
4367
+ async addtriggerule(rule) {
4368
+ const rules = (await this.gettriggerules()).filter((entry) => entry.id !== rule.id);
4369
+ await this.adapter.set("triggerules", [rule, ...rules]);
4370
+ }
4371
+ /** Returns every armed trigger rule, newest first. */
4372
+ async gettriggerules() {
4373
+ return await this.adapter.get("triggerules") ?? [];
4374
+ }
4375
+ /** Returns one armed trigger rule by its id. */
4376
+ async gettriggerule(id) {
4377
+ return (await this.gettriggerules()).find((rule) => rule.id === id);
4378
+ }
4379
+ /** Replaces one stored rule after an enable, disable, pause, resume, cooldown or fire bookkeeping change. */
4380
+ async settriggerule(rule) {
4381
+ const rules = await this.gettriggerules();
4382
+ await this.adapter.set("triggerules", rules.map((entry) => entry.id === rule.id ? rule : entry));
4383
+ }
4384
+ /** Replaces every stored rule at once so the session pause and resume suspend and release the whole rule set atomically. */
4385
+ async settriggerules(rules) {
4386
+ return this.adapter.set("triggerules", rules);
4387
+ }
4388
+ /** Removes one armed rule when the user disarms it; the fire history survives for the audit trail. */
4389
+ async removetriggerule(id) {
4390
+ await this.adapter.set("triggerules", (await this.gettriggerules()).filter((rule) => rule.id !== id));
4391
+ }
4392
+ /** Lists every armed rule joined with the name of its composed workflow so the trigger list shows what each rule launches. */
4393
+ async listtriggers() {
4394
+ const rules = await this.gettriggerules();
4395
+ const names = new Map((await this.listworkflows()).map((record2) => [record2.id, record2.name]));
4396
+ return rules.map((rule) => ({ rule, ...names.has(rule.workflowid) ? { workflowname: names.get(rule.workflowid) } : {} }));
4397
+ }
4398
+ /** Records one trigger fire with the reviewed retention window; an absent window keeps every fire record while the rule counters always survive. */
4399
+ async addtriggerfire(fire) {
4400
+ const fires = await this.listtriggerfires();
4401
+ const combined = [fire, ...fires];
4402
+ const retention = (await this.getsettings())?.triggerretention;
4403
+ await this.adapter.set("triggerfires", retention === void 0 ? combined : combined.slice(0, retention));
4404
+ }
4405
+ /** Returns every stored trigger fire record, newest first, optionally filtered to one rule. */
4406
+ async listtriggerfires(ruleid) {
4407
+ const fires = await this.adapter.get("triggerfires") ?? [];
4408
+ return ruleid === void 0 ? fires : fires.filter((fire) => fire.ruleid === ruleid);
4409
+ }
4410
+ /** Stores the pending trigger queue: fires that arrived while the target run was busy or the session paused; the resume drains them through the same gates. */
4411
+ async settriggerqueue(queue) {
4412
+ return this.adapter.set("triggerqueue", queue);
4413
+ }
4414
+ /** Returns the pending trigger queue, oldest first. */
4415
+ async gettriggerqueue() {
4416
+ return await this.adapter.get("triggerqueue") ?? [];
4417
+ }
4418
+ /** Stores one verified webhook payload of a rule; the executor verifies the shared secret and the schema before anything persists. */
4419
+ async addwebhookpayload(ruleid, payload, at) {
4420
+ const stored = await this.adapter.get("webhookpayloads") ?? [];
4421
+ await this.adapter.set("webhookpayloads", [{ ruleid, payload, at }, ...stored]);
4422
+ }
4423
+ /** Returns the stored webhook payloads of one rule, newest first; only secret verified deliveries ever reach this store. */
4424
+ async listwebhookpayloads(ruleid) {
4425
+ const stored = await this.adapter.get("webhookpayloads") ?? [];
4426
+ return stored.filter((entry) => entry.ruleid === ruleid);
4427
+ }
4428
+ /** Stores one manual run preview with its step list so the panel renders it before confirmation. */
4429
+ async addmanualrun(preview) {
4430
+ const runs = (await this.listmanualruns()).filter((entry) => entry.id !== preview.id);
4431
+ await this.adapter.set("manualruns", [preview, ...runs]);
4432
+ }
4433
+ /** Returns every stored manual run preview with its confirmation outcome, newest first. */
4434
+ async listmanualruns() {
4435
+ return await this.adapter.get("manualruns") ?? [];
4436
+ }
4366
4437
  };
4367
4438
  function mediakindof(record2) {
4368
4439
  if ("pages" in record2) return "pdf";
@@ -4899,6 +4970,401 @@ function extractvalues(body, paths) {
4899
4970
  return fields.map((field) => ({ path: field.path, ...field.value !== void 0 ? { value: field.value } : {}, ...field.missing ? { missing: true } : {} }));
4900
4971
  }
4901
4972
 
4973
+ // trigger.ts
4974
+ var triggerkinds = ["visitrule", "urlrule", "menurule", "keyrule", "buttonrule", "cronrule", "intervalrule", "urllistrule", "webhookrule", "eventrule"];
4975
+ var triggerfamilies = ["visit", "url", "menu", "key", "button", "cron", "interval", "urllist", "webhook", "event"];
4976
+ var triggereventcatalog = ["mutate", "focus", "banner", "console", "error", "navigate"];
4977
+ var defaulttriggercooldown = 1e4;
4978
+ function istriggerkind(kind) {
4979
+ return triggerkinds.includes(kind);
4980
+ }
4981
+ function triggerfamilyof(kind) {
4982
+ const index = triggerkinds.indexOf(kind);
4983
+ return index >= 0 ? triggerfamilies[index] : void 0;
4984
+ }
4985
+ function triggerlabel(value) {
4986
+ return typeof value === "string" && value.trim() ? value.trim() : void 0;
4987
+ }
4988
+ function positivewindow(value) {
4989
+ if (value === void 0) return void 0;
4990
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : void 0;
4991
+ }
4992
+ function jitterwindow(value) {
4993
+ if (value === void 0) return void 0;
4994
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
4995
+ }
4996
+ function httpsorigin(value) {
4997
+ if (typeof value !== "string" || !value.trim()) return void 0;
4998
+ try {
4999
+ const parsed = new URL(value.trim());
5000
+ if (parsed.protocol !== "https:") return void 0;
5001
+ return parsed.origin;
5002
+ } catch {
5003
+ return void 0;
5004
+ }
5005
+ }
5006
+ function webhookfieldof(value) {
5007
+ if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
5008
+ const candidate = value;
5009
+ if (typeof candidate.name !== "string" || !/^[a-z][a-z0-9]*$/i.test(candidate.name)) return void 0;
5010
+ if (candidate.kind !== "string" && candidate.kind !== "number" && candidate.kind !== "boolean") return void 0;
5011
+ if (candidate.required !== void 0 && typeof candidate.required !== "boolean") return void 0;
5012
+ return { name: candidate.name, kind: candidate.kind, ...candidate.required === true ? { required: true } : {} };
5013
+ }
5014
+ function triggerpayloadof(family, value) {
5015
+ if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
5016
+ const candidate = value;
5017
+ if (family === "visit") {
5018
+ if (!Array.isArray(candidate.origins) || candidate.origins.length === 0) return void 0;
5019
+ const origins = candidate.origins.map((origin) => httpsorigin(origin));
5020
+ if (origins.some((origin) => origin === void 0)) return void 0;
5021
+ return { origins: [...new Set(origins)] };
5022
+ }
5023
+ if (family === "url") {
5024
+ if (typeof candidate.pattern !== "string" || !candidate.pattern.trim()) return void 0;
5025
+ if (httpsorigin(candidate.pattern) === void 0) return void 0;
5026
+ return { pattern: candidate.pattern.trim() };
5027
+ }
5028
+ if (family === "menu") {
5029
+ const title = triggerlabel(candidate.title);
5030
+ if (!title) return void 0;
5031
+ return { title };
5032
+ }
5033
+ if (family === "key") {
5034
+ if (typeof candidate.command !== "string" || !/^[a-z][a-z0-9-]*$/.test(candidate.command)) return void 0;
5035
+ if (candidate.key !== void 0 && (typeof candidate.key !== "string" || !candidate.key.trim())) return void 0;
5036
+ return { command: candidate.command, ...candidate.key !== void 0 ? { key: candidate.key } : {} };
5037
+ }
5038
+ if (family === "button") return {};
5039
+ if (family === "cron") {
5040
+ if (typeof candidate.cron !== "string" || !candidate.cron.trim()) return void 0;
5041
+ if (cronparse(candidate.cron) === void 0) return void 0;
5042
+ if (candidate.timezone !== void 0 && (typeof candidate.timezone !== "string" || !timezonevalid(candidate.timezone))) return void 0;
5043
+ return { cron: candidate.cron.trim(), ...candidate.timezone !== void 0 ? { timezone: candidate.timezone } : {} };
5044
+ }
5045
+ if (family === "interval") {
5046
+ const period = positivewindow(candidate.period);
5047
+ if (period === void 0) return void 0;
5048
+ const jitter = jitterwindow(candidate.jitter);
5049
+ if (candidate.jitter !== void 0 && jitter === void 0) return void 0;
5050
+ return { period, ...jitter !== void 0 ? { jitter } : {} };
5051
+ }
5052
+ if (family === "urllist") {
5053
+ if (!Array.isArray(candidate.urls) || candidate.urls.length === 0) return void 0;
5054
+ const urls = candidate.urls.map((url) => httpsorigin(url) === void 0 ? void 0 : url.trim());
5055
+ if (urls.some((url) => url === void 0)) return void 0;
5056
+ return { urls };
5057
+ }
5058
+ if (family === "webhook") {
5059
+ if (typeof candidate.secret !== "string" || !webhooksecretok(candidate.secret)) return void 0;
5060
+ if (!Array.isArray(candidate.schema) || candidate.schema.length === 0) return void 0;
5061
+ const schema = candidate.schema.map((field) => webhookfieldof(field));
5062
+ if (schema.some((field) => field === void 0)) return void 0;
5063
+ const names = schema.map((field) => field.name);
5064
+ if (new Set(names).size !== names.length) return void 0;
5065
+ return { secret: candidate.secret, schema };
5066
+ }
5067
+ const events = candidate.events;
5068
+ if (!Array.isArray(events) || events.length === 0) return void 0;
5069
+ if (!events.every((name) => typeof name === "string" && triggereventcatalog.includes(name))) return void 0;
5070
+ return { events: [...new Set(events)] };
5071
+ }
5072
+ function webhooksecretok(secret) {
5073
+ if (secret.length < 24) return false;
5074
+ if (/^(.)\1+$/.test(secret)) return false;
5075
+ return /[a-z]/i.test(secret) && /\d/.test(secret);
5076
+ }
5077
+ function timezonevalid(timezone) {
5078
+ try {
5079
+ new Intl.DateTimeFormat("en-US", { timeZone: timezone });
5080
+ return true;
5081
+ } catch {
5082
+ return false;
5083
+ }
5084
+ }
5085
+ function armrule(input) {
5086
+ if (typeof input.workflowid !== "string" || !input.workflowid.trim()) return void 0;
5087
+ const payload = triggerpayloadof(input.family, input.payload);
5088
+ if (!payload) return void 0;
5089
+ if (input.cooldown !== void 0 && (typeof input.cooldown !== "number" || !Number.isFinite(input.cooldown) || input.cooldown <= 0)) return void 0;
5090
+ const cooldown = input.cooldown ?? (input.family === "webhook" || input.family === "event" ? defaulttriggercooldown : 0);
5091
+ const label = input.label ?? `The ${input.family} rule of ${input.workflowid}`;
5092
+ return { id: input.id ?? crypto.randomUUID(), kind: input.family, workflowid: input.workflowid, label, ...payload, cooldown, state: { enabled: true, cooldown }, stats: { fires: 0, launches: 0, suppressions: 0 }, createdat: input.now };
5093
+ }
5094
+ function updaterule(rule, patch) {
5095
+ return { ...rule, ...patch.state !== void 0 ? { state: { ...rule.state, ...patch.state } } : {}, ...patch.stats !== void 0 ? { stats: { ...rule.stats, ...patch.stats } } : {} };
5096
+ }
5097
+ function matchurl(pattern, url) {
5098
+ let parsedpattern;
5099
+ let parsedurl;
5100
+ try {
5101
+ parsedpattern = new URL(pattern);
5102
+ parsedurl = new URL(url);
5103
+ } catch {
5104
+ return false;
5105
+ }
5106
+ if (parsedpattern.protocol !== parsedurl.protocol) return false;
5107
+ if (parsedpattern.hostname !== parsedurl.hostname) return false;
5108
+ if (parsedpattern.port !== "" && parsedpattern.port !== parsedurl.port) return false;
5109
+ return globmatch(`${parsedpattern.pathname}${parsedpattern.search}`, `${parsedurl.pathname}${parsedurl.search}`);
5110
+ }
5111
+ function globmatch(pattern, text2) {
5112
+ const escaped = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
5113
+ const expression = new RegExp(["^", pattern.split("**").map((segment) => segment.split("*").map(escaped).join("[^/]*")).join(".*"), "$"].join(""));
5114
+ return expression.test(text2);
5115
+ }
5116
+ function visitmatch(origins, url) {
5117
+ let origin = "";
5118
+ try {
5119
+ origin = new URL(url).origin;
5120
+ } catch {
5121
+ return false;
5122
+ }
5123
+ return origins.includes(origin);
5124
+ }
5125
+ function cronparse(expression) {
5126
+ const fields = expression.trim().split(/\s+/);
5127
+ if (fields.length !== 5) return void 0;
5128
+ const minutes = cronfield(fields[0] ?? "", 0, 59);
5129
+ const hours = cronfield(fields[1] ?? "", 0, 23);
5130
+ const daysofmonth = cronfield(fields[2] ?? "", 1, 31);
5131
+ const months = cronfield(fields[3] ?? "", 1, 12, monthnames);
5132
+ const daysofweek = cronfield(fields[4] ?? "", 0, 7, weekdaynames, true);
5133
+ if (!minutes || !hours || !daysofmonth || !months || !daysofweek) return void 0;
5134
+ return { minutes, hours, daysofmonth, months, daysofweek: [...new Set(daysofweek.map((day) => day % 7))].sort((left, right) => left - right) };
5135
+ }
5136
+ var weekdaynames = { sun: 0, mon: 1, tue: 2, wed: 3, thu: 4, fri: 5, sat: 6 };
5137
+ var monthnames = { jan: 1, feb: 2, mar: 3, apr: 4, may: 5, jun: 6, jul: 7, aug: 8, sep: 9, oct: 10, nov: 11, dec: 12 };
5138
+ function cronfield(field, min, max, names, sundayseven = false) {
5139
+ const values = /* @__PURE__ */ new Set();
5140
+ for (const part of field.split(",")) {
5141
+ if (!part) return void 0;
5142
+ const [range, stepstring] = part.split("/");
5143
+ const step = stepstring === void 0 ? 1 : Number(stepstring);
5144
+ if (!Number.isInteger(step) || step < 1) return void 0;
5145
+ let low = min;
5146
+ let high = max;
5147
+ if (range !== void 0 && range !== "*") {
5148
+ const bounds = range.split("-");
5149
+ if (bounds.length > 2) return void 0;
5150
+ const lowvalue = cronvalue(bounds[0] ?? "", min, max, names);
5151
+ if (lowvalue === void 0) return void 0;
5152
+ low = lowvalue;
5153
+ high = lowvalue;
5154
+ if (bounds.length === 2) {
5155
+ const highvalue = cronvalue(bounds[1] ?? "", min, max, names);
5156
+ if (highvalue === void 0 || highvalue < lowvalue) return void 0;
5157
+ high = highvalue;
5158
+ }
5159
+ }
5160
+ for (let value = low; value <= high; value += step) values.add(value);
5161
+ }
5162
+ const list = [...values];
5163
+ if (list.some((value) => value < min || value > max)) return void 0;
5164
+ if (sundayseven && values.has(7)) {
5165
+ values.delete(7);
5166
+ values.add(0);
5167
+ }
5168
+ return [...values].sort((left, right) => left - right);
5169
+ }
5170
+ function cronvalue(value, min, max, names) {
5171
+ const candidate = names?.[value.toLowerCase()];
5172
+ if (candidate !== void 0) return candidate;
5173
+ if (!/^\d+$/.test(value)) return void 0;
5174
+ const parsed = Number(value);
5175
+ if (parsed < min || parsed > max) return void 0;
5176
+ return parsed;
5177
+ }
5178
+ function calendarparts(at, timezone) {
5179
+ if (timezone === void 0) {
5180
+ const date = new Date(at);
5181
+ return { minute: date.getUTCMinutes(), hour: date.getUTCHours(), day: date.getUTCDate(), month: date.getUTCMonth() + 1, weekday: date.getUTCDay() };
5182
+ }
5183
+ const parts = new Intl.DateTimeFormat("en-US", { timeZone: timezone, hourCycle: "h23", minute: "numeric", hour: "numeric", day: "numeric", month: "short", weekday: "short" }).formatToParts(new Date(at));
5184
+ const pick = (type) => parts.find((part) => part.type === type)?.value ?? "";
5185
+ const weekday = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"].indexOf(pick("weekday"));
5186
+ const month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"].indexOf(pick("month")) + 1;
5187
+ return { minute: Number(pick("minute")), hour: Number(pick("hour")), day: Number(pick("day")), month, weekday };
5188
+ }
5189
+ function crondaymatch(schedule, parts) {
5190
+ if (!schedule.months.includes(parts.month)) return false;
5191
+ const domfull = schedule.daysofmonth.length === 31;
5192
+ const dowfull = schedule.daysofweek.length === 7;
5193
+ const dommatch = schedule.daysofmonth.includes(parts.day);
5194
+ const dowmatch = schedule.daysofweek.includes(parts.weekday);
5195
+ if (!domfull && !dowfull) return dommatch || dowmatch;
5196
+ if (!domfull) return dommatch;
5197
+ if (!dowfull) return dowmatch;
5198
+ return true;
5199
+ }
5200
+ function cronnext(expression, from, timezone) {
5201
+ const schedule = cronparse(expression);
5202
+ if (!schedule) return void 0;
5203
+ const minute = 6e4;
5204
+ const hour = 60 * minute;
5205
+ const day = 24 * hour;
5206
+ let candidate = Math.floor(from / minute) * minute + minute;
5207
+ const horizon = from + 4 * 366 * day;
5208
+ while (candidate <= horizon) {
5209
+ const parts = calendarparts(candidate, timezone);
5210
+ if (!crondaymatch(schedule, parts)) {
5211
+ candidate += day - parts.hour * hour - parts.minute * minute;
5212
+ continue;
5213
+ }
5214
+ if (!schedule.hours.includes(parts.hour)) {
5215
+ const later = schedule.hours.find((value) => value > parts.hour);
5216
+ candidate += later === void 0 ? day - parts.hour * hour - parts.minute * minute : (later - parts.hour) * hour - parts.minute * minute;
5217
+ continue;
5218
+ }
5219
+ if (!schedule.minutes.includes(parts.minute)) {
5220
+ const later = schedule.minutes.find((value) => value > parts.minute);
5221
+ candidate += later === void 0 ? (60 - parts.minute) * minute : (later - parts.minute) * minute;
5222
+ continue;
5223
+ }
5224
+ return candidate;
5225
+ }
5226
+ return void 0;
5227
+ }
5228
+ function schedulecron(rule, from) {
5229
+ return cronnext(rule.cron, from, rule.timezone);
5230
+ }
5231
+ function scheduleinterval(rule, lastfire, armedat, seed) {
5232
+ const base = (lastfire ?? armedat) + rule.period;
5233
+ const jitter = rule.jitter ?? 0;
5234
+ if (jitter <= 0) return base;
5235
+ return Math.max(0, Math.round(base - jitter / 2 + seededrandom(seed) * jitter));
5236
+ }
5237
+ function listdue(rules, now) {
5238
+ return rules.flatMap((rule) => {
5239
+ if (rule.state.nextfireat === void 0 || rule.state.nextfireat > now) return [];
5240
+ if (!rule.state.enabled || rule.state.pausedat !== void 0) return [];
5241
+ return [{ rule, overdueby: now - rule.state.nextfireat }];
5242
+ });
5243
+ }
5244
+ function applycooldown(rule, now) {
5245
+ const lastfireat = rule.state.lastfireat;
5246
+ if (lastfireat === void 0 || rule.state.cooldown <= 0) return { suppressed: false, remaining: 0 };
5247
+ const remaining = lastfireat + rule.state.cooldown - now;
5248
+ return { suppressed: remaining > 0, remaining: Math.max(0, remaining) };
5249
+ }
5250
+ function evaluatetrigger(input) {
5251
+ const rule = input.rule;
5252
+ if (!rule.state.enabled) return { fired: false, suppressed: "disabled" };
5253
+ if (rule.state.pausedat !== void 0) return { fired: false, suppressed: "paused" };
5254
+ if (!input.workflowreviewed) return { fired: false, suppressed: "unreviewed" };
5255
+ if (input.runactive) return { fired: false, suppressed: "dedupe" };
5256
+ const cooldown = applycooldown(rule, input.now);
5257
+ if (cooldown.suppressed) return { fired: false, suppressed: "cooldown", remaining: cooldown.remaining };
5258
+ const fire = { id: crypto.randomUUID(), ruleid: rule.id, at: input.now, cause: input.cause, ...input.url !== void 0 ? { url: input.url } : {}, ...input.title !== void 0 ? { title: input.title } : {}, ...input.payload !== void 0 ? { payload: input.payload } : {} };
5259
+ return { fired: true, fire };
5260
+ }
5261
+ function queuefire(queue, fire) {
5262
+ if (queue.some((pending) => pending.ruleid === fire.ruleid)) return { queue, queued: false, deduped: true };
5263
+ return { queue: [...queue, fire], queued: true, deduped: false };
5264
+ }
5265
+ async function drainqueue(queue, launch) {
5266
+ let remaining = [...queue];
5267
+ let launched = 0;
5268
+ while (remaining.length > 0) {
5269
+ const fire = remaining[0];
5270
+ try {
5271
+ await launch(fire);
5272
+ } catch {
5273
+ return { launched, remaining };
5274
+ }
5275
+ remaining = remaining.slice(1);
5276
+ launched += 1;
5277
+ }
5278
+ return { launched, remaining };
5279
+ }
5280
+ function runurllist(rule, now) {
5281
+ const urls = rule.urls ?? [];
5282
+ return urls.map((url) => ({ id: crypto.randomUUID(), ruleid: rule.id, at: now, cause: "urllist", url }));
5283
+ }
5284
+ function verifywebhook(input) {
5285
+ if (typeof input.rule.secret !== "string" || !input.rule.secret) return { verified: false, reason: "The webhook rule carries no reviewed secret." };
5286
+ if (!secrectsmatch(input.secret, input.rule.secret)) return { verified: false, reason: "The webhook secret does not match the reviewed secret of the rule." };
5287
+ const payload = input.payload;
5288
+ if (!payload || typeof payload !== "object" || Array.isArray(payload)) return { verified: false, reason: "The webhook payload must be a JSON object." };
5289
+ const candidate = payload;
5290
+ for (const field of input.rule.schema ?? []) {
5291
+ const value = candidate[field.name];
5292
+ if (value === void 0) {
5293
+ if (field.required === true) return { verified: false, reason: `The required webhook field ${field.name} is missing.` };
5294
+ continue;
5295
+ }
5296
+ if (typeof value !== field.kind) return { verified: false, reason: `The webhook field ${field.name} is not a ${field.kind}.` };
5297
+ }
5298
+ return { verified: true };
5299
+ }
5300
+ function secrectsmatch(left, right) {
5301
+ if (left.length !== right.length) return false;
5302
+ let same = true;
5303
+ for (let index = 0; index < left.length; index += 1) if (left.charCodeAt(index) !== right.charCodeAt(index)) same = false;
5304
+ return same;
5305
+ }
5306
+ function eventrulematches(rule, event) {
5307
+ return (rule.events ?? []).includes(event);
5308
+ }
5309
+ function observeevents(rules, event) {
5310
+ if (!triggereventcatalog.includes(event)) return [];
5311
+ return rules.filter((rule) => rule.kind === "event" && rule.state.enabled && rule.state.pausedat === void 0 && eventrulematches(rule, event));
5312
+ }
5313
+ function pauseall(rules, now) {
5314
+ return rules.map((rule) => rule.state.enabled && rule.state.pausedat === void 0 ? updaterule(rule, { state: { pausedat: now } }) : rule);
5315
+ }
5316
+ function resumeall(rules) {
5317
+ return rules.map((rule) => {
5318
+ if (rule.state.pausedat === void 0) return rule;
5319
+ const state = { ...rule.state };
5320
+ delete state.pausedat;
5321
+ return { ...rule, state };
5322
+ });
5323
+ }
5324
+ function manualpreview(record2, now) {
5325
+ return { id: crypto.randomUUID(), workflowid: record2.id, preview: record2.steps.map((step) => ({ stepid: step.id, kind: step.kind, label: step.label, ...step.block !== void 0 ? { block: step.block } : {}, ...controlsummary(step) !== void 0 ? { control: controlsummary(step) } : {} })), at: now };
5326
+ }
5327
+ function confirmmanualrun(preview, confirmed, now) {
5328
+ return { ...preview, confirmed, decidedat: now };
5329
+ }
5330
+ function triggersummary(rule) {
5331
+ return {
5332
+ kind: rule.kind,
5333
+ workflowid: rule.workflowid,
5334
+ label: rule.label,
5335
+ ...rule.origins !== void 0 ? { origins: rule.origins } : {},
5336
+ ...rule.pattern !== void 0 ? { pattern: rule.pattern } : {},
5337
+ ...rule.title !== void 0 ? { title: rule.title } : {},
5338
+ ...rule.command !== void 0 ? { command: rule.command } : {},
5339
+ ...rule.key !== void 0 ? { key: rule.key } : {},
5340
+ ...rule.cron !== void 0 ? { cron: rule.cron, ...rule.timezone !== void 0 ? { timezone: rule.timezone } : {} } : {},
5341
+ ...rule.period !== void 0 ? { period: rule.period, ...rule.jitter !== void 0 ? { jitter: rule.jitter } : {} } : {},
5342
+ ...rule.urls !== void 0 ? { urls: rule.urls } : {},
5343
+ ...rule.events !== void 0 ? { events: rule.events } : {},
5344
+ ...rule.schema !== void 0 ? { fields: rule.schema.length } : {},
5345
+ cooldown: rule.state.cooldown,
5346
+ enabled: rule.state.enabled,
5347
+ ...rule.state.nextfireat !== void 0 ? { nextfireat: rule.state.nextfireat } : {}
5348
+ };
5349
+ }
5350
+ function ruleorigins(rule) {
5351
+ const origins = /* @__PURE__ */ new Set();
5352
+ for (const origin of rule.origins ?? []) origins.add(origin);
5353
+ if (rule.pattern !== void 0) {
5354
+ const origin = httpsorigin(rule.pattern);
5355
+ if (origin !== void 0) origins.add(origin);
5356
+ }
5357
+ for (const url of rule.urls ?? []) {
5358
+ const origin = httpsorigin(url);
5359
+ if (origin !== void 0) origins.add(origin);
5360
+ }
5361
+ return [...origins];
5362
+ }
5363
+ function ruleoriginsgranted(rule, workfloworigins) {
5364
+ const granted = new Set(workfloworigins);
5365
+ return ruleorigins(rule).every((origin) => granted.has(origin));
5366
+ }
5367
+
4902
5368
  // runtimeline.ts
4903
5369
  var timelinekinds = ["watchconsole", "watcherrors", "watchtasks"];
4904
5370
  var loglevels = ["error", "warn", "info", "log", "debug", "trace"];
@@ -5309,7 +5775,7 @@ function polldecision(input) {
5309
5775
  }
5310
5776
 
5311
5777
  // policy.ts
5312
- var sensitiveactions = /* @__PURE__ */ new Set(["click", "type", "navigate", "select", "presskey", "drag", "drop", "upload", "clear", "check", "uncheck", "toggle", "submit", "reload", "back", "forward", "writestorage", "setattribute", "removeattribute", "evaluate", "tabcreate", "tabactivate", "tabclose", "tabreload", "windowcreate", "windowclose", "windowresize", "downloadfile", "clickpoint", "shiftclick", "dismissdialog", "enterframe", "typetime", "appendtext", "setvalue", "typeedit", "keyhold", "keyrelease", "submitsearch", "selectmulti", "chooseradio", "setslider", "setdate", "setcolor", "openlink", "openprivate", "reloadcache", "stopnav", "followlink", "spanav", "rewritequery", "setfragment", "navlist", "navprofile", "handleauth", "printpdf", "prefetch", "preconnect", "deeplink", "reopentab", "pausenav", "navrate", "openclipboard", "batchopen", "duplicatetab", "closepattern", "pintab", "mutetab", "movetab", "movetabwindow", "grouptabs", "colorgroup", "collapsegroup", "discardtab", "reloadtabs", "zoomin", "zoomout", "switchtab", "maximizewindow", "minimizewindow", "restorewindow", "focuswindow", "scratchwindow", "incognitowindow", "restoretab", "restorelayout", "reopenrun", "badgetab", "fillform", "filllabel", "fillplaceholder", "submitform", "retryform", "runwizard", "selectchain", "picktypeahead", "pickdate", "attachfile", "fillcard", "fillcode", "consentpassword", "exportcsv", "exportjson", "exportexcel", "copytable", "pushsheets", "streamdisk", "paginateextract", "resumeextract", "batchdownload", "pausedownload", "resumedownload", "interceptmime", "readclipboard", "writeclipboard", "copyscreen", "quarantinedownload", "scanvirus", "cleanupartifacts", "recordscreen", "captureaudio", "downloadimages", "callrest", "callgraphql", "sendmessage", "blockrequest", "mockresponse", "rewriteheaders", "setcookies", "clearcookies", "authflow", "saveapikey", "routeproxy", "postform", "postfiles", "attachcdp", "detachcdp", "cdpcmd", "overridescript", "heapshot", "profilecpu", "capturesourcemaps", "emulatedevice", "emulatenetwork", "emulatelocate", "setuseragent", "overridepermission", "restoresession", "exportsessions", "importsessions", "runworkflow"]);
5778
+ var sensitiveactions = /* @__PURE__ */ new Set(["click", "type", "navigate", "select", "presskey", "drag", "drop", "upload", "clear", "check", "uncheck", "toggle", "submit", "reload", "back", "forward", "writestorage", "setattribute", "removeattribute", "evaluate", "tabcreate", "tabactivate", "tabclose", "tabreload", "windowcreate", "windowclose", "windowresize", "downloadfile", "clickpoint", "shiftclick", "dismissdialog", "enterframe", "typetime", "appendtext", "setvalue", "typeedit", "keyhold", "keyrelease", "submitsearch", "selectmulti", "chooseradio", "setslider", "setdate", "setcolor", "openlink", "openprivate", "reloadcache", "stopnav", "followlink", "spanav", "rewritequery", "setfragment", "navlist", "navprofile", "handleauth", "printpdf", "prefetch", "preconnect", "deeplink", "reopentab", "pausenav", "navrate", "openclipboard", "batchopen", "duplicatetab", "closepattern", "pintab", "mutetab", "movetab", "movetabwindow", "grouptabs", "colorgroup", "collapsegroup", "discardtab", "reloadtabs", "zoomin", "zoomout", "switchtab", "maximizewindow", "minimizewindow", "restorewindow", "focuswindow", "scratchwindow", "incognitowindow", "restoretab", "restorelayout", "reopenrun", "badgetab", "fillform", "filllabel", "fillplaceholder", "submitform", "retryform", "runwizard", "selectchain", "picktypeahead", "pickdate", "attachfile", "fillcard", "fillcode", "consentpassword", "exportcsv", "exportjson", "exportexcel", "copytable", "pushsheets", "streamdisk", "paginateextract", "resumeextract", "batchdownload", "pausedownload", "resumedownload", "interceptmime", "readclipboard", "writeclipboard", "copyscreen", "quarantinedownload", "scanvirus", "cleanupartifacts", "recordscreen", "captureaudio", "downloadimages", "callrest", "callgraphql", "sendmessage", "blockrequest", "mockresponse", "rewriteheaders", "setcookies", "clearcookies", "authflow", "saveapikey", "routeproxy", "postform", "postfiles", "attachcdp", "detachcdp", "cdpcmd", "overridescript", "heapshot", "profilecpu", "capturesourcemaps", "emulatedevice", "emulatenetwork", "emulatelocate", "setuseragent", "overridepermission", "restoresession", "exportsessions", "importsessions", "runworkflow", "visitrule", "urlrule", "menurule", "keyrule", "buttonrule", "cronrule", "intervalrule", "urllistrule", "webhookrule", "eventrule"]);
5313
5779
  var interactionactions = /* @__PURE__ */ new Set(["focus", "scroll", "hover", "clickdeep", "rightclick", "doubleclick", "scrollpage", "scrollby", "scrollend", "scrolltop", "fullscreen", "zoomset", "movepointer", "clicktext", "clickaria", "clickname", "expanddetails", "pierceshadow", "retryaction", "capturebodies", "setbreakpoint", "stepcode", "watchexpr", "loop", "repeatuntil", "whileloop", "foreach", "parallel", "trycatch"]);
5314
5780
  var readactions = /* @__PURE__ */ new Set(["observe", "inspect", "extract", "wait", "waitfor", "waittext", "readattribute", "readstyle", "readgeometry", "readvalue", "readtext", "readhtml", "countelements", "readtable", "readlinks", "readimages", "readmeta", "readforms", "readstorage", "highlight", "tablist", "windowlist", "tabsnapshot", "mapclicks", "verifyvisible", "verifyenabled", "resolvexpath", "a11ytree", "readvisible", "readertree", "detectlists", "detecttables", "readjson", "watchmutate", "waitquiet", "watchbanner", "detectinfinitescroll", "detectvirtual", "detectlazy", "readscrollpos", "readlang", "readoutline", "countpages", "listshadow", "listframes", "classifypage", "fingerprintsection", "diffsnapshots", "readselection", "watchfocus", "detectsticky", "detectscrolllock", "readopengraph", "detectlanguage", "deriveselector", "waitload", "waiturl", "spawait", "detecthttp", "readredirects", "readfinalurl", "trailaudit", "navintent", "checksafe", "querytabs", "watchtab", "findclones", "searchtabs", "listaudio", "snapshotsession", "savelayout", "attachmeta", "detectfields", "generatevalues", "saveprofiles", "asksubmit", "readerrors", "skiphoneypot", "detectlogin", "detecttemplate", "handoffcaptcha", "scrapetable", "importcsv", "looprows", "transformvalues", "deduperows", "mergepages", "stamplerows", "previewgrid", "logprovenance", "verifydownload", "exportnetlog", "namecaptures", "shotview", "shotfullpage", "shotelement", "shotregion", "contactsheet", "capturepdf", "captureframe", "readmedia", "readassets", "probestream", "timelapse", "shotcanvas", "convertimage", "makethumbs", "fetchurl", "parsejson", "parsehtml", "opensocket", "waitmessage", "watchrequests", "readheaders", "mapapi", "subscribesse", "longpoll", "extractapi", "readcookies", "watchconsole", "watcherrors", "watchtasks", "watchcdp", "measureflow", "trackmemory", "watchshifts", "traceload", "annotatetrace", "replaytrace", "blackboxscripts", "persiststate", "capturesession", "namedsessions", "diffsessions", "searchsessions", "composeworkflow", "savetemplate", "dryrun", "delay", "waitelement", "compute", "extractvars", "condition", "branch"]);
5315
5781
  var allowedactions = /* @__PURE__ */ new Set([...sensitiveactions, ...interactionactions, ...readactions]);
@@ -5333,6 +5799,7 @@ var profileractions = /* @__PURE__ */ new Set(["measureflow", "heapshot", "track
5333
5799
  var emulationactions = /* @__PURE__ */ new Set(["emulatedevice", "emulatenetwork", "emulatelocate", "setuseragent", "overridepermission", "blackboxscripts"]);
5334
5800
  var sessionactions = /* @__PURE__ */ new Set(["persiststate", "capturesession", "restoresession", "namedsessions", "diffsessions", "searchsessions", "exportsessions", "importsessions"]);
5335
5801
  var workflowactions = /* @__PURE__ */ new Set(["composeworkflow", "savetemplate", "runworkflow", "dryrun", "delay", "waitelement", "compute", "extractvars", "condition", "branch", "loop", "repeatuntil", "whileloop", "foreach", "parallel", "trycatch"]);
5802
+ var triggeractions = /* @__PURE__ */ new Set(["visitrule", "urlrule", "menurule", "keyrule", "buttonrule", "cronrule", "intervalrule", "urllistrule", "webhookrule", "eventrule"]);
5336
5803
  var credentialheaders = /* @__PURE__ */ new Set(["authorization", "proxy-authorization", "cookie", "cookie2", "set-cookie", "api-key", "x-api-key", "x-auth-token", "x-session-token", "proxy-authorization"]);
5337
5804
  var fieldkinds = ["text", "email", "phone", "date", "number", "select", "check", "radio", "file", "password", "card", "code"];
5338
5805
  var layoutmutationactions = /* @__PURE__ */ new Set(["grouptabs", "colorgroup", "collapsegroup", "savelayout", "restorelayout"]);
@@ -5354,6 +5821,9 @@ function issessionkind(kind) {
5354
5821
  function isworkflowkind(kind) {
5355
5822
  return workflowactions.has(kind);
5356
5823
  }
5824
+ function istriggeraction(kind) {
5825
+ return triggeractions.has(kind);
5826
+ }
5357
5827
  function iswatchkind(kind) {
5358
5828
  return watchactions.has(kind);
5359
5829
  }
@@ -7028,6 +7498,79 @@ function workflowgate(input) {
7028
7498
  }
7029
7499
  return { allowed: true };
7030
7500
  }
7501
+ function validatetriggergrammar(step, options) {
7502
+ const family = triggerfamilyof(step.kind);
7503
+ if (family === void 0) return { allowed: false, reason: "The trigger step is not a reviewed trigger kind." };
7504
+ if (typeof options.workflowid !== "string" || !options.workflowid.trim()) return { allowed: false, reason: "Every trigger rule needs the reviewed id of the composed workflow it launches." };
7505
+ if (options.reviewed !== true) return { allowed: false, reason: "Every trigger rule needs the explicit arm review with its match fields and bound workflow shown before it arms." };
7506
+ if (options.label !== void 0 && (typeof options.label !== "string" || !options.label.trim())) return { allowed: false, reason: "The reviewed trigger label must be a non-empty string." };
7507
+ if (options.cooldown !== void 0 && (typeof options.cooldown !== "number" || !Number.isFinite(options.cooldown) || options.cooldown <= 0)) return { allowed: false, reason: "The reviewed cooldown window must be a positive number of milliseconds with no code ceiling; the webhook and event families keep the documented default when the review configures none." };
7508
+ const payload = options.rule;
7509
+ if (!payload || typeof payload !== "object" || Array.isArray(payload)) return { allowed: false, reason: `The ${step.kind} step needs its reviewed rule payload in options.` };
7510
+ if (triggerpayloadof(family, payload) === void 0) {
7511
+ if (family === "visit") return { allowed: false, reason: "The visit rule needs a non-empty reviewed list of HTTPS origins it fires on." };
7512
+ if (family === "url") return { allowed: false, reason: "The url rule needs a reviewed HTTPS glob url pattern; `*` spans one path segment and `**` spans across segments." };
7513
+ if (family === "menu") return { allowed: false, reason: "The menu rule needs a reviewed non-empty context menu entry title." };
7514
+ if (family === "key") return { allowed: false, reason: "The keyboard shortcut rule needs a reviewed lowercase command name and an optional suggested key binding." };
7515
+ if (family === "cron") return { allowed: false, reason: "The cron rule needs a reviewed five field cron expression of minutes, hours, days, months and weekdays with named weekdays and months and an optional resolvable timezone; unparseable schedules are refused." };
7516
+ if (family === "interval") return { allowed: false, reason: "The interval rule needs a reviewed positive period in milliseconds with an optional zero or positive jitter window." };
7517
+ if (family === "urllist") return { allowed: false, reason: "The url list rule needs a reviewed non-empty list of HTTPS urls its workflow runs across." };
7518
+ if (family === "webhook") return { allowed: false, reason: `The webhook rule needs a reviewed shared secret of at least twenty four characters mixing letters and digits and a non-empty payload schema of named string, number or boolean fields.` };
7519
+ if (family === "event") return { allowed: false, reason: `The page event rule needs a reviewed non-empty list of event names of the observed event catalog: ${triggereventcatalog.join(", ")}.` };
7520
+ return { allowed: false, reason: "The trigger rule payload does not follow its family grammar." };
7521
+ }
7522
+ if (family === "cron") {
7523
+ const candidate = payload;
7524
+ if (typeof candidate.cron === "string" && cronparse(candidate.cron) === void 0) return { allowed: false, reason: "The cron expression does not parse as a five field schedule and is refused." };
7525
+ }
7526
+ if (family === "webhook") {
7527
+ const candidate = payload;
7528
+ if (typeof candidate.secret === "string" && !webhooksecretok(candidate.secret)) return { allowed: false, reason: "The webhook shared secret must hold at least twenty four characters mixing letters and digits; the entropy floor is a floor, never a cap." };
7529
+ }
7530
+ const armed = armrule({ family, workflowid: options.workflowid, ...typeof options.label === "string" && options.label.trim() ? { label: options.label } : {}, payload, ...typeof options.cooldown === "number" ? { cooldown: options.cooldown } : {}, now: 0 });
7531
+ if (armed === void 0) return { allowed: false, reason: "The trigger rule payload does not arm as a reviewed rule." };
7532
+ return { allowed: true };
7533
+ }
7534
+ function triggergate(input) {
7535
+ const gate = sessiongate({ session: input.session, tabid: input.tabid, origin: input.origin, now: input.now, action: "arm the trigger rule" });
7536
+ if (!gate.allowed) return gate;
7537
+ if (!input.plan || input.plan.state !== "approved") return { allowed: false, reason: "Trigger rules need the approved plan review before they arm." };
7538
+ let triggeroptions = {};
7539
+ try {
7540
+ triggeroptions = parseoptions(input.step);
7541
+ } catch {
7542
+ triggeroptions = {};
7543
+ }
7544
+ if (triggeroptions.reviewed !== true) return { allowed: false, reason: "Every trigger rule needs the explicit arm review with its match fields and bound workflow shown before it arms." };
7545
+ return { allowed: true };
7546
+ }
7547
+ function triggerorigins(step) {
7548
+ let triggeroptions = {};
7549
+ try {
7550
+ triggeroptions = parseoptions(step);
7551
+ } catch {
7552
+ return [];
7553
+ }
7554
+ const family = triggerfamilyof(step.kind);
7555
+ if (family === void 0) return [];
7556
+ const armed = armrule({ family, workflowid: typeof triggeroptions.workflowid === "string" ? triggeroptions.workflowid : "", payload: triggeroptions.rule, ...typeof triggeroptions.cooldown === "number" ? { cooldown: triggeroptions.cooldown } : {}, now: 0 });
7557
+ if (armed === void 0) return [];
7558
+ const origins = [];
7559
+ for (const origin of armed.origins ?? []) origins.push(origin);
7560
+ if (armed.pattern !== void 0) {
7561
+ try {
7562
+ origins.push(new URL(armed.pattern).origin);
7563
+ } catch {
7564
+ }
7565
+ }
7566
+ for (const url of armed.urls ?? []) {
7567
+ try {
7568
+ origins.push(new URL(url).origin);
7569
+ } catch {
7570
+ }
7571
+ }
7572
+ return [...new Set(origins)];
7573
+ }
7031
7574
  function dryrunprojection(step) {
7032
7575
  if (iscontrolflowkind(step.kind)) {
7033
7576
  for (const child of controlsteps(step)) {
@@ -7624,6 +8167,10 @@ function validatestep(step, origin) {
7624
8167
  const workflowcheck = validateworkflowgrammar(step, options);
7625
8168
  if (!workflowcheck.allowed) return workflowcheck;
7626
8169
  }
8170
+ if (istriggeraction(step.kind)) {
8171
+ const triggercheck = validatetriggergrammar(step, options);
8172
+ if (!triggercheck.allowed) return triggercheck;
8173
+ }
7627
8174
  if (step.kind === "tabcreate") {
7628
8175
  if (options.background !== void 0 && typeof options.background !== "boolean") return { allowed: false, reason: "The reviewed background flag must be a boolean." };
7629
8176
  if (options.window !== void 0 && (typeof options.window !== "number" || !Number.isInteger(options.window) || options.window < 0)) return { allowed: false, reason: "The reviewed target window id must be a non-negative integer." };
@@ -7818,6 +8365,10 @@ function canexecute(input) {
7818
8365
  const workflowgatecheck = workflowgate({ session: input.session, plan: input.plan, step: input.step, tabid: input.tabid, origin: input.origin, now });
7819
8366
  if (!workflowgatecheck.allowed) return workflowgatecheck;
7820
8367
  }
8368
+ if (istriggeraction(input.step.kind)) {
8369
+ const triggergatecheck = triggergate({ session: input.session, plan: input.plan, step: input.step, tabid: input.tabid, origin: input.origin, now });
8370
+ if (!triggergatecheck.allowed) return triggergatecheck;
8371
+ }
7821
8372
  if (iscontrolkind(input.step.kind)) {
7822
8373
  const controlgate = sessiongate({ session: input.session, tabid: input.tabid, origin: input.origin, now, action: "control the network" });
7823
8374
  if (!controlgate.allowed) return controlgate;
@@ -7901,7 +8452,7 @@ function canexecute(input) {
7901
8452
  }
7902
8453
 
7903
8454
  // version.ts
7904
- var packageversion = "1.1.51";
8455
+ var packageversion = "1.1.52";
7905
8456
 
7906
8457
  // types.ts
7907
8458
  var protocolversion = packageversion;
@@ -8140,6 +8691,25 @@ function parseproposal(value, origin, grants) {
8140
8691
  }
8141
8692
  if (step.kind === "runworkflow" && workflowoptions.reviewed !== true) throw new Error("Workflow runs without the explicit run review of the expanded step list are refused.");
8142
8693
  }
8694
+ if (istriggeraction(step.kind)) {
8695
+ let triggeroptions = {};
8696
+ try {
8697
+ triggeroptions = parseoptions(step);
8698
+ } catch {
8699
+ triggeroptions = {};
8700
+ }
8701
+ if (triggeroptions.reviewed !== true) throw new Error("Trigger rules without the explicit arm review of their match fields and bound workflow are refused.");
8702
+ for (const ruleorigin of triggerorigins(step)) {
8703
+ const granted = covered.some((pattern) => {
8704
+ try {
8705
+ return new URL(ruleorigin).origin === new URL(pattern).origin;
8706
+ } catch {
8707
+ return false;
8708
+ }
8709
+ });
8710
+ if (!granted) throw new Error(`The trigger on ${ruleorigin} stays outside the grants.`);
8711
+ }
8712
+ }
8143
8713
  const evaluation = validatestep(step, origin);
8144
8714
  if (!evaluation.allowed) throw new Error(evaluation.reason);
8145
8715
  const target = outboundtarget(step);
@@ -8282,7 +8852,7 @@ function requestbody(input) {
8282
8852
  return JSON.stringify({ version: protocolversion, objective: input.objective, session: input.session, observation: input.observation, capabilities: input.capabilities });
8283
8853
  }
8284
8854
  function outcomeresponse(input) {
8285
- return JSON.stringify({ version: protocolversion, planid: input.plan.id, planstate: input.plan.state, outcome: input.outcome, ...input.resolvedtarget ? { resolvedtarget: input.resolvedtarget } : {}, ...input.capture ? { capture: input.capture } : {}, ...input.media ? { media: input.media } : {}, ...input.transport ? { transport: input.transport } : {}, ...input.network ? { network: input.network } : {}, ...input.control ? { control: input.control } : {}, ...input.timeline ? { timeline: input.timeline } : {}, ...input.cdp ? { cdp: input.cdp } : {}, ...input.profile ? { profile: input.profile } : {}, ...input.emulation ? { emulation: input.emulation } : {}, ...input.session ? { session: input.session } : {}, ...input.workflow ? { workflow: { runid: input.workflow.runid, state: input.workflow.state, ...input.workflow.dryrun === true ? { dryrun: true } : {}, produced: input.workflow.produced, consumed: input.workflow.consumed, ...input.workflow.timeout !== void 0 ? { timeout: input.workflow.timeout } : {}, ...input.workflow.retry !== void 0 ? { retry: input.workflow.retry } : {} } } : {} });
8855
+ return JSON.stringify({ version: protocolversion, planid: input.plan.id, planstate: input.plan.state, outcome: input.outcome, ...input.resolvedtarget ? { resolvedtarget: input.resolvedtarget } : {}, ...input.capture ? { capture: input.capture } : {}, ...input.media ? { media: input.media } : {}, ...input.transport ? { transport: input.transport } : {}, ...input.network ? { network: input.network } : {}, ...input.control ? { control: input.control } : {}, ...input.timeline ? { timeline: input.timeline } : {}, ...input.cdp ? { cdp: input.cdp } : {}, ...input.profile ? { profile: input.profile } : {}, ...input.emulation ? { emulation: input.emulation } : {}, ...input.session ? { session: input.session } : {}, ...input.workflow ? { workflow: { runid: input.workflow.runid, state: input.workflow.state, ...input.workflow.dryrun === true ? { dryrun: true } : {}, produced: input.workflow.produced, consumed: input.workflow.consumed, ...input.workflow.timeout !== void 0 ? { timeout: input.workflow.timeout } : {}, ...input.workflow.retry !== void 0 ? { retry: input.workflow.retry } : {} } } : {}, ...input.trigger ? { trigger: { ruleid: input.trigger.ruleid, kind: input.trigger.kind, enabled: input.trigger.enabled, ...input.trigger.nextfireat !== void 0 ? { nextfireat: input.trigger.nextfireat } : {} } } : {} });
8286
8856
  }
8287
8857
  function mapresponse(input) {
8288
8858
  return JSON.stringify({ version: protocolversion, planid: input.plan.id, planstate: input.plan.state, map: input.map });
@@ -8434,6 +9004,51 @@ function sessionreport(input) {
8434
9004
  function workflowreport(input) {
8435
9005
  return { version: protocolversion, workflows: input.workflows, runs: input.runs, templates: input.templates, log: input.log ?? [], scopes: input.scopes ?? [], provenance: input.provenance ?? [], control: input.control ?? [] };
8436
9006
  }
9007
+ function triggerlist(input) {
9008
+ const names = new Map(input.workflows.map((record2) => [record2.id, record2.name]));
9009
+ const rules = input.rules.map((rule) => {
9010
+ const workflowname = names.get(rule.workflowid);
9011
+ return {
9012
+ id: rule.id,
9013
+ kind: rule.kind,
9014
+ workflowid: rule.workflowid,
9015
+ ...workflowname !== void 0 ? { workflowname } : {},
9016
+ label: rule.label,
9017
+ enabled: rule.state.enabled,
9018
+ ...rule.state.pausedat !== void 0 ? { paused: true } : {},
9019
+ cooldown: rule.state.cooldown,
9020
+ ...rule.state.lastfireat !== void 0 ? { lastfireat: rule.state.lastfireat } : {},
9021
+ ...rule.state.nextfireat !== void 0 ? { nextfireat: rule.state.nextfireat } : {},
9022
+ fires: rule.stats.fires,
9023
+ launches: rule.stats.launches,
9024
+ suppressions: rule.stats.suppressions,
9025
+ summary: triggersummaryof(rule)
9026
+ };
9027
+ });
9028
+ return { version: protocolversion, rules, queued: (input.queue ?? []).length };
9029
+ }
9030
+ function triggersummaryof(rule) {
9031
+ const summary = { kind: rule.kind, workflowid: rule.workflowid };
9032
+ if (rule.origins !== void 0) summary.origins = rule.origins;
9033
+ if (rule.pattern !== void 0) summary.pattern = rule.pattern;
9034
+ if (rule.title !== void 0) summary.title = rule.title;
9035
+ if (rule.command !== void 0) summary.command = rule.command;
9036
+ if (rule.key !== void 0) summary.key = rule.key;
9037
+ if (rule.cron !== void 0) summary.cron = rule.cron;
9038
+ if (rule.timezone !== void 0) summary.timezone = rule.timezone;
9039
+ if (rule.period !== void 0) summary.period = rule.period;
9040
+ if (rule.jitter !== void 0) summary.jitter = rule.jitter;
9041
+ if (rule.urls !== void 0) summary.urls = rule.urls;
9042
+ if (rule.events !== void 0) summary.events = rule.events;
9043
+ if (rule.schema !== void 0) summary.fields = rule.schema.length;
9044
+ return summary;
9045
+ }
9046
+ function triggerfired(input) {
9047
+ return { version: protocolversion, triggerfired: { fireid: input.fire.id, ruleid: input.fire.ruleid, workflowid: input.workflowid, at: input.fire.at, cause: input.fire.cause, ...input.fire.url !== void 0 ? { url: input.fire.url } : {}, ...input.fire.title !== void 0 ? { title: input.fire.title } : {}, ...input.runid !== void 0 ? { runid: input.runid } : {} } };
9048
+ }
9049
+ function manualrunpreview(input) {
9050
+ return { version: protocolversion, manualrun: input.preview, ...input.workflowname !== void 0 ? { workflowname: input.workflowname } : {} };
9051
+ }
8437
9052
  export {
8438
9053
  activelayers,
8439
9054
  agentgrammarvalid,
@@ -8445,12 +9060,14 @@ export {
8445
9060
  apientries,
8446
9061
  apikeyconsentgranted,
8447
9062
  apireplayspecof,
9063
+ applycooldown,
8448
9064
  applyheaderules,
8449
9065
  applylayer,
8450
9066
  applyretry,
8451
9067
  applyruntimeout,
8452
9068
  applytimeout,
8453
9069
  argkind,
9070
+ armrule,
8454
9071
  assetentries,
8455
9072
  attachcdpsession,
8456
9073
  attachtargetof,
@@ -8513,6 +9130,7 @@ export {
8513
9130
  collectmessages,
8514
9131
  composeworkflow,
8515
9132
  conditionof,
9133
+ confirmmanualrun,
8516
9134
  consolecapture,
8517
9135
  consoleconsentcovers,
8518
9136
  consolediff,
@@ -8531,6 +9149,8 @@ export {
8531
9149
  correlationid,
8532
9150
  cpusnap,
8533
9151
  crashinterrupted,
9152
+ cronnext,
9153
+ cronparse,
8534
9154
  croprect,
8535
9155
  crossesviewport,
8536
9156
  cursorfrom,
@@ -8540,6 +9160,7 @@ export {
8540
9160
  debugwaitbudgetallowed,
8541
9161
  dedupeimages,
8542
9162
  defaultloopbound,
9163
+ defaulttriggercooldown,
8543
9164
  delayjitter,
8544
9165
  actionrisk as deriveactionrisk,
8545
9166
  detachcdpsession,
@@ -8548,6 +9169,7 @@ export {
8548
9169
  diffreviewgrade,
8549
9170
  diffsessionrecords,
8550
9171
  downloadreport,
9172
+ drainqueue,
8551
9173
  dryrunprojection,
8552
9174
  dryrunworkflow,
8553
9175
  emugate,
@@ -8559,7 +9181,9 @@ export {
8559
9181
  errorcapture,
8560
9182
  errorreportresponse,
8561
9183
  evaluatecondition,
9184
+ evaluatetrigger,
8562
9185
  eventresponse,
9186
+ eventrulematches,
8563
9187
  exchangesreport,
8564
9188
  expandblocks,
8565
9189
  expirelayers,
@@ -8616,6 +9240,8 @@ export {
8616
9240
  isprofilekind,
8617
9241
  issessionkind,
8618
9242
  issocketkind,
9243
+ istriggeraction,
9244
+ istriggerkind,
8619
9245
  iswatchkind,
8620
9246
  isworkflowkind,
8621
9247
  joinbranches,
@@ -8625,6 +9251,7 @@ export {
8625
9251
  layernames,
8626
9252
  layoutreport,
8627
9253
  levelrank,
9254
+ listdue,
8628
9255
  locationconsentcovers,
8629
9256
  locationconsentgate,
8630
9257
  locationpresetof,
@@ -8632,9 +9259,12 @@ export {
8632
9259
  loglevels,
8633
9260
  longtaskcapture,
8634
9261
  loopof,
9262
+ manualpreview,
9263
+ manualrunpreview,
8635
9264
  mapresponse,
8636
9265
  mapurlof,
8637
9266
  matchmessage,
9267
+ matchurl,
8638
9268
  matchurlpattern,
8639
9269
  measure,
8640
9270
  mediaentries,
@@ -8665,6 +9295,7 @@ export {
8665
9295
  oauthflowof,
8666
9296
  observationmodeof,
8667
9297
  observationresponse,
9298
+ observeevents,
8668
9299
  openchannel,
8669
9300
  outcomeresponse,
8670
9301
  overrideinputof,
@@ -8679,6 +9310,7 @@ export {
8679
9310
  parseworkflowproposal,
8680
9311
  passwordconsentgranted,
8681
9312
  patternorigin,
9313
+ pauseall,
8682
9314
  pauseretentionwindow,
8683
9315
  pauserun,
8684
9316
  payloadshapeof,
@@ -8710,6 +9342,7 @@ export {
8710
9342
  publishmessage,
8711
9343
  pushscope,
8712
9344
  quarantinereport,
9345
+ queuefire,
8713
9346
  randomid,
8714
9347
  rankapis,
8715
9348
  ratelimitbudgetallowed,
@@ -8738,6 +9371,7 @@ export {
8738
9371
  restoreoriginsgranted,
8739
9372
  restoreplanof,
8740
9373
  restorereviewgranted,
9374
+ resumeall,
8741
9375
  retryafterof,
8742
9376
  revertalllayers,
8743
9377
  revertlayer,
@@ -8747,6 +9381,8 @@ export {
8747
9381
  rewritesourcelocation,
8748
9382
  rotatelogs,
8749
9383
  rotationruleof,
9384
+ ruleorigins,
9385
+ ruleoriginsgranted,
8750
9386
  runcatch,
8751
9387
  runcontrolstep,
8752
9388
  runforeach,
@@ -8755,10 +9391,13 @@ export {
8755
9391
  runrepeatuntil,
8756
9392
  runstep,
8757
9393
  runtry,
9394
+ runurllist,
8758
9395
  runwhile,
8759
9396
  runworkflow,
8760
9397
  safetyresponse,
8761
9398
  scaledrect,
9399
+ schedulecron,
9400
+ scheduleinterval,
8762
9401
  seamweights,
8763
9402
  searchfields,
8764
9403
  searchqueryof,
@@ -8818,6 +9457,7 @@ export {
8818
9457
  timelinereport,
8819
9458
  timelineretentionwindow,
8820
9459
  timelinesources,
9460
+ timezonevalid,
8821
9461
  tokenrequest,
8822
9462
  tracecategories,
8823
9463
  traceceilingof,
@@ -8825,8 +9465,19 @@ export {
8825
9465
  tracetofile,
8826
9466
  trailreport,
8827
9467
  transformgrammar,
9468
+ triggereventcatalog,
9469
+ triggerfamilies,
9470
+ triggerfamilyof,
9471
+ triggerfired,
9472
+ triggergate,
9473
+ triggerkinds,
9474
+ triggerlist,
9475
+ triggerorigins,
9476
+ triggerpayloadof,
9477
+ triggersummary,
8828
9478
  tryof,
8829
9479
  unwrapgraphql,
9480
+ updaterule,
8830
9481
  urlencodeform,
8831
9482
  validatebreakpointcondition,
8832
9483
  validatecontrolpayload,
@@ -8837,11 +9488,14 @@ export {
8837
9488
  validatetargetref,
8838
9489
  validatevaluegen,
8839
9490
  validateworkflow,
9491
+ verifywebhook,
9492
+ visitmatch,
8840
9493
  waitelementplan,
8841
9494
  watchcdpevents,
8842
9495
  watcherdetached,
8843
9496
  watchexpressionof,
8844
9497
  watchgate,
9498
+ webhooksecretok,
8845
9499
  whileof,
8846
9500
  wizardreport,
8847
9501
  workflowblockof,