@burdenoff/fe-libs 2026.1112.4 → 2026.1112.6
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/shared/assistant/api.d.ts +7 -0
- package/dist/shared/assistant/api.js +47 -45
- package/dist/shared/assistant/createSandboxAssistantTransport.js +2 -1
- package/dist/shared/assistant/gatewayClient.js +1 -0
- package/dist/shared/assistant/index.d.ts +4 -0
- package/dist/shared/assistant/keepAlive.d.ts +74 -0
- package/dist/shared/assistant/keepAlive.js +77 -0
- package/dist/shared/assistant/prewarm.d.ts +20 -0
- package/dist/shared/assistant/prewarm.js +25 -4
- package/dist/shared/assistant/runtime.d.ts +7 -2
- package/dist/shared/assistant/runtime.js +23 -22
- package/dist/shared/assistant/signInWarm.d.ts +60 -0
- package/dist/shared/assistant/signInWarm.js +111 -0
- package/dist/shared/assistant/snapshotPoller.d.ts +16 -0
- package/dist/shared/assistant/snapshotPoller.js +29 -22
- package/dist/shared/assistant/staleSession.d.ts +27 -0
- package/dist/shared/assistant/staleSession.js +15 -0
- package/dist/shared/assistant/turnProgress.d.ts +16 -0
- package/dist/shared/assistant/turnProgress.js +30 -4
- package/dist/shared/assistant/ui/AssistantChatArea.js +1286 -1271
- package/dist/shared/assistant/ui/AssistantOverlay.d.ts +7 -0
- package/dist/shared/assistant/ui/AssistantOverlay.js +256 -248
- package/dist/shared/assistant/usageReporting.d.ts +18 -0
- package/dist/shared/assistant/usageReporting.js +17 -5
- package/dist/shared/assistant/useAssistantHeartbeat.d.ts +24 -4
- package/dist/shared/assistant/useAssistantHeartbeat.js +43 -24
- package/dist/shared/assistant/useAssistantSignInWarm.d.ts +19 -0
- package/dist/shared/assistant/useAssistantSignInWarm.js +55 -0
- package/dist/shared/assistant/writeProposals.d.ts +9 -0
- package/dist/shared/components/assistantWidget/AssistantWidget.d.ts +7 -0
- package/dist/shared/components/assistantWidget/AssistantWidget.js +289 -285
- package/dist/shared/graphql/fetch.d.ts +2 -1
- package/dist/shared/graphql/fetch.js +14 -11
- package/dist/shared/providers/shell/AuthTokenProvider.d.ts +6 -0
- package/dist/shared/providers/shell/AuthTokenProvider.js +4 -1
- package/dist/shared/providers/shell/index.d.ts +1 -1
- package/dist/shared/utils/gatewayFetchRewrite.js +1 -1
- package/dist/shared-assistant.js +374 -370
- package/dist/shared-providers-shell.js +12 -12
- package/package.json +1 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { createAssistantSandbox as e, createAssistantSession as t,
|
|
1
|
+
import { createAssistantSandbox as e, createAssistantSession as t, findExistingSandbox as n, waitForAssistantServiceReady as r, waitForSandboxRunning as i } from "./api.js";
|
|
2
|
+
import { ASSISTANT_KEEP_ALIVE_INTERVAL_MS as a, subscribeAssistantActivity as o } from "./keepAlive.js";
|
|
3
|
+
import { keepAssistantSandboxAlive as s } from "./useAssistantHeartbeat.js";
|
|
2
4
|
// src/shared/assistant/runtime.ts
|
|
3
|
-
var
|
|
5
|
+
var c = class {
|
|
4
6
|
deps;
|
|
5
7
|
sandboxId = null;
|
|
6
8
|
sessionId = null;
|
|
@@ -8,7 +10,7 @@ var s = 24e4, c = class {
|
|
|
8
10
|
quarantinedSandboxIds = /* @__PURE__ */ new Set();
|
|
9
11
|
inFlight = null;
|
|
10
12
|
keepWarmTimer = null;
|
|
11
|
-
|
|
13
|
+
stopActivity = null;
|
|
12
14
|
constructor(e) {
|
|
13
15
|
this.deps = e;
|
|
14
16
|
try {
|
|
@@ -36,20 +38,20 @@ var s = 24e4, c = class {
|
|
|
36
38
|
sessionId: this.sessionId
|
|
37
39
|
});
|
|
38
40
|
if (this.inFlight) return this.inFlight;
|
|
39
|
-
let
|
|
40
|
-
if (!
|
|
41
|
-
let
|
|
41
|
+
let a = this.deps.getWorkspaceId();
|
|
42
|
+
if (!a) return Promise.reject(/* @__PURE__ */ Error("The assistant needs an active workspace. Open a workspace and try again."));
|
|
43
|
+
let o = this.deps.getAuthContext();
|
|
42
44
|
return this.inFlight = (async () => {
|
|
43
45
|
let s = this.deps.isProd(), c = this.sandboxId;
|
|
44
46
|
if (!c) {
|
|
45
|
-
if (c = await
|
|
46
|
-
if (!
|
|
47
|
-
c = await e(this.deps.product, this.deps.mode,
|
|
47
|
+
if (c = await n(a, this.deps.product, this.deps.mode, s, o, this.quarantinedSandboxIds), !c) {
|
|
48
|
+
if (!o.accessToken) throw Error("The assistant requires an authenticated session. Please sign in again.");
|
|
49
|
+
c = await e(this.deps.product, this.deps.mode, a, s, this.deps.ttlSeconds, o);
|
|
48
50
|
}
|
|
49
|
-
this.provisioningSandboxId = c, await
|
|
51
|
+
this.provisioningSandboxId = c, await i(c, a, o), await r(c, a, this.deps.mode, o), this.sandboxId = c, this.provisioningSandboxId = null;
|
|
50
52
|
}
|
|
51
53
|
let l = this.sessionId;
|
|
52
|
-
return l || (l = (await t(c,
|
|
54
|
+
return l || (l = (await t(c, a, this.deps.mode, o)).sessionId, this.sessionId = l), this.persist(), {
|
|
53
55
|
sandboxId: c,
|
|
54
56
|
sessionId: l
|
|
55
57
|
};
|
|
@@ -66,27 +68,26 @@ var s = 24e4, c = class {
|
|
|
66
68
|
if (e === "probe") {
|
|
67
69
|
if (this.sandboxId || this.inFlight) return;
|
|
68
70
|
let e = this.deps.getAuthContext();
|
|
69
|
-
|
|
70
|
-
n && (await
|
|
71
|
+
n(t, this.deps.product, this.deps.mode, this.deps.isProd(), e, this.quarantinedSandboxIds).then(async (n) => {
|
|
72
|
+
n && (await r(n, t, this.deps.mode, e).catch(() => void 0), this.sandboxId = n, this.persist());
|
|
71
73
|
}).catch(() => void 0);
|
|
72
|
-
} else this.ensureRuntime().catch(() => void 0);
|
|
74
|
+
} else this.ensureRuntime().then(() => this.startKeepWarm()).catch(() => void 0);
|
|
73
75
|
}
|
|
74
76
|
}
|
|
75
77
|
startKeepWarm() {
|
|
76
78
|
if (this.keepWarmTimer) return;
|
|
77
79
|
let e = () => {
|
|
78
|
-
if (
|
|
80
|
+
if (!this.sandboxId) return;
|
|
79
81
|
let e = this.deps.getWorkspaceId();
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
e && s(this.sandboxId, e, this.deps.getAuthContext(), this.sessionId ? {
|
|
83
|
+
sessionId: this.sessionId,
|
|
84
|
+
mode: this.deps.mode
|
|
85
|
+
} : void 0);
|
|
83
86
|
};
|
|
84
|
-
this.keepWarmTimer = setInterval(e,
|
|
85
|
-
typeof document < "u" && document.visibilityState === "visible" && e();
|
|
86
|
-
}, typeof document < "u" && document.addEventListener("visibilitychange", this.visibilityHandler);
|
|
87
|
+
this.keepWarmTimer = setInterval(e, a), this.stopActivity = o(e);
|
|
87
88
|
}
|
|
88
89
|
stopKeepWarm() {
|
|
89
|
-
this.keepWarmTimer &&= (clearInterval(this.keepWarmTimer), null), this.
|
|
90
|
+
this.keepWarmTimer &&= (clearInterval(this.keepWarmTimer), null), this.stopActivity?.(), this.stopActivity = null;
|
|
90
91
|
}
|
|
91
92
|
getSandboxId() {
|
|
92
93
|
return this.sandboxId ?? this.provisioningSandboxId;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { AssistantMode, AssistantSandboxAuthContext } from './types';
|
|
2
|
+
/** Why a warm was asked for. */
|
|
3
|
+
export type SignInWarmTrigger = 'sign-in' | 'panel-open' | 'resumed';
|
|
4
|
+
/** A trigger inside this window of the last one, for the same workspace, does nothing. */
|
|
5
|
+
export declare const SIGN_IN_WARM_COOLDOWN_MS = 30000;
|
|
6
|
+
/**
|
|
7
|
+
* `resumed` re-warms only for someone who sent a turn on this page this
|
|
8
|
+
* recently. Someone who signed in and never asked anything gets the sign-in
|
|
9
|
+
* warm and nothing more.
|
|
10
|
+
*/
|
|
11
|
+
export declare const RESUME_WARM_RECENT_USE_MS: number;
|
|
12
|
+
export interface SignInWarmInput {
|
|
13
|
+
trigger: SignInWarmTrigger;
|
|
14
|
+
product: string;
|
|
15
|
+
workspaceId: string;
|
|
16
|
+
authContext: AssistantSandboxAuthContext;
|
|
17
|
+
isProd: boolean;
|
|
18
|
+
/** Default `AUTO_READ_MODE`. Only a read-only mode may be warmed. */
|
|
19
|
+
mode?: AssistantMode;
|
|
20
|
+
now?: number;
|
|
21
|
+
}
|
|
22
|
+
/** A turn was sent on this page: `resumed` may re-warm for this person. */
|
|
23
|
+
export declare function noteAssistantTurnSent(now?: number): void;
|
|
24
|
+
/**
|
|
25
|
+
* Should this trigger warm? Pure apart from the cooldown map, so the rules are
|
|
26
|
+
* tested rather than read.
|
|
27
|
+
*/
|
|
28
|
+
export declare function signInWarmWanted(input: {
|
|
29
|
+
trigger: SignInWarmTrigger;
|
|
30
|
+
workspaceId: string;
|
|
31
|
+
product: string;
|
|
32
|
+
hasAccessToken: boolean;
|
|
33
|
+
now: number;
|
|
34
|
+
lastTurnAt: number | null;
|
|
35
|
+
lastTriggerAt: number | undefined;
|
|
36
|
+
/** This page already ran its sign-in warm for the workspace. */
|
|
37
|
+
signInDone: boolean;
|
|
38
|
+
warming: boolean;
|
|
39
|
+
turnInFlight: boolean;
|
|
40
|
+
}): boolean;
|
|
41
|
+
export interface SignInWarmResult {
|
|
42
|
+
sandboxId: string;
|
|
43
|
+
/** A sandbox was created for it. */
|
|
44
|
+
created: boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Prepare a running, proven Ask sandbox and pre-open its first session.
|
|
48
|
+
* Resolves the sandbox, or null when nothing was warmed (not wanted, refused,
|
|
49
|
+
* cancelled by a send, or failed). Never rejects.
|
|
50
|
+
*/
|
|
51
|
+
export declare function warmAssistantOnSignIn(input: SignInWarmInput): Promise<SignInWarmResult | null>;
|
|
52
|
+
/**
|
|
53
|
+
* One keep-alive tick for the warmed sandbox: extend it if the person was
|
|
54
|
+
* active (`keepAssistantSandboxAlive`), and when that went out, read its
|
|
55
|
+
* `/health` too, which renews the warm proof the next send relies on. Never
|
|
56
|
+
* rejects.
|
|
57
|
+
*/
|
|
58
|
+
export declare function keepSignInWarmAlive(sandboxId: string, workspaceId: string, mode: AssistantMode, authContext: AssistantSandboxAuthContext): Promise<void>;
|
|
59
|
+
/** Tests only. */
|
|
60
|
+
export declare function resetSignInWarmForTest(): void;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { createAssistantSandbox as e, createAssistantSession as t, findExistingSandboxWithStatus as n, readSandboxWriteCapabilitiesOnce as r, waitForAssistantServiceReady as i, waitForSandboxRunning as a } from "./api.js";
|
|
2
|
+
import "./autoRouting.js";
|
|
3
|
+
import "./keepAlive.js";
|
|
4
|
+
import { QuarantineSet as o, WarmCancelled as s, dropWarmProof as c, hasFreshWarmProof as l, preopenKey as u, preopenWanted as d, recordWarmProof as f, startPreopen as p, startWarm as m, warmState as h } from "./prewarm.js";
|
|
5
|
+
import { conversationHasHistory as g } from "./history/historyList.js";
|
|
6
|
+
import { useAssistantStore as _ } from "./store.js";
|
|
7
|
+
import { isTurnInFlight as v } from "./turnState.js";
|
|
8
|
+
import { keepAssistantSandboxAlive as y } from "./useAssistantHeartbeat.js";
|
|
9
|
+
// src/shared/assistant/signInWarm.ts
|
|
10
|
+
var b = 3e4, x = 18e5, S = /* @__PURE__ */ new Map(), C = /* @__PURE__ */ new Set(), w = null, T = new o();
|
|
11
|
+
function E(e = Date.now()) {
|
|
12
|
+
w = e;
|
|
13
|
+
}
|
|
14
|
+
function D(e) {
|
|
15
|
+
return !e.workspaceId || !e.product || !e.hasAccessToken || e.warming || e.turnInFlight || e.trigger === "sign-in" && e.signInDone || e.lastTriggerAt !== void 0 && e.now - e.lastTriggerAt < 3e4 ? !1 : e.trigger !== "resumed" || e.lastTurnAt !== null && e.now - e.lastTurnAt < 18e5;
|
|
16
|
+
}
|
|
17
|
+
async function O(r) {
|
|
18
|
+
let o = r.now ?? Date.now(), c = r.mode ?? "assistant", { workspaceId: b, product: x, authContext: E, isProd: O } = r, k = _.getState(), A = `${b}\u0000${x}`;
|
|
19
|
+
if (!D({
|
|
20
|
+
trigger: r.trigger,
|
|
21
|
+
workspaceId: b,
|
|
22
|
+
product: x,
|
|
23
|
+
hasAccessToken: !!E.accessToken,
|
|
24
|
+
now: o,
|
|
25
|
+
lastTurnAt: w,
|
|
26
|
+
lastTriggerAt: S.get(A),
|
|
27
|
+
signInDone: C.has(A),
|
|
28
|
+
warming: h(b).warming,
|
|
29
|
+
turnInFlight: Object.values(k.processingByConversationId).some((e) => v(e?.status))
|
|
30
|
+
})) return null;
|
|
31
|
+
S.set(A, o), C.add(A);
|
|
32
|
+
let j = m(b, {
|
|
33
|
+
mode: c,
|
|
34
|
+
mayCreate: !0
|
|
35
|
+
}, o), M = () => j.signal.aborted, N = () => {
|
|
36
|
+
if (M()) throw new s("cancelled");
|
|
37
|
+
}, P = !1, F = !1;
|
|
38
|
+
try {
|
|
39
|
+
let r = null, o = k.sandboxesByMode[c]?.sandboxId ?? null;
|
|
40
|
+
if (o && !T.has(o) && l(o) && (r = o), !r) {
|
|
41
|
+
let e = await n(b, x, c, O, E, T, "proposal-v1");
|
|
42
|
+
if (N(), e) {
|
|
43
|
+
(e.status === "PROVISIONING" || e.status === "PENDING") && (j.beginBoot(), F = !0);
|
|
44
|
+
try {
|
|
45
|
+
await a(e.id, b, E, 3e5), N(), await i(e.id, b, c, E, 9e4), N(), r = e.id;
|
|
46
|
+
} catch (t) {
|
|
47
|
+
if (t instanceof s || M()) throw t;
|
|
48
|
+
T.add(e.id), j.dead.push(e.id);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (!r) {
|
|
53
|
+
let t = j.beginCreate();
|
|
54
|
+
F = !0;
|
|
55
|
+
try {
|
|
56
|
+
r = await e(x, c, b, O, 300, E, { writeApproval: "proposal-v1" });
|
|
57
|
+
} finally {
|
|
58
|
+
t();
|
|
59
|
+
}
|
|
60
|
+
P = !0, N(), await a(r, b, E, 3e5), N(), await i(r, b, c, E, 9e4), N();
|
|
61
|
+
}
|
|
62
|
+
f(r), _.getState().setSandbox(c, r, "running"), j.finish({
|
|
63
|
+
ok: !0,
|
|
64
|
+
sandboxId: r,
|
|
65
|
+
didWork: !0,
|
|
66
|
+
booted: F,
|
|
67
|
+
dead: j.dead
|
|
68
|
+
}), y(r, b, E);
|
|
69
|
+
let m = _.getState(), h = m.activeConversationId ? m.conversations.find((e) => e.id === m.activeConversationId) : void 0;
|
|
70
|
+
if (d({
|
|
71
|
+
active: h ? {
|
|
72
|
+
mode: h.mode,
|
|
73
|
+
backendSessionId: h.backendSessionId,
|
|
74
|
+
continuable: !0,
|
|
75
|
+
hasHistory: g(h)
|
|
76
|
+
} : void 0,
|
|
77
|
+
mode: c
|
|
78
|
+
})) {
|
|
79
|
+
let e = r;
|
|
80
|
+
p(u({
|
|
81
|
+
workspaceId: b,
|
|
82
|
+
mode: c,
|
|
83
|
+
sandboxId: e,
|
|
84
|
+
userId: E.userId
|
|
85
|
+
}), () => t(e, b, c, E).then((e) => e.sessionId), Date.now());
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
sandboxId: r,
|
|
89
|
+
created: P
|
|
90
|
+
};
|
|
91
|
+
} catch {
|
|
92
|
+
return j.finish({
|
|
93
|
+
ok: !1,
|
|
94
|
+
didWork: !1,
|
|
95
|
+
booted: F,
|
|
96
|
+
dead: j.dead
|
|
97
|
+
}), null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async function k(e, t, n, i) {
|
|
101
|
+
try {
|
|
102
|
+
if (!await y(e, t, i)) return;
|
|
103
|
+
await r(e, t, n, i) ? f(e) : c(e);
|
|
104
|
+
} catch {
|
|
105
|
+
c(e);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function A() {
|
|
109
|
+
S.clear(), C.clear(), w = null, T.clear();
|
|
110
|
+
}
|
|
111
|
+
export { x as RESUME_WARM_RECENT_USE_MS, b as SIGN_IN_WARM_COOLDOWN_MS, k as keepSignInWarmAlive, E as noteAssistantTurnSent, A as resetSignInWarmForTest, D as signInWarmWanted, O as warmAssistantOnSignIn };
|
|
@@ -24,7 +24,21 @@
|
|
|
24
24
|
export interface SnapshotPollerOptions {
|
|
25
25
|
/** Extra requests the idle fast path may start per turn. */
|
|
26
26
|
maxExtra?: number;
|
|
27
|
+
/**
|
|
28
|
+
* ★ BOFF-12187: a request still unanswered after this long gets a second one
|
|
29
|
+
* beside it — a hedge. In production one poll in 48 stalled for 7.5 s on its
|
|
30
|
+
* way to the load balancer while the origin answered in under a second, and
|
|
31
|
+
* because polls run one at a time that one request held the whole turn. The
|
|
32
|
+
* read is idempotent, so the first answer wins (the rules above apply).
|
|
33
|
+
* `0` turns hedging off.
|
|
34
|
+
*/
|
|
35
|
+
hedgeAfterMs?: number;
|
|
36
|
+
/** Hedges per turn. */
|
|
37
|
+
maxHedges?: number;
|
|
27
38
|
}
|
|
39
|
+
/** Ten times a normal poll's round trip; well past any healthy one. */
|
|
40
|
+
export declare const POLL_HEDGE_AFTER_MS = 3000;
|
|
41
|
+
export declare const POLL_MAX_HEDGES = 3;
|
|
28
42
|
export interface SnapshotPoller<T> {
|
|
29
43
|
/**
|
|
30
44
|
* The next snapshot to apply. Starts a request when none is pending; when a
|
|
@@ -43,5 +57,7 @@ export interface SnapshotPoller<T> {
|
|
|
43
57
|
/** Requests started in all, for tests and for the timeline. */
|
|
44
58
|
readonly started: number;
|
|
45
59
|
readonly extraStarted: number;
|
|
60
|
+
/** Requests started because the one before them stalled (BOFF-12187). */
|
|
61
|
+
readonly hedgesStarted: number;
|
|
46
62
|
}
|
|
47
63
|
export declare function createSnapshotPoller<T>(fetch: () => Promise<T>, options?: SnapshotPollerOptions): SnapshotPoller<T>;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
// src/shared/assistant/snapshotPoller.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
var e = 3e3, t = 3;
|
|
3
|
+
function n(e, t = {}) {
|
|
4
|
+
let n = t.maxExtra ?? 2, r = t.hedgeAfterMs ?? 3e3, i = t.maxHedges ?? 3, a = [], o = 0, s = 0, c = 0, l = null, u = () => {
|
|
5
|
+
let e = l;
|
|
6
|
+
l = null, e?.();
|
|
7
|
+
}, d = () => {
|
|
7
8
|
let t = {
|
|
8
|
-
seq:
|
|
9
|
+
seq: o += 1,
|
|
10
|
+
startedAt: Date.now(),
|
|
9
11
|
done: !1,
|
|
10
12
|
failed: !1,
|
|
11
13
|
value: void 0,
|
|
@@ -17,41 +19,46 @@ function e(e, t = {}) {
|
|
|
17
19
|
n = Promise.reject(e);
|
|
18
20
|
}
|
|
19
21
|
return n.then((e) => {
|
|
20
|
-
t.value = e, t.done = !0,
|
|
22
|
+
t.value = e, t.done = !0, u();
|
|
21
23
|
}, (e) => {
|
|
22
|
-
t.failed = !0, t.error = e, t.done = !0,
|
|
23
|
-
}),
|
|
24
|
+
t.failed = !0, t.error = e, t.done = !0, u();
|
|
25
|
+
}), a.push(t), t;
|
|
24
26
|
};
|
|
25
27
|
return {
|
|
26
28
|
async next() {
|
|
27
|
-
for (
|
|
28
|
-
let e =
|
|
29
|
+
for (a.length === 0 && d();;) {
|
|
30
|
+
let e = a.filter((e) => e.done && !e.failed);
|
|
29
31
|
if (e.length > 0) {
|
|
30
32
|
let t = e.reduce((e, t) => t.seq > e.seq ? t : e);
|
|
31
|
-
return
|
|
33
|
+
return a = a.filter((e) => e.seq > t.seq && !(e.done && e.failed)), t.value;
|
|
32
34
|
}
|
|
33
|
-
let t =
|
|
35
|
+
let t = a.filter((e) => !e.done);
|
|
34
36
|
if (t.length === 0) {
|
|
35
|
-
let e =
|
|
36
|
-
throw
|
|
37
|
+
let e = a.reduce((e, t) => t.seq > e.seq ? t : e);
|
|
38
|
+
throw a = [], e.error;
|
|
37
39
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
a = t;
|
|
41
|
+
let n = t.reduce((e, t) => t.seq > e.seq ? t : e), o = r > 0 && c < i && a.length < 3 ? Math.max(0, n.startedAt + r - Date.now()) : null, s, u = await new Promise((e) => {
|
|
42
|
+
l = () => e(!1), o !== null && (s = setTimeout(() => e(!0), o));
|
|
40
43
|
});
|
|
44
|
+
s !== void 0 && clearTimeout(s), u && (l = null, a.some((e) => e.done) || (c += 1, d()));
|
|
41
45
|
}
|
|
42
46
|
},
|
|
43
47
|
startExtra() {
|
|
44
|
-
return !
|
|
48
|
+
return !a.some((e) => !e.done) || a.length >= 2 || s >= n ? !1 : (s += 1, d(), !0);
|
|
45
49
|
},
|
|
46
50
|
hasPending() {
|
|
47
|
-
return
|
|
51
|
+
return a.length > 0;
|
|
48
52
|
},
|
|
49
53
|
get started() {
|
|
50
|
-
return
|
|
54
|
+
return o;
|
|
51
55
|
},
|
|
52
56
|
get extraStarted() {
|
|
53
|
-
return
|
|
57
|
+
return s;
|
|
58
|
+
},
|
|
59
|
+
get hedgesStarted() {
|
|
60
|
+
return c;
|
|
54
61
|
}
|
|
55
62
|
};
|
|
56
63
|
}
|
|
57
|
-
export { e as createSnapshotPoller };
|
|
64
|
+
export { e as POLL_HEDGE_AFTER_MS, t as POLL_MAX_HEDGES, n as createSnapshotPoller };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ★ BOFF-12187: a follow-up sent without checking its session first.
|
|
3
|
+
*
|
|
4
|
+
* The panel used to confirm a stored session was alive — a round trip into the
|
|
5
|
+
* sandbox — before every follow-up prompt. Where the sandbox's own `/health`
|
|
6
|
+
* says it refuses a prompt for a session it does not hold
|
|
7
|
+
* (`promptRejectsUnknownSession`), the panel sends at once instead and treats
|
|
8
|
+
* the refusal as the check: 404 `SESSION_NOT_FOUND` (the container was
|
|
9
|
+
* replaced, or the session deleted) or 409 `SESSION_MODE_MISMATCH`. Both are
|
|
10
|
+
* refused before anything runs, so the same prompt is sent again, once, to a
|
|
11
|
+
* new session.
|
|
12
|
+
*
|
|
13
|
+
* A LEAF MODULE, like `sandboxProxyError.ts`: no imports.
|
|
14
|
+
*/
|
|
15
|
+
export declare const STALE_SESSION_CODES: readonly ["SESSION_NOT_FOUND", "SESSION_MODE_MISMATCH"];
|
|
16
|
+
export type StaleSessionCode = (typeof STALE_SESSION_CODES)[number];
|
|
17
|
+
/**
|
|
18
|
+
* Was this send refused because the session is gone or in another mode?
|
|
19
|
+
* Duck-typed on the error's own `extensions.code` (where `SandboxProxyError`
|
|
20
|
+
* puts a refusal's code) and its status, so a second copy of this module in a
|
|
21
|
+
* consumer's bundle reads it the same.
|
|
22
|
+
*/
|
|
23
|
+
export declare function isStaleSessionRefusal(error: unknown): boolean;
|
|
24
|
+
/** Thrown inside a send attempt to re-run it on a new session. Never surfaces. */
|
|
25
|
+
export declare class StaleSessionRestart extends Error {
|
|
26
|
+
constructor();
|
|
27
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/shared/assistant/staleSession.ts
|
|
2
|
+
var e = ["SESSION_NOT_FOUND", "SESSION_MODE_MISMATCH"];
|
|
3
|
+
function t(t) {
|
|
4
|
+
if (!t || typeof t != "object") return !1;
|
|
5
|
+
let { extensions: n, status: r } = t;
|
|
6
|
+
if (!n || typeof n != "object") return !1;
|
|
7
|
+
let i = n.code;
|
|
8
|
+
return typeof i != "string" || !e.includes(i) ? !1 : i === "SESSION_NOT_FOUND" ? r === 404 : r === 409;
|
|
9
|
+
}
|
|
10
|
+
var n = class extends Error {
|
|
11
|
+
constructor() {
|
|
12
|
+
super("assistant session no longer held by the sandbox"), this.name = "StaleSessionRestart";
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
export { e as STALE_SESSION_CODES, n as StaleSessionRestart, t as isStaleSessionRefusal };
|
|
@@ -133,6 +133,22 @@ export interface SessionReadAhead {
|
|
|
133
133
|
export declare function startSessionReadAhead(sandboxId: string, sessionId: string, read: (sandboxId: string, sessionId: string) => Promise<AssistantRawMessage[]>): SessionReadAhead;
|
|
134
134
|
/** The read-ahead's messages — only for the session the prompt is sent to. */
|
|
135
135
|
export declare function readAheadFor(readAhead: SessionReadAhead | null, sandboxId: string, sessionId: string): Promise<AssistantRawMessage[]> | null;
|
|
136
|
+
/** A remembered floor older than this is not used. */
|
|
137
|
+
export declare const REMEMBERED_FLOOR_MAX_AGE_MS: number;
|
|
138
|
+
/**
|
|
139
|
+
* Record the newest message of a session whose turn just COMPLETED. `messages`
|
|
140
|
+
* is that turn's final poll. Nothing is recorded when it lists no timestamp.
|
|
141
|
+
*/
|
|
142
|
+
export declare function rememberSessionFloor(sandboxId: string, sessionId: string, messages: readonly AssistantRawMessage[], now?: number): void;
|
|
143
|
+
/**
|
|
144
|
+
* The remembered floor for this sandbox and session, or null. Single-use: it
|
|
145
|
+
* is taken, so a second turn can never reuse a floor the first one has moved.
|
|
146
|
+
*/
|
|
147
|
+
export declare function takeRememberedSessionFloor(sandboxId: string, sessionId: string, now?: number): number | null;
|
|
148
|
+
/** Peek without taking — whether a follow-up here could skip its read. */
|
|
149
|
+
export declare function hasRememberedSessionFloor(sandboxId: string, sessionId: string, now?: number): boolean;
|
|
150
|
+
/** Tests only. */
|
|
151
|
+
export declare function resetRememberedSessionFloorsForTest(): void;
|
|
136
152
|
/** Where a turn's first answer text is, while it is still only a candidate. */
|
|
137
153
|
export interface FirstTextTracker {
|
|
138
154
|
messageId: string | null;
|
|
@@ -55,20 +55,46 @@ function c(e, t, n) {
|
|
|
55
55
|
function l(e, t, n) {
|
|
56
56
|
return e?.sandboxId === t && e.sessionId === n ? e.messages : null;
|
|
57
57
|
}
|
|
58
|
-
var u = {
|
|
58
|
+
var u = 6e5, d = 64, f = /* @__PURE__ */ new Map(), p = (e, t) => `${e}\u0000${t}`;
|
|
59
|
+
function m(e, t, n, i = Date.now()) {
|
|
60
|
+
let a = n.reduce((e, t) => Math.max(e, r(t)), 0);
|
|
61
|
+
if (!(a > 0)) return;
|
|
62
|
+
let o = p(e, t);
|
|
63
|
+
for (f.delete(o); f.size >= d;) {
|
|
64
|
+
let e = f.keys().next();
|
|
65
|
+
if (e.done) break;
|
|
66
|
+
f.delete(e.value);
|
|
67
|
+
}
|
|
68
|
+
f.set(o, {
|
|
69
|
+
floorMs: a,
|
|
70
|
+
recordedAt: i
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function h(e, t, n = Date.now()) {
|
|
74
|
+
let r = p(e, t), i = f.get(r);
|
|
75
|
+
return f.delete(r), !i || n - i.recordedAt > 6e5 || i.recordedAt > n ? null : i.floorMs;
|
|
76
|
+
}
|
|
77
|
+
function g(e, t, n = Date.now()) {
|
|
78
|
+
let r = f.get(p(e, t));
|
|
79
|
+
return !!r && n - r.recordedAt <= 6e5 && r.recordedAt <= n;
|
|
80
|
+
}
|
|
81
|
+
function _() {
|
|
82
|
+
f.clear();
|
|
83
|
+
}
|
|
84
|
+
var v = {
|
|
59
85
|
messageId: null,
|
|
60
86
|
at: null
|
|
61
87
|
};
|
|
62
|
-
function
|
|
88
|
+
function y(e, t, n) {
|
|
63
89
|
let r = t.messageId ?? null, i = e;
|
|
64
90
|
t.hasText ? (e.at === null || e.messageId !== r) && (i = {
|
|
65
91
|
messageId: r,
|
|
66
92
|
at: n
|
|
67
|
-
}) : i =
|
|
93
|
+
}) : i = v;
|
|
68
94
|
let a = t.done && i.at !== null && i.messageId === r ? i.at : null;
|
|
69
95
|
return {
|
|
70
96
|
tracker: i,
|
|
71
97
|
confirmedAt: a
|
|
72
98
|
};
|
|
73
99
|
}
|
|
74
|
-
export {
|
|
100
|
+
export { v as NO_FIRST_TEXT, u as REMEMBERED_FLOOR_MAX_AGE_MS, o as buildAssistantProgress, g as hasRememberedSessionFloor, l as readAheadFor, m as rememberSessionFloor, _ as resetRememberedSessionFloorsForTest, s as snapshotReplyFloor, c as startSessionReadAhead, h as takeRememberedSessionFloor, y as trackFirstText };
|