@syntrologie/adapt-chatbot 2.8.0-canary.621 → 2.8.0-canary.622

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.
@@ -1 +1 @@
1
- {"version":3,"file":"hostAgentController.d.ts","sourceRoot":"","sources":["../src/hostAgentController.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEpD,uFAAuF;AACvF,MAAM,WAAW,eAAe;IAC9B,oBAAoB,CAClB,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,EACnC,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GACjC,MAAM,IAAI,CAAC;IACd;;;;;;OAMG;IACH,cAAc,CAAC,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACjG;;;;OAIG;IACH,qBAAqB,CAAC,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;IACzD;;;OAGG;IACH,iBAAiB,CAAC,CAChB,QAAQ,EAAE,CACR,IAAI,EACA;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,GACtD;QAAE,KAAK,EAAE,QAAQ,CAAA;KAAE,GACnB;QAAE,KAAK,EAAE,WAAW,CAAA;KAAE,KACvB,IAAI,GACR,MAAM,IAAI,CAAC;CACf;AAYD;;;GAGG;AACH,eAAO,MAAM,cAAc,SAAU,CAAC;AAKtC,MAAM,WAAW,0BAA0B;IACzC,wEAAwE;IACxE,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAwJD,UAAU,oBAAoB;IAC5B,cAAc,CAAC,CAAC,W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D_SIBLING_WINDOW_MS = 6e3;
3524
3524
  var CARD_HEARTBEAT_STALE_MS = 6e4;
3525
+ var FOLLOW_MAX_ATTEMPTS = 3;
3525
3526
  var CARD_SUPERSEDED = "canvas:superseded";
3526
3527
  var DOCKED_PREFIX = "syntro:mcp-docked:";
3527
3528
  var DOCKED_FOR_MS = 24 * 60 * 60 * 1e3;
@@ -3648,6 +3649,10 @@ function activateHostAgentController(runtime2, bridge, hostUi, options = {}) {
3648
3649
  let answerIssuedAt;
3649
3650
  let heartbeatSession;
3650
3651
  let folded = false;
3652
+ let followBaseline;
3653
+ let followTarget;
3654
+ let followAttempts = 0;
3655
+ let followInFlight = false;
3651
3656
  function hostSurface() {
3652
3657
  try {
3653
3658
  return runtime2.context?.get().surface ?? {};
@@ -3681,6 +3686,7 @@ function activateHostAgentController(runtime2, bridge, hostUi, options = {}) {
3681
3686
  } catch {
3682
3687
  }
3683
3688
  considerFold();
3689
+ considerFollow();
3684
3690
  }
3685
3691
  function considerFold() {
3686
3692
  if (folded || disposed || !heartbeatSession || born === void 0) return;
@@ -3692,6 +3698,31 @@ function activateHostAgentController(runtime2, bridge, hostUi, options = {}) {
3692
3698
  folded = true;
3693
3699
  runtime2.events.publish(CARD_SUPERSEDED, { superseded: true });
3694
3700
  }
3701
+ function considerFollow() {
3702
+ if (disposed || !heartbeatSession || born === void 0) return;
3703
+ const surface = hostSurface();
3704
+ if (surface.type !== "mcp-app" || surface.displayMode !== "fullscreen") {
3705
+ followBaseline = void 0;
3706
+ return;
3707
+ }
3708
+ const newest = Math.max(0, ...freshSiblings(heartbeatSession).map((beat) => beat.born ?? 0));
3709
+ if (followBaseline === void 0) {
3710
+ followBaseline = Math.max(born, newest);
3711
+ return;
3712
+ }
3713
+ if (followInFlight || newest <= followBaseline) return;
3714
+ if (followTarget !== newest) {
3715
+ followTarget = newest;
3716
+ followAttempts = 0;
3717
+ }
3718
+ if (followAttempts >= FOLLOW_MAX_ATTEMPTS) return;
3719
+ followAttempts++;
3720
+ followInFlight = true;
3721
+ scheduleHostRead(heartbeatSession, "follow", (landed) => {
3722
+ followInFlight = false;
3723
+ if (landed && followBaseline !== void 0) followBaseline = Math.max(followBaseline, newest);
3724
+ });
3725
+ }
3695
3726
  function pruneHeartbeats() {
3696
3727
  try {
3697
3728
  const store = cardStorage();
@@ -3838,8 +3869,11 @@ function activateHostAgentController(runtime2, bridge, hostUi, options = {}) {
3838
3869
  }
3839
3870
  });
3840
3871
  }
3841
- function scheduleHostRead(sessionRef, why = "reload") {
3842
- if (disposed || readRequested || typeof bridge.callServerTool !== "function") return;
3872
+ function scheduleHostRead(sessionRef, why = "reload", settled) {
3873
+ if (disposed || readRequested && why !== "follow" || typeof bridge.callServerTool !== "function") {
3874
+ settled?.(false);
3875
+ return;
3876
+ }
3843
3877
  const call = bridge.callServerTool.bind(bridge);
3844
3878
  readRequested = true;
3845
3879
  const expected = generation;
@@ -3849,20 +3883,27 @@ function activateHostAgentController(runtime2, bridge, hostUi, options = {}) {
3849
3883
  if (session) scheduleHostRead(session.session_ref);
3850
3884
  };
3851
3885
  void Promise.resolve().then(() => {
3852
- if (disposed) return;
3853
- if (expected !== generation) return readAgain();
3886
+ if (disposed) return settled?.(false);
3887
+ if (expected !== generation) {
3888
+ settled?.(false);
3889
+ return readAgain();
3890
+ }
3854
3891
  queue(async () => {
3855
3892
  const appliedAtIssue = applied;
3856
3893
  reportCardStage("read_brand_view_called", { why });
3857
- void call({ name: READ_TOOL, arguments: { sessionRef } }).then((result) => {
3894
+ void call({ name: READ_TOOL, arguments: { sessionRef } }).then(async (result) => {
3858
3895
  reportReadAnswer(why, result);
3859
- if (disposed) return;
3860
- if (expected !== generation) return readAgain();
3896
+ if (disposed) return settled?.(false);
3897
+ if (expected !== generation) {
3898
+ settled?.(false);
3899
+ return readAgain();
3900
+ }
3861
3901
  if (applied !== appliedAtIssue) {
3862
3902
  reportCardStage("tool_result_rejected", { reason: "stale" });
3863
- return;
3903
+ return settled?.(false);
3864
3904
  }
3865
- return consumeToolResult(result, { earlyRead: why === "turn_started" });
3905
+ await consumeToolResult(result, { earlyRead: why === "turn_started" });
3906
+ settled?.(decodeAgentTurn(result) !== void 0);
3866
3907
  }).catch((error) => {
3867
3908
  reportCardStage("read_brand_view_answered", {
3868
3909
  why,
@@ -3873,6 +3914,7 @@ function activateHostAgentController(runtime2, bridge, hostUi, options = {}) {
3873
3914
  reason: readFailureReason(error instanceof Error ? error.message : String(error))
3874
3915
  });
3875
3916
  if (why === "turn_started") return readAgain();
3917
+ if (why === "follow") return settled?.(false);
3876
3918
  if (!disposed && expected === generation)
3877
3919
  runtime2.events.publish("host.ui_error", { reason: "refresh_required" });
3878
3920
  });