@burdenoff/fe-libs 2026.1112.3 → 2026.1112.5
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/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-assistant.js +374 -370
- package/dist/shared-providers-shell.js +12 -12
- package/dist/storage/index.d.ts +2 -0
- package/dist/storage/index.js +6 -5
- package/dist/storage/uploadBlob.d.ts +3 -0
- package/dist/storage/uploadBlob.js +39 -37
- package/dist/storage/uploadVisibility.d.ts +3 -0
- package/dist/storage/uploadVisibility.js +6 -0
- package/dist/storage/useSaveToFiles.d.ts +3 -0
- package/dist/storage/useSaveToFiles.js +57 -53
- package/package.json +1 -1
|
@@ -83,6 +83,24 @@ export declare function classifyUsageReportFailure(error: unknown): UsageReportF
|
|
|
83
83
|
* `retryPendingUsageReports` first and is refused while that still fails.
|
|
84
84
|
*/
|
|
85
85
|
export declare function reportUsageWithRetry(report: UsageReport, fn: UsageReporter, options?: UsageReportingOptions): Promise<UsageReportResult>;
|
|
86
|
+
/**
|
|
87
|
+
* `reportUsageWithRetry`, without making the caller wait (BOFF-12187).
|
|
88
|
+
*
|
|
89
|
+
* A turn used to stay "in progress" until its charge had been recorded — up to
|
|
90
|
+
* two round trips after the answer was already on screen, and longer when a
|
|
91
|
+
* retry ran. The charge now goes out in the background and the turn completes
|
|
92
|
+
* at once. What the wait protected is kept: the NEXT send calls
|
|
93
|
+
* `settleInFlightUsageReports` first, so it still sees a settled ledger, and a
|
|
94
|
+
* charge that fails after its retries is held exactly as before.
|
|
95
|
+
*/
|
|
96
|
+
export declare function reportUsageInBackground(report: UsageReport, fn: UsageReporter, options?: UsageReportingOptions): Promise<UsageReportResult>;
|
|
97
|
+
/**
|
|
98
|
+
* Wait for every background charge of this ledger and workspace to settle.
|
|
99
|
+
* Never rejects (`reportUsageWithRetry` never does). Resolves at once when
|
|
100
|
+
* nothing is in flight, which is the usual case: a person takes longer to type
|
|
101
|
+
* the next question than a charge takes to record.
|
|
102
|
+
*/
|
|
103
|
+
export declare function settleInFlightUsageReports(ledger: string, workspaceId: string): Promise<void>;
|
|
86
104
|
/** Whether any report is held for this ledger and workspace. */
|
|
87
105
|
export declare function hasPendingUsageReports(ledger: string, workspaceId: string): boolean;
|
|
88
106
|
/** Why the assistant is paused for this ledger and workspace, or null. */
|
|
@@ -133,14 +133,26 @@ async function T(e, t, n = {}) {
|
|
|
133
133
|
kind: l
|
|
134
134
|
};
|
|
135
135
|
}
|
|
136
|
-
|
|
136
|
+
var E = /* @__PURE__ */ new Map();
|
|
137
|
+
function D(e, t, n = {}) {
|
|
138
|
+
let r = h(n.ledger ?? s, e.workspaceId), i = T(e, t, n), a = E.get(r);
|
|
139
|
+
return a || (a = /* @__PURE__ */ new Set(), E.set(r, a)), a.add(i), i.finally(() => {
|
|
140
|
+
let e = E.get(r);
|
|
141
|
+
e?.delete(i), e && e.size === 0 && E.delete(r);
|
|
142
|
+
}), i;
|
|
143
|
+
}
|
|
144
|
+
async function O(e, t) {
|
|
145
|
+
let n = E.get(h(e, t));
|
|
146
|
+
n && n.size !== 0 && await Promise.all([...n]);
|
|
147
|
+
}
|
|
148
|
+
function k(e, t) {
|
|
137
149
|
return S(e, t).reports.size > 0;
|
|
138
150
|
}
|
|
139
|
-
function
|
|
151
|
+
function A(e, t) {
|
|
140
152
|
let n = S(e, t);
|
|
141
153
|
return n.reports.size > 0 ? { kind: n.kind } : null;
|
|
142
154
|
}
|
|
143
|
-
function
|
|
155
|
+
function j(e, t, n) {
|
|
144
156
|
let r = h(e, t), i = m.get(r);
|
|
145
157
|
if (i) return i;
|
|
146
158
|
let a = (async () => {
|
|
@@ -160,7 +172,7 @@ function O(e, t, n) {
|
|
|
160
172
|
})().finally(() => m.delete(r));
|
|
161
173
|
return m.set(r, a), a;
|
|
162
174
|
}
|
|
163
|
-
function
|
|
175
|
+
function M(e) {
|
|
164
176
|
return e === "permission" ? new t("usage-not-permitted", n.usageNotPermitted.fallback) : new t("usage-not-recorded", n.usageNotRecorded.fallback);
|
|
165
177
|
}
|
|
166
|
-
export { i as USAGE_REPORT_FAILED_EVENT, r as USAGE_REPORT_RETRY_DELAYS_MS, l as assistantUsageLedger, d as classifyUsageReportFailure,
|
|
178
|
+
export { i as USAGE_REPORT_FAILED_EVENT, r as USAGE_REPORT_RETRY_DELAYS_MS, l as assistantUsageLedger, d as classifyUsageReportFailure, A as getUsageBlock, k as hasPendingUsageReports, D as reportUsageInBackground, T as reportUsageWithRetry, j as retryPendingUsageReports, O as settleInFlightUsageReports, u as usagePendingStorageKey, a as usageReportClock, M as usageSendRefusal };
|
|
@@ -1,11 +1,31 @@
|
|
|
1
|
-
import { AssistantMode } from './types';
|
|
1
|
+
import { AssistantMode, AssistantSandboxAuthContext } from './types';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Extend `sandboxId` by `ASSISTANT_IDLE_TTL_SECONDS` from now, but only if the
|
|
4
|
+
* person was active since the last extension (BOFF-12187, `keepAlive.ts`) and
|
|
5
|
+
* nothing extended it in the last interval. Never throws; resolves true when
|
|
6
|
+
* an extension was sent and accepted.
|
|
7
|
+
*
|
|
8
|
+
* `session` also pings the agent's own heartbeat, which resets the bridge's
|
|
9
|
+
* inactivity timer.
|
|
10
|
+
*/
|
|
11
|
+
export declare function keepAssistantSandboxAlive(sandboxId: string, workspaceId: string, authContext: AssistantSandboxAuthContext, session?: {
|
|
12
|
+
sessionId: string;
|
|
13
|
+
mode: AssistantMode;
|
|
14
|
+
}, now?: number): Promise<boolean>;
|
|
15
|
+
/** A sandbox was stopped or proved dead: forget its last extension. */
|
|
16
|
+
export declare function forgetAssistantSandboxKeepAlive(sandboxId: string): void;
|
|
17
|
+
/** Tests only. */
|
|
18
|
+
export declare function resetAssistantKeepAliveForTest(): void;
|
|
19
|
+
/**
|
|
20
|
+
* Keeps the sandbox alive while the panel is open, a session is live AND the
|
|
21
|
+
* person is active (BOFF-12187).
|
|
4
22
|
*
|
|
5
23
|
* The sandbox is reaped on TTL expiry, so without this a user reading a long
|
|
6
24
|
* answer loses the environment mid-conversation and the next turn pays a full
|
|
7
|
-
* cold provision.
|
|
8
|
-
* the
|
|
25
|
+
* cold provision. It extends once a minute, and at once when the person comes
|
|
26
|
+
* back to the page after a pause, so a sandbox that is about to lapse is
|
|
27
|
+
* caught. A panel left open on an idle page stops extending, and the sandbox
|
|
28
|
+
* expires five minutes after the last activity.
|
|
9
29
|
*
|
|
10
30
|
* Best-effort by contract: a failed ping is logged, never surfaced. The user has
|
|
11
31
|
* their answer; the worst case is the reprovision this was avoiding.
|
|
@@ -2,36 +2,55 @@ import { useAuthToken as e } from "../providers/shell/AuthTokenProvider.js";
|
|
|
2
2
|
import "../../shared-providers-shell.js";
|
|
3
3
|
import { extendAssistantSandboxTTL as t, sendHeartbeat as n } from "./api.js";
|
|
4
4
|
import { getWorkspaceId as r } from "./context.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { ASSISTANT_KEEP_ALIVE_INTERVAL_MS as i, assistantActivitySince as a, subscribeAssistantActivity as o } from "./keepAlive.js";
|
|
6
|
+
import { useAssistantStore as s } from "./store.js";
|
|
7
|
+
import { useEffect as c } from "react";
|
|
7
8
|
// src/shared/assistant/useAssistantHeartbeat.ts
|
|
8
|
-
var
|
|
9
|
-
function
|
|
10
|
-
let
|
|
11
|
-
a(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
var l = /* @__PURE__ */ new Map(), u = 32, d = 5e3;
|
|
10
|
+
async function f(e, r, i, o, s = Date.now()) {
|
|
11
|
+
let c = l.get(e);
|
|
12
|
+
if (c !== void 0 && s - c < 6e4 - d || c !== void 0 && !a(c)) return !1;
|
|
13
|
+
l.size >= u && !l.has(e) && l.clear(), l.set(e, s);
|
|
14
|
+
try {
|
|
15
|
+
return await Promise.all([t(e, r, 300, i), o ? n(e, r, o.sessionId, o.mode, i) : Promise.resolve()]), !0;
|
|
16
|
+
} catch (t) {
|
|
17
|
+
return l.delete(e), console.warn("[heartbeat] Failed:", t), !1;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function p(e) {
|
|
21
|
+
l.delete(e);
|
|
22
|
+
}
|
|
23
|
+
function m() {
|
|
24
|
+
l.clear();
|
|
25
|
+
}
|
|
26
|
+
function h(t, n, a) {
|
|
27
|
+
let { getAccessToken: l, getWorkspaceToken: u } = e();
|
|
28
|
+
c(() => {
|
|
29
|
+
if (!t || !n || !a) return;
|
|
30
|
+
let e = n, c = s.getState().sandboxesByMode[e]?.sandboxId;
|
|
31
|
+
if (!c) return;
|
|
32
|
+
let d = r();
|
|
33
|
+
if (!d) return;
|
|
17
34
|
let p = () => {
|
|
18
|
-
|
|
19
|
-
accessToken:
|
|
20
|
-
workspaceToken:
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
35
|
+
f(c, d, {
|
|
36
|
+
accessToken: l(),
|
|
37
|
+
workspaceToken: u()
|
|
38
|
+
}, {
|
|
39
|
+
sessionId: t,
|
|
40
|
+
mode: e
|
|
24
41
|
});
|
|
25
42
|
};
|
|
26
43
|
p();
|
|
27
|
-
let m = setInterval(p, o);
|
|
28
|
-
return () =>
|
|
44
|
+
let m = setInterval(p, i), h = o(p);
|
|
45
|
+
return () => {
|
|
46
|
+
clearInterval(m), h();
|
|
47
|
+
};
|
|
29
48
|
}, [
|
|
30
|
-
|
|
31
|
-
|
|
49
|
+
t,
|
|
50
|
+
n,
|
|
51
|
+
a,
|
|
32
52
|
l,
|
|
33
|
-
u
|
|
34
|
-
d
|
|
53
|
+
u
|
|
35
54
|
]);
|
|
36
55
|
}
|
|
37
|
-
export {
|
|
56
|
+
export { p as forgetAssistantSandboxKeepAlive, f as keepAssistantSandboxAlive, m as resetAssistantKeepAliveForTest, h as useAssistantHeartbeat };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface UseAssistantSignInWarmOptions {
|
|
2
|
+
/** The product id the sandbox is provisioned for. Nothing runs without it. */
|
|
3
|
+
product: string;
|
|
4
|
+
/** False turns the whole warm off (a shell that opts out). */
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
/** The panel is open: opening it is a trigger of its own. */
|
|
7
|
+
panelOpen?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* ★★ BOFF-12187: warm the assistant's sandbox when a signed-in person loads the
|
|
11
|
+
* app, again when they open the panel, and — if they used the assistant
|
|
12
|
+
* recently — when they come back after it lapsed; keep it alive once a minute
|
|
13
|
+
* while they are active (`signInWarm.ts`, `keepAlive.ts`).
|
|
14
|
+
*
|
|
15
|
+
* Mounted where the assistant's launcher lives (the overlay, the widget), which
|
|
16
|
+
* is on screen for every signed-in page, so it runs whether or not the panel
|
|
17
|
+
* has been opened. Every call it makes is best-effort and silent.
|
|
18
|
+
*/
|
|
19
|
+
export declare function useAssistantSignInWarm({ product, enabled, panelOpen, }: UseAssistantSignInWarmOptions): void;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { useAuthTokenOrNull as e } from "../providers/shell/AuthTokenProvider.js";
|
|
2
|
+
import { isProdRuntime as t } from "./env.js";
|
|
3
|
+
import "../../shared-providers-shell.js";
|
|
4
|
+
import { AUTO_READ_MODE as n } from "./autoRouting.js";
|
|
5
|
+
import { getOrganizationId as r, getWorkspaceId as i } from "./context.js";
|
|
6
|
+
import { ASSISTANT_KEEP_ALIVE_INTERVAL_MS as a, subscribeAssistantActivity as o } from "./keepAlive.js";
|
|
7
|
+
import { keepSignInWarmAlive as s, warmAssistantOnSignIn as c } from "./signInWarm.js";
|
|
8
|
+
import { useAssistantStore as l } from "./store.js";
|
|
9
|
+
import { useEffect as u, useRef as d } from "react";
|
|
10
|
+
// src/shared/assistant/useAssistantSignInWarm.ts
|
|
11
|
+
function f({ product: f, enabled: p, panelOpen: m = !1 }) {
|
|
12
|
+
let h = e(), g = h?.userId ?? null, _ = d(h);
|
|
13
|
+
u(() => {
|
|
14
|
+
_.current = h;
|
|
15
|
+
});
|
|
16
|
+
let v = d(null);
|
|
17
|
+
u(() => {
|
|
18
|
+
if (!p || !f || !g) return;
|
|
19
|
+
let e = !1, u = n, d = () => ({
|
|
20
|
+
accessToken: _.current?.getAccessToken() ?? null,
|
|
21
|
+
workspaceToken: _.current?.getWorkspaceToken() ?? null,
|
|
22
|
+
userId: _.current?.userId ?? null,
|
|
23
|
+
organizationId: r()
|
|
24
|
+
}), m = (n) => {
|
|
25
|
+
let r = i();
|
|
26
|
+
!e && r && c({
|
|
27
|
+
trigger: n,
|
|
28
|
+
product: f,
|
|
29
|
+
workspaceId: r,
|
|
30
|
+
authContext: d(),
|
|
31
|
+
isProd: t(),
|
|
32
|
+
mode: u
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
v.current = m;
|
|
36
|
+
let h = () => {
|
|
37
|
+
let t = i(), n = l.getState().sandboxesByMode[u]?.sandboxId;
|
|
38
|
+
!e && t && n && s(n, t, u, d());
|
|
39
|
+
};
|
|
40
|
+
m("sign-in");
|
|
41
|
+
let y = setInterval(h, a), b = o(({ resumed: e }) => {
|
|
42
|
+
m("sign-in"), e ? m("resumed") : h();
|
|
43
|
+
});
|
|
44
|
+
return () => {
|
|
45
|
+
e = !0, v.current = null, clearInterval(y), b();
|
|
46
|
+
};
|
|
47
|
+
}, [
|
|
48
|
+
p,
|
|
49
|
+
f,
|
|
50
|
+
g
|
|
51
|
+
]), u(() => {
|
|
52
|
+
m && v.current?.("panel-open");
|
|
53
|
+
}, [m]);
|
|
54
|
+
}
|
|
55
|
+
export { f as useAssistantSignInWarm };
|
|
@@ -33,6 +33,15 @@ export interface SandboxWriteCapabilities {
|
|
|
33
33
|
* (`/health` `capabilities.clientTools === 1`). Absent: no manifest is sent.
|
|
34
34
|
*/
|
|
35
35
|
clientTools?: true;
|
|
36
|
+
/**
|
|
37
|
+
* ★ BOFF-12187: the image refuses a prompt for a session it does not hold
|
|
38
|
+
* with 404 `SESSION_NOT_FOUND` (and a mode mismatch with 409
|
|
39
|
+
* `SESSION_MODE_MISMATCH`) before anything runs (`/health`
|
|
40
|
+
* `capabilities.promptRejectsUnknownSession === true`). The panel then sends
|
|
41
|
+
* a follow-up without checking the session first. Absent: an older image
|
|
42
|
+
* that accepted such a prompt and ran nothing, so the check stays.
|
|
43
|
+
*/
|
|
44
|
+
promptRejectsUnknownSession?: true;
|
|
36
45
|
}
|
|
37
46
|
export type WriteProposalStatus = 'pending' | 'executing' | 'succeeded' | 'failed' | 'outcome_unknown' | 'declined' | 'superseded' | 'expired';
|
|
38
47
|
export type WriteProposalStatusReason = 'user_declined' | 'corrected' | 'redirected' | 'not_chosen' | 'user_replied' | 'conversation_closed' | 'mode_switched' | 'sandbox_replaced' | 'ttl' | 'evicted' | 'context_changed' | 'stale_execution';
|
|
@@ -67,6 +67,13 @@ export interface AssistantWidgetProps {
|
|
|
67
67
|
* a panel whose buttons do nothing is worse than no panel.
|
|
68
68
|
*/
|
|
69
69
|
showSessionPanel?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* ★★ BOFF-12187: warm the assistant as soon as the widget mounts for a
|
|
72
|
+
* signed-in person, so the first question does not pay the cold start. The
|
|
73
|
+
* transport keeps it alive while the person is active and lets it lapse five
|
|
74
|
+
* minutes after they stop. On by default; `false` opts a shell out.
|
|
75
|
+
*/
|
|
76
|
+
warmOnSignIn?: boolean;
|
|
70
77
|
/** Route in-app links from assistant replies without a full page reload. */
|
|
71
78
|
onNavigate?: (href: string) => void;
|
|
72
79
|
/**
|