litepaseo 0.13.1 → 0.13.3
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/CHANGELOG.md +22 -0
- package/dist/server/cli.mjs +2 -2
- package/dist/server/{worker-DfNLXgRM.mjs → worker-Dtl_KOz9.mjs} +348 -416
- package/dist/web/assets/{AddProjectDialog-BH4t1mH0.js → AddProjectDialog-D4KTzyPI.js} +1 -1
- package/dist/web/assets/AddProjectDialog-D4KTzyPI.js.br +0 -0
- package/dist/web/assets/AddProjectDialog-D4KTzyPI.js.gz +0 -0
- package/dist/web/assets/{ArchivedWorkspaces-c0EOLkEH.js → ArchivedWorkspaces-B6bLcQJ-.js} +1 -1
- package/dist/web/assets/ArchivedWorkspaces-B6bLcQJ-.js.br +0 -0
- package/dist/web/assets/ArchivedWorkspaces-B6bLcQJ-.js.gz +0 -0
- package/dist/web/assets/{ChangesPanel-DjkKjhfi.js → ChangesPanel-CuxrSgBA.js} +1 -1
- package/dist/web/assets/ChangesPanel-CuxrSgBA.js.br +0 -0
- package/dist/web/assets/ChangesPanel-CuxrSgBA.js.gz +0 -0
- package/dist/web/assets/{CodeBlockNode-bijGGeoN.js → CodeBlockNode-DLSSXpT7.js} +1 -1
- package/dist/web/assets/CodeBlockNode-DLSSXpT7.js.br +0 -0
- package/dist/web/assets/CodeBlockNode-DLSSXpT7.js.gz +0 -0
- package/dist/web/assets/{CommandCenter-CCTGjCPX.js → CommandCenter-DSyTWz2W.js} +1 -1
- package/dist/web/assets/CommandCenter-DSyTWz2W.js.br +0 -0
- package/dist/web/assets/CommandCenter-DSyTWz2W.js.gz +0 -0
- package/dist/web/assets/{ConversationSearch-1MY_nmz4.js → ConversationSearch-XHuI36Ap.js} +1 -1
- package/dist/web/assets/ConversationSearch-XHuI36Ap.js.br +0 -0
- package/dist/web/assets/ConversationSearch-XHuI36Ap.js.gz +0 -0
- package/dist/web/assets/{FileViewer-B0bQlA3z.js → FileViewer-XmGlYpEM.js} +1 -1
- package/dist/web/assets/FileViewer-XmGlYpEM.js.br +0 -0
- package/dist/web/assets/FileViewer-XmGlYpEM.js.gz +0 -0
- package/dist/web/assets/{FilesPanel-D_-v_ZcF.js → FilesPanel-COVntcP9.js} +1 -1
- package/dist/web/assets/FilesPanel-COVntcP9.js.br +0 -0
- package/dist/web/assets/FilesPanel-COVntcP9.js.gz +0 -0
- package/dist/web/assets/{HostSettings-DSgKGO4q.js → HostSettings-BxT-XGb_.js} +1 -1
- package/dist/web/assets/HostSettings-BxT-XGb_.js.br +0 -0
- package/dist/web/assets/HostSettings-BxT-XGb_.js.gz +0 -0
- package/dist/web/assets/{KanbanPage-CdxFwCay.js → KanbanPage-DBzWmFTR.js} +1 -1
- package/dist/web/assets/KanbanPage-DBzWmFTR.js.br +0 -0
- package/dist/web/assets/KanbanPage-DBzWmFTR.js.gz +0 -0
- package/dist/web/assets/{LabelsDialog-BLDf7cQV.js → LabelsDialog-D3JUaW7X.js} +1 -1
- package/dist/web/assets/LabelsDialog-D3JUaW7X.js.br +0 -0
- package/dist/web/assets/LabelsDialog-D3JUaW7X.js.gz +0 -0
- package/dist/web/assets/{MarkdownMessage-C7r5tc7R.js → MarkdownMessage-4EV-Csqd.js} +5 -5
- package/dist/web/assets/MarkdownMessage-4EV-Csqd.js.br +0 -0
- package/dist/web/assets/MarkdownMessage-4EV-Csqd.js.gz +0 -0
- package/dist/web/assets/{PreCodeBlock-Df4DvpxT.js → PreCodeBlock-iU8Ae5Pp.js} +1 -1
- package/dist/web/assets/{PreCodeBlock.vue_vue_type_style_index_0_lang-bn_V109a.js → PreCodeBlock.vue_vue_type_style_index_0_lang-CQCjU4ly.js} +1 -1
- package/dist/web/assets/PreCodeBlock.vue_vue_type_style_index_0_lang-CQCjU4ly.js.br +0 -0
- package/dist/web/assets/PreCodeBlock.vue_vue_type_style_index_0_lang-CQCjU4ly.js.gz +0 -0
- package/dist/web/assets/{SubagentsPanel-CU1DOqGi.js → SubagentsPanel-DMpI6doQ.js} +1 -1
- package/dist/web/assets/SubagentsPanel-DMpI6doQ.js.br +0 -0
- package/dist/web/assets/SubagentsPanel-DMpI6doQ.js.gz +0 -0
- package/dist/web/assets/{TerminalPanel-CKE10Knv.js → TerminalPanel-C2e3jrrJ.js} +1 -1
- package/dist/web/assets/TerminalPanel-C2e3jrrJ.js.br +0 -0
- package/dist/web/assets/TerminalPanel-C2e3jrrJ.js.gz +0 -0
- package/dist/web/assets/{Tooltip-CKIQz11V.js → Tooltip-CiobMXRt.js} +1 -1
- package/dist/web/assets/Tooltip-CiobMXRt.js.br +0 -0
- package/dist/web/assets/Tooltip-CiobMXRt.js.gz +0 -0
- package/dist/web/assets/index-D8mUG3zq.js +39 -0
- package/dist/web/assets/index-D8mUG3zq.js.br +0 -0
- package/dist/web/assets/index-D8mUG3zq.js.gz +0 -0
- package/dist/web/assets/index-mcXZ0n9O.css +1 -0
- package/dist/web/assets/index-mcXZ0n9O.css.br +0 -0
- package/dist/web/assets/index-mcXZ0n9O.css.gz +0 -0
- package/dist/web/assets/{index10-BH5cR790.js → index10-p0ATOJmS.js} +1 -1
- package/dist/web/assets/index10-p0ATOJmS.js.br +0 -0
- package/dist/web/assets/index10-p0ATOJmS.js.gz +0 -0
- package/dist/web/assets/index3-Brjzo8xB.js +1 -0
- package/dist/web/assets/index4-vKTqdN94.js +1 -0
- package/dist/web/assets/{index5-COjA17v2.js → index5-DB7kSJs1.js} +1 -1
- package/dist/web/assets/index5-DB7kSJs1.js.br +0 -0
- package/dist/web/assets/index5-DB7kSJs1.js.gz +0 -0
- package/dist/web/assets/{index6-C7WwIv8h.js → index6-CsKr5ieO.js} +1 -1
- package/dist/web/assets/index6-CsKr5ieO.js.br +0 -0
- package/dist/web/assets/index6-CsKr5ieO.js.gz +0 -0
- package/dist/web/assets/{index7-MofimpJO.js → index7-DthosqAO.js} +1 -1
- package/dist/web/assets/index7-DthosqAO.js.br +0 -0
- package/dist/web/assets/index7-DthosqAO.js.gz +0 -0
- package/dist/web/assets/{index8-BN62x6v7.js → index8-DuhcyzWn.js} +1 -1
- package/dist/web/assets/index8-DuhcyzWn.js.br +0 -0
- package/dist/web/assets/index8-DuhcyzWn.js.gz +0 -0
- package/dist/web/assets/{index9-DSF8wXFh.js → index9-I5anZSYr.js} +1 -1
- package/dist/web/assets/index9-I5anZSYr.js.br +0 -0
- package/dist/web/assets/index9-I5anZSYr.js.gz +0 -0
- package/dist/web/index.html +2 -2
- package/dist/web/index.html.br +0 -0
- package/dist/web/index.html.gz +0 -0
- package/package.json +1 -1
- package/dist/web/assets/AddProjectDialog-BH4t1mH0.js.br +0 -0
- package/dist/web/assets/AddProjectDialog-BH4t1mH0.js.gz +0 -0
- package/dist/web/assets/ArchivedWorkspaces-c0EOLkEH.js.br +0 -0
- package/dist/web/assets/ArchivedWorkspaces-c0EOLkEH.js.gz +0 -0
- package/dist/web/assets/ChangesPanel-DjkKjhfi.js.br +0 -0
- package/dist/web/assets/ChangesPanel-DjkKjhfi.js.gz +0 -0
- package/dist/web/assets/CodeBlockNode-bijGGeoN.js.br +0 -0
- package/dist/web/assets/CodeBlockNode-bijGGeoN.js.gz +0 -0
- package/dist/web/assets/CommandCenter-CCTGjCPX.js.br +0 -0
- package/dist/web/assets/CommandCenter-CCTGjCPX.js.gz +0 -0
- package/dist/web/assets/ConversationSearch-1MY_nmz4.js.br +0 -0
- package/dist/web/assets/ConversationSearch-1MY_nmz4.js.gz +0 -0
- package/dist/web/assets/FileViewer-B0bQlA3z.js.br +0 -0
- package/dist/web/assets/FileViewer-B0bQlA3z.js.gz +0 -0
- package/dist/web/assets/FilesPanel-D_-v_ZcF.js.br +0 -0
- package/dist/web/assets/FilesPanel-D_-v_ZcF.js.gz +0 -0
- package/dist/web/assets/HostSettings-DSgKGO4q.js.br +0 -0
- package/dist/web/assets/HostSettings-DSgKGO4q.js.gz +0 -0
- package/dist/web/assets/KanbanPage-CdxFwCay.js.br +0 -0
- package/dist/web/assets/KanbanPage-CdxFwCay.js.gz +0 -0
- package/dist/web/assets/LabelsDialog-BLDf7cQV.js.br +0 -0
- package/dist/web/assets/LabelsDialog-BLDf7cQV.js.gz +0 -0
- package/dist/web/assets/MarkdownMessage-C7r5tc7R.js.br +0 -0
- package/dist/web/assets/MarkdownMessage-C7r5tc7R.js.gz +0 -0
- package/dist/web/assets/PreCodeBlock.vue_vue_type_style_index_0_lang-bn_V109a.js.br +0 -0
- package/dist/web/assets/PreCodeBlock.vue_vue_type_style_index_0_lang-bn_V109a.js.gz +0 -0
- package/dist/web/assets/SubagentsPanel-CU1DOqGi.js.br +0 -0
- package/dist/web/assets/SubagentsPanel-CU1DOqGi.js.gz +0 -0
- package/dist/web/assets/TerminalPanel-CKE10Knv.js.br +0 -0
- package/dist/web/assets/TerminalPanel-CKE10Knv.js.gz +0 -0
- package/dist/web/assets/Tooltip-CKIQz11V.js.br +0 -0
- package/dist/web/assets/Tooltip-CKIQz11V.js.gz +0 -0
- package/dist/web/assets/index--Rpf_YJs.js +0 -39
- package/dist/web/assets/index--Rpf_YJs.js.br +0 -0
- package/dist/web/assets/index--Rpf_YJs.js.gz +0 -0
- package/dist/web/assets/index-CnAv6NUR.css +0 -1
- package/dist/web/assets/index-CnAv6NUR.css.br +0 -0
- package/dist/web/assets/index-CnAv6NUR.css.gz +0 -0
- package/dist/web/assets/index10-BH5cR790.js.br +0 -0
- package/dist/web/assets/index10-BH5cR790.js.gz +0 -0
- package/dist/web/assets/index3-OdSvV8Az.js +0 -1
- package/dist/web/assets/index4-p9EqAM3V.js +0 -1
- package/dist/web/assets/index5-COjA17v2.js.br +0 -0
- package/dist/web/assets/index5-COjA17v2.js.gz +0 -0
- package/dist/web/assets/index6-C7WwIv8h.js.br +0 -0
- package/dist/web/assets/index6-C7WwIv8h.js.gz +0 -0
- package/dist/web/assets/index7-MofimpJO.js.br +0 -0
- package/dist/web/assets/index7-MofimpJO.js.gz +0 -0
- package/dist/web/assets/index8-BN62x6v7.js.br +0 -0
- package/dist/web/assets/index8-BN62x6v7.js.gz +0 -0
- package/dist/web/assets/index9-DSF8wXFh.js.br +0 -0
- package/dist/web/assets/index9-DSF8wXFh.js.gz +0 -0
|
@@ -9,7 +9,6 @@ import { createHostClient, parseHostTarget } from "@getpaseo/client/node";
|
|
|
9
9
|
import { createPaseoApi } from "@getpaseo/client";
|
|
10
10
|
import { deriveAgentStateBucket } from "@getpaseo/protocol/agent-state-bucket";
|
|
11
11
|
import { getParentAgentIdFromLabels } from "@getpaseo/protocol/agent-labels";
|
|
12
|
-
import { timelineItemIdentity } from "@getpaseo/protocol/timeline-identity";
|
|
13
12
|
import { lstat, readFile, realpath } from "node:fs/promises";
|
|
14
13
|
import { Hono } from "hono";
|
|
15
14
|
import { bodyLimit } from "hono/body-limit";
|
|
@@ -733,465 +732,407 @@ var HostWorkspaces = class extends HostMirror {
|
|
|
733
732
|
};
|
|
734
733
|
// src/server/timeline-view.ts
|
|
735
734
|
const TAIL_LIMIT = 60;
|
|
736
|
-
|
|
737
|
-
/** Catch-up pages read in one go; further behind than this, reloading the tail is cheaper. */
|
|
738
|
-
const MAX_CATCH_UP_PAGES = 25;
|
|
739
|
-
/** Viewers that joined a loading view tracked for its load report. */
|
|
740
|
-
const MAX_JOINERS = 64;
|
|
741
|
-
/** Rows kept per view; older rows are dropped and stay reachable through history pages. */
|
|
735
|
+
/** Rows kept per view; older rows stay reachable through on-demand history pages. */
|
|
742
736
|
const MAX_ROWS = 600;
|
|
743
737
|
const KEEP_ROWS = 500;
|
|
744
738
|
/** Rows sent to a client that (re)joins; older ones load on demand. */
|
|
745
739
|
const RESET_ROWS = 200;
|
|
746
|
-
const
|
|
747
|
-
|
|
740
|
+
const MAX_JOINERS = 64;
|
|
741
|
+
/** Low-frequency pull interval while an agent is actively running and watched. */
|
|
742
|
+
const DEFAULT_POLL_MS = 1500;
|
|
743
|
+
/** Short burst interval right after sending a message or rewind so the new row lands quickly. */
|
|
744
|
+
const FAST_POLL_MS = 300;
|
|
745
|
+
/** Max fast-burst follow-up polls (~1.8 s at 300 ms); exits early as soon as rows change. */
|
|
746
|
+
const FAST_BURST_POLLS = 6;
|
|
747
|
+
/** Retry delay when the initial load fails. */
|
|
748
748
|
const RETRY_MS = 2e3;
|
|
749
|
+
/** One-shot follow-up delay after a turn ends if turnMetrics have not landed yet. */
|
|
750
|
+
const METRICS_SETTLE_MS = 700;
|
|
751
|
+
/** Per-pull RPC timeout so a wedged remote host can never lock `inFlight` forever. */
|
|
752
|
+
const PULL_TIMEOUT_MS = 2e4;
|
|
753
|
+
/** If a browser reconnects/resumes after this much silence, verify once against the daemon. */
|
|
754
|
+
const RESUME_VERIFY_MS = 5e3;
|
|
749
755
|
const now = () => performance.now();
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
...
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
...existing,
|
|
760
|
-
...incoming,
|
|
761
|
-
detail,
|
|
762
|
-
metadata
|
|
756
|
+
function toRow(entry) {
|
|
757
|
+
return {
|
|
758
|
+
seqStart: entry.seqStart,
|
|
759
|
+
seqEnd: entry.seqEnd,
|
|
760
|
+
timestamp: entry.timestamp,
|
|
761
|
+
provider: entry.provider,
|
|
762
|
+
...entry.turnId ? { turnId: entry.turnId } : {},
|
|
763
|
+
item: entry.item,
|
|
764
|
+
...entry.turnMetrics?.length ? { turnMetrics: entry.turnMetrics } : {}
|
|
763
765
|
};
|
|
764
|
-
if (incoming.status === "failed") merged.error = incoming.error;
|
|
765
|
-
else if (incoming.status === "completed" || incoming.status === "canceled") merged.error = null;
|
|
766
|
-
else if (incoming.error !== void 0) merged.error = incoming.error;
|
|
767
|
-
return merged;
|
|
768
766
|
}
|
|
769
|
-
function
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
767
|
+
function rowFingerprint(row) {
|
|
768
|
+
return JSON.stringify([
|
|
769
|
+
row.seqEnd,
|
|
770
|
+
row.timestamp,
|
|
771
|
+
row.provider,
|
|
772
|
+
row.turnId ?? null,
|
|
773
|
+
row.item,
|
|
774
|
+
row.turnMetrics ?? null
|
|
775
|
+
]);
|
|
774
776
|
}
|
|
775
777
|
/**
|
|
776
|
-
*
|
|
777
|
-
*
|
|
778
|
-
*
|
|
779
|
-
*
|
|
778
|
+
* Single-source-of-truth projected timeline view (Wake + Pull).
|
|
779
|
+
*
|
|
780
|
+
* Every row comes directly from the daemon's `fetchAgentTimeline(..., projection: "projected")`:
|
|
781
|
+
* - Idle conversations do zero polling and use zero timers.
|
|
782
|
+
* - Active (running) conversations pull at a low cadence (1.5 s) while watched and broadcast only
|
|
783
|
+
* rows whose fingerprint actually changed.
|
|
784
|
+
* - Turning idle triggers a final pull (with one short follow-up if turnMetrics haven't landed),
|
|
785
|
+
* and every changed row advances a monotonic `revision` so returning tabs resume cleanly with
|
|
786
|
+
* all updates including `turnMetrics`.
|
|
780
787
|
*/
|
|
781
788
|
var TimelineView = class {
|
|
782
789
|
rows = [];
|
|
783
790
|
bySeqStart = /* @__PURE__ */ new Map();
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
metricsTouched = /* @__PURE__ */ new Set();
|
|
791
|
+
fingerprints = /* @__PURE__ */ new Map();
|
|
792
|
+
rowRev = /* @__PURE__ */ new Map();
|
|
787
793
|
epoch = "";
|
|
788
|
-
|
|
794
|
+
revision = 0;
|
|
795
|
+
resumeFloor = 0;
|
|
789
796
|
hasOlder = false;
|
|
790
797
|
startCursor = null;
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
* can resume with just those rows. Set by each load; raised when rows are trimmed.
|
|
794
|
-
*/
|
|
795
|
-
resumeFloor = Number.POSITIVE_INFINITY;
|
|
796
|
-
/** True while rows reach back to the first projected row, so unseen identities are new. */
|
|
797
|
-
complete = false;
|
|
798
|
-
state = "loading";
|
|
799
|
-
buffer = [];
|
|
800
|
-
overflowed = false;
|
|
798
|
+
state = "idle";
|
|
799
|
+
active = false;
|
|
801
800
|
watchers = /* @__PURE__ */ new Set();
|
|
802
|
-
|
|
803
|
-
pending = /* @__PURE__ */ new Map();
|
|
804
|
-
pendingReset = false;
|
|
805
|
-
flushTimer;
|
|
801
|
+
pollTimer;
|
|
806
802
|
retryTimer;
|
|
807
|
-
|
|
803
|
+
settleTimer;
|
|
804
|
+
fastPollsLeft = 0;
|
|
805
|
+
inFlight = false;
|
|
806
|
+
pendingPull = false;
|
|
807
|
+
pendingSettle = false;
|
|
808
|
+
consecutiveFailures = 0;
|
|
809
|
+
lastPullAt = 0;
|
|
808
810
|
token = 0;
|
|
809
|
-
loads = 0;
|
|
810
|
-
/** Timings of the load in progress, until the first rows go out. */
|
|
811
811
|
timing = null;
|
|
812
|
-
/** Viewers that joined while the view was loading, waiting for its first rows. */
|
|
813
812
|
joiners = [];
|
|
814
813
|
driver;
|
|
815
814
|
agentId;
|
|
816
815
|
report;
|
|
817
|
-
|
|
816
|
+
pollMs;
|
|
817
|
+
fastPollMs;
|
|
818
|
+
constructor(driver, agentId, report, pollMs = DEFAULT_POLL_MS) {
|
|
818
819
|
this.driver = driver;
|
|
819
820
|
this.agentId = agentId;
|
|
820
821
|
this.report = report;
|
|
822
|
+
this.pollMs = pollMs;
|
|
823
|
+
this.fastPollMs = Math.min(pollMs, FAST_POLL_MS);
|
|
821
824
|
}
|
|
822
825
|
get watcherCount() {
|
|
823
826
|
return this.watchers.size;
|
|
824
827
|
}
|
|
825
|
-
/** Where the view stands, for diagnosing a viewer that waits. */
|
|
826
828
|
get status() {
|
|
827
829
|
return this.state;
|
|
828
830
|
}
|
|
829
831
|
start() {
|
|
830
|
-
|
|
832
|
+
if (this.state === "disposed" || this.state === "loading" || this.state === "live") return;
|
|
831
833
|
this.state = "loading";
|
|
832
|
-
this.
|
|
833
|
-
this.
|
|
834
|
-
|
|
835
|
-
if (this.timing) {
|
|
836
|
-
this.timing.attempts++;
|
|
837
|
-
this.timing.attemptAt = attemptAt;
|
|
838
|
-
} else this.timing = {
|
|
839
|
-
startedAt: attemptAt,
|
|
840
|
-
attemptAt,
|
|
841
|
-
subscribeMs: null,
|
|
834
|
+
this.token++;
|
|
835
|
+
this.timing ??= {
|
|
836
|
+
startedAt: now(),
|
|
842
837
|
fetchMs: null,
|
|
843
|
-
attempts:
|
|
838
|
+
attempts: 0,
|
|
844
839
|
failures: 0
|
|
845
840
|
};
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
841
|
+
this.timing.attempts++;
|
|
842
|
+
this.pull(true);
|
|
843
|
+
}
|
|
844
|
+
/** Updates whether this conversation is actively running; drives low-frequency pulling. */
|
|
845
|
+
setActive(running) {
|
|
846
|
+
if (this.state === "disposed") return;
|
|
847
|
+
const wasActive = this.active;
|
|
848
|
+
this.active = running;
|
|
849
|
+
clearTimeout(this.settleTimer);
|
|
850
|
+
this.settleTimer = void 0;
|
|
851
|
+
if (running) {
|
|
852
|
+
if (this.state === "live") {
|
|
853
|
+
this.pull(false);
|
|
854
|
+
this.schedulePoll();
|
|
855
|
+
}
|
|
856
|
+
} else {
|
|
857
|
+
if (!this.inFastBurst()) {
|
|
858
|
+
clearTimeout(this.pollTimer);
|
|
859
|
+
this.pollTimer = void 0;
|
|
860
|
+
}
|
|
861
|
+
if (wasActive && this.state === "live") this.pull(false, true);
|
|
862
|
+
}
|
|
865
863
|
}
|
|
866
864
|
/**
|
|
867
|
-
*
|
|
868
|
-
*
|
|
869
|
-
*
|
|
865
|
+
* Requests an immediate pull (e.g. after a message send, rewind, reconnect, or state update).
|
|
866
|
+
* With `followUp = true`, opens a short fast-burst window (up to 2 s at 300 ms cadence) that
|
|
867
|
+
* runs regardless of `active` so a newly submitted user_message lands quickly instead of
|
|
868
|
+
* waiting for the 1.5 s steady-state poll, and exits early as soon as rows change.
|
|
870
869
|
*/
|
|
870
|
+
wake(followUp = false) {
|
|
871
|
+
if (this.state === "disposed") return;
|
|
872
|
+
if (followUp) {
|
|
873
|
+
this.fastPollsLeft = FAST_BURST_POLLS;
|
|
874
|
+
clearTimeout(this.pollTimer);
|
|
875
|
+
this.pollTimer = void 0;
|
|
876
|
+
}
|
|
877
|
+
if (this.state === "idle" || this.state === "failed") return this.start();
|
|
878
|
+
if (this.state === "live") this.pull(false);
|
|
879
|
+
else this.pendingPull = true;
|
|
880
|
+
}
|
|
881
|
+
/** Backwards-compatible alias for one-shot tail refresh. */
|
|
882
|
+
refreshTailMetrics() {
|
|
883
|
+
this.wake();
|
|
884
|
+
}
|
|
871
885
|
watch(watcher, since) {
|
|
872
|
-
if (this.state === "live" || this.state === "catching-up") {
|
|
873
|
-
this.flush();
|
|
874
|
-
const resumed = since ? this.resumeOps(since) : null;
|
|
875
|
-
if (!resumed) watcher([this.resetOp()]);
|
|
876
|
-
else if (resumed.length) watcher(resumed);
|
|
877
|
-
} else if (this.watchers.size && this.joiners.length < MAX_JOINERS) this.joiners.push(now());
|
|
878
886
|
this.watchers.add(watcher);
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
887
|
+
if (this.state === "live") {
|
|
888
|
+
const ops = since ? this.resumeOps(since) : null;
|
|
889
|
+
if (ops) {
|
|
890
|
+
if (ops.length) watcher(ops);
|
|
891
|
+
} else watcher([this.resetOp()]);
|
|
892
|
+
if (this.active || this.inFastBurst()) this.schedulePoll();
|
|
893
|
+
else if (since && now() - this.lastPullAt >= RESUME_VERIFY_MS) this.wake();
|
|
894
|
+
} else if (this.state === "loading" && this.joiners.length < MAX_JOINERS) this.joiners.push(now());
|
|
895
|
+
return () => {
|
|
896
|
+
this.watchers.delete(watcher);
|
|
897
|
+
if (!this.watchers.size) {
|
|
898
|
+
clearTimeout(this.pollTimer);
|
|
899
|
+
this.pollTimer = void 0;
|
|
888
900
|
}
|
|
889
|
-
|
|
890
|
-
this.reload();
|
|
891
|
-
return;
|
|
892
|
-
case "agent.timeline.subscription_restored":
|
|
893
|
-
this.state === "live" && this.catchUp();
|
|
894
|
-
return;
|
|
895
|
-
case "agent.timeline.error": return this.fail(this.token);
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
bufferEvent(payload) {
|
|
899
|
-
if (this.overflowed) return;
|
|
900
|
-
if (this.buffer.length >= MAX_BUFFER) {
|
|
901
|
-
this.buffer = [];
|
|
902
|
-
this.overflowed = true;
|
|
903
|
-
return;
|
|
904
|
-
}
|
|
905
|
-
this.buffer.push(payload);
|
|
901
|
+
};
|
|
906
902
|
}
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
903
|
+
dispose() {
|
|
904
|
+
this.state = "disposed";
|
|
905
|
+
this.token++;
|
|
906
|
+
this.fastPollsLeft = 0;
|
|
907
|
+
clearTimeout(this.pollTimer);
|
|
908
|
+
clearTimeout(this.retryTimer);
|
|
909
|
+
clearTimeout(this.settleTimer);
|
|
910
|
+
this.pollTimer = this.retryTimer = this.settleTimer = void 0;
|
|
911
|
+
this.watchers.clear();
|
|
912
|
+
return Promise.resolve();
|
|
913
|
+
}
|
|
914
|
+
inFastBurst() {
|
|
915
|
+
return this.fastPollsLeft > 0;
|
|
916
|
+
}
|
|
917
|
+
schedulePoll() {
|
|
918
|
+
if (this.state !== "live" || !this.watchers.size || this.pollTimer) return;
|
|
919
|
+
const fast = this.inFastBurst();
|
|
920
|
+
if (!this.active && !fast) return;
|
|
921
|
+
const delay = fast ? this.fastPollMs : this.pollMs;
|
|
922
|
+
this.pollTimer = setTimeout(() => {
|
|
923
|
+
this.pollTimer = void 0;
|
|
924
|
+
if (this.state !== "live" || !this.watchers.size) return;
|
|
925
|
+
if (fast && this.fastPollsLeft > 0) this.fastPollsLeft--;
|
|
926
|
+
if (!this.active && !fast) return;
|
|
927
|
+
this.pull(false);
|
|
928
|
+
}, delay);
|
|
929
|
+
this.pollTimer.unref?.();
|
|
930
|
+
}
|
|
931
|
+
async pull(initial, checkMetricsSettle = false) {
|
|
932
|
+
if (this.state === "disposed") return;
|
|
933
|
+
if (this.inFlight) {
|
|
934
|
+
this.pendingPull = true;
|
|
935
|
+
if (checkMetricsSettle) this.pendingSettle = true;
|
|
914
936
|
return;
|
|
915
937
|
}
|
|
916
|
-
|
|
917
|
-
this.lastSeq = seq;
|
|
918
|
-
}
|
|
919
|
-
/** Folds one source event; false when the view cannot decide locally. */
|
|
920
|
-
applyLive(payload) {
|
|
921
|
-
const entry = {
|
|
922
|
-
seqStart: payload.seq,
|
|
923
|
-
seqEnd: payload.seq,
|
|
924
|
-
timestamp: payload.timestamp,
|
|
925
|
-
provider: payload.event.provider ?? "",
|
|
926
|
-
...payload.event.turnId ? { turnId: payload.event.turnId } : {},
|
|
927
|
-
item: payload.event.item
|
|
928
|
-
};
|
|
929
|
-
const identity = timelineItemIdentity(entry.item);
|
|
930
|
-
if (identity !== null) {
|
|
931
|
-
const existing = this.identities.get(identity);
|
|
932
|
-
if (existing) {
|
|
933
|
-
if (entry.item.type === "tool_call") {
|
|
934
|
-
if (existing.item.type === "tool_call" && existing.turnId === entry.turnId) {
|
|
935
|
-
existing.item = mergeToolCallItems(existing.item, entry.item);
|
|
936
|
-
existing.timestamp = entry.timestamp;
|
|
937
|
-
existing.seqEnd = Math.max(existing.seqEnd, entry.seqEnd);
|
|
938
|
-
this.mark(existing.seqStart, true);
|
|
939
|
-
return true;
|
|
940
|
-
}
|
|
941
|
-
} else if (entry.item.type === "plugin" && existing.item.type === "plugin") {
|
|
942
|
-
Object.assign(existing, {
|
|
943
|
-
...entry,
|
|
944
|
-
seqStart: existing.seqStart
|
|
945
|
-
});
|
|
946
|
-
this.mark(existing.seqStart, true);
|
|
947
|
-
return true;
|
|
948
|
-
}
|
|
949
|
-
} else if (!this.complete) return false;
|
|
950
|
-
}
|
|
951
|
-
const previous = this.rows.at(-1);
|
|
952
|
-
if (previous && textMergeable(previous, entry)) {
|
|
953
|
-
const text = entry.item.text ?? "";
|
|
954
|
-
previous.item = {
|
|
955
|
-
type: previous.item.type,
|
|
956
|
-
text: (previous.item.text ?? "") + text,
|
|
957
|
-
...previous.item.type === "assistant_message" && previous.item.messageId ? { messageId: previous.item.messageId } : {}
|
|
958
|
-
};
|
|
959
|
-
previous.timestamp = entry.timestamp;
|
|
960
|
-
previous.seqEnd = entry.seqEnd;
|
|
961
|
-
this.mark(previous.seqStart, false, text);
|
|
962
|
-
return true;
|
|
963
|
-
}
|
|
964
|
-
this.insert(entry);
|
|
965
|
-
return true;
|
|
966
|
-
}
|
|
967
|
-
async reload() {
|
|
938
|
+
this.inFlight = true;
|
|
968
939
|
const token = this.token;
|
|
969
|
-
const load = ++this.loads;
|
|
970
|
-
this.state = "loading";
|
|
971
940
|
const fetchAt = now();
|
|
941
|
+
let timeoutHandle;
|
|
972
942
|
try {
|
|
973
|
-
const
|
|
943
|
+
const fetchPromise = this.driver.fetchAgentTimeline(this.agentId, {
|
|
974
944
|
direction: "tail",
|
|
975
945
|
limit: TAIL_LIMIT,
|
|
976
946
|
projection: "projected",
|
|
977
|
-
wholeTurns: false
|
|
947
|
+
wholeTurns: false,
|
|
948
|
+
timeout: 15e3
|
|
978
949
|
});
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
this.
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
if (
|
|
1005
|
-
|
|
1006
|
-
this.
|
|
1007
|
-
|
|
950
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
951
|
+
timeoutHandle = setTimeout(() => reject(/* @__PURE__ */ new Error("Timeline fetch timed out")), PULL_TIMEOUT_MS);
|
|
952
|
+
timeoutHandle.unref?.();
|
|
953
|
+
});
|
|
954
|
+
const page = await Promise.race([fetchPromise, timeoutPromise]);
|
|
955
|
+
if (token !== this.token) return;
|
|
956
|
+
this.lastPullAt = now();
|
|
957
|
+
if (this.timing) this.timing.fetchMs = Math.round(this.lastPullAt - fetchAt);
|
|
958
|
+
this.consecutiveFailures = 0;
|
|
959
|
+
if (initial || this.state !== "live" || page.reset || page.epoch !== this.epoch) {
|
|
960
|
+
this.replaceWith(page);
|
|
961
|
+
this.state = "live";
|
|
962
|
+
this.loaded();
|
|
963
|
+
if (initial && page.entries.length === 0 && this.watchers.size > 0) this.fastPollsLeft = Math.max(this.fastPollsLeft, FAST_BURST_POLLS);
|
|
964
|
+
else if (page.entries.length > 0) this.fastPollsLeft = 0;
|
|
965
|
+
this.broadcast([this.resetOp()]);
|
|
966
|
+
} else {
|
|
967
|
+
const ops = this.mergeTail(page);
|
|
968
|
+
if (ops.length) {
|
|
969
|
+
this.fastPollsLeft = 0;
|
|
970
|
+
this.broadcast(ops);
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
if (checkMetricsSettle && !this.active) {
|
|
974
|
+
const latest = [...page.entries].reverse().find((e) => e.item.type === "assistant_message" || e.item.type === "tool_call");
|
|
975
|
+
if (latest && !latest.turnMetrics?.length) {
|
|
976
|
+
clearTimeout(this.settleTimer);
|
|
977
|
+
this.settleTimer = setTimeout(() => {
|
|
978
|
+
this.settleTimer = void 0;
|
|
979
|
+
if (this.state === "live" && !this.active) this.pull(false, false);
|
|
980
|
+
}, METRICS_SETTLE_MS);
|
|
981
|
+
this.settleTimer.unref?.();
|
|
1008
982
|
}
|
|
1009
|
-
for (const entry of page.entries) this.upsertFetched(entry);
|
|
1010
|
-
const end = page.endCursor?.seq ?? (page.hasNewer ? null : page.window.maxSeq);
|
|
1011
|
-
if (end === null) break;
|
|
1012
|
-
this.lastSeq = Math.max(this.lastSeq, end);
|
|
1013
|
-
if (!page.hasNewer) break;
|
|
1014
|
-
if (end <= before || pages >= MAX_CATCH_UP_PAGES) return void this.reload();
|
|
1015
983
|
}
|
|
1016
|
-
this.settle();
|
|
1017
984
|
} catch {
|
|
1018
|
-
this.
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
this.
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
985
|
+
if (token !== this.token) return;
|
|
986
|
+
this.consecutiveFailures++;
|
|
987
|
+
if (this.timing) this.timing.failures++;
|
|
988
|
+
if (initial || this.state !== "live") {
|
|
989
|
+
this.state = "failed";
|
|
990
|
+
this.broadcast([{
|
|
991
|
+
type: "error",
|
|
992
|
+
message: "Timeline sync interrupted; retrying"
|
|
993
|
+
}]);
|
|
994
|
+
clearTimeout(this.retryTimer);
|
|
995
|
+
this.retryTimer = setTimeout(() => {
|
|
996
|
+
this.retryTimer = void 0;
|
|
997
|
+
if (this.state === "failed" && token === this.token) this.start();
|
|
998
|
+
}, RETRY_MS);
|
|
999
|
+
this.retryTimer.unref?.();
|
|
1000
|
+
} else if (this.consecutiveFailures >= 3) this.broadcast([{
|
|
1001
|
+
type: "error",
|
|
1002
|
+
message: "Timeline sync interrupted; retrying"
|
|
1003
|
+
}]);
|
|
1004
|
+
} finally {
|
|
1005
|
+
clearTimeout(timeoutHandle);
|
|
1006
|
+
this.inFlight = false;
|
|
1007
|
+
if (this.state === "live") {
|
|
1008
|
+
if (this.pendingPull) {
|
|
1009
|
+
const settle = this.pendingSettle;
|
|
1010
|
+
this.pendingPull = false;
|
|
1011
|
+
this.pendingSettle = false;
|
|
1012
|
+
this.pull(false, settle);
|
|
1013
|
+
} else if ((this.active || this.inFastBurst()) && this.watchers.size) this.schedulePoll();
|
|
1037
1014
|
}
|
|
1038
1015
|
}
|
|
1039
1016
|
}
|
|
1040
|
-
fail(token) {
|
|
1041
|
-
if (token !== this.token || this.state === "disposed") return;
|
|
1042
|
-
this.state = "failed";
|
|
1043
|
-
if (this.timing) this.timing.failures++;
|
|
1044
|
-
this.broadcast([{
|
|
1045
|
-
type: "error",
|
|
1046
|
-
message: "Timeline sync interrupted; retrying"
|
|
1047
|
-
}]);
|
|
1048
|
-
clearTimeout(this.retryTimer);
|
|
1049
|
-
this.retryTimer = setTimeout(() => {
|
|
1050
|
-
if (this.state !== "failed" || token !== this.token) return;
|
|
1051
|
-
this.subscription?.release().catch(() => {});
|
|
1052
|
-
this.start();
|
|
1053
|
-
}, RETRY_MS);
|
|
1054
|
-
this.retryTimer.unref?.();
|
|
1055
|
-
}
|
|
1056
1017
|
replaceWith(page) {
|
|
1057
1018
|
this.rows = [];
|
|
1058
1019
|
this.bySeqStart.clear();
|
|
1059
|
-
this.
|
|
1060
|
-
this.
|
|
1061
|
-
this.metricsTouched.clear();
|
|
1020
|
+
this.fingerprints.clear();
|
|
1021
|
+
this.rowRev.clear();
|
|
1062
1022
|
this.epoch = page.epoch;
|
|
1063
|
-
this.
|
|
1064
|
-
this.resumeFloor = this.
|
|
1023
|
+
this.revision++;
|
|
1024
|
+
this.resumeFloor = this.revision;
|
|
1065
1025
|
this.hasOlder = page.hasOlder;
|
|
1066
1026
|
this.startCursor = page.startCursor;
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
this.
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1027
|
+
for (const entry of page.entries) {
|
|
1028
|
+
const row = toRow(entry);
|
|
1029
|
+
this.insertRow(row, this.revision);
|
|
1030
|
+
}
|
|
1031
|
+
this.trimIfNeeded();
|
|
1032
|
+
}
|
|
1033
|
+
mergeTail(page) {
|
|
1034
|
+
if (this.rows.length > 0) {
|
|
1035
|
+
if (page.entries.length === 0) {
|
|
1036
|
+
this.replaceWith(page);
|
|
1037
|
+
return [this.resetOp()];
|
|
1038
|
+
}
|
|
1039
|
+
const tailFirst = page.entries[0].seqStart;
|
|
1040
|
+
const ourLast = this.rows.at(-1);
|
|
1041
|
+
if (page.hasOlder && tailFirst > ourLast.seqEnd + 1) {
|
|
1042
|
+
this.replaceWith(page);
|
|
1043
|
+
return [this.resetOp()];
|
|
1044
|
+
}
|
|
1045
|
+
const incomingStarts = new Set(page.entries.map((e) => e.seqStart));
|
|
1046
|
+
for (let i = this.rows.length - 1; i >= 0; i--) {
|
|
1047
|
+
const r = this.rows[i];
|
|
1048
|
+
if (r.seqStart < tailFirst) break;
|
|
1049
|
+
if (!incomingStarts.has(r.seqStart)) {
|
|
1050
|
+
this.replaceWith(page);
|
|
1051
|
+
return [this.resetOp()];
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
const ops = [];
|
|
1056
|
+
let touched = false;
|
|
1057
|
+
for (const entry of page.entries) {
|
|
1058
|
+
const row = toRow(entry);
|
|
1059
|
+
const fp = rowFingerprint(row);
|
|
1060
|
+
const existing = this.bySeqStart.get(row.seqStart);
|
|
1061
|
+
if (existing) {
|
|
1062
|
+
if (this.fingerprints.get(row.seqStart) === fp) continue;
|
|
1063
|
+
if (!touched) {
|
|
1064
|
+
this.revision++;
|
|
1065
|
+
touched = true;
|
|
1066
|
+
}
|
|
1067
|
+
Object.assign(existing, row);
|
|
1068
|
+
if (!row.turnId) delete existing.turnId;
|
|
1069
|
+
if (!row.turnMetrics?.length) delete existing.turnMetrics;
|
|
1070
|
+
this.fingerprints.set(row.seqStart, fp);
|
|
1071
|
+
this.rowRev.set(row.seqStart, this.revision);
|
|
1072
|
+
ops.push({
|
|
1073
|
+
type: "upsert",
|
|
1074
|
+
row: { ...existing },
|
|
1075
|
+
seq: this.revision
|
|
1076
|
+
});
|
|
1077
|
+
continue;
|
|
1078
|
+
}
|
|
1079
|
+
if (this.hasOlder && this.startCursor && row.seqStart < this.startCursor.seq) continue;
|
|
1080
|
+
if (!touched) {
|
|
1081
|
+
this.revision++;
|
|
1082
|
+
touched = true;
|
|
1083
|
+
}
|
|
1084
|
+
this.insertRow(row, this.revision);
|
|
1085
|
+
ops.push({
|
|
1086
|
+
type: "upsert",
|
|
1087
|
+
row: { ...row },
|
|
1088
|
+
seq: this.revision
|
|
1089
|
+
});
|
|
1092
1090
|
}
|
|
1093
|
-
|
|
1094
|
-
|
|
1091
|
+
this.trimIfNeeded();
|
|
1092
|
+
return ops;
|
|
1095
1093
|
}
|
|
1096
|
-
|
|
1094
|
+
insertRow(row, rev) {
|
|
1095
|
+
const fp = rowFingerprint(row);
|
|
1097
1096
|
let index = this.rows.length;
|
|
1098
1097
|
if (index && this.rows[index - 1].seqStart > row.seqStart) {
|
|
1099
|
-
let low = 0
|
|
1098
|
+
let low = 0;
|
|
1099
|
+
let high = index;
|
|
1100
1100
|
while (low < high) {
|
|
1101
|
-
const
|
|
1102
|
-
if (this.rows[
|
|
1103
|
-
else high =
|
|
1101
|
+
const mid = low + high >>> 1;
|
|
1102
|
+
if (this.rows[mid].seqStart < row.seqStart) low = mid + 1;
|
|
1103
|
+
else high = mid;
|
|
1104
1104
|
}
|
|
1105
1105
|
index = low;
|
|
1106
1106
|
}
|
|
1107
|
-
|
|
1108
|
-
else this.rows.splice(index, 0, row);
|
|
1107
|
+
this.rows.splice(index, 0, row);
|
|
1109
1108
|
this.bySeqStart.set(row.seqStart, row);
|
|
1110
|
-
this.
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
const current = this.identities.get(identity);
|
|
1119
|
-
if (!current || current.seqStart <= row.seqStart) this.identities.set(identity, row);
|
|
1120
|
-
}
|
|
1121
|
-
trim() {
|
|
1122
|
-
const removed = this.rows.splice(0, this.rows.length - KEEP_ROWS);
|
|
1123
|
-
for (const row of removed) {
|
|
1124
|
-
this.resumeFloor = Math.max(this.resumeFloor, row.seqEnd);
|
|
1109
|
+
this.fingerprints.set(row.seqStart, fp);
|
|
1110
|
+
this.rowRev.set(row.seqStart, rev);
|
|
1111
|
+
}
|
|
1112
|
+
trimIfNeeded() {
|
|
1113
|
+
if (this.rows.length <= MAX_ROWS) return;
|
|
1114
|
+
const dropped = this.rows.slice(0, this.rows.length - KEEP_ROWS);
|
|
1115
|
+
this.rows = this.rows.slice(this.rows.length - KEEP_ROWS);
|
|
1116
|
+
for (const row of dropped) {
|
|
1125
1117
|
this.bySeqStart.delete(row.seqStart);
|
|
1126
|
-
this.
|
|
1127
|
-
|
|
1128
|
-
if (identity !== null && this.identities.get(identity) === row) this.identities.delete(identity);
|
|
1118
|
+
this.fingerprints.delete(row.seqStart);
|
|
1119
|
+
this.rowRev.delete(row.seqStart);
|
|
1129
1120
|
}
|
|
1130
|
-
this.complete = false;
|
|
1131
1121
|
this.hasOlder = true;
|
|
1132
|
-
this.startCursor = {
|
|
1122
|
+
this.startCursor = this.rows[0] ? {
|
|
1133
1123
|
epoch: this.epoch,
|
|
1134
1124
|
seq: this.rows[0].seqStart
|
|
1135
|
-
};
|
|
1136
|
-
|
|
1137
|
-
mark(seqStart, full, text = "") {
|
|
1138
|
-
if (this.pendingReset || !this.watchers.size) return;
|
|
1139
|
-
const pending = this.pending.get(seqStart);
|
|
1140
|
-
if (!pending) this.pending.set(seqStart, {
|
|
1141
|
-
full,
|
|
1142
|
-
text: full ? "" : text
|
|
1143
|
-
});
|
|
1144
|
-
else if (full) {
|
|
1145
|
-
pending.full = true;
|
|
1146
|
-
pending.text = "";
|
|
1147
|
-
} else if (!pending.full) pending.text += text;
|
|
1148
|
-
this.scheduleFlush();
|
|
1149
|
-
}
|
|
1150
|
-
scheduleFlush() {
|
|
1151
|
-
if (this.flushTimer || !this.watchers.size) return;
|
|
1152
|
-
this.flushTimer = setTimeout(() => this.flush(), FLUSH_MS$2);
|
|
1153
|
-
this.flushTimer.unref?.();
|
|
1154
|
-
}
|
|
1155
|
-
flush() {
|
|
1156
|
-
clearTimeout(this.flushTimer);
|
|
1157
|
-
this.flushTimer = void 0;
|
|
1158
|
-
if (this.pendingReset) {
|
|
1159
|
-
this.pendingReset = false;
|
|
1160
|
-
this.pending.clear();
|
|
1161
|
-
this.broadcast([this.resetOp()]);
|
|
1162
|
-
return this.loaded();
|
|
1163
|
-
}
|
|
1164
|
-
if (!this.pending.size) return;
|
|
1165
|
-
const ops = [];
|
|
1166
|
-
for (const [seqStart, change] of this.pending) {
|
|
1167
|
-
const row = this.bySeqStart.get(seqStart);
|
|
1168
|
-
if (!row) continue;
|
|
1169
|
-
ops.push(change.full ? {
|
|
1170
|
-
type: "upsert",
|
|
1171
|
-
row: { ...row }
|
|
1172
|
-
} : {
|
|
1173
|
-
type: "append",
|
|
1174
|
-
seqStart,
|
|
1175
|
-
seqEnd: row.seqEnd,
|
|
1176
|
-
timestamp: row.timestamp,
|
|
1177
|
-
text: change.text
|
|
1178
|
-
});
|
|
1179
|
-
}
|
|
1180
|
-
this.pending.clear();
|
|
1181
|
-
if (ops.length) this.broadcast(ops);
|
|
1125
|
+
} : this.startCursor;
|
|
1126
|
+
this.resumeFloor = this.revision;
|
|
1182
1127
|
}
|
|
1183
|
-
/**
|
|
1184
|
-
* The rows a returning browser lacks: those from its window on that changed after `since.seq`,
|
|
1185
|
-
* as upserts. Null when the view cannot tell (another epoch, history it no longer holds) or
|
|
1186
|
-
* when so much changed that a reset is the smaller answer.
|
|
1187
|
-
*/
|
|
1188
1128
|
resumeOps(since) {
|
|
1189
|
-
if (since.epoch !== this.epoch || since.seq < this.resumeFloor || since.seq > this.
|
|
1190
|
-
const changed = this.rows.filter((row) => row.seqStart >= since.from && (
|
|
1129
|
+
if (since.epoch !== this.epoch || since.seq < this.resumeFloor || since.seq > this.revision) return null;
|
|
1130
|
+
const changed = this.rows.filter((row) => row.seqStart >= since.from && (this.rowRev.get(row.seqStart) ?? 0) > since.seq);
|
|
1191
1131
|
if (changed.length > RESET_ROWS) return null;
|
|
1192
1132
|
return changed.map((row) => ({
|
|
1193
1133
|
type: "upsert",
|
|
1194
|
-
row: { ...row }
|
|
1134
|
+
row: { ...row },
|
|
1135
|
+
seq: this.revision
|
|
1195
1136
|
}));
|
|
1196
1137
|
}
|
|
1197
1138
|
resetOp() {
|
|
@@ -1206,10 +1147,9 @@ var TimelineView = class {
|
|
|
1206
1147
|
epoch: this.epoch,
|
|
1207
1148
|
seq: rows[0].seqStart
|
|
1208
1149
|
} : this.startCursor,
|
|
1209
|
-
seq: this.
|
|
1150
|
+
seq: this.revision
|
|
1210
1151
|
};
|
|
1211
1152
|
}
|
|
1212
|
-
/** The first rows went out: report how long the view, and anyone who joined it, waited. */
|
|
1213
1153
|
loaded() {
|
|
1214
1154
|
const timing = this.timing;
|
|
1215
1155
|
const joiners = this.joiners;
|
|
@@ -1218,7 +1158,7 @@ var TimelineView = class {
|
|
|
1218
1158
|
if (!timing || !this.watchers.size) return;
|
|
1219
1159
|
const done = now();
|
|
1220
1160
|
const base = {
|
|
1221
|
-
subscribeMs:
|
|
1161
|
+
subscribeMs: null,
|
|
1222
1162
|
fetchMs: timing.fetchMs,
|
|
1223
1163
|
attempts: timing.attempts,
|
|
1224
1164
|
failures: timing.failures
|
|
@@ -1234,43 +1174,6 @@ var TimelineView = class {
|
|
|
1234
1174
|
kind: "join"
|
|
1235
1175
|
});
|
|
1236
1176
|
}
|
|
1237
|
-
/**
|
|
1238
|
-
* Pulls the last few projected entries after a turn finishes so daemon-computed turnMetrics
|
|
1239
|
-
* (speed, tokens, cache, cost) attach to live rows without reloading the whole timeline.
|
|
1240
|
-
*/
|
|
1241
|
-
async refreshTailMetrics(attempt = 0) {
|
|
1242
|
-
if (this.state !== "live") return;
|
|
1243
|
-
const token = this.token;
|
|
1244
|
-
try {
|
|
1245
|
-
const page = await this.driver.fetchAgentTimeline(this.agentId, {
|
|
1246
|
-
direction: "tail",
|
|
1247
|
-
limit: 12,
|
|
1248
|
-
projection: "projected",
|
|
1249
|
-
wholeTurns: false
|
|
1250
|
-
});
|
|
1251
|
-
if (token !== this.token || this.state !== "live" || page.epoch !== this.epoch) return;
|
|
1252
|
-
let updated = false;
|
|
1253
|
-
let latestHasMetrics = false;
|
|
1254
|
-
const latestAssistant = [...page.entries].reverse().find((e) => e.item.type === "assistant_message" || e.item.type === "tool_call");
|
|
1255
|
-
for (const entry of page.entries) {
|
|
1256
|
-
if (!entry.turnMetrics?.length) continue;
|
|
1257
|
-
if (latestAssistant && entry.seqStart === latestAssistant.seqStart) latestHasMetrics = true;
|
|
1258
|
-
const existing = this.bySeqStart.get(entry.seqStart) ?? this.rows.find((r) => r.seqStart <= entry.seqEnd && r.seqEnd >= entry.seqStart);
|
|
1259
|
-
if (!existing) continue;
|
|
1260
|
-
if (JSON.stringify(existing.turnMetrics ?? null) === JSON.stringify(entry.turnMetrics)) continue;
|
|
1261
|
-
existing.turnMetrics = entry.turnMetrics;
|
|
1262
|
-
this.metricsTouched.add(existing.seqStart);
|
|
1263
|
-
if (this.metricsTouched.size > 16) {
|
|
1264
|
-
const oldest = this.metricsTouched.values().next().value;
|
|
1265
|
-
if (oldest !== void 0) this.metricsTouched.delete(oldest);
|
|
1266
|
-
}
|
|
1267
|
-
this.mark(existing.seqStart, true);
|
|
1268
|
-
updated = true;
|
|
1269
|
-
}
|
|
1270
|
-
if (updated) this.flush();
|
|
1271
|
-
if (!latestHasMetrics && attempt < 2) setTimeout(() => void this.refreshTailMetrics(attempt + 1), attempt === 0 ? 600 : 1500).unref?.();
|
|
1272
|
-
} catch {}
|
|
1273
|
-
}
|
|
1274
1177
|
broadcast(ops) {
|
|
1275
1178
|
notifyListeners(this.watchers, ops);
|
|
1276
1179
|
}
|
|
@@ -1343,6 +1246,10 @@ var HostSubagents = class {
|
|
|
1343
1246
|
this.releaseUse();
|
|
1344
1247
|
};
|
|
1345
1248
|
}
|
|
1249
|
+
/** Current status of a provider subagent, if known. */
|
|
1250
|
+
statusOf(parentAgentId, subagentId) {
|
|
1251
|
+
return this.parents.get(parentAgentId)?.subagents.get(subagentId)?.status;
|
|
1252
|
+
}
|
|
1346
1253
|
/** A TimelineView driver for one subagent conversation. */
|
|
1347
1254
|
timelineDriver(parentAgentId, subagentId) {
|
|
1348
1255
|
const key = `${parentAgentId}\0${subagentId}`;
|
|
@@ -1789,7 +1696,14 @@ var Hosts = class {
|
|
|
1789
1696
|
attach(hostId, driver, api) {
|
|
1790
1697
|
this.assertDetached(hostId);
|
|
1791
1698
|
const directory = new HostDirectory(hostId, driver, this.agents, () => this.emit(this.agentListeners), (previous, next) => {
|
|
1792
|
-
if (
|
|
1699
|
+
if (next) {
|
|
1700
|
+
const view = this.timelines.get(next.key)?.view;
|
|
1701
|
+
if (view) {
|
|
1702
|
+
const running = next.turnActive === true || next.state === "running" || next.status === "running" || next.status === "initializing";
|
|
1703
|
+
view.setActive(running);
|
|
1704
|
+
if (!running && previous && (previous.activityAt !== next.activityAt || previous.state !== next.state)) view.wake();
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1793
1707
|
notifyListeners(this.transitionListeners, previous, next);
|
|
1794
1708
|
});
|
|
1795
1709
|
const workspaces = new HostWorkspaces(hostId, driver, this.workspaces, () => this.emit(this.agentListeners), this.emptyProjects);
|
|
@@ -1802,6 +1716,7 @@ var Hosts = class {
|
|
|
1802
1716
|
});
|
|
1803
1717
|
this.diagnostics.set(hostId, { lastConnectedAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
1804
1718
|
this.clients.get(hostId)?.backgroundWork.reconnect();
|
|
1719
|
+
for (const entry of this.timelines.values()) if (entry.hostId === hostId && entry.view.watcherCount > 0) entry.view.wake();
|
|
1805
1720
|
} else if (state.status === "connecting") this.diagnostics.set(hostId, {
|
|
1806
1721
|
...previous,
|
|
1807
1722
|
nextRetryAt: void 0,
|
|
@@ -1929,9 +1844,21 @@ var Hosts = class {
|
|
|
1929
1844
|
this.hostListeners.add(listener);
|
|
1930
1845
|
return () => this.hostListeners.delete(listener);
|
|
1931
1846
|
}
|
|
1847
|
+
/** Wakes a watched timeline view immediately (e.g. after sending a message or rewinding). */
|
|
1848
|
+
wakeTimeline(hostId, agentId, followUp = false) {
|
|
1849
|
+
const view = this.timelines.get(`${hostId}:${agentId}`)?.view;
|
|
1850
|
+
if (!view) return;
|
|
1851
|
+
view.wake(followUp);
|
|
1852
|
+
}
|
|
1932
1853
|
/** The provider subagents of one agent, as they change. */
|
|
1933
1854
|
watchSubagents(hostId, agentId, listener) {
|
|
1934
|
-
return this.get(hostId).subagents.watch(agentId,
|
|
1855
|
+
return this.get(hostId).subagents.watch(agentId, (subagents) => {
|
|
1856
|
+
for (const s of subagents) {
|
|
1857
|
+
const subView = this.timelines.get(`${hostId}:${agentId}:subagent:${s.id}`)?.view;
|
|
1858
|
+
if (subView) subView.setActive(s.status === "running");
|
|
1859
|
+
}
|
|
1860
|
+
listener(subagents);
|
|
1861
|
+
});
|
|
1935
1862
|
}
|
|
1936
1863
|
/** Background tasks and heartbeats of one agent, as they change. */
|
|
1937
1864
|
watchBackgroundWork(hostId, agentId, listener) {
|
|
@@ -1961,6 +1888,9 @@ var Hosts = class {
|
|
|
1961
1888
|
...report
|
|
1962
1889
|
});
|
|
1963
1890
|
});
|
|
1891
|
+
const agent = subagentId ? void 0 : this.agents.get(key);
|
|
1892
|
+
const running = subagentId ? client.subagents.statusOf(agentId, subagentId) === "running" : !!(agent && (agent.turnActive === true || agent.state === "running" || agent.status === "running" || agent.status === "initializing"));
|
|
1893
|
+
view.setActive(running);
|
|
1964
1894
|
entry = {
|
|
1965
1895
|
view,
|
|
1966
1896
|
hostId,
|
|
@@ -2003,7 +1933,7 @@ var Hosts = class {
|
|
|
2003
1933
|
if (waiting && ops.some((op) => op.type === "reset")) finishWait(false);
|
|
2004
1934
|
watcher(ops);
|
|
2005
1935
|
}, since);
|
|
2006
|
-
if (joined.state === "live"
|
|
1936
|
+
if (joined.state === "live") finishWait(false);
|
|
2007
1937
|
const current = entry;
|
|
2008
1938
|
return () => {
|
|
2009
1939
|
finishWait(true);
|
|
@@ -5455,6 +5385,7 @@ function registerTimelineRoutes(app, { store, hosts, streamValidity, encodingOf
|
|
|
5455
5385
|
if (!rewindModes(facts.capabilities).includes(mode)) return c.json({ error: "This agent cannot rewind that way." }, 400);
|
|
5456
5386
|
try {
|
|
5457
5387
|
await client.driver.rewindAgent(c.req.param("agent"), messageId, mode);
|
|
5388
|
+
hosts.wakeTimeline(c.req.param("host"), c.req.param("agent"), true);
|
|
5458
5389
|
return c.json({ ok: true });
|
|
5459
5390
|
} catch (error) {
|
|
5460
5391
|
return c.json({ error: errorMessage(error, "Rewind failed") }, 502);
|
|
@@ -5656,6 +5587,7 @@ function registerMessageRoutes(app, { store, hosts, attachments, sendQueue, stre
|
|
|
5656
5587
|
...prepared.attachments.length ? { attachments: prepared.attachments } : {}
|
|
5657
5588
|
});
|
|
5658
5589
|
attachments.consumed(input.attachmentIds);
|
|
5590
|
+
hosts.wakeTimeline(host, agent, true);
|
|
5659
5591
|
return c.json({
|
|
5660
5592
|
status: "acknowledged",
|
|
5661
5593
|
messageId: input.messageId
|