@wenathlan/extension 1.1.58 → 1.1.59

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
@@ -1908,6 +1908,8 @@ function watchdogpass(input) {
1908
1908
  function roledefaults(role) {
1909
1909
  if (role === "planner") return { toolnamespaces: ["workflow", "memory", "system"], description: "Planners compose reviewed plans and read memory; they never act on the page themselves." };
1910
1910
  if (role === "observer") return { toolnamespaces: ["memory", "system"], description: "Observers read the shared memory and the system reports only." };
1911
+ if (role === "critic") return { toolnamespaces: ["workflow", "memory", "system"], description: "Critics review the outputs of the other agents read only; they never act on the page themselves." };
1912
+ if (role === "verifier") return { toolnamespaces: ["browser", "memory", "system"], description: "Verifiers re-read the page to check the claims of the other agents; their checks stay read side." };
1911
1913
  return { toolnamespaces: ["browser", "workflow", "memory", "system"], description: role === "worker" ? "Workers execute the reviewed steps of approved plans." : `The custom role ${role} carries the worker defaults until the user narrows its scope.` };
1912
1914
  }
1913
1915
  function registeragent(input) {
@@ -4233,6 +4235,129 @@ var sessionmemory = class {
4233
4235
  const mailboxes = await this.getmailboxes();
4234
4236
  return swarmoverview({ agents, queue: queue ?? { lanes: [], priorities: [], completionpolicy: "all", items: [], claims: [] }, mailboxes });
4235
4237
  }
4238
+ /** Returns the leader worker topology of the 1.1.59 swarm with its leader, worker, critic and verifier lanes and its worker assignments. */
4239
+ async gettopology() {
4240
+ return this.adapter.get("swarmtopology");
4241
+ }
4242
+ /** Replaces the stored leader worker topology after one election, assignment, collection or scaling change. */
4243
+ async settopology(topology) {
4244
+ return this.adapter.set("swarmtopology", topology);
4245
+ }
4246
+ /** Returns the stored planner executor splits of the 1.1.59 swarm with their step reports. */
4247
+ async getplannersplits() {
4248
+ return await this.adapter.get("swarmsplits") ?? [];
4249
+ }
4250
+ /** Replaces the stored planner executor splits after one split or one executor step report. */
4251
+ async setplannersplits(splits) {
4252
+ return this.adapter.set("swarmsplits", splits);
4253
+ }
4254
+ /** Records one critic review of an agent output, newest first. */
4255
+ async addcriticreview(review) {
4256
+ await this.adapter.set("swarmreviews", [review, ...await this.adapter.get("swarmreviews") ?? []]);
4257
+ }
4258
+ /** Returns the recorded critic reviews, newest first. */
4259
+ async getcriticreviews() {
4260
+ return await this.adapter.get("swarmreviews") ?? [];
4261
+ }
4262
+ /** Records one verifier check of a result claim, newest first. */
4263
+ async addverifiercheck(check) {
4264
+ await this.adapter.set("swarmverifierchecks", [check, ...await this.adapter.get("swarmverifierchecks") ?? []]);
4265
+ }
4266
+ /** Returns the recorded verifier checks with their pass and fail outcomes, newest first. */
4267
+ async getverifierchecks() {
4268
+ return await this.adapter.get("swarmverifierchecks") ?? [];
4269
+ }
4270
+ /** Replaces the stored review requests routed between agents after one request, ack, answer or timeout. */
4271
+ async setreviewrequests(requests) {
4272
+ return this.adapter.set("swarmreviewrequests", requests);
4273
+ }
4274
+ /** Returns the stored review requests routed between agents. */
4275
+ async getreviewrequests() {
4276
+ return await this.adapter.get("swarmreviewrequests") ?? [];
4277
+ }
4278
+ /** Records one tab handoff with its packaged task state and its resumed state. */
4279
+ async addhandoff(record2) {
4280
+ await this.adapter.set("swarmhandoffs", [record2, ...await this.adapter.get("swarmhandoffs") ?? []].filter((entry, index, all) => all.findIndex((candidate) => candidate.id === entry.id) === index));
4281
+ }
4282
+ /** Replaces one stored handoff record after its transfer or resume. */
4283
+ async updatehandoff(record2) {
4284
+ await this.adapter.set("swarmhandoffs", (await this.adapter.get("swarmhandoffs") ?? []).map((entry) => entry.id === record2.id ? record2 : entry));
4285
+ }
4286
+ /** Returns the handoff log of tab transfers between agents, newest first. */
4287
+ async gethandoffs() {
4288
+ return await this.adapter.get("swarmhandoffs") ?? [];
4289
+ }
4290
+ /** Replaces the stored resource locks after one acquire, release or expiry sweep. */
4291
+ async setlocks(locks) {
4292
+ return this.adapter.set("swarmlocks", locks);
4293
+ }
4294
+ /** Returns the held resource locks with their holders and expiries. */
4295
+ async getlocks() {
4296
+ return await this.adapter.get("swarmlocks") ?? [];
4297
+ }
4298
+ /** Records one conflict scan report of overlapping writes, newest first. */
4299
+ async addconflictscan(scan) {
4300
+ await this.adapter.set("swarmconflicts", [scan, ...await this.adapter.get("swarmconflicts") ?? []]);
4301
+ }
4302
+ /** Returns the recorded conflict scan reports, newest first. */
4303
+ async getconflictscans() {
4304
+ return await this.adapter.get("swarmconflicts") ?? [];
4305
+ }
4306
+ /** Stores the merged result report with its mergeentry provenance. */
4307
+ async setreport(report) {
4308
+ return this.adapter.set("swarmreport", report);
4309
+ }
4310
+ /** Returns the stored merged result report across agents. */
4311
+ async getreport() {
4312
+ return this.adapter.get("swarmreport");
4313
+ }
4314
+ /** Records one progressboard snapshot under the user configured retention window; an absent window keeps every snapshot. */
4315
+ async addboardsnapshot(board) {
4316
+ const retention = (await this.getsettings())?.boardretention;
4317
+ await this.adapter.set("swarmboards", [board, ...await this.adapter.get("swarmboards") ?? []].slice(0, retention ?? 100));
4318
+ }
4319
+ /** Returns the stored progressboard snapshots, newest first. */
4320
+ async getboardsnapshots() {
4321
+ return await this.adapter.get("swarmboards") ?? [];
4322
+ }
4323
+ /** Records one escalation lifted to the user, newest first. */
4324
+ async addescalation(escalation) {
4325
+ await this.adapter.set("swarmescalations", [escalation, ...await this.adapter.get("swarmescalations") ?? []]);
4326
+ }
4327
+ /** Replaces one stored escalation after its user decision. */
4328
+ async updateescalation(escalation) {
4329
+ await this.adapter.set("swarmescalations", (await this.adapter.get("swarmescalations") ?? []).map((entry) => entry.id === escalation.id ? escalation : entry));
4330
+ }
4331
+ /** Returns the escalations awaiting the user and the decided ones, newest first. */
4332
+ async getescalations() {
4333
+ return await this.adapter.get("swarmescalations") ?? [];
4334
+ }
4335
+ /** Records one consensus round or replaces the stored one after a vote. */
4336
+ async setconsensusround(round) {
4337
+ const rounds = await this.adapter.get("swarmconsensus") ?? [];
4338
+ await this.adapter.set("swarmconsensus", rounds.some((entry) => entry.id === round.id) ? rounds.map((entry) => entry.id === round.id ? round : entry) : [round, ...rounds]);
4339
+ }
4340
+ /** Returns the consensus rounds with their votes and quorum states, newest first. */
4341
+ async getconsensusrounds() {
4342
+ return await this.adapter.get("swarmconsensus") ?? [];
4343
+ }
4344
+ /** Appends one action to the interleaved timeline of swarm actions, oldest first under a window of 500. */
4345
+ async addswarmaction(action) {
4346
+ await this.adapter.set("swarmtimeline", [...await this.adapter.get("swarmtimeline") ?? [], action].slice(-500));
4347
+ }
4348
+ /** Returns the interleaved timeline of swarm actions with the optional agent and kind filters, oldest first. */
4349
+ async getswarmtimeline(filters) {
4350
+ const actions = await this.adapter.get("swarmtimeline") ?? [];
4351
+ return actions.filter((action) => filters?.agentid === void 0 || action.agentid === filters.agentid).filter((action) => filters?.kind === void 0 || action.kind === filters.kind).filter((action) => filters?.since === void 0 || action.at >= filters.since);
4352
+ }
4353
+ /** Stores one shared cost accounting snapshot of the swarm, newest first. */
4354
+ async addswarmcost(cost) {
4355
+ await this.adapter.set("swarmcosts", [cost, ...await this.adapter.get("swarmcosts") ?? []].slice(0, 100));
4356
+ }
4357
+ /** Returns the stored shared cost accounting snapshots of the swarm, newest first. */
4358
+ async getswarmcosts() {
4359
+ return await this.adapter.get("swarmcosts") ?? [];
4360
+ }
4236
4361
  };
4237
4362
  function mediakindof(record2) {
4238
4363
  if ("pages" in record2) return "pdf";
@@ -4873,6 +4998,155 @@ function tlsstateof(tls) {
4873
4998
  return { mode: tls.mode, certificaterequired: tls.mode === "required" || tls.certificatefingerprint !== void 0, verified: tls.verifiedat !== void 0 };
4874
4999
  }
4875
5000
 
5001
+ // coordination.ts
5002
+ function lockkey(origin, selector) {
5003
+ return `${origin}|${selector}`;
5004
+ }
5005
+ function preparehandoff(input) {
5006
+ if (!input.agents.some((agent) => agent.id === input.fromagentid)) throw new Error(`The handoff names the transferring agent ${input.fromagentid} which is not registered.`);
5007
+ if (!input.agents.some((agent) => agent.id === input.toagentid)) throw new Error(`The handoff names the receiving agent ${input.toagentid} which is not registered.`);
5008
+ if (input.fromagentid === input.toagentid) throw new Error("A handoff moves a task between two different agents; an agent never hands off to itself.");
5009
+ if (input.taskstate.trim() === "") throw new Error("The handoff needs its packaged task state in plain language; the resume continues exactly from it.");
5010
+ const from = input.agents.find((agent) => agent.id === input.fromagentid);
5011
+ const tabid = input.tabid ?? from.tabid;
5012
+ if (tabid === void 0) throw new Error("The handoff needs its tab id; the transferring agent holds no tab to hand off.");
5013
+ return { id: input.id, fromagentid: input.fromagentid, toagentid: input.toagentid, tabid, taskstate: input.taskstate, state: "prepared", ...input.reason !== void 0 && input.reason.trim() !== "" ? { reason: input.reason } : {}, createdat: input.now };
5014
+ }
5015
+ function transferhandoff(input) {
5016
+ const record2 = input.handoffs.find((entry) => entry.id === input.id);
5017
+ if (!record2) throw new Error(`The handoff ${input.id} does not exist.`);
5018
+ if (record2.state !== "prepared") throw new Error(`The handoff ${record2.id} is ${record2.state}; only a prepared handoff transfers.`);
5019
+ const receiver = input.agents.find((agent) => agent.id === record2.toagentid);
5020
+ if (!receiver) throw new Error(`The receiving agent ${record2.toagentid} is not registered.`);
5021
+ if (receiver.state === "stopped") throw new Error(`The receiving agent ${receiver.name} is stopped; the handoff waits for its resume or another receiver.`);
5022
+ const holder = input.agents.find((agent) => agent.tabid === record2.tabid && agent.id !== record2.fromagentid && agent.state !== "stopped");
5023
+ if (holder) throw new Error(`Tab ${record2.tabid} already holds the agent ${holder.name}; one tab binds one agent.`);
5024
+ const agents = input.agents.map((agent) => {
5025
+ if (agent.id === record2.fromagentid) {
5026
+ const { tabid, ...rest } = agent;
5027
+ void tabid;
5028
+ return rest;
5029
+ }
5030
+ if (agent.id === record2.toagentid && record2.tabid !== void 0) return { ...agent, tabid: record2.tabid };
5031
+ return agent;
5032
+ });
5033
+ return { agents, handoffs: input.handoffs.map((entry) => entry.id === input.id ? { ...entry, state: "transferred", transferredat: input.now } : entry) };
5034
+ }
5035
+ function resumehandoff(input) {
5036
+ const record2 = input.handoffs.find((entry) => entry.id === input.id);
5037
+ if (!record2) throw new Error(`The handoff ${input.id} does not exist.`);
5038
+ if (record2.state !== "transferred") throw new Error(`The handoff ${record2.id} is ${record2.state}; only a transferred handoff resumes.`);
5039
+ return { ...record2, state: "resumed", resumedat: input.now };
5040
+ }
5041
+ function acquirelock(input) {
5042
+ if (input.holder.trim() === "") throw new Error("The lock needs its holder agent id.");
5043
+ if (input.origin.trim() === "") throw new Error("The lock needs its origin; a lock never spans unrelated origins.");
5044
+ if (input.selector.trim() === "") throw new Error("The lock needs its selector of the origin.");
5045
+ const kind = input.kind ?? "exclusive";
5046
+ const key = lockkey(input.origin.trim(), input.selector.trim());
5047
+ const held = input.locks.filter((lock2) => lock2.key === key);
5048
+ if (held.some((lock2) => lock2.holder === input.holder)) return { locks: input.locks, acquired: false, reason: `The agent ${input.holder} already holds the lock ${key}.` };
5049
+ if (held.length > 0) {
5050
+ if (held.some((lock2) => lock2.kind === "exclusive") || kind === "exclusive") return { locks: input.locks, acquired: false, reason: `The lock ${key} is held ${held.some((lock2) => lock2.kind === "exclusive") ? "exclusively" : "shared"}; the ${kind} request of ${input.holder} refuses.` };
5051
+ }
5052
+ const lock = { key, holder: input.holder, kind, origin: input.origin.trim(), selector: input.selector.trim(), acquiredat: input.now, ...input.expiresat !== void 0 ? { expiresat: input.expiresat } : {} };
5053
+ return { locks: [...input.locks, lock], acquired: true, reason: `The ${kind} lock ${key} went to the agent ${input.holder}.` };
5054
+ }
5055
+ function releaselock(input) {
5056
+ const lock = input.locks.find((entry) => entry.key === input.key && entry.holder === input.holder);
5057
+ if (!lock) return { locks: input.locks, released: false };
5058
+ return { locks: input.locks.filter((entry) => entry.key !== input.key || entry.holder !== input.holder), released: true };
5059
+ }
5060
+ function expirelocks(input) {
5061
+ const stale = input.locks.filter((lock) => lock.expiresat !== void 0 && input.now > lock.expiresat);
5062
+ if (stale.length === 0) return { locks: input.locks, expired: [] };
5063
+ const keys = new Set(stale.map((lock) => `${lock.key}:${lock.holder}`));
5064
+ return { locks: input.locks.filter((lock) => !keys.has(`${lock.key}:${lock.holder}`)), expired: [...keys] };
5065
+ }
5066
+ function scanconflicts(input) {
5067
+ const targets = /* @__PURE__ */ new Map();
5068
+ for (const writer of input.writers) {
5069
+ const key = lockkey(writer.origin, writer.selector);
5070
+ targets.set(key, [...targets.get(key) ?? [], writer]);
5071
+ }
5072
+ const overlaps = [...targets.entries()].filter(([, writers]) => writers.length > 1).map(([key, writers]) => ({ origin: writers[0].origin, selector: writers[0].selector, writers: writers.map((writer) => writer.agentid) }));
5073
+ const overlappingagents = new Set(overlaps.flatMap((entry) => entry.writers));
5074
+ return {
5075
+ id: input.id,
5076
+ writers: input.writers,
5077
+ overlaps,
5078
+ suggestedorder: input.writers.filter((writer) => overlappingagents.has(writer.agentid)).map((writer) => writer.agentid).filter((agentid, index, all) => all.indexOf(agentid) === index).sort((one, two) => one < two ? -1 : 1),
5079
+ clean: overlaps.length === 0,
5080
+ scannedat: input.now
5081
+ };
5082
+ }
5083
+ function mergeresults(input) {
5084
+ const keys = /* @__PURE__ */ new Map();
5085
+ for (const entry of input.entries) {
5086
+ keys.set(entry.key, [...keys.get(entry.key) ?? [], entry]);
5087
+ }
5088
+ const conflicts = [];
5089
+ const merged = [];
5090
+ for (const [key, entries] of keys) {
5091
+ const ordered = [...entries].sort((one, two) => one.mergedat - two.mergedat);
5092
+ if (ordered.length === 1) {
5093
+ merged.push(ordered[0]);
5094
+ continue;
5095
+ }
5096
+ if (input.rule === "fail") {
5097
+ conflicts.push(`The key ${key} carries ${ordered.length} parallel values from ${ordered.map((entry) => entry.agentid).join(", ")}; the fail rule refuses the fold.`);
5098
+ continue;
5099
+ }
5100
+ const winner = input.rule === "first" ? ordered[0] : input.rule === "last" ? ordered[ordered.length - 1] : ordered.find((entry) => entry.agentid === input.preferagent) ?? ordered[ordered.length - 1];
5101
+ const note = input.rule === "preferagent" && input.preferagent !== void 0 && !ordered.some((entry) => entry.agentid === input.preferagent) ? `The preferagent rule names the agent ${input.preferagent} which wrote no value; the latest value of ${winner.agentid} stayed.` : `The ${input.rule} rule kept the value of ${winner.agentid} from ${ordered.map((entry) => entry.agentid).join(", ")}.`;
5102
+ conflicts.push(`The key ${key}: ${note}`);
5103
+ merged.push({ ...winner, id: `${winner.id}:merged`, conflict: note });
5104
+ }
5105
+ return { entries: merged, conflicts, refused: input.rule === "fail" && conflicts.length > 0 };
5106
+ }
5107
+ function swarmreport(input) {
5108
+ if (input.title.trim() === "") throw new Error("The report needs its title.");
5109
+ const fold = mergeresults({ entries: input.outputs, rule: input.rule, ...input.preferagent !== void 0 ? { preferagent: input.preferagent } : {}, now: input.now });
5110
+ const groups = /* @__PURE__ */ new Map();
5111
+ for (const entry of fold.entries) {
5112
+ const group = entry.taskid ?? "general";
5113
+ groups.set(group, [...groups.get(group) ?? [], entry]);
5114
+ }
5115
+ const sections = [...groups.entries()].map(([taskid, entries]) => ({ title: `Task ${taskid}`, entries, sources: [...new Set(input.outputs.filter((output) => (output.taskid ?? "general") === taskid).map((output) => output.agentid))] }));
5116
+ return {
5117
+ report: { id: input.id, title: input.title.trim(), sections, sources: [...new Set(input.outputs.map((output) => output.agentid))], ...input.confidence !== void 0 && input.confidence.trim() !== "" ? { confidence: input.confidence } : {}, createdat: input.now },
5118
+ conflicts: fold.conflicts,
5119
+ refused: fold.refused
5120
+ };
5121
+ }
5122
+ function compareoutputs(input) {
5123
+ if (input.subject.trim() === "") throw new Error("The comparison needs its subject.");
5124
+ if (input.outputs.length < 2) throw new Error("The comparison contrasts at least two competing outputs.");
5125
+ const differences = input.outputs.filter((output) => output.value !== input.outputs[0]?.value).map((output) => `The agent ${output.agentid} answers ${output.value} while the agent ${input.outputs[0].agentid} answers ${input.outputs[0].value}.`);
5126
+ return { id: input.id, subject: input.subject, outputs: input.outputs, differences, comparedat: input.now };
5127
+ }
5128
+ function interleavetimeline(actions) {
5129
+ return [...actions].sort((one, two) => one.at - two.at || (one.id < two.id ? -1 : 1));
5130
+ }
5131
+ function sharelesson(input) {
5132
+ if (input.statement.trim() === "") throw new Error("The lesson needs its statement in plain language.");
5133
+ if (input.verifiedby.trim() === "") throw new Error("The lesson needs its verifier; only a verified lesson lands on the board.");
5134
+ return postentry({ board: input.board, id: input.id, key: `lesson:${input.statement.trim().slice(0, 40)}`, value: `${input.statement.trim()} (verified by ${input.verifiedby.trim()})`, section: input.section ?? "findings", author: input.agentid.trim() === "" ? "user" : input.agentid, consentclass: input.consentclass ?? "read", now: input.now });
5135
+ }
5136
+ function swarmcosts(input) {
5137
+ return {
5138
+ agents: input.usage.length,
5139
+ tokens: input.usage.reduce((total, usage) => total + usage.tokens, 0),
5140
+ cost: input.usage.reduce((total, usage) => total + usage.cost, 0),
5141
+ steps: input.usage.reduce((total, usage) => total + usage.steps, 0),
5142
+ ...input.currency !== void 0 && input.currency.trim() !== "" ? { currency: input.currency } : {},
5143
+ computedat: input.now
5144
+ };
5145
+ }
5146
+ function replayagentrun(input) {
5147
+ return interleavetimeline(input.events.filter((event) => event.agentid === input.agentid).map((event) => ({ id: event.id, kind: event.kind, summary: event.summary, at: event.at, ...event.agentid !== void 0 ? { agentid: event.agentid } : {} })));
5148
+ }
5149
+
4876
5150
  // httpclient.ts
4877
5151
  var httpkinds = ["fetchurl", "parsejson", "parsehtml", "callrest", "callgraphql"];
4878
5152
  var redirectstatuses = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
@@ -9855,7 +10129,7 @@ function budgetcheck(input) {
9855
10129
  }
9856
10130
 
9857
10131
  // version.ts
9858
- var packageversion = "1.1.58";
10132
+ var packageversion = "1.1.59";
9859
10133
 
9860
10134
  // types.ts
9861
10135
  var protocolversion = packageversion;
@@ -10495,6 +10769,175 @@ function bumprevision(route, now) {
10495
10769
  return { ...route, revision: route.revision + 1, updatedat: now };
10496
10770
  }
10497
10771
 
10772
+ // orchestration.ts
10773
+ function electleader(input) {
10774
+ const live = input.agents.filter((agent) => agent.state !== "stopped");
10775
+ if (live.length === 0) throw new Error("The swarm holds no live agent; the leader election waits for the user to register one.");
10776
+ const rule = input.rule ?? { kind: "first" };
10777
+ let leader;
10778
+ if (rule.kind === "named") {
10779
+ if (rule.agentid === void 0 || rule.agentid.trim() === "") throw new Error("The named election rule needs the agent id the user named.");
10780
+ leader = live.find((agent) => agent.id === rule.agentid);
10781
+ if (!leader) throw new Error(`The named election rule names the agent ${rule.agentid} which is not a live agent of the swarm.`);
10782
+ } else {
10783
+ leader = live[live.length - 1];
10784
+ }
10785
+ if (!leader) throw new Error("The leader election found no live agent.");
10786
+ const leaderid = leader.id;
10787
+ const workers = live.filter((agent) => agent.id !== leaderid && agent.role === "worker");
10788
+ const critics = live.filter((agent) => agent.id !== leaderid && agent.role === "critic");
10789
+ const verifiers = live.filter((agent) => agent.id !== leaderid && agent.role === "verifier");
10790
+ return {
10791
+ id: input.id,
10792
+ leaderid: leader.id,
10793
+ workerids: workers.map((agent) => agent.id),
10794
+ criticids: critics.map((agent) => agent.id),
10795
+ verifierids: verifiers.map((agent) => agent.id),
10796
+ assignments: [],
10797
+ rule: { kind: rule.kind, ...rule.agentid !== void 0 ? { agentid: rule.agentid } : {} },
10798
+ electedat: input.now
10799
+ };
10800
+ }
10801
+ function assignwork(input) {
10802
+ if (input.topology.workerids.length === 0) throw new Error("The topology holds no worker; the user adds workers before the assignment.");
10803
+ const assignments = [];
10804
+ const tasks = input.tasks.filter((task) => task.state === "queued" || task.state === "claimed");
10805
+ tasks.forEach((task, index) => {
10806
+ const workerid = input.topology.workerids[index % input.topology.workerids.length];
10807
+ assignments.push({ workerid, taskid: task.id, slice: `${task.payload} (slice ${Math.floor(index / input.topology.workerids.length) + 1} of lane ${task.lane})`, assignedat: input.now });
10808
+ });
10809
+ return { ...input.topology, assignments };
10810
+ }
10811
+ function collectresults(input) {
10812
+ const gathered = input.topology.assignments.map((assignment) => {
10813
+ const output = input.outputs.find((entry) => entry.taskid === assignment.taskid && entry.workerid === assignment.workerid);
10814
+ return output ?? { workerid: assignment.workerid, taskid: assignment.taskid, state: "pending", summary: `The worker ${assignment.workerid} has not returned its slice of the task ${assignment.taskid} yet.` };
10815
+ });
10816
+ return { gathered, missing: gathered.filter((entry) => entry.state === "pending").map((entry) => `${entry.workerid}:${entry.taskid}`) };
10817
+ }
10818
+ function scaleworkers(input) {
10819
+ const live = input.agents.filter((agent) => agent.state === "active" && agent.role === "worker" && agent.id !== input.topology.leaderid);
10820
+ const current = input.topology.workerids.filter((workerid) => live.some((agent) => agent.id === workerid));
10821
+ const ceiling = input.bound;
10822
+ if (input.pending > current.length) {
10823
+ const available = live.filter((agent) => !current.includes(agent.id)).map((agent) => agent.id);
10824
+ const wanted = input.pending - current.length;
10825
+ const addable = ceiling === void 0 ? available.slice(0, wanted) : available.slice(0, Math.min(wanted, Math.max(ceiling - current.length, 0)));
10826
+ if (addable.length === 0) return { topology: input.topology, added: [], retired: [], reason: ceiling === void 0 ? `The load of ${input.pending} pending slices exceeds the ${current.length} workers but the swarm holds no further live worker role agent to add.` : `The load of ${input.pending} pending slices exceeds the ${current.length} workers but the user configured bound of ${ceiling} workers holds.` };
10827
+ return { topology: { ...input.topology, workerids: [...current, ...addable], electedat: input.topology.electedat, assignments: input.topology.assignments }, added: addable, retired: [], reason: `The load of ${input.pending} pending slices added the workers ${addable.join(", ")}; ${ceiling === void 0 ? "no bound is configured so the user scale stands alone" : `the user configured bound of ${ceiling} workers holds`}.` };
10828
+ }
10829
+ const keep = Math.max(input.pending, 0);
10830
+ if (current.length > keep) {
10831
+ const retired = current.slice(keep);
10832
+ return { topology: { ...input.topology, workerids: current.slice(0, keep), electedat: input.topology.electedat, assignments: input.topology.assignments.filter((assignment) => !retired.includes(assignment.workerid)) }, added: [], retired, reason: `The load of ${input.pending} pending slices retired the idle workers ${retired.join(", ")}.` };
10833
+ }
10834
+ return { topology: input.topology, added: [], retired: [], reason: `The load of ${input.pending} pending slices matches the ${current.length} workers; the scale stays unchanged.` };
10835
+ }
10836
+ function plannersplit(input) {
10837
+ if (input.planownerid.trim() === "" || input.runownerid.trim() === "") throw new Error("The planner executor split needs its plan owner and run owner agent ids.");
10838
+ if (input.planownerid === input.runownerid) throw new Error("The planner executor split keeps plan drafting and execution in different agents; one agent holds both sides never.");
10839
+ return { id: input.id, planownerid: input.planownerid, runownerid: input.runownerid, ...input.taskid !== void 0 && input.taskid.trim() !== "" ? { taskid: input.taskid } : {}, stepreports: [], splitat: input.now };
10840
+ }
10841
+ function reportstep(input) {
10842
+ if (input.stepid.trim() === "") throw new Error("The executor report needs its step id.");
10843
+ if (input.detail.trim() === "") throw new Error("The executor report needs its detail in plain language.");
10844
+ const report = { stepid: input.stepid.trim(), outcome: input.outcome, detail: input.detail, reportedat: input.now };
10845
+ return { ...input.split, stepreports: [...input.split.stepreports.filter((entry) => entry.stepid !== report.stepid), report] };
10846
+ }
10847
+ function requestreview(input) {
10848
+ if (input.subject.trim() === "") throw new Error("The review request needs its subject.");
10849
+ if (input.payload.trim() === "") throw new Error("The review request needs its payload.");
10850
+ if (input.toagentid.trim() === "" || input.toagentid === input.fromagentid) throw new Error("The review request names another reviewing agent, never its own requester.");
10851
+ const request = { id: input.id, fromagentid: input.fromagentid, toagentid: input.toagentid, subject: input.subject, payload: input.payload, state: "open", requestedat: input.now, ...input.timeoutms !== void 0 ? { timeoutat: input.now + input.timeoutms } : {} };
10852
+ return [request, ...input.requests];
10853
+ }
10854
+ function ackreview(input) {
10855
+ const request = input.requests.find((entry) => entry.id === input.id);
10856
+ if (!request) throw new Error(`The review request ${input.id} does not exist.`);
10857
+ if (request.state !== "open") throw new Error(`The review request ${input.id} is ${request.state}; only an open request receives its ack.`);
10858
+ return input.requests.map((entry) => entry.id === input.id ? { ...entry, state: "acked", ackedat: input.now } : entry);
10859
+ }
10860
+ function applyreview(input) {
10861
+ const request = input.requests.find((entry) => entry.id === input.id);
10862
+ if (!request) throw new Error(`The review request ${input.id} does not exist.`);
10863
+ if (request.state === "answered" || request.state === "timeout") throw new Error(`The review request ${input.id} is ${request.state}; an answered or timed out request never reviews again.`);
10864
+ if (request.toagentid !== input.reviewerid) throw new Error(`The review request ${input.id} routes to the agent ${request.toagentid}; the agent ${input.reviewerid} never answers in its place.`);
10865
+ if (input.verdict === "changes" && input.requiredchanges.length === 0) throw new Error("A changes verdict needs its required changes in plain language.");
10866
+ const review = { id: request.id, reviewerid: input.reviewerid, subjectagentid: request.fromagentid, ...input.taskid !== void 0 && input.taskid.trim() !== "" ? { taskid: input.taskid } : {}, verdict: input.verdict, issues: input.issues, requiredchanges: input.requiredchanges, reviewedat: input.now };
10867
+ return { review, requests: input.requests.map((entry) => entry.id === input.id ? { ...entry, state: "answered", answeredat: input.now } : entry) };
10868
+ }
10869
+ function sweepreviews(input) {
10870
+ const expired = input.requests.filter((request) => request.state === "open" || request.state === "acked").filter((request) => request.timeoutat !== void 0 && input.now > request.timeoutat);
10871
+ if (expired.length === 0) return { requests: input.requests, timedout: [] };
10872
+ const ids = new Set(expired.map((request) => request.id));
10873
+ return { requests: input.requests.map((request) => ids.has(request.id) ? { ...request, state: "timeout" } : request), timedout: [...ids] };
10874
+ }
10875
+ function checkclaim(input) {
10876
+ if (input.claim.trim() === "") throw new Error("The verifier check needs its claim in plain language.");
10877
+ if (input.method.trim() === "") throw new Error("The verifier check needs the method the user configured.");
10878
+ if (input.claimagentid.trim() === "") throw new Error("The verifier check names the agent whose claim it checks.");
10879
+ return { id: input.id, verifierid: input.verifierid, claimagentid: input.claimagentid, ...input.taskid !== void 0 && input.taskid.trim() !== "" ? { taskid: input.taskid } : {}, claim: input.claim, method: input.method, outcome: input.outcome, ...input.evidence !== void 0 && input.evidence.trim() !== "" ? { evidence: input.evidence } : {}, checkedat: input.now };
10880
+ }
10881
+ function boardstate(input) {
10882
+ const lanes = input.agents.filter((agent) => agent.state !== "stopped").map((agent) => {
10883
+ const assignment = input.topology?.assignments.find((entry) => entry.workerid === agent.id);
10884
+ const claim2 = input.queue.claims.find((record2) => record2.agentid === agent.id && input.queue.items.some((item) => item.id === record2.taskid && item.state === "claimed"));
10885
+ const task = claim2 !== void 0 ? input.queue.items.find((item) => item.id === claim2.taskid) : void 0;
10886
+ const lane = task?.lane ?? (agent.role === "critic" || agent.role === "verifier" ? agent.role : agent.role === "planner" ? "planning" : "idle");
10887
+ return { agentid: agent.id, name: agent.name, role: agent.role, state: agent.state, lane, ...task !== void 0 ? { currenttask: task.payload } : assignment !== void 0 ? { currenttask: assignment.slice } : {}, milestones: input.milestones?.[agent.id] ?? [] };
10888
+ });
10889
+ return { id: `board:${input.now}`, lanes, builtat: input.now };
10890
+ }
10891
+ function escalate(input) {
10892
+ if (input.subject.trim() === "") throw new Error("The escalation needs its subject.");
10893
+ if (input.context.trim() === "") throw new Error("The escalation needs its full context in plain language; the user decides on what the agent saw.");
10894
+ if (input.agentid.trim() === "") throw new Error("The escalation names the agent whose decision it lifts.");
10895
+ return { id: input.id, agentid: input.agentid, subject: input.subject, context: input.context, state: "open", raisedat: input.now };
10896
+ }
10897
+ function resolveescalation(input) {
10898
+ if (input.escalation.state === "decided") throw new Error("The escalation already carries its user decision.");
10899
+ if (input.decision.trim() === "") throw new Error("The escalation decision needs the words the user wrote.");
10900
+ return { ...input.escalation, state: "decided", decision: input.decision, decidedat: input.now };
10901
+ }
10902
+ function arbitrate(input) {
10903
+ if (input.claims.length === 0) return [];
10904
+ if (input.rule.strategy === "priority") {
10905
+ const order = input.rule.priorityorder;
10906
+ return [...input.claims].sort((one, two) => {
10907
+ const oneindex = order.indexOf(one.agentid);
10908
+ const twoindex = order.indexOf(two.agentid);
10909
+ return (oneindex === -1 ? order.length : oneindex) - (twoindex === -1 ? order.length : twoindex) || one.claimedat - two.claimedat;
10910
+ }).map((claim2) => claim2.agentid);
10911
+ }
10912
+ if (input.rule.strategy === "age") return [...input.claims].sort((one, two) => one.claimedat - two.claimedat || (one.agentid < two.agentid ? -1 : 1)).map((claim2) => claim2.agentid);
10913
+ if (input.leaderid === void 0) throw new Error("The leader arbitration strategy needs the elected leader of the topology.");
10914
+ return [...input.claims].sort((one, two) => (one.agentid === input.leaderid ? -1 : 1) - (two.agentid === input.leaderid ? -1 : 1) || one.claimedat - two.claimedat).map((claim2) => claim2.agentid);
10915
+ }
10916
+ function openconsensus(input) {
10917
+ if (input.subject.trim() === "") throw new Error("The consensus round needs its subject in plain language.");
10918
+ if (!Number.isInteger(input.quorum) || input.quorum < 1) throw new Error("The consensus round needs its quorum as a positive whole number the user configured.");
10919
+ return { id: input.id, subject: input.subject, votes: [], quorum: input.quorum, state: "open", openedat: input.now };
10920
+ }
10921
+ function castvote(input) {
10922
+ if (input.round.state !== "open") throw new Error(`The consensus round ${input.round.id} is ${input.round.state}; a closed round collects no vote.`);
10923
+ if (input.round.votes.some((entry) => entry.agentid === input.agentid)) throw new Error(`The agent ${input.agentid} already voted in the round ${input.round.id}.`);
10924
+ const votes = [...input.round.votes, { agentid: input.agentid, vote: input.vote, votedat: input.now }];
10925
+ const yes = votes.filter((entry) => entry.vote === "yes").length;
10926
+ const no = votes.filter((entry) => entry.vote === "no").length;
10927
+ if (yes >= input.round.quorum) return { ...input.round, votes, state: "carried", closedat: input.now };
10928
+ if (no >= input.round.quorum) return { ...input.round, votes, state: "failed", closedat: input.now };
10929
+ return { ...input.round, votes };
10930
+ }
10931
+ function consensusstate(round) {
10932
+ return {
10933
+ yes: round.votes.filter((entry) => entry.vote === "yes").length,
10934
+ no: round.votes.filter((entry) => entry.vote === "no").length,
10935
+ abstain: round.votes.filter((entry) => entry.vote === "abstain").length,
10936
+ quorum: round.quorum,
10937
+ state: round.state
10938
+ };
10939
+ }
10940
+
10498
10941
  // promptlibrary.ts
10499
10942
  function templatevariables(body) {
10500
10943
  const names = [];
@@ -11367,6 +11810,48 @@ function swarmstatereport(state) {
11367
11810
  function agenteventframe(event) {
11368
11811
  return { jsonrpc: "2.0", method: "agents/notify", params: { eventid: event.id, kind: event.kind, ...event.agentid !== void 0 ? { agentid: event.agentid } : {}, ...event.taskid !== void 0 ? { taskid: event.taskid } : {}, summary: event.summary, at: event.at } };
11369
11812
  }
11813
+ function boardstatesnapshot(board) {
11814
+ return {
11815
+ version: protocolversion,
11816
+ board: {
11817
+ id: board.id,
11818
+ builtat: board.builtat,
11819
+ lanes: board.lanes.map((lane) => ({ agentid: lane.agentid, name: lane.name, role: lane.role, state: lane.state, lane: lane.lane, ...lane.currenttask !== void 0 ? { currenttask: lane.currenttask } : {}, milestones: lane.milestones.map((milestone) => ({ label: milestone.label, done: milestone.done, ...milestone.at !== void 0 ? { at: milestone.at } : {} })) }))
11820
+ }
11821
+ };
11822
+ }
11823
+ function handoffframe(record2) {
11824
+ return {
11825
+ jsonrpc: "2.0",
11826
+ method: "agents/handoff",
11827
+ params: {
11828
+ id: record2.id,
11829
+ from: record2.fromagentid,
11830
+ to: record2.toagentid,
11831
+ ...record2.tabid !== void 0 ? { tabid: record2.tabid } : {},
11832
+ taskstate: record2.taskstate,
11833
+ state: record2.state,
11834
+ ...record2.transferredat !== void 0 ? { transferredat: record2.transferredat } : {},
11835
+ ...record2.resumedat !== void 0 ? { resumedat: record2.resumedat } : {}
11836
+ }
11837
+ };
11838
+ }
11839
+ function reviewframe(input) {
11840
+ return {
11841
+ jsonrpc: "2.0",
11842
+ method: "agents/review",
11843
+ params: {
11844
+ id: input.request.id,
11845
+ from: input.request.fromagentid,
11846
+ to: input.request.toagentid,
11847
+ subject: input.request.subject,
11848
+ state: input.request.state,
11849
+ ...input.request.ackedat !== void 0 ? { ackedat: input.request.ackedat } : {},
11850
+ ...input.request.answeredat !== void 0 ? { answeredat: input.request.answeredat } : {},
11851
+ ...input.review !== void 0 ? { verdict: input.review.verdict, issues: input.review.issues, requiredchanges: input.review.requiredchanges } : {}
11852
+ }
11853
+ };
11854
+ }
11370
11855
 
11371
11856
  // workfloweditor.ts
11372
11857
  var palettecategories = ["actions", "controlflow", "waits", "variables", "triggers"];
@@ -12072,6 +12557,8 @@ function yamlscalarvalue(text2) {
12072
12557
  return text2;
12073
12558
  }
12074
12559
  export {
12560
+ ackreview,
12561
+ acquirelock,
12075
12562
  activelayers,
12076
12563
  addedge,
12077
12564
  addnode,
@@ -12099,14 +12586,17 @@ export {
12099
12586
  applylayer,
12100
12587
  applyoverride,
12101
12588
  applyretry,
12589
+ applyreview,
12102
12590
  applyruntimeout,
12103
12591
  applytimeout,
12104
12592
  approvalframes,
12105
12593
  approvalprompt,
12594
+ arbitrate,
12106
12595
  argkind,
12107
12596
  armrule,
12108
12597
  assetentries,
12109
12598
  assignrole,
12599
+ assignwork,
12110
12600
  attachcdpsession,
12111
12601
  attachtargetof,
12112
12602
  attachtimeline,
@@ -12130,6 +12620,8 @@ export {
12130
12620
  blockingduration,
12131
12621
  blockinvocationof,
12132
12622
  blockruleof,
12623
+ boardstate,
12624
+ boardstatesnapshot,
12133
12625
  boardsummary,
12134
12626
  bodyfilterof,
12135
12627
  bodymatches,
@@ -12174,6 +12666,7 @@ export {
12174
12666
  capturestitched,
12175
12667
  capturetargets,
12176
12668
  capturevisible,
12669
+ castvote,
12177
12670
  cdpallowlistof,
12178
12671
  cdpdomains,
12179
12672
  cdpeventruleof,
@@ -12183,6 +12676,7 @@ export {
12183
12676
  channeloptionsof,
12184
12677
  channelorigin,
12185
12678
  checkallowlist,
12679
+ checkclaim,
12186
12680
  choosebranch,
12187
12681
  claim,
12188
12682
  claimheartbeat,
@@ -12190,12 +12684,15 @@ export {
12190
12684
  closechannel,
12191
12685
  closeidlechannels,
12192
12686
  collectmessages,
12687
+ collectresults,
12193
12688
  commandguard,
12689
+ compareoutputs,
12194
12690
  complete,
12195
12691
  composeworkflow,
12196
12692
  conditionof,
12197
12693
  confirmmanualrun,
12198
12694
  connectclient,
12695
+ consensusstate,
12199
12696
  consolecapture,
12200
12697
  consoleconsentcovers,
12201
12698
  consolediff,
@@ -12259,6 +12756,7 @@ export {
12259
12756
  editorstate,
12260
12757
  editstep,
12261
12758
  egressconsentgate,
12759
+ electleader,
12262
12760
  emptyboard,
12263
12761
  emptyqueue,
12264
12762
  emugate,
@@ -12273,6 +12771,7 @@ export {
12273
12771
  entryfresh,
12274
12772
  errorcapture,
12275
12773
  errorreportresponse,
12774
+ escalate,
12276
12775
  evaluatecondition,
12277
12776
  evaluatetrigger,
12278
12777
  eventnotification,
@@ -12283,6 +12782,7 @@ export {
12283
12782
  expandtemplate,
12284
12783
  expireapprovals,
12285
12784
  expirelayers,
12785
+ expirelocks,
12286
12786
  expireprofilerecords,
12287
12787
  expiresessions,
12288
12788
  expiretokens,
@@ -12322,6 +12822,7 @@ export {
12322
12822
  guardoutput,
12323
12823
  guardverdictgate,
12324
12824
  handleframe,
12825
+ handoffframe,
12325
12826
  headerfilterof,
12326
12827
  headeruleof,
12327
12828
  heapintervalallowed,
@@ -12346,6 +12847,7 @@ export {
12346
12847
  inflightreport,
12347
12848
  inheritconsent,
12348
12849
  initialize,
12850
+ interleavetimeline,
12349
12851
  iscdpkind,
12350
12852
  iscontrolflowkind,
12351
12853
  iscontrolkind,
@@ -12387,6 +12889,7 @@ export {
12387
12889
  locationconsentgate,
12388
12890
  locationpresetof,
12389
12891
  locationrangevalid,
12892
+ lockkey,
12390
12893
  loglevels,
12391
12894
  longtaskcapture,
12392
12895
  loopof,
@@ -12404,6 +12907,7 @@ export {
12404
12907
  mediaentries,
12405
12908
  mediakinds,
12406
12909
  mediareport,
12910
+ mergeresults,
12407
12911
  messageegressgrade,
12408
12912
  messagefilterof,
12409
12913
  methoddomain,
@@ -12440,6 +12944,7 @@ export {
12440
12944
  observationresponse,
12441
12945
  observeevents,
12442
12946
  openchannel,
12947
+ openconsensus,
12443
12948
  openstreamchannel,
12444
12949
  opentabagent,
12445
12950
  outcomeresponse,
@@ -12485,11 +12990,13 @@ export {
12485
12990
  planallowlist,
12486
12991
  plandraftreviewgate,
12487
12992
  planlint,
12993
+ plannersplit,
12488
12994
  pollcursorof,
12489
12995
  polldecision,
12490
12996
  pollurl,
12491
12997
  popscope,
12492
12998
  postentry,
12999
+ preparehandoff,
12493
13000
  privatemime,
12494
13001
  profilegrantgranted,
12495
13002
  profilereport,
@@ -12538,6 +13045,7 @@ export {
12538
13045
  registeragent,
12539
13046
  rejectioncapture,
12540
13047
  relayframe,
13048
+ releaselock,
12541
13049
  removeedge,
12542
13050
  removenode,
12543
13051
  removetemplate,
@@ -12548,14 +13056,18 @@ export {
12548
13056
  repeatuntilof,
12549
13057
  replannonfail,
12550
13058
  replanreviewgate,
13059
+ replayagentrun,
12551
13060
  replaytrace,
12552
13061
  replayurl,
13062
+ reportstep,
12553
13063
  requestbody,
13064
+ requestreview,
12554
13065
  requeue,
12555
13066
  requireapproval,
12556
13067
  resolutionverdict,
12557
13068
  resolveapproval,
12558
13069
  resolvedrisk,
13070
+ resolveescalation,
12559
13071
  resolverecipients,
12560
13072
  resolveroute,
12561
13073
  resolvetool,
@@ -12568,6 +13080,7 @@ export {
12568
13080
  restoreplanof,
12569
13081
  restorereviewgranted,
12570
13082
  resumeall,
13083
+ resumehandoff,
12571
13084
  resumeone,
12572
13085
  retireentries,
12573
13086
  retireentry,
@@ -12577,6 +13090,7 @@ export {
12577
13090
  revertplanof,
12578
13091
  revertrule,
12579
13092
  reviewedkinds,
13093
+ reviewframe,
12580
13094
  revocationruleof,
12581
13095
  revokeclient,
12582
13096
  rewritesourcelocation,
@@ -12611,6 +13125,8 @@ export {
12611
13125
  savetemplate,
12612
13126
  saveworkflow,
12613
13127
  scaledrect,
13128
+ scaleworkers,
13129
+ scanconflicts,
12614
13130
  schedulecron,
12615
13131
  scheduleinterval,
12616
13132
  scopecheck,
@@ -12644,6 +13160,7 @@ export {
12644
13160
  sessionrestoregate,
12645
13161
  sessiontabof,
12646
13162
  setvariable,
13163
+ sharelesson,
12647
13164
  shareworkflow,
12648
13165
  shiftentryof,
12649
13166
  signalsreport,
@@ -12679,9 +13196,12 @@ export {
12679
13196
  submitreviewgranted,
12680
13197
  subscriptionframes,
12681
13198
  subscriptionoptionsof,
13199
+ swarmcosts,
12682
13200
  swarmoverview,
13201
+ swarmreport,
12683
13202
  swarmstateof,
12684
13203
  swarmstatereport,
13204
+ sweepreviews,
12685
13205
  tabreportresponse,
12686
13206
  targetgate,
12687
13207
  taskcounts,
@@ -12726,6 +13246,7 @@ export {
12726
13246
  tracestart,
12727
13247
  tracetofile,
12728
13248
  trailreport,
13249
+ transferhandoff,
12729
13250
  transformgrammar,
12730
13251
  triggereventcatalog,
12731
13252
  triggerfamilies,