@burdenoff/fe-libs 2026.1112.6 → 2026.1113.2

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.
Files changed (57) hide show
  1. package/dist/shared/assistant/i18nManifest.d.ts +40 -0
  2. package/dist/shared/assistant/i18nManifest.js +40 -0
  3. package/dist/shared/proactive/ProactiveProvider.d.ts +67 -0
  4. package/dist/shared/proactive/ProactiveProvider.js +128 -0
  5. package/dist/shared/proactive/actions.d.ts +101 -0
  6. package/dist/shared/proactive/actions.js +71 -0
  7. package/dist/shared/proactive/activity.d.ts +27 -0
  8. package/dist/shared/proactive/activity.js +37 -0
  9. package/dist/shared/proactive/adapters.d.ts +54 -0
  10. package/dist/shared/proactive/adapters.js +62 -0
  11. package/dist/shared/proactive/anchors.d.ts +47 -0
  12. package/dist/shared/proactive/anchors.js +53 -0
  13. package/dist/shared/proactive/budget.d.ts +17 -0
  14. package/dist/shared/proactive/budget.js +30 -0
  15. package/dist/shared/proactive/capabilities.d.ts +26 -0
  16. package/dist/shared/proactive/capabilities.js +63 -0
  17. package/dist/shared/proactive/coalesce.d.ts +11 -0
  18. package/dist/shared/proactive/coalesce.js +15 -0
  19. package/dist/shared/proactive/context.d.ts +42 -0
  20. package/dist/shared/proactive/context.js +31 -0
  21. package/dist/shared/proactive/flags.d.ts +5 -0
  22. package/dist/shared/proactive/flags.js +11 -0
  23. package/dist/shared/proactive/index.d.ts +40 -0
  24. package/dist/shared/proactive/metadata.d.ts +48 -0
  25. package/dist/shared/proactive/metadata.js +126 -0
  26. package/dist/shared/proactive/operations.d.ts +96 -0
  27. package/dist/shared/proactive/operations.js +117 -0
  28. package/dist/shared/proactive/severityCopy.d.ts +4 -0
  29. package/dist/shared/proactive/severityCopy.js +10 -0
  30. package/dist/shared/proactive/snooze.d.ts +4 -0
  31. package/dist/shared/proactive/snooze.js +9 -0
  32. package/dist/shared/proactive/transport.d.ts +32 -0
  33. package/dist/shared/proactive/transport.js +124 -0
  34. package/dist/shared/proactive/types.d.ts +83 -0
  35. package/dist/shared/proactive/ui/ProactiveInbox.d.ts +20 -0
  36. package/dist/shared/proactive/ui/ProactiveInbox.js +78 -0
  37. package/dist/shared/proactive/ui/ProactiveSettingsPanel.d.ts +8 -0
  38. package/dist/shared/proactive/ui/ProactiveSettingsPanel.js +210 -0
  39. package/dist/shared/proactive/ui/SuggestionAnchorsLayer.d.ts +9 -0
  40. package/dist/shared/proactive/ui/SuggestionAnchorsLayer.js +140 -0
  41. package/dist/shared/proactive/ui/SuggestionBadge.d.ts +11 -0
  42. package/dist/shared/proactive/ui/SuggestionBadge.js +53 -0
  43. package/dist/shared/proactive/ui/SuggestionCard.d.ts +23 -0
  44. package/dist/shared/proactive/ui/SuggestionCard.js +119 -0
  45. package/dist/shared/proactive/ui/anchorLayerDom.d.ts +28 -0
  46. package/dist/shared/proactive/ui/anchorLayerDom.js +23 -0
  47. package/dist/shared/proactive/useProactiveSession.d.ts +56 -0
  48. package/dist/shared/proactive/useProactiveSession.js +150 -0
  49. package/dist/shared/proactive/useSuggestionControls.d.ts +25 -0
  50. package/dist/shared/proactive/useSuggestionControls.js +118 -0
  51. package/dist/shared/providers/shell/PermissionProvider.d.ts +16 -0
  52. package/dist/shared/providers/shell/PermissionProvider.js +51 -30
  53. package/dist/shared/providers/shell/index.d.ts +1 -1
  54. package/dist/shared-proactive.d.ts +2 -0
  55. package/dist/shared-proactive.js +21 -0
  56. package/dist/shared-providers-shell.js +14 -14
  57. package/package.json +5 -1
@@ -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';
@@ -0,0 +1,48 @@
1
+ import { ProactiveSeverity, ProactiveSuggestion } from './types';
2
+ /** The notification category every proactive suggestion carries (contract C3). */
3
+ export declare const PROACTIVE_CATEGORY = "proactive";
4
+ /** The payload discriminator and version this client understands (contract C4). */
5
+ export declare const PROACTIVE_SUGGESTION_KIND = "proactive-suggestion";
6
+ export declare const PROACTIVE_SUGGESTION_VERSION = 1;
7
+ export declare const PROACTIVE_TITLE_MAX = 80;
8
+ export declare const PROACTIVE_WHY_MAX = 400;
9
+ export declare const PROACTIVE_ACTION_LABEL_MAX = 60;
10
+ /** At most this many actions are kept per suggestion; the rest are ignored. */
11
+ export declare const PROACTIVE_MAX_ACTIONS = 4;
12
+ export declare const PROACTIVE_SEVERITIES: readonly ProactiveSeverity[];
13
+ /** Product slug: the same shape the assistant accepts for `x-product-id`. */
14
+ export declare const PROACTIVE_PRODUCT_PATTERN: RegExp;
15
+ /** An action type: a built-in (`navigate`, …) or a product-registered one. */
16
+ export declare const PROACTIVE_ACTION_TYPE_PATTERN: RegExp;
17
+ /**
18
+ * Plain text, safe to render as one line or paragraph: unsafe characters become
19
+ * spaces, runs of whitespace collapse to one space, and the ends are trimmed.
20
+ */
21
+ export declare function normalizePlainText(value: string): string;
22
+ /** The fields of a notification row this module reads. */
23
+ export interface ProactiveNotificationRow {
24
+ id: string;
25
+ appName?: string | null;
26
+ category?: string | null;
27
+ isRead?: boolean | null;
28
+ createdAt?: string | null;
29
+ snoozedUntil?: string | null;
30
+ archivedAt?: string | null;
31
+ metadata?: unknown;
32
+ }
33
+ /**
34
+ * One notification row to a suggestion, or null when it is not a valid, active
35
+ * proactive suggestion for `product`.
36
+ *
37
+ * Refused: another category, another product (on the row or in the payload),
38
+ * an archived row, a row snoozed into the future, and any payload that does not
39
+ * match contract C4 version 1.
40
+ */
41
+ export declare function parseProactiveSuggestion(row: ProactiveNotificationRow, product: string, now?: number): ProactiveSuggestion | null;
42
+ /**
43
+ * Every valid suggestion among `rows`, one per finding: when two notifications
44
+ * carry the same `findingKey`, the newer one wins.
45
+ */
46
+ export declare function parseProactiveSuggestions(rows: readonly ProactiveNotificationRow[], product: string, now?: number): ProactiveSuggestion[];
47
+ /** A suggestion's creation time in ms, or 0 when it cannot be read. */
48
+ export declare function createdAtMs(suggestion: Pick<ProactiveSuggestion, 'createdAt'>): number;
@@ -0,0 +1,126 @@
1
+ import { z as e } from "zod";
2
+ // src/shared/proactive/metadata.ts
3
+ var t = "proactive", n = "proactive-suggestion", r = 1, i = 80, a = 400, o = 60, s = 4, c = [
4
+ "low",
5
+ "medium",
6
+ "high",
7
+ "urgent"
8
+ ], l = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/, u = /^[a-z][a-z0-9-]{0,63}$/;
9
+ function d(e) {
10
+ return e <= 31 || e >= 127 && e <= 159 || e === 8206 || e === 8207 || e >= 8234 && e <= 8238 || e >= 8294 && e <= 8297;
11
+ }
12
+ function f(e) {
13
+ for (let t = 0; t < e.length; t += 1) if (d(e.charCodeAt(t)) || /\s/.test(e[t] ?? "")) return !1;
14
+ return !0;
15
+ }
16
+ function p(e) {
17
+ let t = "";
18
+ for (let n = 0; n < e.length; n += 1) t += d(e.charCodeAt(n)) ? " " : e[n];
19
+ return t.replace(/\s+/g, " ").trim();
20
+ }
21
+ var m = (t) => e.string().transform(p).pipe(e.string().min(1).max(t)), h = (t) => e.string().min(1).max(t).refine(f, "must be one segment of printable text"), g = e.object({
22
+ entityType: h(64),
23
+ entityId: h(256),
24
+ part: h(128).optional()
25
+ }), _ = e.object({
26
+ id: h(64),
27
+ type: e.string().regex(u),
28
+ label: m(60),
29
+ args: e.record(e.string(), e.unknown()).optional()
30
+ }), v = e.object({
31
+ jobId: e.string().max(256).optional(),
32
+ model: e.string().max(256).optional(),
33
+ packVersion: e.string().min(1).max(64),
34
+ createdAt: e.string().min(1).max(64)
35
+ }), y = e.object({
36
+ kind: e.literal(n),
37
+ v: e.literal(1),
38
+ suggestionId: h(128),
39
+ findingKey: e.string().min(1).max(512),
40
+ product: e.string().regex(l),
41
+ anchor: g,
42
+ severity: e.enum([
43
+ "low",
44
+ "medium",
45
+ "high",
46
+ "urgent"
47
+ ]),
48
+ title: m(80),
49
+ why: m(400),
50
+ ai: e.literal(!0),
51
+ actions: e.array(e.unknown()).max(32).optional(),
52
+ provenance: v
53
+ });
54
+ function b(e) {
55
+ if (!e) return [];
56
+ let t = [], n = /* @__PURE__ */ new Set();
57
+ for (let r of e) {
58
+ let e = _.safeParse(r);
59
+ if (e.success && !n.has(e.data.id) && (n.add(e.data.id), t.push({
60
+ id: e.data.id,
61
+ type: e.data.type,
62
+ label: e.data.label,
63
+ args: e.data.args ?? {}
64
+ }), t.length === 4)) break;
65
+ }
66
+ return t;
67
+ }
68
+ function x(e) {
69
+ if (typeof e != "string") return e;
70
+ try {
71
+ return JSON.parse(e);
72
+ } catch {
73
+ return null;
74
+ }
75
+ }
76
+ function S(e, t) {
77
+ if (!e) return !1;
78
+ let n = Date.parse(e);
79
+ return Number.isFinite(n) && n > t;
80
+ }
81
+ function C(e, t, n = Date.now()) {
82
+ if (!e || typeof e.id != "string" || e.id.length === 0 || e.category !== "proactive" || e.appName !== t || e.archivedAt || S(e.snoozedUntil, n)) return null;
83
+ let r = y.safeParse(x(e.metadata));
84
+ if (!r.success) return null;
85
+ let i = r.data;
86
+ if (i.product !== t) return null;
87
+ let a = {
88
+ entityType: i.anchor.entityType,
89
+ entityId: i.anchor.entityId,
90
+ ...i.anchor.part ? { part: i.anchor.part } : {}
91
+ }, o = {
92
+ packVersion: i.provenance.packVersion,
93
+ createdAt: i.provenance.createdAt,
94
+ ...i.provenance.jobId ? { jobId: i.provenance.jobId } : {},
95
+ ...i.provenance.model ? { model: i.provenance.model } : {}
96
+ };
97
+ return {
98
+ notificationId: e.id,
99
+ suggestionId: i.suggestionId,
100
+ findingKey: i.findingKey,
101
+ product: i.product,
102
+ anchor: a,
103
+ severity: i.severity,
104
+ title: i.title,
105
+ why: i.why,
106
+ actions: b(i.actions),
107
+ provenance: o,
108
+ isRead: e.isRead === !0,
109
+ createdAt: typeof e.createdAt == "string" ? e.createdAt : i.provenance.createdAt
110
+ };
111
+ }
112
+ function w(e, t, n = Date.now()) {
113
+ let r = /* @__PURE__ */ new Map();
114
+ for (let i of e) {
115
+ let e = C(i, t, n);
116
+ if (!e) continue;
117
+ let a = r.get(e.findingKey);
118
+ (!a || T(e) > T(a)) && r.set(e.findingKey, e);
119
+ }
120
+ return [...r.values()];
121
+ }
122
+ function T(e) {
123
+ let t = Date.parse(e.createdAt);
124
+ return Number.isFinite(t) ? t : 0;
125
+ }
126
+ export { o as PROACTIVE_ACTION_LABEL_MAX, u as PROACTIVE_ACTION_TYPE_PATTERN, t as PROACTIVE_CATEGORY, s as PROACTIVE_MAX_ACTIONS, l as PROACTIVE_PRODUCT_PATTERN, c as PROACTIVE_SEVERITIES, n as PROACTIVE_SUGGESTION_KIND, r as PROACTIVE_SUGGESTION_VERSION, i as PROACTIVE_TITLE_MAX, a as PROACTIVE_WHY_MAX, T as createdAtMs, p as normalizePlainText, C as parseProactiveSuggestion, w as parseProactiveSuggestions };