@burdenoff/fe-libs 2026.1113.1 → 2026.1113.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/shared/assistant/askAbout/AskAboutLayer.js +47 -47
- package/dist/shared/assistant/askAbout/askAboutStore.d.ts +7 -0
- package/dist/shared/assistant/askAbout/focus.js +1 -1
- package/dist/shared/assistant/askAbout/placement.d.ts +9 -0
- package/dist/shared/assistant/askAbout/placement.js +5 -1
- package/dist/shared/assistant/askAbout/useAskable.js +6 -5
- package/dist/shared/assistant/i18nManifest.d.ts +40 -0
- package/dist/shared/assistant/i18nManifest.js +40 -0
- package/dist/shared/proactive/ProactiveProvider.d.ts +67 -0
- package/dist/shared/proactive/ProactiveProvider.js +128 -0
- package/dist/shared/proactive/actions.d.ts +101 -0
- package/dist/shared/proactive/actions.js +71 -0
- package/dist/shared/proactive/activity.d.ts +27 -0
- package/dist/shared/proactive/activity.js +37 -0
- package/dist/shared/proactive/adapters.d.ts +54 -0
- package/dist/shared/proactive/adapters.js +62 -0
- package/dist/shared/proactive/anchors.d.ts +47 -0
- package/dist/shared/proactive/anchors.js +53 -0
- package/dist/shared/proactive/budget.d.ts +17 -0
- package/dist/shared/proactive/budget.js +30 -0
- package/dist/shared/proactive/capabilities.d.ts +26 -0
- package/dist/shared/proactive/capabilities.js +63 -0
- package/dist/shared/proactive/coalesce.d.ts +11 -0
- package/dist/shared/proactive/coalesce.js +15 -0
- package/dist/shared/proactive/context.d.ts +42 -0
- package/dist/shared/proactive/context.js +31 -0
- package/dist/shared/proactive/flags.d.ts +5 -0
- package/dist/shared/proactive/flags.js +11 -0
- package/dist/shared/proactive/index.d.ts +40 -0
- package/dist/shared/proactive/metadata.d.ts +48 -0
- package/dist/shared/proactive/metadata.js +126 -0
- package/dist/shared/proactive/operations.d.ts +96 -0
- package/dist/shared/proactive/operations.js +117 -0
- package/dist/shared/proactive/severityCopy.d.ts +4 -0
- package/dist/shared/proactive/severityCopy.js +10 -0
- package/dist/shared/proactive/snooze.d.ts +4 -0
- package/dist/shared/proactive/snooze.js +9 -0
- package/dist/shared/proactive/transport.d.ts +32 -0
- package/dist/shared/proactive/transport.js +124 -0
- package/dist/shared/proactive/types.d.ts +83 -0
- package/dist/shared/proactive/ui/ProactiveInbox.d.ts +20 -0
- package/dist/shared/proactive/ui/ProactiveInbox.js +78 -0
- package/dist/shared/proactive/ui/ProactiveSettingsPanel.d.ts +8 -0
- package/dist/shared/proactive/ui/ProactiveSettingsPanel.js +210 -0
- package/dist/shared/proactive/ui/SuggestionAnchorsLayer.d.ts +9 -0
- package/dist/shared/proactive/ui/SuggestionAnchorsLayer.js +140 -0
- package/dist/shared/proactive/ui/SuggestionBadge.d.ts +11 -0
- package/dist/shared/proactive/ui/SuggestionBadge.js +53 -0
- package/dist/shared/proactive/ui/SuggestionCard.d.ts +23 -0
- package/dist/shared/proactive/ui/SuggestionCard.js +119 -0
- package/dist/shared/proactive/ui/anchorLayerDom.d.ts +28 -0
- package/dist/shared/proactive/ui/anchorLayerDom.js +23 -0
- package/dist/shared/proactive/useProactiveSession.d.ts +56 -0
- package/dist/shared/proactive/useProactiveSession.js +150 -0
- package/dist/shared/proactive/useSuggestionControls.d.ts +25 -0
- package/dist/shared/proactive/useSuggestionControls.js +118 -0
- package/dist/shared-assistant.js +301 -301
- package/dist/shared-proactive.d.ts +2 -0
- package/dist/shared-proactive.js +21 -0
- package/package.json +5 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { isSafeInAppPath as e } from "../navigation/inAppPath.js";
|
|
2
|
+
import { z as t } from "zod";
|
|
3
|
+
// src/shared/proactive/actions.ts
|
|
4
|
+
var n = Symbol("burdenoff.proactive.action"), r = class extends Error {
|
|
5
|
+
constructor(e) {
|
|
6
|
+
super(`The arguments of this "${e}" action are not valid.`), this.name = "ProactiveActionArgsError";
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
function i(e) {
|
|
10
|
+
return {
|
|
11
|
+
[n]: !0,
|
|
12
|
+
accepts: (t) => e.args.safeParse(t).success,
|
|
13
|
+
execute: async (t, n) => {
|
|
14
|
+
let i = e.args.safeParse(t);
|
|
15
|
+
if (!i.success) throw new r(n.action.type);
|
|
16
|
+
await e.run(i.data, n);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function a(e) {
|
|
21
|
+
return typeof e == "object" && !!e && e[n] === !0;
|
|
22
|
+
}
|
|
23
|
+
var o = t.string().trim().min(1).max(255), s = t.string().max(1e3).regex(/^\/(?!\/)\S*$/).refine(e), c = t.strictObject({ path: s }), l = t.strictObject({
|
|
24
|
+
entityType: o,
|
|
25
|
+
entityId: o,
|
|
26
|
+
prompt: t.string().trim().min(1).max(400).optional()
|
|
27
|
+
}), u = t.strictObject({ proposalId: o }), d = ["navigate", "open-in-assistant"];
|
|
28
|
+
function f(e) {
|
|
29
|
+
let t = e.isAllowedRoute ?? (() => !0), n = { navigate: i({
|
|
30
|
+
args: c.refine((e) => t(e.path)),
|
|
31
|
+
run: (e, t) => {
|
|
32
|
+
t.navigate(e.path);
|
|
33
|
+
}
|
|
34
|
+
}) };
|
|
35
|
+
e.canOpenAssistant !== !1 && (n["open-in-assistant"] = i({
|
|
36
|
+
args: l,
|
|
37
|
+
run: (t, n) => {
|
|
38
|
+
n.openInAssistant(t.prompt ?? e.defaultAssistantPrompt(n.suggestion));
|
|
39
|
+
}
|
|
40
|
+
}));
|
|
41
|
+
let r = e.reviewProposal;
|
|
42
|
+
return r && (n["review-proposal"] = i({
|
|
43
|
+
args: u,
|
|
44
|
+
run: (e, t) => r(e.proposalId, t)
|
|
45
|
+
})), n;
|
|
46
|
+
}
|
|
47
|
+
function p(e, t) {
|
|
48
|
+
let n = { ...e };
|
|
49
|
+
for (let [e, r] of Object.entries(t ?? {})) d.includes(e) ? console.warn(`[proactive] The "${e}" action is built in and cannot be replaced; configure it through the provider props instead.`) : a(r) ? n[e] = r : console.warn(`[proactive] The "${e}" action handler was not made with defineProactiveAction and is ignored.`);
|
|
50
|
+
return n;
|
|
51
|
+
}
|
|
52
|
+
function m(e, t) {
|
|
53
|
+
return e.actions.filter((e) => {
|
|
54
|
+
let n = Object.hasOwn(t, e.type) ? t[e.type] : void 0;
|
|
55
|
+
return n !== void 0 && n.accepts(e.args);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
async function h(e, t) {
|
|
59
|
+
let { action: n } = t, i = Object.hasOwn(e, n.type) ? e[n.type] : void 0;
|
|
60
|
+
if (!i) return { status: "unavailable" };
|
|
61
|
+
if (!i.accepts(n.args)) return { status: "invalid-args" };
|
|
62
|
+
try {
|
|
63
|
+
return await i.execute(n.args, t), { status: "done" };
|
|
64
|
+
} catch (e) {
|
|
65
|
+
return e instanceof r ? { status: "invalid-args" } : {
|
|
66
|
+
status: "failed",
|
|
67
|
+
error: e
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export { c as NAVIGATE_ARGS, l as OPEN_IN_ASSISTANT_ARGS, r as ProactiveActionArgsError, d as RESERVED_ACTION_TYPES, u as REVIEW_PROPOSAL_ARGS, f as createBuiltInActions, i as defineProactiveAction, a as isProactiveActionHandler, p as mergeActionRegistries, m as offeredActions, h as runProactiveAction };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ProactiveActivityEntity } from './types';
|
|
2
|
+
export declare const ACTIVITY_DEBOUNCE_MS = 2000;
|
|
3
|
+
/**
|
|
4
|
+
* The entity in a product's page context (`gatherPageContext()`), or null. Only
|
|
5
|
+
* `entityType` and `entityId` are read, and only values that match the report's
|
|
6
|
+
* strict patterns are kept.
|
|
7
|
+
*/
|
|
8
|
+
export declare function readActivityEntity(pageContext: unknown): ProactiveActivityEntity | null;
|
|
9
|
+
/** A stable key for an entity (or for "no entity"). */
|
|
10
|
+
export declare function activityKey(entity: ProactiveActivityEntity | null): string;
|
|
11
|
+
export interface ActivityReporterOptions {
|
|
12
|
+
report: (entity: ProactiveActivityEntity | null) => Promise<void>;
|
|
13
|
+
/** Told when a report fails; the reporter keeps going unless `stop()` is called. */
|
|
14
|
+
onError?: (error: unknown) => void;
|
|
15
|
+
debounceMs?: number;
|
|
16
|
+
setTimer?: (callback: () => void, ms: number) => unknown;
|
|
17
|
+
clearTimer?: (handle: unknown) => void;
|
|
18
|
+
}
|
|
19
|
+
export interface ActivityReporter {
|
|
20
|
+
/** Report the session start, with the entity open now (if any). Once. */
|
|
21
|
+
start(entity: ProactiveActivityEntity | null): void;
|
|
22
|
+
/** The entity the user has open now; reported after the debounce if it changed. */
|
|
23
|
+
update(entity: ProactiveActivityEntity | null): void;
|
|
24
|
+
/** Stop for good: cancels a pending report and ignores every later call. */
|
|
25
|
+
stop(): void;
|
|
26
|
+
}
|
|
27
|
+
export declare function createActivityReporter(options: ActivityReporterOptions): ActivityReporter;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ACTIVITY_ENTITY_ID_PATTERN as e, ACTIVITY_ENTITY_TYPE_PATTERN as t } from "./operations.js";
|
|
2
|
+
// src/shared/proactive/activity.ts
|
|
3
|
+
var n = 2e3;
|
|
4
|
+
function r(n) {
|
|
5
|
+
if (!n || typeof n != "object") return null;
|
|
6
|
+
let { entityType: r, entityId: i } = n;
|
|
7
|
+
return typeof r != "string" || typeof i != "string" || !t.test(r) || !e.test(i) ? null : {
|
|
8
|
+
entityType: r,
|
|
9
|
+
entityId: i
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function i(e) {
|
|
13
|
+
return e ? `${e.entityType}\u0000${e.entityId}` : "";
|
|
14
|
+
}
|
|
15
|
+
function a(e) {
|
|
16
|
+
let t = e.debounceMs ?? 2e3, n = e.setTimer ?? ((e, t) => setTimeout(e, t)), r = e.clearTimer ?? ((e) => clearTimeout(e)), a = !1, o = !1, s = null, c = null, l = null, u = (t) => {
|
|
17
|
+
s = i(t), e.report(t).catch((t) => e.onError?.(t));
|
|
18
|
+
}, d = () => {
|
|
19
|
+
l !== null && r(l), l = null, c = null;
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
start(e) {
|
|
23
|
+
a || o || (a = !0, u(e));
|
|
24
|
+
},
|
|
25
|
+
update(e) {
|
|
26
|
+
if (!a || o) return;
|
|
27
|
+
let r = i(e);
|
|
28
|
+
r !== c && (d(), r !== s && e !== null && (c = r, l = n(() => {
|
|
29
|
+
l = null, c = null, !o && r !== s && u(e);
|
|
30
|
+
}, t)));
|
|
31
|
+
},
|
|
32
|
+
stop() {
|
|
33
|
+
o = !0, d();
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export { n as ACTIVITY_DEBOUNCE_MS, i as activityKey, a as createActivityReporter, r as readActivityEntity };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ProactiveActionOutcome } from './actions';
|
|
2
|
+
import { AssistantTr } from '../assistant/i18n';
|
|
3
|
+
import { ProactiveAnchor, ProactiveSnoozeDuration, ProactiveSuggestion, ProactiveSuggestionAction } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* What a card needs to render a suggestion and act on it. The provider builds
|
|
6
|
+
* one and passes it to adapters and to its own components; an adapter's tree
|
|
7
|
+
* may sit outside the provider, so nothing here is read from React context.
|
|
8
|
+
*/
|
|
9
|
+
export interface SuggestionControls {
|
|
10
|
+
/** Translate a relative assistant key (the provider's product namespace). */
|
|
11
|
+
tr: AssistantTr;
|
|
12
|
+
/** Whether snoozing is available (the notification service supports it). */
|
|
13
|
+
canSnooze: boolean;
|
|
14
|
+
/** The actions that can run here: known type, valid arguments. */
|
|
15
|
+
offeredActions(suggestion: ProactiveSuggestion): readonly ProactiveSuggestionAction[];
|
|
16
|
+
/** Run an action. Call ONLY from a person's click. */
|
|
17
|
+
runAction(suggestion: ProactiveSuggestion, action: ProactiveSuggestionAction): Promise<ProactiveActionOutcome>;
|
|
18
|
+
/** Dismiss (archive) a suggestion. Resolves false when it failed. */
|
|
19
|
+
dismiss(suggestion: ProactiveSuggestion): Promise<boolean>;
|
|
20
|
+
/** Snooze a suggestion. Resolves false when it failed. */
|
|
21
|
+
snooze(suggestion: ProactiveSuggestion, duration: ProactiveSnoozeDuration): Promise<boolean>;
|
|
22
|
+
/** The card was opened: the suggestion counts as read. Best-effort. */
|
|
23
|
+
markSeen(suggestion: ProactiveSuggestion): void;
|
|
24
|
+
}
|
|
25
|
+
export interface SuggestionAnchorAdapter {
|
|
26
|
+
/**
|
|
27
|
+
* Can the adapter show this anchor right now (the node is on the canvas)?
|
|
28
|
+
* Absent: always. A suggestion it cannot show does not use a budget slot.
|
|
29
|
+
*/
|
|
30
|
+
canResolve?(anchor: ProactiveAnchor): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* The suggestions to render for this entity type, already budgeted and
|
|
33
|
+
* ordered. An empty list means: show none. Called again on every change.
|
|
34
|
+
*/
|
|
35
|
+
update(suggestions: readonly ProactiveSuggestion[], controls: SuggestionControls): void;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Register an adapter for `entityType`. Newest wins while several are
|
|
39
|
+
* registered (a route transition mounts the next page before the old one
|
|
40
|
+
* cleans up); the returned function removes exactly this registration.
|
|
41
|
+
*/
|
|
42
|
+
export declare function registerSuggestionAnchorAdapter(entityType: string, adapter: SuggestionAnchorAdapter): () => void;
|
|
43
|
+
/** The adapter in force for an entity type, or undefined. */
|
|
44
|
+
export declare function getSuggestionAnchorAdapter(entityType: string): SuggestionAnchorAdapter | undefined;
|
|
45
|
+
/** Every entity type that has an adapter. */
|
|
46
|
+
export declare function listSuggestionAnchorAdapterTypes(): string[];
|
|
47
|
+
/** Be told when an adapter is registered or removed. Returns the unsubscribe. */
|
|
48
|
+
export declare function subscribeSuggestionAnchorAdapters(listener: () => void): () => void;
|
|
49
|
+
/** Changes whenever an adapter is registered or removed. */
|
|
50
|
+
export declare function getSuggestionAnchorAdapterVersion(): number;
|
|
51
|
+
/** Remove every adapter (tests). */
|
|
52
|
+
export declare function clearSuggestionAnchorAdapters(): void;
|
|
53
|
+
/** Controls that do nothing: what a removed adapter is last called with. */
|
|
54
|
+
export declare const EMPTY_CONTROLS: SuggestionControls;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// src/shared/proactive/adapters.ts
|
|
2
|
+
var e = Symbol.for("burdenoff.fe-libs.proactive.anchorAdapters.v1");
|
|
3
|
+
function t() {
|
|
4
|
+
let t = globalThis, n = t[e];
|
|
5
|
+
if (n && n.stacks instanceof Map && n.listeners instanceof Set) return typeof n.version != "number" && (n.version = 0), n;
|
|
6
|
+
let r = {
|
|
7
|
+
stacks: /* @__PURE__ */ new Map(),
|
|
8
|
+
listeners: /* @__PURE__ */ new Set(),
|
|
9
|
+
version: 0
|
|
10
|
+
};
|
|
11
|
+
return t[e] = r, r;
|
|
12
|
+
}
|
|
13
|
+
function n() {
|
|
14
|
+
let e = t();
|
|
15
|
+
e.version += 1;
|
|
16
|
+
for (let t of e.listeners) t();
|
|
17
|
+
}
|
|
18
|
+
function r(e, r) {
|
|
19
|
+
let { stacks: i } = t(), a = Symbol(e), o = i.get(e) ?? [];
|
|
20
|
+
o.push({
|
|
21
|
+
token: a,
|
|
22
|
+
adapter: r
|
|
23
|
+
}), i.set(e, o), n();
|
|
24
|
+
let s = !1;
|
|
25
|
+
return () => {
|
|
26
|
+
if (s) return;
|
|
27
|
+
s = !0;
|
|
28
|
+
let i = t().stacks.get(e);
|
|
29
|
+
if (!i) return;
|
|
30
|
+
let o = i.filter((e) => e.token !== a);
|
|
31
|
+
o.length === 0 ? t().stacks.delete(e) : t().stacks.set(e, o), r.update([], l), n();
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function i(e) {
|
|
35
|
+
let n = t().stacks.get(e);
|
|
36
|
+
return n?.[n.length - 1]?.adapter;
|
|
37
|
+
}
|
|
38
|
+
function a() {
|
|
39
|
+
return [...t().stacks.keys()];
|
|
40
|
+
}
|
|
41
|
+
function o(e) {
|
|
42
|
+
let { listeners: n } = t();
|
|
43
|
+
return n.add(e), () => {
|
|
44
|
+
n.delete(e);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function s() {
|
|
48
|
+
return t().version;
|
|
49
|
+
}
|
|
50
|
+
function c() {
|
|
51
|
+
t().stacks.clear(), n();
|
|
52
|
+
}
|
|
53
|
+
var l = {
|
|
54
|
+
tr: (e, t, n) => n ? Object.entries(n).reduce((e, [t, n]) => e.split(`{{${t}}}`).join(String(n)), t) : t,
|
|
55
|
+
canSnooze: !1,
|
|
56
|
+
offeredActions: () => [],
|
|
57
|
+
runAction: () => Promise.resolve({ status: "unavailable" }),
|
|
58
|
+
dismiss: () => Promise.resolve(!1),
|
|
59
|
+
snooze: () => Promise.resolve(!1),
|
|
60
|
+
markSeen: () => {}
|
|
61
|
+
};
|
|
62
|
+
export { l as EMPTY_CONTROLS, c as clearSuggestionAnchorAdapters, i as getSuggestionAnchorAdapter, s as getSuggestionAnchorAdapterVersion, a as listSuggestionAnchorAdapterTypes, r as registerSuggestionAnchorAdapter, o as subscribeSuggestionAnchorAdapters };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ProactiveAnchor } from './types';
|
|
2
|
+
/** The attribute a product puts on an element a suggestion may anchor to. */
|
|
3
|
+
export declare const SUGGEST_ANCHOR_ATTRIBUTE = "data-suggest-anchor";
|
|
4
|
+
/**
|
|
5
|
+
* Can this anchor be written as a C7 attribute value? Each segment must be
|
|
6
|
+
* non-empty and free of the `:` separator and of whitespace; a suggestion whose
|
|
7
|
+
* anchor cannot be written this way still shows in the inbox and through an
|
|
8
|
+
* adapter, just never against a DOM element.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isDomAddressableAnchor(anchor: ProactiveAnchor): boolean;
|
|
11
|
+
/** The attribute value for an anchor, or null when it is not DOM-addressable. */
|
|
12
|
+
export declare function formatSuggestAnchor(anchor: ProactiveAnchor): string | null;
|
|
13
|
+
/** An attribute value back to an anchor, or null when it is malformed. */
|
|
14
|
+
export declare function parseSuggestAnchor(value: string | null | undefined): ProactiveAnchor | null;
|
|
15
|
+
/**
|
|
16
|
+
* Props that mark an element as an anchor, for products to spread:
|
|
17
|
+
* `<tr {...suggestAnchorProps({ entityType: 'workflow-run', entityId: run.id })}>`.
|
|
18
|
+
* Empty when the anchor is not DOM-addressable.
|
|
19
|
+
*/
|
|
20
|
+
export declare function suggestAnchorProps(anchor: ProactiveAnchor): Record<string, string>;
|
|
21
|
+
/**
|
|
22
|
+
* How well an element's anchor value fits a suggestion's anchor:
|
|
23
|
+
* - 2: exactly the same entity and part;
|
|
24
|
+
* - 1: the same entity, where the suggestion names a part the page does not mark
|
|
25
|
+
* (the comment goes on the entity), or the suggestion names no part and the
|
|
26
|
+
* element marks one part of the entity;
|
|
27
|
+
* - 0: no fit.
|
|
28
|
+
*/
|
|
29
|
+
export declare function anchorMatchScore(elementValue: string | null, anchor: ProactiveAnchor): number;
|
|
30
|
+
/** The parts of an element the resolver reads; a seam for tests. */
|
|
31
|
+
export interface AnchorCandidate {
|
|
32
|
+
getAttribute(name: string): string | null;
|
|
33
|
+
getBoundingClientRect(): {
|
|
34
|
+
width: number;
|
|
35
|
+
height: number;
|
|
36
|
+
};
|
|
37
|
+
isConnected?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** A candidate occupies space on the page (not `display: none`, not detached). */
|
|
40
|
+
export declare function isRenderedCandidate(candidate: AnchorCandidate): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* The best element for `anchor` among `candidates`, or null. The first element
|
|
43
|
+
* with the highest score wins; elements that take no space are skipped.
|
|
44
|
+
*/
|
|
45
|
+
export declare function findAnchorElement<T extends AnchorCandidate>(candidates: Iterable<T>, anchor: ProactiveAnchor): T | null;
|
|
46
|
+
/** Every element on the page that declares an anchor. */
|
|
47
|
+
export declare function queryAnchorCandidates(root: ParentNode | null | undefined): Element[];
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// src/shared/proactive/anchors.ts
|
|
2
|
+
var e = "data-suggest-anchor";
|
|
3
|
+
function t(e) {
|
|
4
|
+
return [
|
|
5
|
+
e.entityType,
|
|
6
|
+
e.entityId,
|
|
7
|
+
...e.part ? [e.part] : []
|
|
8
|
+
].every((e) => e.length > 0 && !e.includes(":") && !/\s/.test(e));
|
|
9
|
+
}
|
|
10
|
+
function n(e) {
|
|
11
|
+
if (!t(e)) return null;
|
|
12
|
+
let n = `${e.entityType}:${e.entityId}`;
|
|
13
|
+
return e.part ? `${n}:${e.part}` : n;
|
|
14
|
+
}
|
|
15
|
+
function r(e) {
|
|
16
|
+
if (typeof e != "string") return null;
|
|
17
|
+
let t = e.split(":");
|
|
18
|
+
if (t.length < 2 || t.length > 3 || t.some((e) => e.length === 0 || /\s/.test(e))) return null;
|
|
19
|
+
let [n, r, i] = t;
|
|
20
|
+
return i === void 0 ? {
|
|
21
|
+
entityType: n,
|
|
22
|
+
entityId: r
|
|
23
|
+
} : {
|
|
24
|
+
entityType: n,
|
|
25
|
+
entityId: r,
|
|
26
|
+
part: i
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function i(t) {
|
|
30
|
+
let r = n(t);
|
|
31
|
+
return r === null ? {} : { [e]: r };
|
|
32
|
+
}
|
|
33
|
+
function a(e, n) {
|
|
34
|
+
let i = r(e);
|
|
35
|
+
return !i || !t(n) || i.entityType !== n.entityType || i.entityId !== n.entityId ? 0 : i.part === n.part ? 2 : n.part && i.part === void 0 || !n.part && i.part !== void 0 ? 1 : 0;
|
|
36
|
+
}
|
|
37
|
+
function o(e) {
|
|
38
|
+
if (e.isConnected === !1) return !1;
|
|
39
|
+
let t = e.getBoundingClientRect();
|
|
40
|
+
return t.width > 0 || t.height > 0;
|
|
41
|
+
}
|
|
42
|
+
function s(t, n) {
|
|
43
|
+
let r = null, i = 0;
|
|
44
|
+
for (let s of t) {
|
|
45
|
+
let t = a(s.getAttribute(e), n);
|
|
46
|
+
if (t > i && o(s) && (r = s, i = t, t === 2)) break;
|
|
47
|
+
}
|
|
48
|
+
return r;
|
|
49
|
+
}
|
|
50
|
+
function c(t) {
|
|
51
|
+
return t ? Array.from(t.querySelectorAll(`[${e}]`)) : [];
|
|
52
|
+
}
|
|
53
|
+
export { e as SUGGEST_ANCHOR_ATTRIBUTE, a as anchorMatchScore, s as findAnchorElement, n as formatSuggestAnchor, t as isDomAddressableAnchor, o as isRenderedCandidate, r as parseSuggestAnchor, c as queryAnchorCandidates, i as suggestAnchorProps };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ProactiveSeverity, ProactiveSuggestion } from './types';
|
|
2
|
+
export declare const DEFAULT_MAX_VISIBLE_PINS = 3;
|
|
3
|
+
/** A product may raise the budget, but never past this. */
|
|
4
|
+
export declare const MAX_VISIBLE_PINS_LIMIT = 10;
|
|
5
|
+
/** Higher is more important. */
|
|
6
|
+
export declare function severityRank(severity: ProactiveSeverity): number;
|
|
7
|
+
/** Severity descending, then newest first, then a stable id order. */
|
|
8
|
+
export declare function compareSuggestions(a: ProactiveSuggestion, b: ProactiveSuggestion): number;
|
|
9
|
+
/** A sorted copy; the input is not changed. */
|
|
10
|
+
export declare function orderSuggestions(suggestions: readonly ProactiveSuggestion[]): ProactiveSuggestion[];
|
|
11
|
+
/** The budget a product asked for, clamped to 0…{@link MAX_VISIBLE_PINS_LIMIT}. */
|
|
12
|
+
export declare function clampPinBudget(requested: number | undefined): number;
|
|
13
|
+
/**
|
|
14
|
+
* The suggestions that get an inline comment: walking `suggestions` in budget
|
|
15
|
+
* order, the first `maxVisiblePins` that `canPin` accepts.
|
|
16
|
+
*/
|
|
17
|
+
export declare function selectPinnedSuggestions(suggestions: readonly ProactiveSuggestion[], canPin: (suggestion: ProactiveSuggestion) => boolean, maxVisiblePins?: number): ProactiveSuggestion[];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createdAtMs as e } from "./metadata.js";
|
|
2
|
+
// src/shared/proactive/budget.ts
|
|
3
|
+
var t = 3, n = 10, r = {
|
|
4
|
+
urgent: 3,
|
|
5
|
+
high: 2,
|
|
6
|
+
medium: 1,
|
|
7
|
+
low: 0
|
|
8
|
+
};
|
|
9
|
+
function i(e) {
|
|
10
|
+
return r[e];
|
|
11
|
+
}
|
|
12
|
+
function a(t, n) {
|
|
13
|
+
let r = i(n.severity) - i(t.severity);
|
|
14
|
+
if (r !== 0) return r;
|
|
15
|
+
let a = e(n) - e(t);
|
|
16
|
+
return a === 0 ? t.notificationId.localeCompare(n.notificationId) : a;
|
|
17
|
+
}
|
|
18
|
+
function o(e) {
|
|
19
|
+
return [...e].sort(a);
|
|
20
|
+
}
|
|
21
|
+
function s(e) {
|
|
22
|
+
return e === void 0 || !Number.isFinite(e) ? 3 : Math.max(0, Math.min(10, Math.floor(e)));
|
|
23
|
+
}
|
|
24
|
+
function c(e, t, n = 3) {
|
|
25
|
+
let r = s(n), i = [];
|
|
26
|
+
if (r === 0) return i;
|
|
27
|
+
for (let n of o(e)) if (t(n) && (i.push(n), i.length === r)) break;
|
|
28
|
+
return i;
|
|
29
|
+
}
|
|
30
|
+
export { t as DEFAULT_MAX_VISIBLE_PINS, n as MAX_VISIBLE_PINS_LIMIT, s as clampPinBudget, a as compareSuggestions, o as orderSuggestions, c as selectPinnedSuggestions, i as severityRank };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** The root fields and types of contracts C3 and C5 this module uses. */
|
|
2
|
+
export declare const PROACTIVE_SCHEMA_FIELDS: readonly ["reportProactiveActivity", "myProactiveSettings", "setMyProactiveSettings", "snoozeNotification", "unsnoozeNotification", "category", "snoozedUntil", "includeSnoozed"];
|
|
3
|
+
export type ProactiveSchemaField = (typeof PROACTIVE_SCHEMA_FIELDS)[number];
|
|
4
|
+
/**
|
|
5
|
+
* Did the gateway refuse because it does not know `field`, as a root field, a
|
|
6
|
+
* field of an existing type, an input field or an argument?
|
|
7
|
+
*
|
|
8
|
+
* Matches the gateway's missing-`@rbac` refusal and `Cannot query field` through
|
|
9
|
+
* the assistant's {@link isMissingGatewayFieldError}, plus the validation
|
|
10
|
+
* messages for an unknown input field (`Field "category" is not defined by type
|
|
11
|
+
* "NotificationFilterInput"`) and an unknown argument (`Unknown argument "until"`).
|
|
12
|
+
*/
|
|
13
|
+
export declare function isMissingProactiveField(error: unknown, field: string): boolean;
|
|
14
|
+
/** Does the error say the gateway lacks ANY of `fields`? */
|
|
15
|
+
export declare function isMissingAnyProactiveField(error: unknown, fields?: readonly string[]): boolean;
|
|
16
|
+
/** The `extensions.code` values carried by a GraphQL error, at any depth Apollo uses. */
|
|
17
|
+
export declare function errorCodesOf(error: unknown): string[];
|
|
18
|
+
/** The orchestrator could not store the delivery frequency (wspace-sandbox-svc). */
|
|
19
|
+
export declare const PREFERENCES_UNAVAILABLE_CODE = "PROACTIVE_PREFERENCES_UNAVAILABLE";
|
|
20
|
+
export declare function isPreferencesUnavailableError(error: unknown): boolean;
|
|
21
|
+
export declare function markProactiveUnsupported(product: string): void;
|
|
22
|
+
export declare function isProactiveUnsupported(product: string): boolean;
|
|
23
|
+
/** Be told when a product is found unsupported (for `useSyncExternalStore`). */
|
|
24
|
+
export declare function subscribeProactiveCapabilities(listener: () => void): () => void;
|
|
25
|
+
/** Forget every detection (tests). */
|
|
26
|
+
export declare function resetProactiveCapabilities(): void;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { isMissingGatewayFieldError as e } from "../assistant/capabilities.js";
|
|
2
|
+
// src/shared/proactive/capabilities.ts
|
|
3
|
+
var t = [
|
|
4
|
+
"reportProactiveActivity",
|
|
5
|
+
"myProactiveSettings",
|
|
6
|
+
"setMyProactiveSettings",
|
|
7
|
+
"snoozeNotification",
|
|
8
|
+
"unsnoozeNotification",
|
|
9
|
+
"category",
|
|
10
|
+
"snoozedUntil",
|
|
11
|
+
"includeSnoozed"
|
|
12
|
+
], n = (e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
13
|
+
function r(e) {
|
|
14
|
+
let t = [], n = (e) => {
|
|
15
|
+
typeof e == "string" && e.length > 0 && t.push(e);
|
|
16
|
+
};
|
|
17
|
+
if (e instanceof Error ? n(e.message) : n(String(e)), e && typeof e == "object") {
|
|
18
|
+
let t = e.errors;
|
|
19
|
+
if (Array.isArray(t)) for (let e of t) n(e?.message);
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
}
|
|
23
|
+
function i(t, i) {
|
|
24
|
+
if (e(t, i)) return !0;
|
|
25
|
+
let a = `["'“]${n(i)}["'”]`, o = RegExp(`Field ${a} is not defined by type`), s = RegExp(`Unknown argument ${a}`), c = RegExp(`Cannot query field ${a}`);
|
|
26
|
+
return r(t).some((e) => o.test(e) || s.test(e) || c.test(e));
|
|
27
|
+
}
|
|
28
|
+
function a(e, n = t) {
|
|
29
|
+
return n.some((t) => i(e, t));
|
|
30
|
+
}
|
|
31
|
+
function o(e) {
|
|
32
|
+
let t = [], n = (e) => {
|
|
33
|
+
if (!e || typeof e != "object") return;
|
|
34
|
+
let r = e.extensions?.code;
|
|
35
|
+
typeof r == "string" && t.push(r);
|
|
36
|
+
let i = e.errors;
|
|
37
|
+
Array.isArray(i) && i.forEach(n);
|
|
38
|
+
};
|
|
39
|
+
return n(e), t;
|
|
40
|
+
}
|
|
41
|
+
var s = "PROACTIVE_PREFERENCES_UNAVAILABLE";
|
|
42
|
+
function c(e) {
|
|
43
|
+
return o(e).includes("PROACTIVE_PREFERENCES_UNAVAILABLE") || r(e).some((e) => e.includes("PROACTIVE_PREFERENCES_UNAVAILABLE"));
|
|
44
|
+
}
|
|
45
|
+
var l = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Set();
|
|
46
|
+
function d() {
|
|
47
|
+
for (let e of u) e();
|
|
48
|
+
}
|
|
49
|
+
function f(e) {
|
|
50
|
+
l.has(e) || (l.add(e), d());
|
|
51
|
+
}
|
|
52
|
+
function p(e) {
|
|
53
|
+
return l.has(e);
|
|
54
|
+
}
|
|
55
|
+
function m(e) {
|
|
56
|
+
return u.add(e), () => {
|
|
57
|
+
u.delete(e);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function h() {
|
|
61
|
+
l.clear(), d();
|
|
62
|
+
}
|
|
63
|
+
export { s as PREFERENCES_UNAVAILABLE_CODE, t as PROACTIVE_SCHEMA_FIELDS, o as errorCodesOf, a as isMissingAnyProactiveField, i as isMissingProactiveField, c as isPreferencesUnavailableError, p as isProactiveUnsupported, f as markProactiveUnsupported, h as resetProactiveCapabilities, m as subscribeProactiveCapabilities };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run `task` once for a burst of requests: the first `schedule()` starts a
|
|
3
|
+
* timer, later ones within `ms` join it, and `cancel()` drops a pending run.
|
|
4
|
+
* The proactive provider uses it so a flurry of live-update signals reads the
|
|
5
|
+
* suggestion list once.
|
|
6
|
+
*/
|
|
7
|
+
export interface Coalescer {
|
|
8
|
+
schedule(): void;
|
|
9
|
+
cancel(): void;
|
|
10
|
+
}
|
|
11
|
+
export declare function createCoalescer(task: () => void, ms: number): Coalescer;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/shared/proactive/coalesce.ts
|
|
2
|
+
function e(e, t) {
|
|
3
|
+
let n = null;
|
|
4
|
+
return {
|
|
5
|
+
schedule() {
|
|
6
|
+
n === null && (n = setTimeout(() => {
|
|
7
|
+
n = null, e();
|
|
8
|
+
}, t));
|
|
9
|
+
},
|
|
10
|
+
cancel() {
|
|
11
|
+
n !== null && clearTimeout(n), n = null;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export { e as createCoalescer };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { SuggestionControls } from './adapters';
|
|
2
|
+
import { ProactiveAnchor, ProactiveSettings, ProactiveSettingsInput, ProactiveStatus, ProactiveSuggestion } from './types';
|
|
3
|
+
export type ProactiveSaveOutcome = {
|
|
4
|
+
status: 'saved';
|
|
5
|
+
settings: ProactiveSettings;
|
|
6
|
+
/** The frequency could not be stored yet; everything else was. */
|
|
7
|
+
frequencyUnavailable: boolean;
|
|
8
|
+
} | {
|
|
9
|
+
status: 'failed';
|
|
10
|
+
} | {
|
|
11
|
+
status: 'unavailable';
|
|
12
|
+
};
|
|
13
|
+
export interface ProactiveContextValue {
|
|
14
|
+
product: string;
|
|
15
|
+
status: ProactiveStatus;
|
|
16
|
+
settings: ProactiveSettings | null;
|
|
17
|
+
/** Every live suggestion, severity-ordered (the inbox). */
|
|
18
|
+
suggestions: readonly ProactiveSuggestion[];
|
|
19
|
+
controls: SuggestionControls;
|
|
20
|
+
maxVisiblePins: number;
|
|
21
|
+
saveSettings(input: ProactiveSettingsInput): Promise<ProactiveSaveOutcome>;
|
|
22
|
+
/** Read the settings and suggestions again. */
|
|
23
|
+
refresh(): void;
|
|
24
|
+
}
|
|
25
|
+
export declare const ProactiveContextProvider: import('react').Provider<ProactiveContextValue | null>;
|
|
26
|
+
/** The proactive state in force, or null outside a `ProactiveProvider`. */
|
|
27
|
+
export declare function useProactiveOrNull(): ProactiveContextValue | null;
|
|
28
|
+
/** The live suggestions, severity-ordered; empty outside a provider or while off. */
|
|
29
|
+
export declare function useProactiveSuggestions(): readonly ProactiveSuggestion[];
|
|
30
|
+
/** How many live suggestions there are (the count badge). */
|
|
31
|
+
export declare function useProactiveSuggestionCount(): number;
|
|
32
|
+
export interface SuggestionAnchorAdapterState {
|
|
33
|
+
suggestions: readonly ProactiveSuggestion[];
|
|
34
|
+
controls: SuggestionControls;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Register a render adapter for `entityType` for as long as the calling
|
|
38
|
+
* component is mounted, and get the suggestions it should render.
|
|
39
|
+
*
|
|
40
|
+
* `canResolve` may change between renders; the latest one is always used.
|
|
41
|
+
*/
|
|
42
|
+
export declare function useSuggestionAnchorAdapter(entityType: string, canResolve?: (anchor: ProactiveAnchor) => boolean): SuggestionAnchorAdapterState;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { EMPTY_CONTROLS as e, registerSuggestionAnchorAdapter as t } from "./adapters.js";
|
|
2
|
+
import { createContext as n, useContext as r, useEffect as i, useRef as a, useState as o } from "react";
|
|
3
|
+
// src/shared/proactive/context.ts
|
|
4
|
+
var s = n(null), c = s.Provider;
|
|
5
|
+
function l() {
|
|
6
|
+
return r(s);
|
|
7
|
+
}
|
|
8
|
+
var u = [];
|
|
9
|
+
function d() {
|
|
10
|
+
let e = r(s);
|
|
11
|
+
return e?.status === "ready" ? e.suggestions : u;
|
|
12
|
+
}
|
|
13
|
+
function f() {
|
|
14
|
+
return d().length;
|
|
15
|
+
}
|
|
16
|
+
function p(n, r) {
|
|
17
|
+
let [s, c] = o({
|
|
18
|
+
suggestions: u,
|
|
19
|
+
controls: e
|
|
20
|
+
}), l = a(r);
|
|
21
|
+
return i(() => {
|
|
22
|
+
l.current = r;
|
|
23
|
+
}), i(() => t(n, {
|
|
24
|
+
canResolve: (e) => l.current?.(e) ?? !0,
|
|
25
|
+
update: (e, t) => c({
|
|
26
|
+
suggestions: e,
|
|
27
|
+
controls: t
|
|
28
|
+
})
|
|
29
|
+
}), [n]), s;
|
|
30
|
+
}
|
|
31
|
+
export { c as ProactiveContextProvider, l as useProactiveOrNull, f as useProactiveSuggestionCount, d as useProactiveSuggestions, p as useSuggestionAnchorAdapter };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const PROACTIVE_GLOBAL_FLAG = "proactive.enabled";
|
|
2
|
+
/** The product's own flag key, e.g. `proactive.fluidgrids.enabled`. */
|
|
3
|
+
export declare function proactiveProductFlag(product: string): string;
|
|
4
|
+
/** Both flags on for `product` (false while flags load, and with no provider). */
|
|
5
|
+
export declare function useProactiveFlagsEnabled(product: string): boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useOptionalFeatureFlag as e } from "../feature-flags/useFeatureFlag.js";
|
|
2
|
+
// src/shared/proactive/flags.ts
|
|
3
|
+
var t = "proactive.enabled";
|
|
4
|
+
function n(e) {
|
|
5
|
+
return `proactive.${e}.enabled`;
|
|
6
|
+
}
|
|
7
|
+
function r(r) {
|
|
8
|
+
let i = e(t, !1), a = e(n(r || "unknown"), !1);
|
|
9
|
+
return r.length > 0 && i && a;
|
|
10
|
+
}
|
|
11
|
+
export { t as PROACTIVE_GLOBAL_FLAG, n as proactiveProductFlag, r as useProactiveFlagsEnabled };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ★ BOFF-13165: proactive AI suggestions — `@burdenoff/fe-libs/shared/proactive`.
|
|
3
|
+
*
|
|
4
|
+
* Suggestions found by the proactive agent (epic BOFF-13159) arrive as in-app
|
|
5
|
+
* notifications and are shown as inline comments anchored to the page and in an
|
|
6
|
+
* inbox. Every action they offer runs only when the person clicks it.
|
|
7
|
+
*
|
|
8
|
+
* ```tsx
|
|
9
|
+
* // once, next to the assistant overlay, inside AssistantProductProvider
|
|
10
|
+
* <ProactiveProvider navigate={navigate} actions={MY_PROACTIVE_ACTIONS} />
|
|
11
|
+
*
|
|
12
|
+
* // on anything a suggestion may be about
|
|
13
|
+
* <tr {...suggestAnchorProps({ entityType: 'workflow-run', entityId: run.id })}>…</tr>
|
|
14
|
+
*
|
|
15
|
+
* // the inbox and the settings, wherever the product wants them
|
|
16
|
+
* <ProactiveInboxButton />
|
|
17
|
+
* <ProactiveSettingsPanel productName="FluidGrids" />
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export * from './types';
|
|
21
|
+
export * from './metadata';
|
|
22
|
+
export * from './anchors';
|
|
23
|
+
export * from './budget';
|
|
24
|
+
export * from './actions';
|
|
25
|
+
export * from './capabilities';
|
|
26
|
+
export * from './operations';
|
|
27
|
+
export * from './transport';
|
|
28
|
+
export * from './adapters';
|
|
29
|
+
export * from './activity';
|
|
30
|
+
export * from './snooze';
|
|
31
|
+
export * from './flags';
|
|
32
|
+
export * from './context';
|
|
33
|
+
export { ProactiveProvider, type ProactiveProviderProps } from './ProactiveProvider';
|
|
34
|
+
export * from './severityCopy';
|
|
35
|
+
export * from './ui/SuggestionCard';
|
|
36
|
+
export * from './ui/SuggestionBadge';
|
|
37
|
+
export * from './ui/anchorLayerDom';
|
|
38
|
+
export * from './ui/SuggestionAnchorsLayer';
|
|
39
|
+
export * from './ui/ProactiveInbox';
|
|
40
|
+
export * from './ui/ProactiveSettingsPanel';
|