@genesislcap/ai-assistant 15.77.0 → 15.78.1
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/ai-assistant.api.json +796 -7
- package/dist/ai-assistant.d.ts +305 -12
- package/dist/chat-driver.cjs +28 -1
- package/dist/chat-driver.cjs.map +2 -2
- package/dist/chat-driver.mjs +28 -1
- package/dist/chat-driver.mjs.map +2 -2
- package/dist/custom-elements.json +1230 -468
- package/dist/dts/autopilot/autopilot-driver.d.ts +28 -0
- package/dist/dts/autopilot/autopilot-driver.d.ts.map +1 -1
- package/dist/dts/channel/ai-activity-channel.d.ts +20 -2
- package/dist/dts/channel/ai-activity-channel.d.ts.map +1 -1
- package/dist/dts/components/chat-bubble/chat-bubble.d.ts +2 -0
- package/dist/dts/components/chat-bubble/chat-bubble.d.ts.map +1 -1
- package/dist/dts/components/chat-driver/interaction-controller.d.ts.map +1 -1
- package/dist/dts/components/notification-level/index.d.ts +2 -0
- package/dist/dts/components/notification-level/index.d.ts.map +1 -0
- package/dist/dts/components/notification-level/notification-level.d.ts +51 -0
- package/dist/dts/components/notification-level/notification-level.d.ts.map +1 -0
- package/dist/dts/components/notification-level/notification-level.styles.d.ts +3 -0
- package/dist/dts/components/notification-level/notification-level.styles.d.ts.map +1 -0
- package/dist/dts/components/notification-level/notification-level.template.d.ts +5 -0
- package/dist/dts/components/notification-level/notification-level.template.d.ts.map +1 -0
- package/dist/dts/components/settings-modal/settings-modal.styles.d.ts.map +1 -1
- package/dist/dts/components/settings-modal/settings-modal.template.d.ts.map +1 -1
- package/dist/dts/config/config.d.ts +2 -2
- package/dist/dts/config/define-stateful-agent.d.ts +1 -1
- package/dist/dts/index.d.ts +2 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/main/main.d.ts +79 -6
- package/dist/dts/main/main.d.ts.map +1 -1
- package/dist/dts/notifications/agent-notifications.d.ts +139 -0
- package/dist/dts/notifications/agent-notifications.d.ts.map +1 -0
- package/dist/dts/notifications/agent-notifier.d.ts +58 -0
- package/dist/dts/notifications/agent-notifier.d.ts.map +1 -0
- package/dist/dts/notifications/index.d.ts +2 -0
- package/dist/dts/notifications/index.d.ts.map +1 -0
- package/dist/dts/notifications/notification-level-picker.template.d.ts +31 -0
- package/dist/dts/notifications/notification-level-picker.template.d.ts.map +1 -0
- package/dist/dts/notifications/notification-settings.d.ts +42 -0
- package/dist/dts/notifications/notification-settings.d.ts.map +1 -0
- package/dist/dts/react.d.ts +10 -0
- package/dist/dts/state/ai-assistant-slice.d.ts +12 -5
- package/dist/dts/state/ai-assistant-slice.d.ts.map +1 -1
- package/dist/dts/state/interaction-context.d.ts +13 -0
- package/dist/dts/state/interaction-context.d.ts.map +1 -1
- package/dist/dts/state/persistence/session-persistence-provider.d.ts +5 -0
- package/dist/dts/state/persistence/session-persistence-provider.d.ts.map +1 -1
- package/dist/dts/state/persistence/session-persister.d.ts.map +1 -1
- package/dist/dts/state/persistence/session-snapshot.d.ts +19 -6
- package/dist/dts/state/persistence/session-snapshot.d.ts.map +1 -1
- package/dist/dts/state/session-store.d.ts +1 -0
- package/dist/dts/state/session-store.d.ts.map +1 -1
- package/dist/dts/types/interaction-context.d.ts +23 -0
- package/dist/dts/types/interaction-context.d.ts.map +1 -1
- package/dist/dts/utils/attachment-note.d.ts +18 -0
- package/dist/dts/utils/attachment-note.d.ts.map +1 -0
- package/dist/dts/utils/resolve-preference-baseline.d.ts +3 -0
- package/dist/dts/utils/resolve-preference-baseline.d.ts.map +1 -1
- package/dist/esm/autopilot/autopilot-driver.js +66 -3
- package/dist/esm/components/chat-bubble/chat-bubble.js +17 -3
- package/dist/esm/components/chat-driver/interaction-controller.js +5 -0
- package/dist/esm/components/notification-level/index.js +1 -0
- package/dist/esm/components/notification-level/notification-level.js +124 -0
- package/dist/esm/components/notification-level/notification-level.styles.js +20 -0
- package/dist/esm/components/notification-level/notification-level.template.js +11 -0
- package/dist/esm/components/settings-modal/settings-modal.styles.js +6 -0
- package/dist/esm/components/settings-modal/settings-modal.template.js +10 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/main/main.js +217 -27
- package/dist/esm/main/main.template.js +2 -2
- package/dist/esm/notifications/agent-notifications.js +172 -0
- package/dist/esm/notifications/agent-notifier.js +86 -0
- package/dist/esm/notifications/index.js +1 -0
- package/dist/esm/notifications/notification-level-picker.template.js +49 -0
- package/dist/esm/notifications/notification-settings.js +42 -0
- package/dist/esm/state/ai-assistant-slice.js +5 -0
- package/dist/esm/state/interaction-context.js +27 -0
- package/dist/esm/state/persistence/session-persister.js +24 -21
- package/dist/esm/state/persistence/session-snapshot.js +20 -7
- package/dist/esm/utils/attachment-note.js +19 -0
- package/dist/esm/utils/resolve-preference-baseline.js +9 -0
- package/dist/react.cjs +7 -0
- package/dist/react.mjs +6 -0
- package/docs/notifications.md +169 -0
- package/docs/styling.md +1 -1
- package/package.json +17 -17
- package/sandbox/fixtures.ts +3 -3
package/dist/esm/main/main.js
CHANGED
|
@@ -40,10 +40,14 @@ import { AiChatMarkdown } from '../components/chat-markdown/chat-markdown';
|
|
|
40
40
|
import { AiFlowingWavesIndicator } from '../components/flowing-waves-indicator';
|
|
41
41
|
import { AiHaloOverlay } from '../components/halo-overlay';
|
|
42
42
|
import { isRateableReply, MessageFeedback, replyKey, } from '../components/message-feedback/message-feedback';
|
|
43
|
+
import { AiNotificationLevel } from '../components/notification-level/notification-level';
|
|
43
44
|
import { asOrchestrator, OrchestratingDriver, } from '../components/orchestrating-driver/orchestrating-driver';
|
|
44
45
|
import { AiPlasmaOrbIndicator } from '../components/plasma-orb-indicator';
|
|
45
46
|
import { SettingsModalController, } from '../components/settings-modal';
|
|
46
47
|
import { AiWavesIndicator } from '../components/waves-indicator';
|
|
48
|
+
import { agentNotificationPermission, asAgentNotificationLevel, belongsToSession, chooseAgentNotificationLevel, effectiveNotificationLevel, levelOffered, notificationPermissionHint, notificationsOffered, watchAgentNotificationPermission, } from '../notifications/agent-notifications';
|
|
49
|
+
import { AgentNotifier } from '../notifications/agent-notifier';
|
|
50
|
+
import { addNotificationSettingsHost, announceNotificationSettings, } from '../notifications/notification-settings';
|
|
47
51
|
import { AssistantAppSettingsProvider, } from '../provider/assistant-app-settings';
|
|
48
52
|
import { recordMetaEvent, getMetaEvents, clearSession as clearMetaSession, DEBUG_LOG_README, } from '../state/debug-event-log';
|
|
49
53
|
import { getOrCreateDriver, getDriver, getDriverAgentsKey, deleteDriver, } from '../state/driver-registry';
|
|
@@ -60,6 +64,7 @@ import { pinColourAt } from '../styles/ai-colours';
|
|
|
60
64
|
import { ChatSuggestions } from '../suggestions/chat-suggestions';
|
|
61
65
|
import { agentsKey } from '../utils/agents-key';
|
|
62
66
|
import { resolveExclusiveLoadingStyle } from '../utils/animation-exclusivity';
|
|
67
|
+
import { withAttachmentNote } from '../utils/attachment-note';
|
|
63
68
|
import { deleteBankedBaseline } from '../utils/banked-usage-baselines';
|
|
64
69
|
import { estimateContextTokens, isContextMeasurable, } from '../utils/context-tokens';
|
|
65
70
|
import { logger } from '../utils/logger';
|
|
@@ -117,6 +122,11 @@ function settleWithin(outcome, ms, what) {
|
|
|
117
122
|
}
|
|
118
123
|
});
|
|
119
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Shared by every assistant on the page, so two views of one session (docked and popped out) keep
|
|
127
|
+
* one memory of what was just shown (GENC-1676).
|
|
128
|
+
*/
|
|
129
|
+
const agentNotifier = new AgentNotifier();
|
|
120
130
|
/**
|
|
121
131
|
* How long the agent-log Send button shows its 'Sent'/'Failed' outcome before
|
|
122
132
|
* returning to idle — long enough to read, short enough that a retry is never blocked.
|
|
@@ -170,7 +180,7 @@ const TIMESTAMP_CLOCK_INTERVAL_MS = 30000;
|
|
|
170
180
|
*/
|
|
171
181
|
export { budgetPercentOf, formatBlockedReason } from './budget-controller';
|
|
172
182
|
// Register supporting components when the main component module is imported.
|
|
173
|
-
avoidTreeShaking(AiChatMarkdown, AiChatInteractionWrapper, AiHaloOverlay, AiWavesIndicator, AiFlowingWavesIndicator, AiPlasmaOrbIndicator, AiChatBubble, AiActivityHalo, ChatSuggestions, AgentPicker, MessageFeedback);
|
|
183
|
+
avoidTreeShaking(AiChatMarkdown, AiChatInteractionWrapper, AiHaloOverlay, AiWavesIndicator, AiFlowingWavesIndicator, AiPlasmaOrbIndicator, AiChatBubble, AiNotificationLevel, AiActivityHalo, ChatSuggestions, AgentPicker, MessageFeedback);
|
|
174
184
|
/**
|
|
175
185
|
* Foundation AI Assistant component.
|
|
176
186
|
*
|
|
@@ -323,6 +333,13 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
|
|
|
323
333
|
this.persistence = {};
|
|
324
334
|
/** When set, enables Redux DevTools for this instance's session store. */
|
|
325
335
|
this.debugRedux = false;
|
|
336
|
+
/** The browser's notification permission, followed while connected. @internal */
|
|
337
|
+
this.notificationPermission = 'unsupported';
|
|
338
|
+
/**
|
|
339
|
+
* Bumped to make the settings picker re-read its value when a choice did not take (permission
|
|
340
|
+
* refused), since the stored level, and so its binding, did not change. @internal
|
|
341
|
+
*/
|
|
342
|
+
this.notificationPickerRevision = 0;
|
|
326
343
|
/**
|
|
327
344
|
* Epoch ms the transcript's relative timestamps are measured against.
|
|
328
345
|
*
|
|
@@ -778,6 +795,114 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
|
|
|
778
795
|
// The mode decides whether the clock needs to run at all.
|
|
779
796
|
this.syncTimestampClock();
|
|
780
797
|
}
|
|
798
|
+
/**
|
|
799
|
+
* The person's agent notification level (GENC-1676): `'off'` (always the default),
|
|
800
|
+
* `'autopilot'` or `'needs-input'`. Saved with the other settings.
|
|
801
|
+
*
|
|
802
|
+
* An app may set it, e.g. after its own "Notify me" invitation, once the person granted
|
|
803
|
+
* permission through `requestAgentNotificationPermission`. Ignored when the app does not offer
|
|
804
|
+
* the level (`chatConfig.ui.notifications`), and before the assistant has a session.
|
|
805
|
+
*/
|
|
806
|
+
get notificationLevel() {
|
|
807
|
+
var _a, _b;
|
|
808
|
+
return (_b = (_a = this._sessionRef) === null || _a === void 0 ? void 0 : _a.store.aiAssistant.notificationLevel) !== null && _b !== void 0 ? _b : 'off';
|
|
809
|
+
}
|
|
810
|
+
set notificationLevel(value) {
|
|
811
|
+
var _a, _b;
|
|
812
|
+
const level = asAgentNotificationLevel(value);
|
|
813
|
+
if (!level || !levelOffered(level, (_a = this.chatConfig.ui) === null || _a === void 0 ? void 0 : _a.notifications))
|
|
814
|
+
return;
|
|
815
|
+
if (preferenceUnchanged(this.notificationLevel, level))
|
|
816
|
+
return;
|
|
817
|
+
(_b = this._sessionRef) === null || _b === void 0 ? void 0 : _b.actions.aiAssistant.setNotificationLevel(level);
|
|
818
|
+
this.persistPreferences();
|
|
819
|
+
announceNotificationSettings(this.getStateKey());
|
|
820
|
+
}
|
|
821
|
+
/**
|
|
822
|
+
* The level that applies: the person's choice, as `'off'` when the app no longer offers it.
|
|
823
|
+
* What the settings picker shows. @internal
|
|
824
|
+
*/
|
|
825
|
+
get effectiveNotificationLevel() {
|
|
826
|
+
var _a;
|
|
827
|
+
return effectiveNotificationLevel(this.notificationLevel, (_a = this.chatConfig.ui) === null || _a === void 0 ? void 0 : _a.notifications);
|
|
828
|
+
}
|
|
829
|
+
/** Whether the settings row shows: offered by the app, and possible in this browser. @internal */
|
|
830
|
+
get notificationSettingVisible() {
|
|
831
|
+
var _a;
|
|
832
|
+
return (notificationsOffered((_a = this.chatConfig.ui) === null || _a === void 0 ? void 0 : _a.notifications) &&
|
|
833
|
+
this.notificationPermission !== 'unsupported');
|
|
834
|
+
}
|
|
835
|
+
/** Whether the settings picker offers the `'autopilot'` level. @internal */
|
|
836
|
+
get notificationAutopilotOffered() {
|
|
837
|
+
var _a;
|
|
838
|
+
return levelOffered('autopilot', (_a = this.chatConfig.ui) === null || _a === void 0 ? void 0 : _a.notifications);
|
|
839
|
+
}
|
|
840
|
+
/**
|
|
841
|
+
* The hint under the settings row when the browser will not show notifications. A block shows
|
|
842
|
+
* even at Off: otherwise a person picking a level would see it snap back with no reason given,
|
|
843
|
+
* since a browser that has blocked them never asks again. @internal
|
|
844
|
+
*/
|
|
845
|
+
get notificationPermissionHint() {
|
|
846
|
+
return notificationPermissionHint(this.effectiveNotificationLevel, this.notificationPermission);
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* The person chose a level in settings (GENC-1676). Turning notifications on asks the browser for
|
|
850
|
+
* permission first — this runs inside their click, which the browser requires — and keeps the
|
|
851
|
+
* old level if they refuse. @internal
|
|
852
|
+
*/
|
|
853
|
+
chooseNotificationLevel(level) {
|
|
854
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
855
|
+
const outcome = yield chooseAgentNotificationLevel(level, this.effectiveNotificationLevel, (next) => (this.notificationLevel = next));
|
|
856
|
+
if (outcome === 'refused')
|
|
857
|
+
this.notificationPickerRevision += 1;
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* Notifications, for this connect (GENC-1676): turn this session's `agent-attention` into
|
|
862
|
+
* browser notifications, follow the browser's permission, and lend this session's settings to
|
|
863
|
+
* pickers outside this element (`foundation-ai-notification-level`).
|
|
864
|
+
*/
|
|
865
|
+
wireNotifications() {
|
|
866
|
+
var _a;
|
|
867
|
+
(_a = this._unwireNotifications) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
868
|
+
this.notificationPermission = agentNotificationPermission();
|
|
869
|
+
const unsubAttention = agenticActivityBus.subscribe('agent-attention', (d) => this.onAgentAttention(d));
|
|
870
|
+
const unwatchPermission = watchAgentNotificationPermission((permission) => {
|
|
871
|
+
this.notificationPermission = permission;
|
|
872
|
+
});
|
|
873
|
+
const removeHost = addNotificationSettingsHost({
|
|
874
|
+
sessionKey: () => this.getStateKey(),
|
|
875
|
+
effectiveLevel: () => this.effectiveNotificationLevel,
|
|
876
|
+
offered: () => { var _a; return notificationsOffered((_a = this.chatConfig.ui) === null || _a === void 0 ? void 0 : _a.notifications); },
|
|
877
|
+
autopilotOffered: () => this.notificationAutopilotOffered,
|
|
878
|
+
setLevel: (level) => {
|
|
879
|
+
this.notificationLevel = level;
|
|
880
|
+
},
|
|
881
|
+
});
|
|
882
|
+
this._unwireNotifications = () => {
|
|
883
|
+
unsubAttention();
|
|
884
|
+
unwatchPermission();
|
|
885
|
+
removeHost();
|
|
886
|
+
};
|
|
887
|
+
}
|
|
888
|
+
/**
|
|
889
|
+
* Turn an `agent-attention` event for this session into a browser notification, if the
|
|
890
|
+
* person's level covers it and they are not looking (GENC-1676).
|
|
891
|
+
*/
|
|
892
|
+
onAgentAttention(detail) {
|
|
893
|
+
var _a;
|
|
894
|
+
const sessionKey = this.getStateKey();
|
|
895
|
+
if (sessionKey === undefined || !belongsToSession(detail.sessionKey, sessionKey))
|
|
896
|
+
return;
|
|
897
|
+
const config = (_a = this.chatConfig.ui) === null || _a === void 0 ? void 0 : _a.notifications;
|
|
898
|
+
agentNotifier.notify(detail, {
|
|
899
|
+
level: this.effectiveNotificationLevel,
|
|
900
|
+
title: this.headerTitle,
|
|
901
|
+
message: config === null || config === void 0 ? void 0 : config.message,
|
|
902
|
+
// Opens a closed bubble, and brings what waits on the person into view.
|
|
903
|
+
onClick: () => agenticActivityBus.publish('autopilot-show-waiting', { sessionKey }),
|
|
904
|
+
});
|
|
905
|
+
}
|
|
781
906
|
/**
|
|
782
907
|
* Start or stop the timestamp clock to match the current mode and connection state.
|
|
783
908
|
*
|
|
@@ -1730,7 +1855,10 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
|
|
|
1730
1855
|
if (this.$fastController.isConnected)
|
|
1731
1856
|
this.wireAutopilot();
|
|
1732
1857
|
}
|
|
1733
|
-
/**
|
|
1858
|
+
/**
|
|
1859
|
+
* Follow the autopilot host's state, publishing the "needs you" signal for the bubble, and bring
|
|
1860
|
+
* what waits on the person into view when asked.
|
|
1861
|
+
*/
|
|
1734
1862
|
wireAutopilot() {
|
|
1735
1863
|
var _a, _b;
|
|
1736
1864
|
(_a = this.autopilotCleanup) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
@@ -1743,17 +1871,16 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
|
|
|
1743
1871
|
setAutopilotNeedsUser(sessionKey, !!(host === null || host === void 0 ? void 0 : host.state.needsUser));
|
|
1744
1872
|
};
|
|
1745
1873
|
read();
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
const unsubscribeHost = host.subscribe(read);
|
|
1749
|
-
// Opened from the badge: bring what waits on the person into view.
|
|
1874
|
+
// Opened from the badge, or from a notification (GENC-1676): bring what waits on the person
|
|
1875
|
+
// into view. With or without an autopilot: a notification can come from a widget alone.
|
|
1750
1876
|
const unsubscribeShow = agenticActivityBus.subscribe('autopilot-show-waiting', (detail) => {
|
|
1751
1877
|
if ((detail === null || detail === void 0 ? void 0 : detail.sessionKey) && detail.sessionKey !== sessionKey)
|
|
1752
1878
|
return;
|
|
1753
1879
|
this.showWaiting();
|
|
1754
1880
|
});
|
|
1881
|
+
const unsubscribeHost = host === null || host === void 0 ? void 0 : host.subscribe(read);
|
|
1755
1882
|
this.autopilotCleanup = () => {
|
|
1756
|
-
unsubscribeHost();
|
|
1883
|
+
unsubscribeHost === null || unsubscribeHost === void 0 ? void 0 : unsubscribeHost();
|
|
1757
1884
|
unsubscribeShow();
|
|
1758
1885
|
};
|
|
1759
1886
|
}
|
|
@@ -2057,6 +2184,7 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
|
|
|
2057
2184
|
agents,
|
|
2058
2185
|
providerRegistry: this.providerRegistry,
|
|
2059
2186
|
sessionKey: (_c = this.getStateKey()) !== null && _c !== void 0 ? _c : '',
|
|
2187
|
+
activityBus: agenticActivityBus,
|
|
2060
2188
|
});
|
|
2061
2189
|
}
|
|
2062
2190
|
return new ChatDriver(this.providerRegistry, {
|
|
@@ -2466,6 +2594,7 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
|
|
|
2466
2594
|
});
|
|
2467
2595
|
}
|
|
2468
2596
|
this.settings.wireAppSettingsProvider();
|
|
2597
|
+
this.wireNotifications();
|
|
2469
2598
|
// Latch the backend block off the activity bus (GENC-1464). This is the primary
|
|
2470
2599
|
// seam: it fires for a turn this element did not start, for a sub-agent's
|
|
2471
2600
|
// wall (the child inherits the parent's bus and publishes its own
|
|
@@ -2576,7 +2705,7 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
|
|
|
2576
2705
|
this.switchSession(currentKey !== null && currentKey !== void 0 ? currentKey : targetKey, targetKey);
|
|
2577
2706
|
}
|
|
2578
2707
|
disconnectedCallback() {
|
|
2579
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
2708
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2580
2709
|
window.removeEventListener('pagehide', this._handlePageHide);
|
|
2581
2710
|
// Drops the menus' document listeners and finalises any in-flight close
|
|
2582
2711
|
// animation. Ordering matters and is satisfied here: `finalize()` writes the
|
|
@@ -2604,10 +2733,12 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
|
|
|
2604
2733
|
this.unsubBus = undefined;
|
|
2605
2734
|
(_b = this._unsubBudgetLatch) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
2606
2735
|
this._unsubBudgetLatch = undefined;
|
|
2607
|
-
(_c = this.
|
|
2736
|
+
(_c = this._unwireNotifications) === null || _c === void 0 ? void 0 : _c.call(this);
|
|
2737
|
+
this._unwireNotifications = undefined;
|
|
2738
|
+
(_d = this.unsubProviderRegistry) === null || _d === void 0 ? void 0 : _d.call(this);
|
|
2608
2739
|
this.unsubProviderRegistry = undefined;
|
|
2609
2740
|
this.settings.unwireAppSettingsProvider();
|
|
2610
|
-
(
|
|
2741
|
+
(_e = this._executionCompletionUnsub) === null || _e === void 0 ? void 0 : _e.call(this);
|
|
2611
2742
|
this._executionCompletionUnsub = undefined;
|
|
2612
2743
|
// Note: the restore-core autosave AND diagnostics-append timers live on the
|
|
2613
2744
|
// shared per-session persister (GENC-1351 §5.10), not here — they must survive a
|
|
@@ -2621,11 +2752,11 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
|
|
|
2621
2752
|
document.removeEventListener('pointerdown', this._handleGlobalInteraction, true);
|
|
2622
2753
|
document.removeEventListener('focusin', this._handleGlobalInteraction, true);
|
|
2623
2754
|
if (this.settingsOpen) {
|
|
2624
|
-
(
|
|
2755
|
+
(_f = this.settingsModal) === null || _f === void 0 ? void 0 : _f.close();
|
|
2625
2756
|
this.settingsOpen = false;
|
|
2626
2757
|
}
|
|
2627
2758
|
// Capture before clearing — `wasBusy` reads the driver, which is dropped below.
|
|
2628
|
-
this.logMeta('assistant.disconnected', { wasBusy: (
|
|
2759
|
+
this.logMeta('assistant.disconnected', { wasBusy: (_h = (_g = this.driver) === null || _g === void 0 ? void 0 : _g.isBusy()) !== null && _h !== void 0 ? _h : false });
|
|
2629
2760
|
// Clear local references only — driver and store stay in their registries.
|
|
2630
2761
|
this.driver = undefined;
|
|
2631
2762
|
this._sessionRef = undefined;
|
|
@@ -2684,6 +2815,8 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
|
|
|
2684
2815
|
// now that (or in case) the config's UI defaults are available (#2). No-op unless
|
|
2685
2816
|
// the store is fresh and the user hasn't already toggled something.
|
|
2686
2817
|
this.applyPreferenceBaseline();
|
|
2818
|
+
// What the app offers may have changed: pickers outside this element re-read it.
|
|
2819
|
+
announceNotificationSettings(this.getStateKey());
|
|
2687
2820
|
this.syncShowingSplash();
|
|
2688
2821
|
this.costLedger.syncActiveTitle();
|
|
2689
2822
|
this.costLedger.reload();
|
|
@@ -3197,6 +3330,8 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
|
|
|
3197
3330
|
showNarration: this.showNarration,
|
|
3198
3331
|
showAgentSwitchIndicator: this.showAgentSwitchIndicator,
|
|
3199
3332
|
timestampDisplay: this.timestampDisplay,
|
|
3333
|
+
// The choice as made, not as narrowed: a level the app stops offering is kept.
|
|
3334
|
+
notificationLevel: this.notificationLevel,
|
|
3200
3335
|
animations: [...this.enabledAnimations],
|
|
3201
3336
|
};
|
|
3202
3337
|
}
|
|
@@ -3238,6 +3373,7 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
|
|
|
3238
3373
|
* whenever `chatConfig` hadn't bound yet.
|
|
3239
3374
|
*/
|
|
3240
3375
|
applyPreferenceBaseline() {
|
|
3376
|
+
var _a;
|
|
3241
3377
|
// The "user changed a pref" latch and the stored blob live on the shared
|
|
3242
3378
|
// per-session persister (§5.10 Phase 2 / issue #1), so both element views agree —
|
|
3243
3379
|
// otherwise one view could re-apply `chatConfig` defaults over the other's live
|
|
@@ -3258,6 +3394,10 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
|
|
|
3258
3394
|
this.showNarration = resolved.showNarration;
|
|
3259
3395
|
this.showAgentSwitchIndicator = resolved.showAgentSwitchIndicator;
|
|
3260
3396
|
this.timestampDisplay = resolved.timestampDisplay;
|
|
3397
|
+
// Through the store, not the setter: the setter drops a level the app does not offer, and
|
|
3398
|
+
// the stored choice must survive that (GENC-1676).
|
|
3399
|
+
(_a = this._sessionRef) === null || _a === void 0 ? void 0 : _a.actions.aiAssistant.setNotificationLevel(resolved.notificationLevel);
|
|
3400
|
+
announceNotificationSettings(this.getStateKey());
|
|
3261
3401
|
this.enabledAnimations = resolved.enabledAnimations;
|
|
3262
3402
|
}
|
|
3263
3403
|
finally {
|
|
@@ -3685,6 +3825,8 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
|
|
|
3685
3825
|
return this.settings.cogVisible;
|
|
3686
3826
|
}
|
|
3687
3827
|
openSettingsModal() {
|
|
3828
|
+
// Permission can change in the browser's own settings while the page is open.
|
|
3829
|
+
this.notificationPermission = agentNotificationPermission();
|
|
3688
3830
|
this.settings.openModal();
|
|
3689
3831
|
}
|
|
3690
3832
|
closeSettingsModal() {
|
|
@@ -3719,11 +3861,23 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
|
|
|
3719
3861
|
get pinLocked() {
|
|
3720
3862
|
return this.flowOwnerAgentName !== null;
|
|
3721
3863
|
}
|
|
3864
|
+
/**
|
|
3865
|
+
* The agent holding the flow lock, by its `displayName` when that is a plain string (the
|
|
3866
|
+
* function form needs the agent's state, so it falls back to `name`, as the driver does).
|
|
3867
|
+
*/
|
|
3868
|
+
get flowOwnerLabel() {
|
|
3869
|
+
var _a, _b;
|
|
3870
|
+
const owner = this.flowOwnerAgentName;
|
|
3871
|
+
if (owner === null)
|
|
3872
|
+
return null;
|
|
3873
|
+
const displayName = (_b = (_a = this.agents) === null || _a === void 0 ? void 0 : _a.find((a) => a.name === owner)) === null || _b === void 0 ? void 0 : _b.displayName;
|
|
3874
|
+
return typeof displayName === 'string' && displayName ? displayName : owner;
|
|
3875
|
+
}
|
|
3722
3876
|
/** Tooltip shown on the picker toggle button. */
|
|
3723
3877
|
get agentToggleTitle() {
|
|
3724
3878
|
var _a;
|
|
3725
3879
|
if (this.pinLocked) {
|
|
3726
|
-
const name = (_a = this.
|
|
3880
|
+
const name = (_a = this.flowOwnerLabel) !== null && _a !== void 0 ? _a : 'This agent';
|
|
3727
3881
|
return `${name} is in the middle of a guided flow. Agent switching is disabled until the flow completes.`;
|
|
3728
3882
|
}
|
|
3729
3883
|
if (this.agentPickerOpen) {
|
|
@@ -3736,32 +3890,52 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
|
|
|
3736
3890
|
}
|
|
3737
3891
|
return `${this.orchestrationMenuLabel}: ${this.orchestrationDescription} Click to pin an agent instead.`;
|
|
3738
3892
|
}
|
|
3893
|
+
/** The agent the chip shows: the flow owner while it holds the picker, else the pin. */
|
|
3894
|
+
get chipAgentName() {
|
|
3895
|
+
var _a;
|
|
3896
|
+
return (_a = this.flowOwnerAgentName) !== null && _a !== void 0 ? _a : this.pinnedAgentName;
|
|
3897
|
+
}
|
|
3739
3898
|
/**
|
|
3740
|
-
*
|
|
3741
|
-
*
|
|
3742
|
-
*
|
|
3743
|
-
*
|
|
3744
|
-
*
|
|
3899
|
+
* The pinned agent's colour. Picked from the brand palette by agent position
|
|
3900
|
+
* (modulo the palette length), so each agent gets a consistent colour across
|
|
3901
|
+
* renders. `undefined` when nothing is pinned, the agent isn't in the current
|
|
3902
|
+
* array, or the host has opted out via `chatConfig.picker.disablePinColours`.
|
|
3903
|
+
* Kept for hosts; the chip's glyph uses
|
|
3904
|
+
* {@link FoundationAiAssistant.agentButtonColour}, which follows the flow
|
|
3905
|
+
* owner while it holds the picker.
|
|
3745
3906
|
*/
|
|
3746
3907
|
get pinnedAgentColour() {
|
|
3908
|
+
return this.agentColour(this.pinnedAgentName);
|
|
3909
|
+
}
|
|
3910
|
+
/** The chip's glyph colour: the pin's tint, for the agent the chip shows. */
|
|
3911
|
+
get agentButtonColour() {
|
|
3912
|
+
return this.agentColour(this.chipAgentName);
|
|
3913
|
+
}
|
|
3914
|
+
agentColour(name) {
|
|
3747
3915
|
var _a, _b, _c;
|
|
3748
|
-
if (
|
|
3916
|
+
if (name === null)
|
|
3749
3917
|
return undefined;
|
|
3750
3918
|
if ((_a = this.chatConfig.picker) === null || _a === void 0 ? void 0 : _a.disablePinColours)
|
|
3751
3919
|
return undefined;
|
|
3752
3920
|
// Indexed against the full agents array — the picker menu tints its rows
|
|
3753
3921
|
// the same way, so the dot beside an agent matches the pin you get.
|
|
3754
|
-
return pinColourAt((_c = (_b = this.agents) === null || _b === void 0 ? void 0 : _b.findIndex((a) => a.name ===
|
|
3922
|
+
return pinColourAt((_c = (_b = this.agents) === null || _b === void 0 ? void 0 : _b.findIndex((a) => a.name === name)) !== null && _c !== void 0 ? _c : -1);
|
|
3923
|
+
}
|
|
3924
|
+
/** The chip's icon: orchestration's, or the pin for one agent getting every message. */
|
|
3925
|
+
get agentButtonGlyph() {
|
|
3926
|
+
return this.chipAgentName === null ? 'sitemap' : 'thumbtack';
|
|
3755
3927
|
}
|
|
3756
3928
|
/**
|
|
3757
3929
|
* Label beside the composer's agent glyph: the orchestration label (`Orchestration` unless the
|
|
3758
3930
|
* host renames it) while the orchestrator is routing, otherwise the pinned agent's name. The name is NOT shortened here —
|
|
3759
3931
|
* the button truncates with an ellipsis in CSS, so the full name stays
|
|
3760
3932
|
* available to a screen reader and to the `title` tooltip.
|
|
3933
|
+
*
|
|
3934
|
+
* While a flow holds the picker, the flow owner is named instead: it gets every message.
|
|
3761
3935
|
*/
|
|
3762
3936
|
get agentButtonLabel() {
|
|
3763
|
-
var _a;
|
|
3764
|
-
return (_a = this.
|
|
3937
|
+
var _a, _b;
|
|
3938
|
+
return (_b = (_a = this.flowOwnerLabel) !== null && _a !== void 0 ? _a : this.pinnedAgentName) !== null && _b !== void 0 ? _b : this.orchestrationLabel;
|
|
3765
3939
|
}
|
|
3766
3940
|
/**
|
|
3767
3941
|
* The picker's name for orchestration, from `chatConfig.picker.orchestrationLabel`. Not "Auto":
|
|
@@ -3785,6 +3959,8 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
|
|
|
3785
3959
|
* Placeholder shown in the chat input. Substitutes the pinned agent's name
|
|
3786
3960
|
* when one is selected so the user has a clearer signal of where their
|
|
3787
3961
|
* message will go; otherwise falls back to the host-provided placeholder.
|
|
3962
|
+
* While a flow holds the picker and the chip is shown, it names the flow
|
|
3963
|
+
* owner, as the chip does.
|
|
3788
3964
|
*/
|
|
3789
3965
|
get effectivePlaceholder() {
|
|
3790
3966
|
// The block outranks the agent pin: while blocked the composer is disabled
|
|
@@ -3797,8 +3973,12 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
|
|
|
3797
3973
|
// remedy is about — so the sentence is where the user is already looking.
|
|
3798
3974
|
if (this.contextGate === 'blocked')
|
|
3799
3975
|
return this.contextGateReason;
|
|
3800
|
-
|
|
3801
|
-
|
|
3976
|
+
// Without the chip there is nothing on screen to say who the owner is, and a host whose only
|
|
3977
|
+
// agent runs a flow would lose its own placeholder to the agent's name.
|
|
3978
|
+
const owner = this.agentPickerEnabled ? this.flowOwnerLabel : null;
|
|
3979
|
+
const agentName = owner !== null && owner !== void 0 ? owner : this.pinnedAgentName;
|
|
3980
|
+
if (agentName)
|
|
3981
|
+
return `Message ${agentName}...`;
|
|
3802
3982
|
return this.placeholder;
|
|
3803
3983
|
}
|
|
3804
3984
|
toggleShowToolCalls() {
|
|
@@ -4613,9 +4793,7 @@ let FoundationAiAssistant = FoundationAiAssistant_1 = class FoundationAiAssistan
|
|
|
4613
4793
|
this.toggleSessionMenu();
|
|
4614
4794
|
this.state = 'loading';
|
|
4615
4795
|
this.startLoadingTimer();
|
|
4616
|
-
const displayInput = (
|
|
4617
|
-
? `${input}\n\n*Attached: ${pendingAttachments.map((a) => a.name).join(', ')}*`
|
|
4618
|
-
: input;
|
|
4796
|
+
const displayInput = withAttachmentNote(input, pendingAttachments);
|
|
4619
4797
|
try {
|
|
4620
4798
|
const result = yield ((_a = this.driver) === null || _a === void 0 ? void 0 : _a.sendMessage(displayInput, pendingAttachments));
|
|
4621
4799
|
// Latch the backend block the moment the driver reports it, so the composer
|
|
@@ -4830,6 +5008,12 @@ __decorate([
|
|
|
4830
5008
|
__decorate([
|
|
4831
5009
|
volatile
|
|
4832
5010
|
], FoundationAiAssistant.prototype, "busy", null);
|
|
5011
|
+
__decorate([
|
|
5012
|
+
observable
|
|
5013
|
+
], FoundationAiAssistant.prototype, "notificationPermission", void 0);
|
|
5014
|
+
__decorate([
|
|
5015
|
+
observable
|
|
5016
|
+
], FoundationAiAssistant.prototype, "notificationPickerRevision", void 0);
|
|
4833
5017
|
__decorate([
|
|
4834
5018
|
observable
|
|
4835
5019
|
], FoundationAiAssistant.prototype, "timestampClock", void 0);
|
|
@@ -4971,6 +5155,12 @@ __decorate([
|
|
|
4971
5155
|
__decorate([
|
|
4972
5156
|
volatile
|
|
4973
5157
|
], FoundationAiAssistant.prototype, "pinnedAgentColour", null);
|
|
5158
|
+
__decorate([
|
|
5159
|
+
volatile
|
|
5160
|
+
], FoundationAiAssistant.prototype, "agentButtonColour", null);
|
|
5161
|
+
__decorate([
|
|
5162
|
+
volatile
|
|
5163
|
+
], FoundationAiAssistant.prototype, "agentButtonGlyph", null);
|
|
4974
5164
|
__decorate([
|
|
4975
5165
|
volatile
|
|
4976
5166
|
], FoundationAiAssistant.prototype, "agentButtonLabel", null);
|
|
@@ -772,9 +772,9 @@ ${(tc) => { var _a; return (((_a = tc.foldPath) === null || _a === void 0 ? void
|
|
|
772
772
|
@click=${(x) => x.toggleAgentPicker()}
|
|
773
773
|
><span
|
|
774
774
|
class="pill-glyph"
|
|
775
|
-
style="${(x) => (x.
|
|
775
|
+
style="${(x) => (x.agentButtonColour ? `color: ${x.agentButtonColour}` : '')}"
|
|
776
776
|
><${iconTag}
|
|
777
|
-
name="${(x) =>
|
|
777
|
+
name="${(x) => x.agentButtonGlyph}"
|
|
778
778
|
></${iconTag}></span
|
|
779
779
|
><span class="pill-label">${(x) => x.agentButtonLabel}</span></${buttonTag}>
|
|
780
780
|
`;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
/**
|
|
3
|
+
* The notification's text when neither the app nor the widget gives one.
|
|
4
|
+
*
|
|
5
|
+
* @beta
|
|
6
|
+
*/
|
|
7
|
+
export const DEFAULT_AGENT_NOTIFICATION_MESSAGE = 'The assistant is ready for your next input';
|
|
8
|
+
/**
|
|
9
|
+
* Every valid level, for narrowing untrusted input. Keyed by the union, so adding a level is a
|
|
10
|
+
* compile error here rather than a value silently rejected at runtime.
|
|
11
|
+
*/
|
|
12
|
+
const LEVELS = {
|
|
13
|
+
off: true,
|
|
14
|
+
autopilot: true,
|
|
15
|
+
'needs-input': true,
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Narrow an untrusted value (a stored preference, a plain-JS app) to a level, or `undefined`.
|
|
19
|
+
* `hasOwnProperty`, not `in`, so `'constructor'` and friends are rejected.
|
|
20
|
+
*
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export const asAgentNotificationLevel = (value) => typeof value === 'string' && Object.prototype.hasOwnProperty.call(LEVELS, value)
|
|
24
|
+
? value
|
|
25
|
+
: undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Whether the app offers notifications at all (`chatConfig.ui.notifications.enabled`).
|
|
28
|
+
*
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
export const notificationsOffered = (config) => (config === null || config === void 0 ? void 0 : config.enabled) !== false;
|
|
32
|
+
/**
|
|
33
|
+
* Whether `level` is one the app offers: anything when notifications are offered, except
|
|
34
|
+
* `'autopilot'` without the `autopilot` option.
|
|
35
|
+
*
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
export const levelOffered = (level, config) => notificationsOffered(config) && (level !== 'autopilot' || (config === null || config === void 0 ? void 0 : config.autopilot) === true);
|
|
39
|
+
/**
|
|
40
|
+
* The level that applies, given the stored one and what the app offers. A stored level the app
|
|
41
|
+
* no longer offers counts as `'off'`; the stored value itself is left alone, so offering it again
|
|
42
|
+
* restores the person's choice.
|
|
43
|
+
*
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
export const effectiveNotificationLevel = (stored, config) => (levelOffered(stored, config) ? stored : 'off');
|
|
47
|
+
/**
|
|
48
|
+
* Whether a level notifies for a kind of event.
|
|
49
|
+
*
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
export const levelAllows = (level, kind) => level === 'needs-input' || (level === 'autopilot' && kind !== 'widget-needs-input');
|
|
53
|
+
/**
|
|
54
|
+
* Whether an event's session is `sessionKey` or one of its sub-agents' sessions.
|
|
55
|
+
*
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
58
|
+
export const belongsToSession = (eventSessionKey, sessionKey) => eventSessionKey === sessionKey || eventSessionKey.startsWith(`${sessionKey}::sub:`);
|
|
59
|
+
/**
|
|
60
|
+
* Whether this page may show notifications. Safe to call anywhere, including Node.
|
|
61
|
+
*
|
|
62
|
+
* @beta
|
|
63
|
+
*/
|
|
64
|
+
export function agentNotificationPermission() {
|
|
65
|
+
if (typeof Notification === 'undefined')
|
|
66
|
+
return 'unsupported';
|
|
67
|
+
if (typeof window !== 'undefined' && window.isSecureContext === false)
|
|
68
|
+
return 'unsupported';
|
|
69
|
+
return Notification.permission;
|
|
70
|
+
}
|
|
71
|
+
/** Everything watching permission on this page; see `watchAgentNotificationPermission`. */
|
|
72
|
+
const permissionWatchers = new Set();
|
|
73
|
+
const announcePermission = () => {
|
|
74
|
+
const permission = agentNotificationPermission();
|
|
75
|
+
for (const watcher of permissionWatchers)
|
|
76
|
+
watcher(permission);
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Ask the person for permission to show notifications, and resolve to the result. Call it from a
|
|
80
|
+
* click or key handler: browsers ignore or refuse a request that does not come from the person.
|
|
81
|
+
* Resolves straight away when permission is already decided or unsupported, since a browser only
|
|
82
|
+
* ever asks once.
|
|
83
|
+
*
|
|
84
|
+
* @beta
|
|
85
|
+
*/
|
|
86
|
+
export function requestAgentNotificationPermission() {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
const current = agentNotificationPermission();
|
|
89
|
+
if (current !== 'default')
|
|
90
|
+
return current;
|
|
91
|
+
try {
|
|
92
|
+
return yield Notification.requestPermission();
|
|
93
|
+
}
|
|
94
|
+
catch (_a) {
|
|
95
|
+
return agentNotificationPermission();
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
// Every picker and settings row on the page shows the answer, not only the one that asked.
|
|
99
|
+
announcePermission();
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Follow this page's notification permission (GENC-1676): `listener` runs whenever it changes —
|
|
105
|
+
* answered here, or changed by the person in the browser's own site settings while the page is
|
|
106
|
+
* open. Returns an unsubscribe. Safe where there is no Permissions API: only answers given here
|
|
107
|
+
* are seen then.
|
|
108
|
+
*
|
|
109
|
+
* @internal
|
|
110
|
+
*/
|
|
111
|
+
export function watchAgentNotificationPermission(listener) {
|
|
112
|
+
var _a;
|
|
113
|
+
permissionWatchers.add(listener);
|
|
114
|
+
let status;
|
|
115
|
+
let stopped = false;
|
|
116
|
+
const onChange = () => listener(agentNotificationPermission());
|
|
117
|
+
if (typeof navigator !== 'undefined' && ((_a = navigator.permissions) === null || _a === void 0 ? void 0 : _a.query)) {
|
|
118
|
+
navigator.permissions
|
|
119
|
+
.query({ name: 'notifications' })
|
|
120
|
+
.then((result) => {
|
|
121
|
+
if (stopped)
|
|
122
|
+
return;
|
|
123
|
+
status = result;
|
|
124
|
+
status.addEventListener('change', onChange);
|
|
125
|
+
})
|
|
126
|
+
.catch(() => undefined);
|
|
127
|
+
}
|
|
128
|
+
return () => {
|
|
129
|
+
stopped = true;
|
|
130
|
+
permissionWatchers.delete(listener);
|
|
131
|
+
status === null || status === void 0 ? void 0 : status.removeEventListener('change', onChange);
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* The hint under a notification level picker when the browser will not show notifications. A
|
|
136
|
+
* block shows even at Off: otherwise picking a level would snap back with no reason given, since
|
|
137
|
+
* a browser that has blocked them never asks again.
|
|
138
|
+
*
|
|
139
|
+
* @internal
|
|
140
|
+
*/
|
|
141
|
+
export function notificationPermissionHint(level, permission) {
|
|
142
|
+
if (permission === 'denied') {
|
|
143
|
+
return 'Your browser is blocking notifications for this site. Allow them in its site settings.';
|
|
144
|
+
}
|
|
145
|
+
if (level === 'off')
|
|
146
|
+
return '';
|
|
147
|
+
if (permission === 'default') {
|
|
148
|
+
return "Your browser hasn't allowed notifications yet. Choose Off, then this option again, to be asked.";
|
|
149
|
+
}
|
|
150
|
+
return '';
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* A person picked a level in a notification picker (GENC-1676). Turning notifications on asks the
|
|
154
|
+
* browser for permission first, and leaves the level alone if they refuse. Call it straight from
|
|
155
|
+
* the click: the request is made before anything is awaited, which the browser requires.
|
|
156
|
+
*
|
|
157
|
+
* Resolves to what happened: `'applied'`; `'refused'`, so the picker can snap back to the level
|
|
158
|
+
* that still applies; or `'same'`, for a picker re-reporting the level it already shows.
|
|
159
|
+
*
|
|
160
|
+
* @internal
|
|
161
|
+
*/
|
|
162
|
+
export function chooseAgentNotificationLevel(level, current, apply) {
|
|
163
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
+
if (level === current)
|
|
165
|
+
return 'same';
|
|
166
|
+
if (level !== 'off' && (yield requestAgentNotificationPermission()) !== 'granted') {
|
|
167
|
+
return 'refused';
|
|
168
|
+
}
|
|
169
|
+
apply(level);
|
|
170
|
+
return 'applied';
|
|
171
|
+
});
|
|
172
|
+
}
|