@kortix/sdk 0.13.32 → 0.13.34
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/README.md +12 -9
- package/dist/browser/stores/diagnostics-store.d.ts.map +1 -1
- package/dist/browser/stores/diagnostics-store.js +20 -39
- package/dist/browser/stores/diagnostics-store.js.map +1 -1
- package/dist/core/client/kortix.d.ts +1 -0
- package/dist/core/client/kortix.d.ts.map +1 -1
- package/dist/core/client/kortix.js +1 -0
- package/dist/core/client/kortix.js.map +1 -1
- package/dist/core/http/api-client.d.ts +15 -0
- package/dist/core/http/api-client.d.ts.map +1 -1
- package/dist/core/http/api-client.js +61 -0
- package/dist/core/http/api-client.js.map +1 -1
- package/dist/core/rest/platform-client/host-boundary.d.ts +15 -1
- package/dist/core/rest/platform-client/host-boundary.d.ts.map +1 -1
- package/dist/core/rest/platform-client/host-boundary.js +2 -2
- package/dist/core/rest/platform-client/host-boundary.js.map +1 -1
- package/dist/core/rest/projects-client/access.d.ts +4 -2
- package/dist/core/rest/projects-client/access.d.ts.map +1 -1
- package/dist/core/rest/projects-client/access.js.map +1 -1
- package/dist/core/rest/projects-client/assignments.d.ts +9 -4
- package/dist/core/rest/projects-client/assignments.d.ts.map +1 -1
- package/dist/core/rest/projects-client/assignments.js.map +1 -1
- package/dist/core/rest/projects-client/connectors.d.ts +44 -0
- package/dist/core/rest/projects-client/connectors.d.ts.map +1 -1
- package/dist/core/rest/projects-client/connectors.js +23 -0
- package/dist/core/rest/projects-client/connectors.js.map +1 -1
- package/dist/core/rest/projects-client/projects.d.ts +8 -0
- package/dist/core/rest/projects-client/projects.d.ts.map +1 -1
- package/dist/core/rest/projects-client/projects.js.map +1 -1
- package/dist/core/rest/projects-client/public-session-shares.d.ts +12 -3
- package/dist/core/rest/projects-client/public-session-shares.d.ts.map +1 -1
- package/dist/core/rest/projects-client/public-session-shares.js +11 -6
- package/dist/core/rest/projects-client/public-session-shares.js.map +1 -1
- package/dist/core/rest/projects-client/sessions.d.ts +23 -1
- package/dist/core/rest/projects-client/sessions.d.ts.map +1 -1
- package/dist/core/rest/projects-client/sessions.js +22 -0
- package/dist/core/rest/projects-client/sessions.js.map +1 -1
- package/dist/core/rest/projects-client/setup-links.d.ts +8 -0
- package/dist/core/rest/projects-client/setup-links.d.ts.map +1 -1
- package/dist/core/rest/projects-client/setup-links.js +1 -0
- package/dist/core/rest/projects-client/setup-links.js.map +1 -1
- package/dist/core/session/wire-id-unwrap.d.ts +21 -0
- package/dist/core/session/wire-id-unwrap.d.ts.map +1 -0
- package/dist/core/session/wire-id-unwrap.js +34 -0
- package/dist/core/session/wire-id-unwrap.js.map +1 -0
- package/dist/core/session/wire-message-id.d.ts +84 -12
- package/dist/core/session/wire-message-id.d.ts.map +1 -1
- package/dist/core/session/wire-message-id.js +105 -49
- package/dist/core/session/wire-message-id.js.map +1 -1
- package/dist/core/session-sync/session-sync-controller.d.ts +4 -2
- package/dist/core/session-sync/session-sync-controller.d.ts.map +1 -1
- package/dist/core/session-sync/session-sync-controller.js +31 -11
- package/dist/core/session-sync/session-sync-controller.js.map +1 -1
- package/dist/core/turns/grouping.d.ts.map +1 -1
- package/dist/core/turns/grouping.js +75 -73
- package/dist/core/turns/grouping.js.map +1 -1
- package/dist/core/turns/segments/index.d.ts +1 -0
- package/dist/core/turns/segments/index.d.ts.map +1 -1
- package/dist/core/turns/segments/index.js +1 -0
- package/dist/core/turns/segments/index.js.map +1 -1
- package/dist/core/turns/segments/show-group.d.ts +54 -0
- package/dist/core/turns/segments/show-group.d.ts.map +1 -0
- package/dist/core/turns/segments/show-group.js +108 -0
- package/dist/core/turns/segments/show-group.js.map +1 -0
- package/dist/core/turns/text-scan.d.ts +13 -0
- package/dist/core/turns/text-scan.d.ts.map +1 -1
- package/dist/core/turns/text-scan.js +107 -11
- package/dist/core/turns/text-scan.js.map +1 -1
- package/dist/core/turns/tools/tool-output-format.js +3 -3
- package/dist/core/turns/tools/tool-output-format.js.map +1 -1
- package/dist/core/turns/tools/web-helpers.d.ts.map +1 -1
- package/dist/core/turns/tools/web-helpers.js +2 -4
- package/dist/core/turns/tools/web-helpers.js.map +1 -1
- package/dist/core/turns/types.d.ts +8 -0
- package/dist/core/turns/types.d.ts.map +1 -1
- package/dist/index.d.ts +8 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/internal/diagnostics-store.d.ts +6 -0
- package/dist/internal/diagnostics-store.d.ts.map +1 -0
- package/dist/internal/diagnostics-store.js +6 -0
- package/dist/internal/diagnostics-store.js.map +1 -0
- package/dist/internal/managed-storage.d.ts +6 -0
- package/dist/internal/managed-storage.d.ts.map +1 -0
- package/dist/internal/managed-storage.js +6 -0
- package/dist/internal/managed-storage.js.map +1 -0
- package/dist/kortix.esm.min.js +35 -35
- package/dist/kortix.global.js +35 -35
- package/dist/platform/storage/managed-storage.d.ts +12 -0
- package/dist/platform/storage/managed-storage.d.ts.map +1 -1
- package/dist/platform/storage/managed-storage.js +98 -31
- package/dist/platform/storage/managed-storage.js.map +1 -1
- package/dist/react/query-contracts.d.ts +8 -1
- package/dist/react/query-contracts.d.ts.map +1 -1
- package/dist/react/query-contracts.js +8 -1
- package/dist/react/query-contracts.js.map +1 -1
- package/dist/react/reset-identity-state.d.ts +5 -4
- package/dist/react/reset-identity-state.d.ts.map +1 -1
- package/dist/react/reset-identity-state.js +7 -4
- package/dist/react/reset-identity-state.js.map +1 -1
- package/dist/react/self-heal-poll-gate.d.ts +38 -0
- package/dist/react/self-heal-poll-gate.d.ts.map +1 -0
- package/dist/react/self-heal-poll-gate.js +31 -0
- package/dist/react/self-heal-poll-gate.js.map +1 -0
- package/dist/react/use-admin-activity-analytics.d.ts.map +1 -1
- package/dist/react/use-admin-activity-analytics.js +8 -0
- package/dist/react/use-admin-activity-analytics.js.map +1 -1
- package/dist/react/use-opencode-events/handle-event.d.ts.map +1 -1
- package/dist/react/use-opencode-events/handle-event.js +3 -0
- package/dist/react/use-opencode-events/handle-event.js.map +1 -1
- package/dist/react/use-permission-self-heal.d.ts +5 -0
- package/dist/react/use-permission-self-heal.d.ts.map +1 -1
- package/dist/react/use-permission-self-heal.js +19 -3
- package/dist/react/use-permission-self-heal.js.map +1 -1
- package/dist/react/use-question-self-heal.d.ts +5 -0
- package/dist/react/use-question-self-heal.d.ts.map +1 -1
- package/dist/react/use-question-self-heal.js +19 -3
- package/dist/react/use-question-self-heal.js.map +1 -1
- package/dist/react/use-session-sync.d.ts.map +1 -1
- package/dist/react/use-session-sync.js +2 -2
- package/dist/react/use-session-sync.js.map +1 -1
- package/package.json +14 -2
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The UNWRAPPED wire-id clock — internal, not exported from any entry point.
|
|
3
|
+
*
|
|
4
|
+
* `core/turns/grouping.ts` orders messages for display on an absolute clock:
|
|
5
|
+
* each placed id is unwrapped against its own `time.created`, so two messages
|
|
6
|
+
* keep their true order even when their `created` stamps disagree with the
|
|
7
|
+
* ring distance between their ids. Every other caller orders on the ring with
|
|
8
|
+
* `wireIdClockDelta` (`./wire-message-id`) and never needs an absolute clock.
|
|
9
|
+
*
|
|
10
|
+
* Kept out of `wire-message-id.ts` so that module stays import-free and its
|
|
11
|
+
* published subpath carries only the names a host needs.
|
|
12
|
+
*/
|
|
13
|
+
/** The unmasked id clock of wall-clock instant `ms`. */
|
|
14
|
+
export declare function absoluteWireIdClockAt(ms: number): bigint;
|
|
15
|
+
/**
|
|
16
|
+
* Undo the 48-bit wrap: the absolute clock congruent to `clock` that is
|
|
17
|
+
* nearest to `anchor` (an absolute clock). Two ids unwrapped against anchors
|
|
18
|
+
* within ~1.1 years of each other keep their true order across a wrap.
|
|
19
|
+
*/
|
|
20
|
+
export declare function unwrapWireIdClock(clock: bigint, anchor: bigint): bigint;
|
|
21
|
+
//# sourceMappingURL=wire-id-unwrap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wire-id-unwrap.d.ts","sourceRoot":"","sources":["../../../src/core/session/wire-id-unwrap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAOH,wDAAwD;AACxD,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAExD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAMvE"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The UNWRAPPED wire-id clock — internal, not exported from any entry point.
|
|
3
|
+
*
|
|
4
|
+
* `core/turns/grouping.ts` orders messages for display on an absolute clock:
|
|
5
|
+
* each placed id is unwrapped against its own `time.created`, so two messages
|
|
6
|
+
* keep their true order even when their `created` stamps disagree with the
|
|
7
|
+
* ring distance between their ids. Every other caller orders on the ring with
|
|
8
|
+
* `wireIdClockDelta` (`./wire-message-id`) and never needs an absolute clock.
|
|
9
|
+
*
|
|
10
|
+
* Kept out of `wire-message-id.ts` so that module stays import-free and its
|
|
11
|
+
* published subpath carries only the names a host needs.
|
|
12
|
+
*/
|
|
13
|
+
import { WIRE_ID_TIME_MASK, WIRE_ID_TIME_SCALE } from './wire-message-id.js';
|
|
14
|
+
const WIRE_ID_TIME_SPAN = WIRE_ID_TIME_MASK + BigInt(1);
|
|
15
|
+
const HALF_SPAN = WIRE_ID_TIME_SPAN / BigInt(2);
|
|
16
|
+
/** The unmasked id clock of wall-clock instant `ms`. */
|
|
17
|
+
export function absoluteWireIdClockAt(ms) {
|
|
18
|
+
return BigInt(Math.trunc(ms)) * WIRE_ID_TIME_SCALE;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Undo the 48-bit wrap: the absolute clock congruent to `clock` that is
|
|
22
|
+
* nearest to `anchor` (an absolute clock). Two ids unwrapped against anchors
|
|
23
|
+
* within ~1.1 years of each other keep their true order across a wrap.
|
|
24
|
+
*/
|
|
25
|
+
export function unwrapWireIdClock(clock, anchor) {
|
|
26
|
+
const base = anchor - (anchor & WIRE_ID_TIME_MASK);
|
|
27
|
+
let unwrapped = base + clock;
|
|
28
|
+
if (unwrapped - anchor > HALF_SPAN)
|
|
29
|
+
unwrapped -= WIRE_ID_TIME_SPAN;
|
|
30
|
+
else if (anchor - unwrapped > HALF_SPAN)
|
|
31
|
+
unwrapped += WIRE_ID_TIME_SPAN;
|
|
32
|
+
return unwrapped;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=wire-id-unwrap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wire-id-unwrap.js","sourceRoot":"","sources":["../../../src/core/session/wire-id-unwrap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE1E,MAAM,iBAAiB,GAAG,iBAAiB,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AACxD,MAAM,SAAS,GAAG,iBAAiB,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AAEhD,wDAAwD;AACxD,MAAM,UAAU,qBAAqB,CAAC,EAAU;IAC9C,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,GAAG,kBAAkB,CAAC;AACrD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAa,EAAE,MAAc;IAC7D,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,MAAM,GAAG,iBAAiB,CAAC,CAAC;IACnD,IAAI,SAAS,GAAG,IAAI,GAAG,KAAK,CAAC;IAC7B,IAAI,SAAS,GAAG,MAAM,GAAG,SAAS;QAAE,SAAS,IAAI,iBAAiB,CAAC;SAC9D,IAAI,MAAM,GAAG,SAAS,GAAG,SAAS;QAAE,SAAS,IAAI,iBAAiB,CAAC;IACxE,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The OpenCode wire message-id clock — framework-free.
|
|
2
|
+
* The OpenCode wire message-id clock — framework-free, with no imports.
|
|
3
3
|
*
|
|
4
4
|
* FORMAT. `msg_` + the LOW 48 bits of `Date.now() * 0x1000` as 12 lowercase
|
|
5
5
|
* hex chars + 14 random base62 chars. OpenCode's own `Identifier.ascending`
|
|
6
6
|
* keeps the low 6 bytes, so the clock wraps every 2^36 ms (~2.2 years); the
|
|
7
|
-
* last wrap was 2026-08-14 11:19:55 UTC.
|
|
7
|
+
* last wrap was 2026-08-14 11:19:55 UTC. Every comparison here is on the ring
|
|
8
|
+
* ({@link wireIdClockDelta}), so ids on both sides of a wrap keep their order.
|
|
8
9
|
*
|
|
9
10
|
* WHY IT MATTERS. A user message's id is its POSITION in the transcript:
|
|
10
11
|
* OpenCode ≤ 1.18.14 decides "has this prompt been answered?" by id order, and
|
|
@@ -13,15 +14,36 @@
|
|
|
13
14
|
* 2026-08-22 until this module existed) lands ~40 days ahead of every id
|
|
14
15
|
* OpenCode mints itself and renders every later turn above it.
|
|
15
16
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
17
|
+
* WHO USES IT. Hosts import it from `@kortix/sdk` or from the
|
|
18
|
+
* `@kortix/sdk/wire-message-id` subpath, which loads this file alone.
|
|
19
|
+
* `apps/api` and `apps/mobile` re-export it under their historical names and
|
|
20
|
+
* compare clocks only through {@link wireIdClockDelta} and
|
|
21
|
+
* {@link maxWireIdClock}. `tests/spec/wire-message-id.vectors.json` pins the
|
|
22
|
+
* behavior.
|
|
23
|
+
*
|
|
24
|
+
* WHAT IS NOT HERE. Three other places touch the clock, each on purpose:
|
|
25
|
+
* - `apps/kortix-sandbox-agent-server/src/harness/pi/wire-id.ts` is the one
|
|
26
|
+
* remaining COPY: it mints the pi harness's reply ids. kortixd is a
|
|
27
|
+
* standalone compiled binary with no workspace dependencies. The copy
|
|
28
|
+
* orders on the ring through its own `wireIdClockDelta`, and
|
|
29
|
+
* `pi-wire-id.test.ts` runs this file's regex and the golden mint and
|
|
30
|
+
* `delta` vectors against it. It mints with no backdate, at the box clock.
|
|
31
|
+
* - `./wire-id-unwrap` (internal, not exported) builds on the constants here:
|
|
32
|
+
* `core/turns/grouping.ts` orders messages for display on an UNWRAPPED
|
|
33
|
+
* clock anchored on `time.created`.
|
|
34
|
+
* - `browser/stores/sync-store/ascending-id.ts` makes tab-local optimistic
|
|
35
|
+
* ids from the HIGH bits. They key a bubble until the server's copy
|
|
36
|
+
* replaces it and are never sent as a prompt's wire `messageID`.
|
|
19
37
|
*/
|
|
38
|
+
/** Sub-millisecond slots per millisecond in the id clock (`Date.now() * 0x1000`). */
|
|
39
|
+
export declare const WIRE_ID_TIME_SCALE: bigint;
|
|
40
|
+
/** OpenCode keeps the low 6 bytes of its id clock. */
|
|
41
|
+
export declare const WIRE_ID_TIME_MASK: bigint;
|
|
20
42
|
/**
|
|
21
43
|
* How far an id's clock may sit from the clock it is compared with and still
|
|
22
44
|
* count as placed by it: 1 hour. Every correct mint is within ~2 minutes of its
|
|
23
45
|
* own server timestamp (the backdate below); the high-bits bug put ids ~40 days
|
|
24
|
-
* out.
|
|
46
|
+
* out. `apps/api` re-exports it as `MAX_WIRE_ID_CLOCK_CORRECTION`.
|
|
25
47
|
*/
|
|
26
48
|
export declare const WIRE_ID_CLOCK_TOLERANCE: bigint;
|
|
27
49
|
/**
|
|
@@ -31,24 +53,74 @@ export declare const WIRE_ID_CLOCK_TOLERANCE: bigint;
|
|
|
31
53
|
* and would sort above its own prompt.
|
|
32
54
|
*/
|
|
33
55
|
export declare const WIRE_ID_BACKDATE_MS: number;
|
|
56
|
+
/** `msg_` + 12 lowercase hex clock chars + 14 base62 chars. */
|
|
57
|
+
export declare const WIRE_MESSAGE_ID: RegExp;
|
|
34
58
|
/** The 48-bit clock encoded in a wire id, or null when `id` is not one. */
|
|
35
59
|
export declare function wireIdClock(id: string | null | undefined): bigint | null;
|
|
36
|
-
/** The unmasked id clock of wall-clock instant `ms`. */
|
|
37
|
-
export declare function absoluteWireIdClockAt(ms: number): bigint;
|
|
38
60
|
/** The 48-bit id clock of wall-clock instant `ms`, as OpenCode writes it. */
|
|
39
61
|
export declare function wireIdClockAt(ms: number): bigint;
|
|
40
62
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
63
|
+
* Signed distance from `reference` to `clock` on the 48-bit ring, in clock
|
|
64
|
+
* ticks: positive when `clock` is ahead, 0 when equal, negative when behind.
|
|
65
|
+
* Wrap-safe for distances under ~1.1 years.
|
|
66
|
+
*
|
|
67
|
+
* This is the ONE ordering primitive. Compare two clocks with
|
|
68
|
+
* `wireIdClockDelta(a, b) > 0`, never with `a > b`: a plain compare puts every
|
|
69
|
+
* id minted after a wrap BELOW every id minted before it.
|
|
70
|
+
*/
|
|
71
|
+
export declare function wireIdClockDelta(clock: bigint, reference: bigint): bigint;
|
|
72
|
+
/**
|
|
73
|
+
* The newest of `clocks` on the ring, or null when none is given. `null` and
|
|
74
|
+
* `undefined` entries are skipped, so a caller can merge optional floors in one
|
|
75
|
+
* call: `maxWireIdClock([transcriptNewest, deliveredNewest, submitted])`.
|
|
44
76
|
*/
|
|
45
|
-
export declare function
|
|
77
|
+
export declare function maxWireIdClock(clocks: Iterable<bigint | null | undefined>): bigint | null;
|
|
46
78
|
/**
|
|
47
79
|
* Whether `id` claims a clock more than {@link WIRE_ID_CLOCK_TOLERANCE} ahead
|
|
48
80
|
* of `nowMs`. Such an id cannot have been placed against any real transcript;
|
|
49
81
|
* a floor or a lift must skip it rather than let it veto every later mint.
|
|
50
82
|
*/
|
|
51
83
|
export declare function isWireIdAheadOf(id: string, nowMs: number): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* The newest clock among `ids`, compared on the ring, or null when none is a
|
|
86
|
+
* wire id. With `nowMs`, an id {@link isWireIdAheadOf} it is skipped: it is not
|
|
87
|
+
* a position, and as a floor it would veto every lift.
|
|
88
|
+
*/
|
|
89
|
+
export declare function newestWireIdClock(ids: Iterable<string | null | undefined>, nowMs?: number): bigint | null;
|
|
90
|
+
/** A minted id and the clock it encodes. */
|
|
91
|
+
export interface MintedWireMessageId {
|
|
92
|
+
id: string;
|
|
93
|
+
time: bigint;
|
|
94
|
+
}
|
|
95
|
+
/** Input for {@link mintWireMessageIdAbove}. */
|
|
96
|
+
export interface MintWireMessageIdAboveInput {
|
|
97
|
+
/** Wall clock to mint at, in ms since epoch. */
|
|
98
|
+
nowMs: number;
|
|
99
|
+
/**
|
|
100
|
+
* The newest clock already on record. The mint sorts strictly after it when
|
|
101
|
+
* it is within {@link WIRE_ID_CLOCK_TOLERANCE} ahead of the backdated clock.
|
|
102
|
+
*/
|
|
103
|
+
newestKnownTime?: bigint | null;
|
|
104
|
+
/**
|
|
105
|
+
* How far back the clock is dated before the lift, in ms. Default:
|
|
106
|
+
* {@link WIRE_ID_BACKDATE_MS}. Pass `0` only when `nowMs` is the clock of the
|
|
107
|
+
* box that will persist the message (a caller that learned the box's skew),
|
|
108
|
+
* so the id lands where OpenCode itself would mint it.
|
|
109
|
+
*/
|
|
110
|
+
backdateMs?: number;
|
|
111
|
+
/** Source for the 14-char tail, in [0, 1). Default: `Math.random`. */
|
|
112
|
+
random?: () => number;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Mint an id above a known floor CLOCK — for a caller that holds the newest
|
|
116
|
+
* position as a number (a database row, a transcript it already reduced)
|
|
117
|
+
* rather than as ids. Pure given `random`: the golden vectors assert it.
|
|
118
|
+
*
|
|
119
|
+
* Dated `backdateMs` (default {@link WIRE_ID_BACKDATE_MS}) back, then lifted
|
|
120
|
+
* to `newestKnownTime + 1` when that floor is 0 to
|
|
121
|
+
* {@link WIRE_ID_CLOCK_TOLERANCE} ahead on the ring.
|
|
122
|
+
*/
|
|
123
|
+
export declare function mintWireMessageIdAbove(input: MintWireMessageIdAboveInput): MintedWireMessageId;
|
|
52
124
|
/** Options for {@link mintWireMessageId}. */
|
|
53
125
|
export interface MintWireMessageIdOptions {
|
|
54
126
|
/** Wall clock to mint at, in ms since epoch. Default: `Date.now()`. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wire-message-id.d.ts","sourceRoot":"","sources":["../../../src/core/session/wire-message-id.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"wire-message-id.d.ts","sourceRoot":"","sources":["../../../src/core/session/wire-message-id.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAIH,qFAAqF;AACrF,eAAO,MAAM,kBAAkB,QAAiB,CAAC;AACjD,sDAAsD;AACtD,eAAO,MAAM,iBAAiB,QAAyB,CAAC;AAIxD;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,QAA8C,CAAC;AAEnF;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,QAAgB,CAAC;AAEjD,+DAA+D;AAC/D,eAAO,MAAM,eAAe,QAAsC,CAAC;AAKnE,2EAA2E;AAC3E,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAGxE;AAED,6EAA6E;AAC7E,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAIzE;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,MAAM,GAAG,IAAI,CAOzF;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAIlE;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,QAAQ,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EACxC,KAAK,CAAC,EAAE,MAAM,GACb,MAAM,GAAG,IAAI,CAGf;AAeD,4CAA4C;AAC5C,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd;AAED,gDAAgD;AAChD,MAAM,WAAW,2BAA2B;IAC1C,gDAAgD;IAChD,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,sEAAsE;IACtE,MAAM,CAAC,EAAE,MAAM,MAAM,CAAC;CACvB;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,2BAA2B,GAAG,mBAAmB,CAW9F;AAED,6CAA6C;AAC7C,MAAM,WAAW,wBAAwB;IACvC,uEAAuE;IACvE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;CAC7C;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,wBAA6B,GAAG,MAAM,CAUhF"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The OpenCode wire message-id clock — framework-free.
|
|
2
|
+
* The OpenCode wire message-id clock — framework-free, with no imports.
|
|
3
3
|
*
|
|
4
4
|
* FORMAT. `msg_` + the LOW 48 bits of `Date.now() * 0x1000` as 12 lowercase
|
|
5
5
|
* hex chars + 14 random base62 chars. OpenCode's own `Identifier.ascending`
|
|
6
6
|
* keeps the low 6 bytes, so the clock wraps every 2^36 ms (~2.2 years); the
|
|
7
|
-
* last wrap was 2026-08-14 11:19:55 UTC.
|
|
7
|
+
* last wrap was 2026-08-14 11:19:55 UTC. Every comparison here is on the ring
|
|
8
|
+
* ({@link wireIdClockDelta}), so ids on both sides of a wrap keep their order.
|
|
8
9
|
*
|
|
9
10
|
* WHY IT MATTERS. A user message's id is its POSITION in the transcript:
|
|
10
11
|
* OpenCode ≤ 1.18.14 decides "has this prompt been answered?" by id order, and
|
|
@@ -13,21 +14,40 @@
|
|
|
13
14
|
* 2026-08-22 until this module existed) lands ~40 days ahead of every id
|
|
14
15
|
* OpenCode mints itself and renders every later turn above it.
|
|
15
16
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
17
|
+
* WHO USES IT. Hosts import it from `@kortix/sdk` or from the
|
|
18
|
+
* `@kortix/sdk/wire-message-id` subpath, which loads this file alone.
|
|
19
|
+
* `apps/api` and `apps/mobile` re-export it under their historical names and
|
|
20
|
+
* compare clocks only through {@link wireIdClockDelta} and
|
|
21
|
+
* {@link maxWireIdClock}. `tests/spec/wire-message-id.vectors.json` pins the
|
|
22
|
+
* behavior.
|
|
23
|
+
*
|
|
24
|
+
* WHAT IS NOT HERE. Three other places touch the clock, each on purpose:
|
|
25
|
+
* - `apps/kortix-sandbox-agent-server/src/harness/pi/wire-id.ts` is the one
|
|
26
|
+
* remaining COPY: it mints the pi harness's reply ids. kortixd is a
|
|
27
|
+
* standalone compiled binary with no workspace dependencies. The copy
|
|
28
|
+
* orders on the ring through its own `wireIdClockDelta`, and
|
|
29
|
+
* `pi-wire-id.test.ts` runs this file's regex and the golden mint and
|
|
30
|
+
* `delta` vectors against it. It mints with no backdate, at the box clock.
|
|
31
|
+
* - `./wire-id-unwrap` (internal, not exported) builds on the constants here:
|
|
32
|
+
* `core/turns/grouping.ts` orders messages for display on an UNWRAPPED
|
|
33
|
+
* clock anchored on `time.created`.
|
|
34
|
+
* - `browser/stores/sync-store/ascending-id.ts` makes tab-local optimistic
|
|
35
|
+
* ids from the HIGH bits. They key a bubble until the server's copy
|
|
36
|
+
* replaces it and are never sent as a prompt's wire `messageID`.
|
|
19
37
|
*/
|
|
20
38
|
// `BigInt(0x…)`, not `0x…n`: consumers typecheck this package under targets
|
|
21
39
|
// below ES2020, where BigInt literals are a compile error.
|
|
22
|
-
|
|
23
|
-
const
|
|
40
|
+
/** Sub-millisecond slots per millisecond in the id clock (`Date.now() * 0x1000`). */
|
|
41
|
+
export const WIRE_ID_TIME_SCALE = BigInt(0x1000);
|
|
42
|
+
/** OpenCode keeps the low 6 bytes of its id clock. */
|
|
43
|
+
export const WIRE_ID_TIME_MASK = BigInt(0xffffffffffff);
|
|
24
44
|
const WIRE_ID_TIME_SPAN = WIRE_ID_TIME_MASK + BigInt(1);
|
|
25
45
|
const HALF_SPAN = WIRE_ID_TIME_SPAN / BigInt(2);
|
|
26
46
|
/**
|
|
27
47
|
* How far an id's clock may sit from the clock it is compared with and still
|
|
28
48
|
* count as placed by it: 1 hour. Every correct mint is within ~2 minutes of its
|
|
29
49
|
* own server timestamp (the backdate below); the high-bits bug put ids ~40 days
|
|
30
|
-
* out.
|
|
50
|
+
* out. `apps/api` re-exports it as `MAX_WIRE_ID_CLOCK_CORRECTION`.
|
|
31
51
|
*/
|
|
32
52
|
export const WIRE_ID_CLOCK_TOLERANCE = BigInt(60 * 60 * 1000) * WIRE_ID_TIME_SCALE;
|
|
33
53
|
/**
|
|
@@ -37,6 +57,8 @@ export const WIRE_ID_CLOCK_TOLERANCE = BigInt(60 * 60 * 1000) * WIRE_ID_TIME_SCA
|
|
|
37
57
|
* and would sort above its own prompt.
|
|
38
58
|
*/
|
|
39
59
|
export const WIRE_ID_BACKDATE_MS = 2 * 60 * 1000;
|
|
60
|
+
/** `msg_` + 12 lowercase hex clock chars + 14 base62 chars. */
|
|
61
|
+
export const WIRE_MESSAGE_ID = /^msg_[0-9a-f]{12}[A-Za-z0-9]{14}$/;
|
|
40
62
|
const WIRE_ID_CLOCK = /^msg_([0-9a-f]{12})/;
|
|
41
63
|
const BASE62 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
|
42
64
|
/** The 48-bit clock encoded in a wire id, or null when `id` is not one. */
|
|
@@ -44,38 +66,40 @@ export function wireIdClock(id) {
|
|
|
44
66
|
const match = WIRE_ID_CLOCK.exec(id ?? '');
|
|
45
67
|
return match ? BigInt(`0x${match[1]}`) : null;
|
|
46
68
|
}
|
|
47
|
-
/** The unmasked id clock of wall-clock instant `ms`. */
|
|
48
|
-
export function absoluteWireIdClockAt(ms) {
|
|
49
|
-
return BigInt(Math.trunc(ms)) * WIRE_ID_TIME_SCALE;
|
|
50
|
-
}
|
|
51
69
|
/** The 48-bit id clock of wall-clock instant `ms`, as OpenCode writes it. */
|
|
52
70
|
export function wireIdClockAt(ms) {
|
|
53
|
-
return
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Undo the 48-bit wrap: the absolute clock congruent to `clock` that is
|
|
57
|
-
* nearest to `anchor` (an absolute clock). Two ids unwrapped against anchors
|
|
58
|
-
* within ~1.1 years of each other keep their true order across a wrap.
|
|
59
|
-
*/
|
|
60
|
-
export function unwrapWireIdClock(clock, anchor) {
|
|
61
|
-
const base = anchor - (anchor & WIRE_ID_TIME_MASK);
|
|
62
|
-
let unwrapped = base + clock;
|
|
63
|
-
if (unwrapped - anchor > HALF_SPAN)
|
|
64
|
-
unwrapped -= WIRE_ID_TIME_SPAN;
|
|
65
|
-
else if (anchor - unwrapped > HALF_SPAN)
|
|
66
|
-
unwrapped += WIRE_ID_TIME_SPAN;
|
|
67
|
-
return unwrapped;
|
|
71
|
+
return (BigInt(Math.trunc(ms)) * WIRE_ID_TIME_SCALE) & WIRE_ID_TIME_MASK;
|
|
68
72
|
}
|
|
69
73
|
/**
|
|
70
|
-
* Signed distance from `reference` to `clock` on the 48-bit ring
|
|
71
|
-
* when `clock` is ahead
|
|
74
|
+
* Signed distance from `reference` to `clock` on the 48-bit ring, in clock
|
|
75
|
+
* ticks: positive when `clock` is ahead, 0 when equal, negative when behind.
|
|
76
|
+
* Wrap-safe for distances under ~1.1 years.
|
|
77
|
+
*
|
|
78
|
+
* This is the ONE ordering primitive. Compare two clocks with
|
|
79
|
+
* `wireIdClockDelta(a, b) > 0`, never with `a > b`: a plain compare puts every
|
|
80
|
+
* id minted after a wrap BELOW every id minted before it.
|
|
72
81
|
*/
|
|
73
|
-
function
|
|
82
|
+
export function wireIdClockDelta(clock, reference) {
|
|
74
83
|
let delta = (clock - reference) & WIRE_ID_TIME_MASK;
|
|
75
84
|
if (delta >= HALF_SPAN)
|
|
76
85
|
delta -= WIRE_ID_TIME_SPAN;
|
|
77
86
|
return delta;
|
|
78
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* The newest of `clocks` on the ring, or null when none is given. `null` and
|
|
90
|
+
* `undefined` entries are skipped, so a caller can merge optional floors in one
|
|
91
|
+
* call: `maxWireIdClock([transcriptNewest, deliveredNewest, submitted])`.
|
|
92
|
+
*/
|
|
93
|
+
export function maxWireIdClock(clocks) {
|
|
94
|
+
let newest = null;
|
|
95
|
+
for (const clock of clocks) {
|
|
96
|
+
if (clock === null || clock === undefined)
|
|
97
|
+
continue;
|
|
98
|
+
if (newest === null || wireIdClockDelta(clock, newest) > BigInt(0))
|
|
99
|
+
newest = clock;
|
|
100
|
+
}
|
|
101
|
+
return newest;
|
|
102
|
+
}
|
|
79
103
|
/**
|
|
80
104
|
* Whether `id` claims a clock more than {@link WIRE_ID_CLOCK_TOLERANCE} ahead
|
|
81
105
|
* of `nowMs`. Such an id cannot have been placed against any real transcript;
|
|
@@ -85,7 +109,49 @@ export function isWireIdAheadOf(id, nowMs) {
|
|
|
85
109
|
const clock = wireIdClock(id);
|
|
86
110
|
if (clock === null)
|
|
87
111
|
return false;
|
|
88
|
-
return
|
|
112
|
+
return wireIdClockDelta(clock, wireIdClockAt(nowMs)) > WIRE_ID_CLOCK_TOLERANCE;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The newest clock among `ids`, compared on the ring, or null when none is a
|
|
116
|
+
* wire id. With `nowMs`, an id {@link isWireIdAheadOf} it is skipped: it is not
|
|
117
|
+
* a position, and as a floor it would veto every lift.
|
|
118
|
+
*/
|
|
119
|
+
export function newestWireIdClock(ids, nowMs) {
|
|
120
|
+
const now = nowMs === undefined ? null : wireIdClockAt(nowMs);
|
|
121
|
+
return newestClockWhere(ids, (clock) => now === null || wireIdClockDelta(clock, now) <= WIRE_ID_CLOCK_TOLERANCE);
|
|
122
|
+
}
|
|
123
|
+
/** The newest clock on the ring among the wire ids in `ids` that `keep` accepts. */
|
|
124
|
+
function newestClockWhere(ids, keep) {
|
|
125
|
+
const kept = [];
|
|
126
|
+
for (const id of ids) {
|
|
127
|
+
const clock = wireIdClock(id);
|
|
128
|
+
if (clock !== null && keep(clock))
|
|
129
|
+
kept.push(clock);
|
|
130
|
+
}
|
|
131
|
+
return maxWireIdClock(kept);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Mint an id above a known floor CLOCK — for a caller that holds the newest
|
|
135
|
+
* position as a number (a database row, a transcript it already reduced)
|
|
136
|
+
* rather than as ids. Pure given `random`: the golden vectors assert it.
|
|
137
|
+
*
|
|
138
|
+
* Dated `backdateMs` (default {@link WIRE_ID_BACKDATE_MS}) back, then lifted
|
|
139
|
+
* to `newestKnownTime + 1` when that floor is 0 to
|
|
140
|
+
* {@link WIRE_ID_CLOCK_TOLERANCE} ahead on the ring.
|
|
141
|
+
*/
|
|
142
|
+
export function mintWireMessageIdAbove(input) {
|
|
143
|
+
const random = input.random ?? Math.random;
|
|
144
|
+
let time = wireIdClockAt(input.nowMs - (input.backdateMs ?? WIRE_ID_BACKDATE_MS));
|
|
145
|
+
const floor = input.newestKnownTime ?? null;
|
|
146
|
+
if (floor !== null) {
|
|
147
|
+
const ahead = wireIdClockDelta(floor, time);
|
|
148
|
+
if (ahead >= BigInt(0) && ahead <= WIRE_ID_CLOCK_TOLERANCE)
|
|
149
|
+
time = (floor + BigInt(1)) & WIRE_ID_TIME_MASK;
|
|
150
|
+
}
|
|
151
|
+
let tail = '';
|
|
152
|
+
for (let i = 0; i < 14; i++)
|
|
153
|
+
tail += BASE62[Math.min(61, Math.floor(random() * 62))];
|
|
154
|
+
return { id: `msg_${time.toString(16).padStart(12, '0')}${tail}`, time };
|
|
89
155
|
}
|
|
90
156
|
/**
|
|
91
157
|
* Mint an OpenCode wire message id for a prompt.
|
|
@@ -98,23 +164,13 @@ export function isWireIdAheadOf(id, nowMs) {
|
|
|
98
164
|
*/
|
|
99
165
|
export function mintWireMessageId(options = {}) {
|
|
100
166
|
const nowMs = options.nowMs ?? Date.now();
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
continue;
|
|
110
|
-
if (newest === null || ringDelta(clock, newest) > BigInt(0))
|
|
111
|
-
newest = clock;
|
|
112
|
-
}
|
|
113
|
-
if (newest !== null)
|
|
114
|
-
encoded = (newest + BigInt(1)) & WIRE_ID_TIME_MASK;
|
|
115
|
-
let tail = '';
|
|
116
|
-
for (let i = 0; i < 14; i++)
|
|
117
|
-
tail += BASE62[Math.floor(Math.random() * 62)];
|
|
118
|
-
return `msg_${encoded.toString(16).padStart(12, '0')}${tail}`;
|
|
167
|
+
const backdated = wireIdClockAt(nowMs - WIRE_ID_BACKDATE_MS);
|
|
168
|
+
// Only ids inside the lift window compete: one further ahead must not hide
|
|
169
|
+
// a lower id that still places the mint.
|
|
170
|
+
const newest = newestClockWhere(options.after ?? [], (clock) => {
|
|
171
|
+
const ahead = wireIdClockDelta(clock, backdated);
|
|
172
|
+
return ahead >= BigInt(0) && ahead <= WIRE_ID_CLOCK_TOLERANCE;
|
|
173
|
+
});
|
|
174
|
+
return mintWireMessageIdAbove({ nowMs, newestKnownTime: newest }).id;
|
|
119
175
|
}
|
|
120
176
|
//# sourceMappingURL=wire-message-id.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wire-message-id.js","sourceRoot":"","sources":["../../../src/core/session/wire-message-id.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"wire-message-id.js","sourceRoot":"","sources":["../../../src/core/session/wire-message-id.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,4EAA4E;AAC5E,2DAA2D;AAC3D,qFAAqF;AACrF,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AACjD,sDAAsD;AACtD,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AACxD,MAAM,iBAAiB,GAAG,iBAAiB,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AACxD,MAAM,SAAS,GAAG,iBAAiB,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,kBAAkB,CAAC;AAEnF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAEjD,+DAA+D;AAC/D,MAAM,CAAC,MAAM,eAAe,GAAG,mCAAmC,CAAC;AAEnE,MAAM,aAAa,GAAG,qBAAqB,CAAC;AAC5C,MAAM,MAAM,GAAG,gEAAgE,CAAC;AAEhF,2EAA2E;AAC3E,MAAM,UAAU,WAAW,CAAC,EAA6B;IACvD,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3C,OAAO,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAChD,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,aAAa,CAAC,EAAU;IACtC,OAAO,CA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AI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;IACrF,OAAO,EAAE,EAAE,EAAE,OAAO,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC;AAC3E,CAAC;AAcD;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAoC,EAAE;IACtE,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;IAC1C,MAAM,SAAS,GAAG,aAAa,CAAC,KAAK,GAAG,mBAAmB,CAAC,CAAC;IAC7D,2EAA2E;IAC3E,yCAAyC;IACzC,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE;QAC7D,MAAM,KAAK,GAAG,gBAAgB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QACjD,OAAO,KAAK,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,uBAAuB,CAAC;IAChE,CAAC,CAAC,CAAC;IACH,OAAO,sBAAsB,CAAC,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC;AACvE,CAAC"}
|
|
@@ -205,6 +205,7 @@ export declare class SessionSyncController {
|
|
|
205
205
|
private tailRequest;
|
|
206
206
|
private olderRequest;
|
|
207
207
|
private livenessTimer;
|
|
208
|
+
private livenessBusy;
|
|
208
209
|
private lastActivityAt;
|
|
209
210
|
private listeners;
|
|
210
211
|
private destroyed;
|
|
@@ -228,9 +229,10 @@ export declare class SessionSyncController {
|
|
|
228
229
|
* NOT an opinion about whether the session is working — that answer belongs
|
|
229
230
|
* to `projectWorking` alone. This only says whether anyone still needs the
|
|
230
231
|
* transcript refreshed behind the SSE stream: a caller passes the working
|
|
231
|
-
* state it already has
|
|
232
|
+
* state it already has. `watchIdle` keeps a visible session on a slower
|
|
233
|
+
* verification cadence when the working signal itself was missed.
|
|
232
234
|
*/
|
|
233
|
-
setBusy(isBusy: boolean): void;
|
|
235
|
+
setBusy(isBusy: boolean, watchIdle?: boolean): void;
|
|
234
236
|
destroy(): void;
|
|
235
237
|
private loadTail;
|
|
236
238
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-sync-controller.d.ts","sourceRoot":"","sources":["../../../src/core/session-sync/session-sync-controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAmC/E,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,2BAA2B,KAAK,CAAC;AAE9C;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAE1C,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;AAEpF,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,IAAI,EAAE,CAAC;CACf;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,kBAAkB,EAAE,CAAC;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,oBAAoB,CAAC;IAChC,QAAQ,EAAE,OAAO,CAAC;IAClB,cAAc,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,MAAM,CAAC;IAClB,WAAW,EAAE,CAAC,OAAO,EAAE,MAA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;
|
|
197
|
+
livenessBusy = false;
|
|
197
198
|
lastActivityAt;
|
|
198
199
|
listeners = new Set();
|
|
199
200
|
destroyed = false;
|
|
@@ -275,10 +276,13 @@ export class SessionSyncController {
|
|
|
275
276
|
* NOT an opinion about whether the session is working — that answer belongs
|
|
276
277
|
* to `projectWorking` alone. This only says whether anyone still needs the
|
|
277
278
|
* transcript refreshed behind the SSE stream: a caller passes the working
|
|
278
|
-
* state it already has
|
|
279
|
+
* state it already has. `watchIdle` keeps a visible session on a slower
|
|
280
|
+
* verification cadence when the working signal itself was missed.
|
|
279
281
|
*/
|
|
280
|
-
setBusy(isBusy) {
|
|
281
|
-
|
|
282
|
+
setBusy(isBusy, watchIdle = false) {
|
|
283
|
+
const turnEnded = this.livenessBusy && !isBusy;
|
|
284
|
+
this.livenessBusy = isBusy;
|
|
285
|
+
if (!isBusy && !watchIdle) {
|
|
282
286
|
// The turn is over — and that is exactly when the transcript is most
|
|
283
287
|
// likely to be short. A stream that dropped its last frames leaves the
|
|
284
288
|
// browser holding a truncated answer while the runtime holds the whole
|
|
@@ -288,14 +292,15 @@ export class SessionSyncController {
|
|
|
288
292
|
// runtime's own terminal while the tab still showed a spinner under a
|
|
289
293
|
// half-written answer.
|
|
290
294
|
//
|
|
291
|
-
// One bounded read
|
|
292
|
-
//
|
|
293
|
-
const wasBusy = this.livenessTimer !== undefined;
|
|
295
|
+
// One bounded read for a session that was actually busy. A watched idle
|
|
296
|
+
// session continues at the verification cadence below.
|
|
294
297
|
this.stopLivenessTimer();
|
|
295
|
-
if (
|
|
298
|
+
if (turnEnded && !this.destroyed)
|
|
296
299
|
void this.reconcile('turn-end');
|
|
297
300
|
return;
|
|
298
301
|
}
|
|
302
|
+
if (turnEnded && !this.destroyed)
|
|
303
|
+
void this.reconcile('turn-end');
|
|
299
304
|
if (this.livenessTimer !== undefined)
|
|
300
305
|
return;
|
|
301
306
|
this.lastActivityAt = this.scheduler.now();
|
|
@@ -472,7 +477,22 @@ export class SessionSyncController {
|
|
|
472
477
|
controller.abort(error);
|
|
473
478
|
}, this.readTimeoutMs);
|
|
474
479
|
});
|
|
475
|
-
|
|
480
|
+
// A loader can throw SYNCHRONOUSLY — the registry's page loader evaluates
|
|
481
|
+
// `resolveClient(key)`, which throws `RuntimeNotReadyError` while the
|
|
482
|
+
// runtime is not bound. That throw must not unwind before `Promise.race`
|
|
483
|
+
// subscribes to `deadline`: the read-timeout timer is already armed, and an
|
|
484
|
+
// unobserved rejection 120 s later reaches the browser's
|
|
485
|
+
// `onunhandledrejection` as a `SessionSyncReadTimeoutError`. Bind a
|
|
486
|
+
// synchronous throw into a rejected promise so the race always observes it
|
|
487
|
+
// and `.finally` cancels the timer.
|
|
488
|
+
let readPromise;
|
|
489
|
+
try {
|
|
490
|
+
readPromise = read(controller.signal);
|
|
491
|
+
}
|
|
492
|
+
catch (error) {
|
|
493
|
+
readPromise = Promise.reject(error);
|
|
494
|
+
}
|
|
495
|
+
return Promise.race([readPromise, deadline]).finally(() => {
|
|
476
496
|
this.cancelTimer(timer);
|
|
477
497
|
lifetime.removeEventListener('abort', onLifetimeAbort);
|
|
478
498
|
});
|
|
@@ -568,10 +588,10 @@ export class SessionSyncController {
|
|
|
568
588
|
const quiet = nowMs - this.lastActivityAt > this.livenessIntervalMs;
|
|
569
589
|
// `noteActivity` proves frames are ARRIVING, not that none were lost. A
|
|
570
590
|
// degraded stream that still delivers a trickle renewed the quiet timer
|
|
571
|
-
// forever while the transcript diverged
|
|
572
|
-
//
|
|
591
|
+
// forever while the transcript diverged. The verification read also runs
|
|
592
|
+
// while idle, because a missed working signal cannot enable the busy poll.
|
|
573
593
|
const verifyDue = nowMs - this.lastTailReadAt >= this.verifyIntervalMs;
|
|
574
|
-
if (!quiet && !verifyDue)
|
|
594
|
+
if (!(this.livenessBusy && quiet) && !verifyDue)
|
|
575
595
|
return;
|
|
576
596
|
// Reconcile the TAIL, and nothing else. This is the repair for a dropped
|
|
577
597
|
// SSE stream: the transcript catches up on messages the stream never
|