@moxt-ai/mobius 0.0.142 → 0.0.143
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/acp/agent-query-processes.js +2 -2
- package/dist/acp/agent-query-processes.js.map +1 -1
- package/dist/acp/agent-runtime-manager.js +4 -4
- package/dist/acp/agent-runtime-manager.js.map +1 -1
- package/dist/acp/agent-session.d.ts.map +1 -1
- package/dist/acp/agent-session.js +37 -34
- package/dist/acp/agent-session.js.map +1 -1
- package/dist/acp/runtime-operations.d.ts +2 -2
- package/dist/acp/runtime-operations.d.ts.map +1 -1
- package/dist/acp/runtime-operations.js +2 -2
- package/dist/acp/runtime-operations.js.map +1 -1
- package/dist/cli.js +339 -315
- package/dist/cli.js.map +4 -4
- package/dist/daemon-active-turn.d.ts +2 -0
- package/dist/daemon-active-turn.d.ts.map +1 -1
- package/dist/daemon-active-turn.js +80 -6
- package/dist/daemon-active-turn.js.map +1 -1
- package/dist/daemon-prompt-executor.d.ts.map +1 -1
- package/dist/daemon-prompt-executor.js +25 -41
- package/dist/daemon-prompt-executor.js.map +1 -1
- package/dist/daemon-turn-registry.d.ts +48 -0
- package/dist/daemon-turn-registry.d.ts.map +1 -1
- package/dist/index.js +338 -314
- package/dist/index.js.map +4 -4
- package/dist/native-sessions/live-history-page.d.ts.map +1 -1
- package/dist/native-sessions/live-history-page.js +40 -24
- package/dist/native-sessions/live-history-page.js.map +1 -1
- package/dist/relay-connection/coalescing-agent-event-publisher.d.ts +32 -0
- package/dist/relay-connection/coalescing-agent-event-publisher.d.ts.map +1 -0
- package/dist/relay-connection/coalescing-agent-event-publisher.js +116 -0
- package/dist/relay-connection/coalescing-agent-event-publisher.js.map +1 -0
- package/dist/runtime.js +338 -314
- package/dist/runtime.js.map +4 -4
- package/package.json +1 -1
- package/dist/relay-connection/coalescing-activity-publisher.d.ts +0 -10
- package/dist/relay-connection/coalescing-activity-publisher.d.ts.map +0 -1
- package/dist/relay-connection/coalescing-activity-publisher.js +0 -54
- package/dist/relay-connection/coalescing-activity-publisher.js.map +0 -1
- package/dist/relay-connection/coalescing-narration-publisher.d.ts +0 -31
- package/dist/relay-connection/coalescing-narration-publisher.d.ts.map +0 -1
- package/dist/relay-connection/coalescing-narration-publisher.js +0 -61
- package/dist/relay-connection/coalescing-narration-publisher.js.map +0 -1
- package/dist/relay-connection/coalescing-text-publisher.d.ts +0 -26
- package/dist/relay-connection/coalescing-text-publisher.d.ts.map +0 -1
- package/dist/relay-connection/coalescing-text-publisher.js +0 -57
- package/dist/relay-connection/coalescing-text-publisher.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { AcpActivity } from "../acp/activity.ts";
|
|
2
|
-
import type { DaemonTimer } from "./timer.ts";
|
|
3
|
-
export declare const AGENT_ACTIVITY_COALESCING_MILLISECONDS = 100;
|
|
4
|
-
export declare class CoalescingDaemonActivityPublisher {
|
|
5
|
-
#private;
|
|
6
|
-
constructor(timer: DaemonTimer, publish: (activity: AcpActivity) => void);
|
|
7
|
-
readonly flush: () => void;
|
|
8
|
-
readonly record: (activity: AcpActivity) => Promise<void>;
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=coalescing-activity-publisher.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"coalescing-activity-publisher.d.ts","sourceRoot":"","sources":["../../src/relay-connection/coalescing-activity-publisher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAuB,WAAW,EAAE,MAAM,YAAY,CAAC;AAEnE,eAAO,MAAM,sCAAsC,MAAM,CAAC;AAE1D,qBAAa,iCAAiC;;IAO1C,YAAY,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,QAAQ,EAAE,WAAW,KAAK,IAAI,EAGvE;IAED,QAAQ,CAAC,KAAK,QAAO,IAAI,CAUvB;IAEF,QAAQ,CAAC,MAAM,aAAc,WAAW,KAAG,OAAO,CAAC,IAAI,CAAC,CAuBtD;CAeL"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
export const AGENT_ACTIVITY_COALESCING_MILLISECONDS = 100;
|
|
2
|
-
export class CoalescingDaemonActivityPublisher {
|
|
3
|
-
#pending = new Map();
|
|
4
|
-
#publish;
|
|
5
|
-
#publishedActivityIds = new Set();
|
|
6
|
-
#scheduled = new Map();
|
|
7
|
-
#timer;
|
|
8
|
-
constructor(timer, publish) {
|
|
9
|
-
this.#publish = publish;
|
|
10
|
-
this.#timer = timer;
|
|
11
|
-
}
|
|
12
|
-
flush = () => {
|
|
13
|
-
const activities = [...this.#pending.values()].sort((left, right) => left.sequence - right.sequence);
|
|
14
|
-
for (const task of this.#scheduled.values()) {
|
|
15
|
-
task.cancel();
|
|
16
|
-
}
|
|
17
|
-
this.#pending.clear();
|
|
18
|
-
this.#scheduled.clear();
|
|
19
|
-
for (const activity of activities) {
|
|
20
|
-
this.#publish(activity);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
record = (activity) => {
|
|
24
|
-
if (activity.status !== "pending" && activity.status !== "running") {
|
|
25
|
-
this.#discardPending(activity.activityId);
|
|
26
|
-
this.#publishedActivityIds.add(activity.activityId);
|
|
27
|
-
this.#publish(activity);
|
|
28
|
-
return Promise.resolve();
|
|
29
|
-
}
|
|
30
|
-
if (!this.#publishedActivityIds.has(activity.activityId)) {
|
|
31
|
-
this.#publishedActivityIds.add(activity.activityId);
|
|
32
|
-
this.#publish(activity);
|
|
33
|
-
return Promise.resolve();
|
|
34
|
-
}
|
|
35
|
-
this.#pending.set(activity.activityId, activity);
|
|
36
|
-
if (!this.#scheduled.has(activity.activityId)) {
|
|
37
|
-
this.#scheduled.set(activity.activityId, this.#timer.schedule(() => this.#flushActivity(activity.activityId), AGENT_ACTIVITY_COALESCING_MILLISECONDS));
|
|
38
|
-
}
|
|
39
|
-
return Promise.resolve();
|
|
40
|
-
};
|
|
41
|
-
#discardPending = (activityId) => {
|
|
42
|
-
this.#scheduled.get(activityId)?.cancel();
|
|
43
|
-
this.#scheduled.delete(activityId);
|
|
44
|
-
this.#pending.delete(activityId);
|
|
45
|
-
};
|
|
46
|
-
#flushActivity = (activityId) => {
|
|
47
|
-
const activity = this.#pending.get(activityId);
|
|
48
|
-
this.#discardPending(activityId);
|
|
49
|
-
if (activity !== undefined) {
|
|
50
|
-
this.#publish(activity);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=coalescing-activity-publisher.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"coalescing-activity-publisher.js","sourceRoot":"","sources":["../../src/relay-connection/coalescing-activity-publisher.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,sCAAsC,GAAG,GAAG,CAAC;AAE1D,MAAM,OAAO,iCAAiC;IACjC,QAAQ,GAAG,IAAI,GAAG,EAAuB,CAAC;IAC1C,QAAQ,CAAkC;IAC1C,qBAAqB,GAAG,IAAI,GAAG,EAAU,CAAC;IAC1C,UAAU,GAAG,IAAI,GAAG,EAA+B,CAAC;IACpD,MAAM,CAAc;IAE7B,YAAY,KAAkB,EAAE,OAAwC;QACpE,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACxB,CAAC;IAEQ,KAAK,GAAG,GAAS,EAAE;QACxB,MAAM,UAAU,GAAG,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;QACrG,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC;YAC1C,IAAI,CAAC,MAAM,EAAE,CAAC;Q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AAU,CAAC,EAC9C,sCAAsC,CACzC,CACJ,CAAC;QACN,CAAC;QACD,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC,CAAC;IAEO,eAAe,GAAG,CAAC,UAAkB,EAAQ,EAAE;QACpD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;QAC1C,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACnC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC,CAAC;IAEO,cAAc,GAAG,CAAC,UAAkB,EAAQ,EAAE;QACnD,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC/C,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;QACjC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YACzB,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAC5B,CAAC;IACL,CAAC,CAAC;CACL"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { DaemonTimer } from "./timer.ts";
|
|
2
|
-
/** One streamed narration increment, already reduced to the text to append. */
|
|
3
|
-
export interface NarrationIncrement {
|
|
4
|
-
readonly activityId: string;
|
|
5
|
-
readonly activityType: string;
|
|
6
|
-
readonly sequence: number;
|
|
7
|
-
readonly text: string;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Coalesces streaming narration increments into bounded, ordered events.
|
|
11
|
-
*
|
|
12
|
-
* Reasoning and progress activities are rewritten by the Agent once per streamed
|
|
13
|
-
* chunk. Publishing each chunk separately saturates the live connection and,
|
|
14
|
-
* when the consumer folds the chunks into a snapshot, makes the accumulated
|
|
15
|
-
* text grow quadratically. Buffering per activity
|
|
16
|
-
* for a short window bounds the event rate while preserving text order: the
|
|
17
|
-
* increments of one activity are sequential, so concatenating them reconstructs
|
|
18
|
-
* exactly the narration the Agent produced.
|
|
19
|
-
*/
|
|
20
|
-
export declare class CoalescingNarrationPublisher {
|
|
21
|
-
#private;
|
|
22
|
-
constructor(timer: DaemonTimer, publish: (increment: NarrationIncrement) => void, coalescingMilliseconds: number, maximumTextLength: number);
|
|
23
|
-
/** Emit every buffered increment now, cancelling the pending flush. */
|
|
24
|
-
readonly flush: () => void;
|
|
25
|
-
/**
|
|
26
|
-
* Buffer an increment, emitting the buffered text when it would exceed the
|
|
27
|
-
* protocol's per-event text limit so no event is rejected by the codec.
|
|
28
|
-
*/
|
|
29
|
-
readonly record: (increment: NarrationIncrement) => void;
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=coalescing-narration-publisher.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"coalescing-narration-publisher.d.ts","sourceRoot":"","sources":["../../src/relay-connection/coalescing-narration-publisher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAuB,WAAW,EAAE,MAAM,YAAY,CAAC;AAEnE,+EAA+E;AAC/E,MAAM,WAAW,kBAAkB;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;GAUG;AACH,qBAAa,4BAA4B;;IAQrC,YACI,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,CAAC,SAAS,EAAE,kBAAkB,KAAK,IAAI,EAChD,sBAAsB,EAAE,MAAM,EAC9B,iBAAiB,EAAE,MAAM,EAM5B;IAED,uEAAuE;IACvE,QAAQ,CAAC,KAAK,QAAO,IAAI,CAevB;IAEF;;;OAGG;IACH,QAAQ,CAAC,MAAM,cAAe,kBAAkB,KAAG,IAAI,CAerD;CACL"}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Coalesces streaming narration increments into bounded, ordered events.
|
|
3
|
-
*
|
|
4
|
-
* Reasoning and progress activities are rewritten by the Agent once per streamed
|
|
5
|
-
* chunk. Publishing each chunk separately saturates the live connection and,
|
|
6
|
-
* when the consumer folds the chunks into a snapshot, makes the accumulated
|
|
7
|
-
* text grow quadratically. Buffering per activity
|
|
8
|
-
* for a short window bounds the event rate while preserving text order: the
|
|
9
|
-
* increments of one activity are sequential, so concatenating them reconstructs
|
|
10
|
-
* exactly the narration the Agent produced.
|
|
11
|
-
*/
|
|
12
|
-
export class CoalescingNarrationPublisher {
|
|
13
|
-
#coalescingMilliseconds;
|
|
14
|
-
#maximumTextLength;
|
|
15
|
-
#publish;
|
|
16
|
-
#timer;
|
|
17
|
-
#pending = new Map();
|
|
18
|
-
#scheduled = null;
|
|
19
|
-
constructor(timer, publish, coalescingMilliseconds, maximumTextLength) {
|
|
20
|
-
this.#publish = publish;
|
|
21
|
-
this.#timer = timer;
|
|
22
|
-
this.#coalescingMilliseconds = coalescingMilliseconds;
|
|
23
|
-
this.#maximumTextLength = maximumTextLength;
|
|
24
|
-
}
|
|
25
|
-
/** Emit every buffered increment now, cancelling the pending flush. */
|
|
26
|
-
flush = () => {
|
|
27
|
-
this.#scheduled?.cancel();
|
|
28
|
-
this.#scheduled = null;
|
|
29
|
-
const increments = [...this.#pending.entries()].map(([activityId, pending]) => ({
|
|
30
|
-
activityId,
|
|
31
|
-
activityType: pending.activityType,
|
|
32
|
-
sequence: pending.sequence,
|
|
33
|
-
text: pending.text,
|
|
34
|
-
}));
|
|
35
|
-
this.#pending.clear();
|
|
36
|
-
for (const increment of increments) {
|
|
37
|
-
this.#publish(increment);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Buffer an increment, emitting the buffered text when it would exceed the
|
|
42
|
-
* protocol's per-event text limit so no event is rejected by the codec.
|
|
43
|
-
*/
|
|
44
|
-
record = (increment) => {
|
|
45
|
-
if (increment.text.length === 0) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const previous = this.#pending.get(increment.activityId);
|
|
49
|
-
if (previous !== undefined && previous.text.length + increment.text.length > this.#maximumTextLength) {
|
|
50
|
-
this.flush();
|
|
51
|
-
}
|
|
52
|
-
const current = this.#pending.get(increment.activityId);
|
|
53
|
-
this.#pending.set(increment.activityId, {
|
|
54
|
-
activityType: increment.activityType,
|
|
55
|
-
sequence: increment.sequence,
|
|
56
|
-
text: `${current?.text ?? ""}${increment.text}`,
|
|
57
|
-
});
|
|
58
|
-
this.#scheduled ??= this.#timer.schedule(this.flush, this.#coalescingMilliseconds);
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
//# sourceMappingURL=coalescing-narration-publisher.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"coalescing-narration-publisher.js","sourceRoot":"","sources":["../../src/relay-connection/coalescing-narration-publisher.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;GAUG;AACH,MAAM,OAAO,4BAA4B;IAC5B,uBAAuB,CAAS;IAChC,kBAAkB,CAAS;IAC3B,QAAQ,CAA0C;IAClD,MAAM,CAAc;IACpB,QAAQ,GAAG,IAAI,GAAG,EAAoE,CAAC;IAChG,UAAU,GAA+B,IAAI,CAAC;IAE9C,YACI,KAAkB,EAClB,OAAgD,EAChD,sBAA8B,EAC9B,iBAAyB;QAEzB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,uBAAuB,GAAG,sBAAsB,CAAC;QACtD,IAAI,CAAC,kBAAkB,GAAG,iBAAiB,CAAC;IAChD,CAAC;IAED,uEAAuE;IAC9D,KAAK,GAAG,GAAS,EAAE;QACxB,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC;QAC1B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,MAAM,UAAU,G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H,IAAI,CAAC,UAAU,KAAK,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,uBAAuB,CAAC,CAAC;IACvF,CAAC,CAAC;CACL"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { DaemonTimer } from "./timer.ts";
|
|
2
|
-
/**
|
|
3
|
-
* Coalesces streaming assistant text into a bounded, ordered event stream.
|
|
4
|
-
*
|
|
5
|
-
* Token-level Agents (Claude Code enables `includePartialMessages`) emit one
|
|
6
|
-
* update per streamed token, so a single final answer can arrive as hundreds or
|
|
7
|
-
* thousands of chunks. Forwarding each chunk saturates the live connection.
|
|
8
|
-
* Buffering the text and flushing on a short timer bounds the event rate
|
|
9
|
-
* without splitting or reordering the answer.
|
|
10
|
-
*
|
|
11
|
-
* Chunks are buffered in a single slot rather than keyed by message id: the
|
|
12
|
-
* deltas of one turn are sequential, and a per-id map would reorder text that
|
|
13
|
-
* interleaves across ids when the slots flush.
|
|
14
|
-
*/
|
|
15
|
-
export declare class CoalescingTextPublisher {
|
|
16
|
-
#private;
|
|
17
|
-
constructor(timer: DaemonTimer, publish: (messageId: string, text: string) => void, coalescingMilliseconds: number, maximumTextLength: number);
|
|
18
|
-
/** Emit any buffered text now, cancelling the pending flush. */
|
|
19
|
-
readonly flush: () => void;
|
|
20
|
-
/**
|
|
21
|
-
* Buffer a chunk, emitting the buffered text when the message changes or the
|
|
22
|
-
* buffer would exceed the protocol's per-event text limit.
|
|
23
|
-
*/
|
|
24
|
-
readonly record: (messageId: string, text: string) => void;
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=coalescing-text-publisher.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"coalescing-text-publisher.d.ts","sourceRoot":"","sources":["../../src/relay-connection/coalescing-text-publisher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAuB,WAAW,EAAE,MAAM,YAAY,CAAC;AAEnE;;;;;;;;;;;;GAYG;AACH,qBAAa,uBAAuB;;IAShC,YACI,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,EAClD,sBAAsB,EAAE,MAAM,EAC9B,iBAAiB,EAAE,MAAM,EAM5B;IAED,gEAAgE;IAChE,QAAQ,CAAC,KAAK,QAAO,IAAI,CAUvB;IAEF;;;OAGG;IACH,QAAQ,CAAC,MAAM,cAAe,MAAM,QAAQ,MAAM,KAAG,IAAI,CAavD;CACL"}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Coalesces streaming assistant text into a bounded, ordered event stream.
|
|
3
|
-
*
|
|
4
|
-
* Token-level Agents (Claude Code enables `includePartialMessages`) emit one
|
|
5
|
-
* update per streamed token, so a single final answer can arrive as hundreds or
|
|
6
|
-
* thousands of chunks. Forwarding each chunk saturates the live connection.
|
|
7
|
-
* Buffering the text and flushing on a short timer bounds the event rate
|
|
8
|
-
* without splitting or reordering the answer.
|
|
9
|
-
*
|
|
10
|
-
* Chunks are buffered in a single slot rather than keyed by message id: the
|
|
11
|
-
* deltas of one turn are sequential, and a per-id map would reorder text that
|
|
12
|
-
* interleaves across ids when the slots flush.
|
|
13
|
-
*/
|
|
14
|
-
export class CoalescingTextPublisher {
|
|
15
|
-
#coalescingMilliseconds;
|
|
16
|
-
#maximumTextLength;
|
|
17
|
-
#publish;
|
|
18
|
-
#timer;
|
|
19
|
-
#messageId = "";
|
|
20
|
-
#scheduled = null;
|
|
21
|
-
#text = "";
|
|
22
|
-
constructor(timer, publish, coalescingMilliseconds, maximumTextLength) {
|
|
23
|
-
this.#publish = publish;
|
|
24
|
-
this.#timer = timer;
|
|
25
|
-
this.#coalescingMilliseconds = coalescingMilliseconds;
|
|
26
|
-
this.#maximumTextLength = maximumTextLength;
|
|
27
|
-
}
|
|
28
|
-
/** Emit any buffered text now, cancelling the pending flush. */
|
|
29
|
-
flush = () => {
|
|
30
|
-
this.#scheduled?.cancel();
|
|
31
|
-
this.#scheduled = null;
|
|
32
|
-
const messageId = this.#messageId;
|
|
33
|
-
const text = this.#text;
|
|
34
|
-
this.#messageId = "";
|
|
35
|
-
this.#text = "";
|
|
36
|
-
if (text.length > 0) {
|
|
37
|
-
this.#publish(messageId, text);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Buffer a chunk, emitting the buffered text when the message changes or the
|
|
42
|
-
* buffer would exceed the protocol's per-event text limit.
|
|
43
|
-
*/
|
|
44
|
-
record = (messageId, text) => {
|
|
45
|
-
if (text.length === 0) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
if (this.#text.length > 0 &&
|
|
49
|
-
(this.#messageId !== messageId || this.#text.length + text.length > this.#maximumTextLength)) {
|
|
50
|
-
this.flush();
|
|
51
|
-
}
|
|
52
|
-
this.#messageId = messageId;
|
|
53
|
-
this.#text = `${this.#text}${text}`;
|
|
54
|
-
this.#scheduled ??= this.#timer.schedule(this.flush, this.#coalescingMilliseconds);
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=coalescing-text-publisher.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"coalescing-text-publisher.js","sourceRoot":"","sources":["../../src/relay-connection/coalescing-text-publisher.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,uBAAuB;IACvB,uBAAuB,CAAS;IAChC,kBAAkB,CAAS;IAC3B,QAAQ,CAA4C;IACpD,MAAM,CAAc;IAC7B,UAAU,GAAG,EAAE,CAAC;IAChB,UAAU,GAA+B,IAAI,CAAC;IAC9C,KAAK,GAAG,EAAE,CAAC;IAEX,YACI,KAAkB,EAClB,OAAkD,EAClD,sBAA8B,EAC9B,iBAAyB;QAEzB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG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