@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
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { logger } from '../utils/logger';
|
|
2
|
+
import { agentNotificationPermission, DEFAULT_AGENT_NOTIFICATION_MESSAGE, levelAllows, } from './agent-notifications';
|
|
3
|
+
/**
|
|
4
|
+
* How long a notification with a given tag holds off another with the same tag. Two sources can
|
|
5
|
+
* report one moment — the autopilot declining a widget it may not answer, and that widget asking
|
|
6
|
+
* for attention — and the second should not alert again. It may still improve the text: see
|
|
7
|
+
* `AgentNotifier.notify`.
|
|
8
|
+
*/
|
|
9
|
+
const REPEAT_WINDOW_MS = 5000;
|
|
10
|
+
const browserEnv = {
|
|
11
|
+
permission: agentNotificationPermission,
|
|
12
|
+
tabActive: () => typeof document !== 'undefined' &&
|
|
13
|
+
document.visibilityState === 'visible' &&
|
|
14
|
+
document.hasFocus(),
|
|
15
|
+
show(title, options, onClick) {
|
|
16
|
+
const notification = new Notification(title, options);
|
|
17
|
+
notification.onclick = () => {
|
|
18
|
+
window.focus();
|
|
19
|
+
notification.close();
|
|
20
|
+
onClick();
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
now: () => Date.now(),
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* The tag a notification carries. The browser replaces a notification that has the same tag, so
|
|
27
|
+
* windows that share a session never stack copies. Interaction ids are unique, so one interaction
|
|
28
|
+
* gets one notification whichever session reported it (a sub-agent's or its parent's); everything
|
|
29
|
+
* else the autopilot reports shares one per session.
|
|
30
|
+
*
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
export const agentNotificationTag = (detail) => detail.interactionId
|
|
34
|
+
? `ai-assistant:${detail.interactionId}`
|
|
35
|
+
: `ai-assistant:${detail.sessionKey}:autopilot`;
|
|
36
|
+
/**
|
|
37
|
+
* Decides whether an `agent-attention` event becomes a browser notification, and shows it
|
|
38
|
+
* (GENC-1676). One per page, shared by every assistant on it.
|
|
39
|
+
*
|
|
40
|
+
* Shows nothing when the level does not cover the event, when permission is not granted, while
|
|
41
|
+
* the person is looking at the page (the in-page UI covers that), or when the same tag was just
|
|
42
|
+
* shown — unless the repeat brings a widget's own message the first lacked. That one replaces the
|
|
43
|
+
* notification under the same tag, silently: the autopilot reports a widget it declines before
|
|
44
|
+
* the widget's own request is reported, and the widget's words are the better ones.
|
|
45
|
+
*
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
export class AgentNotifier {
|
|
49
|
+
constructor(env = browserEnv) {
|
|
50
|
+
this.env = env;
|
|
51
|
+
/** Each tag shown within the repeat window: when, and whether it carried a widget's message. */
|
|
52
|
+
this.shown = new Map();
|
|
53
|
+
}
|
|
54
|
+
/** Show a notification for `detail` if it should be shown. Returns whether it was. */
|
|
55
|
+
notify(detail, context) {
|
|
56
|
+
var _a;
|
|
57
|
+
if (!levelAllows(context.level, detail.kind))
|
|
58
|
+
return false;
|
|
59
|
+
if (this.env.permission() !== 'granted')
|
|
60
|
+
return false;
|
|
61
|
+
if (this.env.tabActive())
|
|
62
|
+
return false;
|
|
63
|
+
const tag = agentNotificationTag(detail);
|
|
64
|
+
const now = this.env.now();
|
|
65
|
+
for (const [key, entry] of this.shown) {
|
|
66
|
+
if (now - entry.at >= REPEAT_WINDOW_MS)
|
|
67
|
+
this.shown.delete(key);
|
|
68
|
+
}
|
|
69
|
+
const previous = this.shown.get(tag);
|
|
70
|
+
// A repeat alerts no one; it only replaces the text, when it brings a message that was missing.
|
|
71
|
+
const replacing = !!previous && !previous.message && !!detail.message;
|
|
72
|
+
if (previous && !replacing)
|
|
73
|
+
return false;
|
|
74
|
+
try {
|
|
75
|
+
this.env.show(context.title, Object.assign({ body: detail.message || context.message || DEFAULT_AGENT_NOTIFICATION_MESSAGE, tag }, (replacing ? { silent: true } : {})), context.onClick);
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
// Some browsers (Chrome on Android) only allow notifications from a service worker, and
|
|
79
|
+
// throw from the constructor.
|
|
80
|
+
logger.warn('AgentNotifier: could not show a notification', e);
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
this.shown.set(tag, { at: (_a = previous === null || previous === void 0 ? void 0 : previous.at) !== null && _a !== void 0 ? _a : now, message: !!detail.message });
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { agentNotificationPermission, DEFAULT_AGENT_NOTIFICATION_MESSAGE, requestAgentNotificationPermission, } from './agent-notifications';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { html, repeat } from '@genesislcap/web-core';
|
|
2
|
+
import { asAgentNotificationLevel } from './agent-notifications';
|
|
3
|
+
/**
|
|
4
|
+
* The notification levels with the autopilot level offered. Keyed by the level, as the timestamp
|
|
5
|
+
* modes are, so a new level is a compile error here rather than one the picker cannot reach.
|
|
6
|
+
*/
|
|
7
|
+
const NOTIFICATION_LEVEL_LABELS = {
|
|
8
|
+
off: 'Off',
|
|
9
|
+
autopilot: 'Autopilot',
|
|
10
|
+
'needs-input': 'Always',
|
|
11
|
+
};
|
|
12
|
+
const NOTIFICATION_LEVEL_OPTIONS = Object.keys(NOTIFICATION_LEVEL_LABELS).map((value) => ({ value, label: NOTIFICATION_LEVEL_LABELS[value] }));
|
|
13
|
+
/** Without the autopilot level there is nothing between the two, so it reads as a plain on/off. */
|
|
14
|
+
const NOTIFICATION_ON_OFF_OPTIONS = [
|
|
15
|
+
{ value: 'off', label: 'Off' },
|
|
16
|
+
{ value: 'needs-input', label: 'On' },
|
|
17
|
+
];
|
|
18
|
+
/**
|
|
19
|
+
* Picker for the agent notification level (GENC-1676): the design system's segmented control, as
|
|
20
|
+
* the timestamps picker uses, with the same guard against the items' own `change` echoes — only
|
|
21
|
+
* the group's own `change` is a choice. The value binding also reads `notificationPickerRevision`,
|
|
22
|
+
* so a refused choice snaps back to the level that still applies.
|
|
23
|
+
*
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
export const notificationLevelPickerTemplate = (segmentedControlTag, segmentedItemTag) => html `
|
|
27
|
+
<${segmentedControlTag}
|
|
28
|
+
part="toggle-notifications"
|
|
29
|
+
aria-label="Notifications"
|
|
30
|
+
:value=${(x) => {
|
|
31
|
+
void x.notificationPickerRevision;
|
|
32
|
+
return x.effectiveNotificationLevel;
|
|
33
|
+
}}
|
|
34
|
+
@change=${(x, c) => {
|
|
35
|
+
if (c.event.target !== c.event.currentTarget)
|
|
36
|
+
return true;
|
|
37
|
+
const next = asAgentNotificationLevel(c.event.target.value);
|
|
38
|
+
if (next)
|
|
39
|
+
void x.chooseNotificationLevel(next);
|
|
40
|
+
return true;
|
|
41
|
+
}}
|
|
42
|
+
>
|
|
43
|
+
${repeat((x) => x.notificationAutopilotOffered ? NOTIFICATION_LEVEL_OPTIONS : NOTIFICATION_ON_OFF_OPTIONS, html `
|
|
44
|
+
<${segmentedItemTag} part="notification-level-option" value="${(option) => option.value}"
|
|
45
|
+
>${(option) => option.label}</${segmentedItemTag}
|
|
46
|
+
>
|
|
47
|
+
`)}
|
|
48
|
+
</${segmentedControlTag}>
|
|
49
|
+
`;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { agenticActivityBus } from '../channel/ai-activity-bus';
|
|
2
|
+
/** Every connected assistant on this page. Two views of one session (docked, popped out) share it. */
|
|
3
|
+
const hosts = new Set();
|
|
4
|
+
/**
|
|
5
|
+
* Make an assistant's notification settings reachable by session. Returns the undo, for its
|
|
6
|
+
* disconnect.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export function addNotificationSettingsHost(host) {
|
|
11
|
+
hosts.add(host);
|
|
12
|
+
announceNotificationSettings(host.sessionKey());
|
|
13
|
+
return () => {
|
|
14
|
+
hosts.delete(host);
|
|
15
|
+
announceNotificationSettings(host.sessionKey());
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The notification settings for a session, from the assistant that holds it; `undefined` while no
|
|
20
|
+
* connected assistant does. The latest to connect wins: its views share one store anyway.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export function notificationSettingsFor(sessionKey) {
|
|
25
|
+
if (!sessionKey)
|
|
26
|
+
return undefined;
|
|
27
|
+
let found;
|
|
28
|
+
for (const host of hosts)
|
|
29
|
+
if (host.sessionKey() === sessionKey)
|
|
30
|
+
found = host;
|
|
31
|
+
return found;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Tell pickers that a session's notification settings may have changed: the level, what the app
|
|
35
|
+
* offers, or which assistant holds the session.
|
|
36
|
+
*
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
export function announceNotificationSettings(sessionKey) {
|
|
40
|
+
if (sessionKey)
|
|
41
|
+
agenticActivityBus.publish('notification-settings-changed', { sessionKey });
|
|
42
|
+
}
|
|
@@ -15,6 +15,7 @@ export function createDefaultSessionState() {
|
|
|
15
15
|
showNarration: false,
|
|
16
16
|
showAgentSwitchIndicator: false,
|
|
17
17
|
timestampDisplay: DEFAULT_TIMESTAMP_DISPLAY,
|
|
18
|
+
notificationLevel: 'off',
|
|
18
19
|
enabledAnimations: [],
|
|
19
20
|
suggestionsState: { status: 'idle' },
|
|
20
21
|
contextTokens: undefined,
|
|
@@ -82,6 +83,9 @@ export const aiAssistantSlice = createSlice({
|
|
|
82
83
|
setTimestampDisplay(state, action) {
|
|
83
84
|
state.timestampDisplay = action.payload;
|
|
84
85
|
},
|
|
86
|
+
setNotificationLevel(state, action) {
|
|
87
|
+
state.notificationLevel = action.payload;
|
|
88
|
+
},
|
|
85
89
|
setEnabledAnimations(state, action) {
|
|
86
90
|
state.enabledAnimations = action.payload;
|
|
87
91
|
},
|
|
@@ -351,6 +355,7 @@ export const aiAssistantSlice = createSlice({
|
|
|
351
355
|
showNarration: state.showNarration,
|
|
352
356
|
showAgentSwitchIndicator: state.showAgentSwitchIndicator,
|
|
353
357
|
timestampDisplay: state.timestampDisplay,
|
|
358
|
+
notificationLevel: state.notificationLevel,
|
|
354
359
|
enabledAnimations: state.enabledAnimations,
|
|
355
360
|
providerStatuses: state.providerStatuses,
|
|
356
361
|
blocked: state.blocked,
|
|
@@ -8,6 +8,7 @@ import { buildDecisionSurface, buildFullSurface } from './decision-surface';
|
|
|
8
8
|
* @internal
|
|
9
9
|
*/
|
|
10
10
|
export function createInteractionContext(interactionId, deps = {}) {
|
|
11
|
+
var _a;
|
|
11
12
|
const state = {};
|
|
12
13
|
const onceCache = new Map();
|
|
13
14
|
const listeners = new Set();
|
|
@@ -20,6 +21,21 @@ export function createInteractionContext(interactionId, deps = {}) {
|
|
|
20
21
|
let surface;
|
|
21
22
|
let lastActivityAt = Date.now();
|
|
22
23
|
let checkpoint = deps.checkpoint;
|
|
24
|
+
// GENC-1676: the widget's first `requestAttention`, held until who holds the interaction is
|
|
25
|
+
// decided (`markOffered`), then reported once — or dropped, if a claimant holds it.
|
|
26
|
+
let offered = false;
|
|
27
|
+
let attention;
|
|
28
|
+
let attentionDone = false;
|
|
29
|
+
const reportAttention = () => {
|
|
30
|
+
var _a;
|
|
31
|
+
if (!offered || !attention || attentionDone || disposed || settled)
|
|
32
|
+
return;
|
|
33
|
+
attentionDone = true;
|
|
34
|
+
// A claimant's: its own hand-back reports, if it gives the interaction back.
|
|
35
|
+
if (heldBy !== 'user')
|
|
36
|
+
return;
|
|
37
|
+
(_a = deps.requestAttention) === null || _a === void 0 ? void 0 : _a.call(deps, attention.message);
|
|
38
|
+
};
|
|
23
39
|
/** Fire every waiting `onSurfaceReady` once the surface has something a claimant could do. */
|
|
24
40
|
const checkReady = () => {
|
|
25
41
|
if (disposed || !surface || readyListeners.size === 0 || !surface.isReady())
|
|
@@ -37,6 +53,7 @@ export function createInteractionContext(interactionId, deps = {}) {
|
|
|
37
53
|
};
|
|
38
54
|
const context = {
|
|
39
55
|
interactionId,
|
|
56
|
+
sessionKey: (_a = deps.sessionKey) !== null && _a !== void 0 ? _a : '',
|
|
40
57
|
get heldBy() {
|
|
41
58
|
return heldBy;
|
|
42
59
|
},
|
|
@@ -137,6 +154,12 @@ export function createInteractionContext(interactionId, deps = {}) {
|
|
|
137
154
|
readyListeners.delete(fn);
|
|
138
155
|
};
|
|
139
156
|
},
|
|
157
|
+
requestAttention(message) {
|
|
158
|
+
if (disposed || settled || attention)
|
|
159
|
+
return;
|
|
160
|
+
attention = { message };
|
|
161
|
+
reportAttention();
|
|
162
|
+
},
|
|
140
163
|
claimantOwns(action) {
|
|
141
164
|
if (heldBy === 'user' || !surface)
|
|
142
165
|
return false;
|
|
@@ -174,6 +197,10 @@ export function createInteractionContext(interactionId, deps = {}) {
|
|
|
174
197
|
setController(value) {
|
|
175
198
|
controller = value;
|
|
176
199
|
},
|
|
200
|
+
markOffered() {
|
|
201
|
+
offered = true;
|
|
202
|
+
reportAttention();
|
|
203
|
+
},
|
|
177
204
|
get surface() {
|
|
178
205
|
return surface;
|
|
179
206
|
},
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
|
+
import { withoutAttachmentNote } from '../../utils/attachment-note';
|
|
2
3
|
import { flattenSubAgentMessages } from '../../utils/flatten-sub-agent-messages';
|
|
3
4
|
import { logger } from '../../utils/logger';
|
|
4
5
|
import { isSessionNoticeMarker, SESSION_RESTORE_FAILED_LABEL, SESSION_RESTORED_LABEL, SESSION_RESUMED_LABEL, } from '../../utils/message-partition';
|
|
@@ -6,7 +7,7 @@ import { withTimeout } from '../../utils/with-timeout';
|
|
|
6
7
|
import { recordMetaEvent } from '../debug-event-log';
|
|
7
8
|
import { diagnosticsMessageKey } from './diagnostics';
|
|
8
9
|
import { getDiagnosticsCursors } from './diagnostics-cursors';
|
|
9
|
-
import { buildResumeNote, createPersistedSession, isRestorableSession, keepThroughLastUserMessage, reconcileAgentSnapshots, resolveNonResumableNotice, toLoadSessionPayload, trimToRestorableBoundary, unknownAgentSnapshots, } from './session-snapshot';
|
|
10
|
+
import { buildResumeNote, createPersistedSession, interruptedPromptFiles, isRestorableSession, keepThroughLastUserMessage, lastUserMessageIndex, reconcileAgentSnapshots, resolveNonResumableNotice, toLoadSessionPayload, trimToRestorableBoundary, unknownAgentSnapshots, } from './session-snapshot';
|
|
10
11
|
const autopilotOf = (driver) => driver && typeof driver.getPersistedMode === 'function'
|
|
11
12
|
? driver
|
|
12
13
|
: undefined;
|
|
@@ -28,7 +29,7 @@ const DEFAULT_DIAGNOSTICS_DEBOUNCE_MS = 4000;
|
|
|
28
29
|
/**
|
|
29
30
|
* Fallback notice shown on return when an agent declared its state non-resumable
|
|
30
31
|
* (GENC-1351 §5.9) and set no `notResumableMessage`. Paired with the composer
|
|
31
|
-
* pre-filled with the
|
|
32
|
+
* pre-filled with the user's last message, so "send it again" is one keystroke.
|
|
32
33
|
*/
|
|
33
34
|
/**
|
|
34
35
|
* Consecutive failed saves before persistence is declared broken (GENC-1511). Two, not one: a
|
|
@@ -351,7 +352,7 @@ export class SessionPersister {
|
|
|
351
352
|
// snapshot from three hours earlier.
|
|
352
353
|
//
|
|
353
354
|
// So the freeze target is now ALWAYS the live transcript through the last user
|
|
354
|
-
// message — the conversation plus the
|
|
355
|
+
// message — the conversation plus the user's latest request, with the
|
|
355
356
|
// agent's in-flight turns and flow-state dropped. Advancing on each new boundary
|
|
356
357
|
// means a long-running flow can no longer cost the user the work that preceded it.
|
|
357
358
|
const { resumeMessage, resumePrompt } = resolveNonResumableNotice({
|
|
@@ -627,23 +628,24 @@ export class SessionPersister {
|
|
|
627
628
|
// display-only and stripped again on the next save.
|
|
628
629
|
const trailerTs = new Date().toISOString();
|
|
629
630
|
let trailers;
|
|
631
|
+
let prefill;
|
|
630
632
|
if (snapshot.interrupted) {
|
|
631
633
|
trailers = [];
|
|
632
|
-
|
|
633
|
-
//
|
|
634
|
-
|
|
635
|
-
// the
|
|
636
|
-
// message
|
|
637
|
-
//
|
|
638
|
-
|
|
639
|
-
const
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
content: snapshot.interrupted.prompt,
|
|
644
|
-
timestamp: trailerTs,
|
|
645
|
-
});
|
|
634
|
+
const { prompt } = snapshot.interrupted;
|
|
635
|
+
// Looked up untrimmed: the restorable-boundary trim can cut back past the message.
|
|
636
|
+
const files = interruptedPromptFiles(snapshot.messages, prompt);
|
|
637
|
+
// Re-append the triggering user message UNLESS it is already the transcript's last
|
|
638
|
+
// user message. The freeze keeps the transcript through that message, sometimes with
|
|
639
|
+
// replies already saved after it, so only an older snapshot frozen before its trigger
|
|
640
|
+
// lacks it — re-appending otherwise duplicates the bubble (GENC-1351 §5.9).
|
|
641
|
+
const lastUser = trimmed[lastUserMessageIndex(trimmed)];
|
|
642
|
+
const promptAlreadyPresent = (lastUser === null || lastUser === void 0 ? void 0 : lastUser.content) === prompt;
|
|
643
|
+
if (prompt && !promptAlreadyPresent) {
|
|
644
|
+
trailers.push(Object.assign(Object.assign({ role: 'user', content: prompt }, (files ? { attachments: files } : {})), { timestamp: trailerTs }));
|
|
646
645
|
}
|
|
646
|
+
// The files stay on the transcript message and aren't put back in the composer, so it
|
|
647
|
+
// gets only what was typed.
|
|
648
|
+
prefill = prompt ? withoutAttachmentNote(prompt, files) : prompt;
|
|
647
649
|
trailers.push({
|
|
648
650
|
role: 'assistant',
|
|
649
651
|
content: snapshot.interrupted.message,
|
|
@@ -690,11 +692,12 @@ export class SessionPersister {
|
|
|
690
692
|
pinnedAgentName: snapshot.pinnedAgentName,
|
|
691
693
|
flowOwnerAgentName: snapshot.flowOwnerAgentName,
|
|
692
694
|
});
|
|
693
|
-
// Interrupted flow (§5.9): pre-fill the composer with the
|
|
694
|
-
//
|
|
695
|
+
// Interrupted flow (§5.9): pre-fill the composer with the user's last message so
|
|
696
|
+
// "send it again" is one keystroke, and record it for observability.
|
|
695
697
|
if (snapshot.interrupted) {
|
|
696
|
-
|
|
697
|
-
|
|
698
|
+
// Empty for a message that was only files: nothing typed to send again.
|
|
699
|
+
if (prefill) {
|
|
700
|
+
ref.actions.aiAssistant.setInputValue(prefill);
|
|
698
701
|
}
|
|
699
702
|
this.logMeta('persistence.not-resumable', {
|
|
700
703
|
hadPrompt: !!snapshot.interrupted.prompt,
|
|
@@ -22,24 +22,26 @@ export function createPersistedSession(input) {
|
|
|
22
22
|
* unit-testable independent of the save path:
|
|
23
23
|
* - `resumeMessage`: the agent's `notResumableMessage` when non-blank, else the
|
|
24
24
|
* passed default.
|
|
25
|
-
* - `resumePrompt`: the
|
|
26
|
-
*
|
|
27
|
-
*
|
|
25
|
+
* - `resumePrompt`: the last user message in the transcript — the request that was
|
|
26
|
+
* in flight — falling back to the captured flow-activating prompt when there is
|
|
27
|
+
* none; `undefined` when neither exists.
|
|
28
28
|
*
|
|
29
29
|
* @internal
|
|
30
30
|
*/
|
|
31
31
|
export function resolveNonResumableNotice(input) {
|
|
32
|
-
var _a, _b;
|
|
32
|
+
var _a, _b, _c;
|
|
33
33
|
const custom = input.notResumableMessage;
|
|
34
34
|
const resumeMessage = custom && custom.trim() ? custom : input.defaultMessage;
|
|
35
|
-
|
|
35
|
+
// Not the activation prompt first: a flow lock can outlive the turn that took it, and the
|
|
36
|
+
// freeze keeps the transcript through this message, so restore finds it already there.
|
|
37
|
+
const resumePrompt = (_c = (_b = (_a = input.messages[lastUserMessageIndex(input.messages)]) === null || _a === void 0 ? void 0 : _a.content) !== null && _b !== void 0 ? _b : input.flowActivationPrompt) !== null && _c !== void 0 ? _c : undefined;
|
|
36
38
|
return { resumeMessage, resumePrompt };
|
|
37
39
|
}
|
|
38
40
|
/**
|
|
39
41
|
* Index of the last `user`-role message in `messages`, or `-1` when there is none.
|
|
40
42
|
* The single backward scan behind "what did the user last say" — used to slice the
|
|
41
|
-
* transcript to a clean boundary (`keepThroughLastUserMessage`) and to
|
|
42
|
-
* flow
|
|
43
|
+
* transcript to a clean boundary (`keepThroughLastUserMessage`) and to pick the
|
|
44
|
+
* prompt an interrupted flow hands back. Allocation-free (no reversed copy).
|
|
43
45
|
*
|
|
44
46
|
* @internal
|
|
45
47
|
*/
|
|
@@ -51,6 +53,17 @@ export function lastUserMessageIndex(messages) {
|
|
|
51
53
|
}
|
|
52
54
|
return -1;
|
|
53
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* The files of the message an interrupted `prompt` came from: the last user message in
|
|
58
|
+
* `messages`, when its text is the prompt. An older snapshot's prompt can be another text, and
|
|
59
|
+
* that message's files are not its own.
|
|
60
|
+
*
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
export function interruptedPromptFiles(messages, prompt) {
|
|
64
|
+
const sent = messages[lastUserMessageIndex(messages)];
|
|
65
|
+
return prompt && (sent === null || sent === void 0 ? void 0 : sent.content) === prompt ? sent.attachments : undefined;
|
|
66
|
+
}
|
|
54
67
|
/**
|
|
55
68
|
* Type guard: is `value` a {@link PersistedSession} we can safely restore?
|
|
56
69
|
* Gates on matching schema version, same host, and a messages array — the
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The line naming the files under a message sent with attachments. Built and taken off only
|
|
3
|
+
* here, so the two can't drift.
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
const attachmentNote = (files) => (files === null || files === void 0 ? void 0 : files.length) ? `\n\n*Attached: ${files.map((f) => f.name).join(', ')}*` : '';
|
|
8
|
+
/** What a message sent with `files` is stored and shown as: the typed text, then the line. */
|
|
9
|
+
export function withAttachmentNote(typed, files) {
|
|
10
|
+
return typed + attachmentNote(files);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The typed text of a message stored with `files`. Takes off only the line those files add, so
|
|
14
|
+
* nothing the user typed is cut.
|
|
15
|
+
*/
|
|
16
|
+
export function withoutAttachmentNote(text, files) {
|
|
17
|
+
const note = attachmentNote(files);
|
|
18
|
+
return note && text.endsWith(note) ? text.slice(0, -note.length) : text;
|
|
19
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DEFAULT_ANIMATIONS } from '../main/main.types';
|
|
2
|
+
import { asAgentNotificationLevel, } from '../notifications/agent-notifications';
|
|
2
3
|
import { resolveExclusiveLoadingStyle } from './animation-exclusivity';
|
|
3
4
|
/**
|
|
4
5
|
* Whether a preference write is a no-op, so a setter can bail before touching the store.
|
|
@@ -78,6 +79,9 @@ export function resolvePreferenceBaseline(ui, stored) {
|
|
|
78
79
|
// Defaults ON, unlike the booleans above — so this reads the config value when it is
|
|
79
80
|
// a valid mode and falls back to `'hover'`, rather than testing `=== true`.
|
|
80
81
|
timestampDisplay: (_a = asTimestampDisplay(u.showTimestamps)) !== null && _a !== void 0 ? _a : DEFAULT_TIMESTAMP_DISPLAY,
|
|
82
|
+
// No config layer, on purpose: the browser makes the person opt in, so nothing in
|
|
83
|
+
// `chatConfig` can switch it on (GENC-1676).
|
|
84
|
+
notificationLevel: 'off',
|
|
81
85
|
enabledAnimations: resolveExclusiveLoadingStyle((_c = (_b = u.animations) === null || _b === void 0 ? void 0 : _b.enabled) !== null && _c !== void 0 ? _c : (u.animations ? [...DEFAULT_ANIMATIONS] : [])),
|
|
82
86
|
};
|
|
83
87
|
// Layer 2 — stored user preferences override the fields they carry.
|
|
@@ -99,6 +103,11 @@ export function resolvePreferenceBaseline(ui, stored) {
|
|
|
99
103
|
const storedMode = asTimestampDisplay(stored.timestampDisplay);
|
|
100
104
|
if (storedMode)
|
|
101
105
|
baseline.timestampDisplay = storedMode;
|
|
106
|
+
// Kept even when the app no longer offers it: what applies is narrowed later, so offering
|
|
107
|
+
// it again restores the choice.
|
|
108
|
+
const storedLevel = asAgentNotificationLevel(stored.notificationLevel);
|
|
109
|
+
if (storedLevel)
|
|
110
|
+
baseline.notificationLevel = storedLevel;
|
|
102
111
|
if (Array.isArray(stored.animations)) {
|
|
103
112
|
// De-dupe defensively — historical blobs may hold duplicates from the old
|
|
104
113
|
// settings-modal append bug (now fixed at the `setEnabledAnimations` source).
|
package/dist/react.cjs
CHANGED
|
@@ -15,6 +15,7 @@ const { AiChatMarkdown: AiChatMarkdownWC } = require('./esm/components/chat-mark
|
|
|
15
15
|
const { AiFlowingWavesIndicator: AiFlowingWavesIndicatorWC } = require('./esm/components/flowing-waves-indicator.js');
|
|
16
16
|
const { AiHaloOverlay: AiHaloOverlayWC } = require('./esm/components/halo-overlay.js');
|
|
17
17
|
const { MessageFeedback: MessageFeedbackWC } = require('./esm/components/message-feedback/message-feedback.js');
|
|
18
|
+
const { AiNotificationLevel: AiNotificationLevelWC } = require('./esm/components/notification-level/notification-level.js');
|
|
18
19
|
const { AiPlasmaOrbIndicator: AiPlasmaOrbIndicatorWC } = require('./esm/components/plasma-orb-indicator.js');
|
|
19
20
|
const { FoundationAiPopoutManager: FoundationAiPopoutManagerWC } = require('./esm/components/popout-manager/popout-manager.js');
|
|
20
21
|
const { AiWavesIndicator: AiWavesIndicatorWC } = require('./esm/components/waves-indicator.js');
|
|
@@ -152,6 +153,11 @@ const MessageFeedback = React.forwardRef(function MessageFeedback(props, ref) {
|
|
|
152
153
|
return React.createElement(customElements.getName(MessageFeedbackWC) ?? 'foundation-ai-message-feedback', { ...rest, ref }, children);
|
|
153
154
|
});
|
|
154
155
|
|
|
156
|
+
const AiNotificationLevel = React.forwardRef(function AiNotificationLevel(props, ref) {
|
|
157
|
+
const { children, ...rest } = props;
|
|
158
|
+
return React.createElement(customElements.getName(AiNotificationLevelWC) ?? 'foundation-ai-notification-level', { ...rest, ref }, children);
|
|
159
|
+
});
|
|
160
|
+
|
|
155
161
|
const FoundationAiPopoutManager = React.forwardRef(function FoundationAiPopoutManager(props, ref) {
|
|
156
162
|
const { children, ...rest } = props;
|
|
157
163
|
return React.createElement(customElements.getName(FoundationAiPopoutManagerWC) ?? 'foundation-ai-popout-manager', { ...rest, ref }, children);
|
|
@@ -188,6 +194,7 @@ module.exports = {
|
|
|
188
194
|
AiChatInteractionWrapper,
|
|
189
195
|
AiChatMarkdown,
|
|
190
196
|
MessageFeedback,
|
|
197
|
+
AiNotificationLevel,
|
|
191
198
|
FoundationAiPopoutManager,
|
|
192
199
|
GenesisWriteReview,
|
|
193
200
|
};
|
package/dist/react.mjs
CHANGED
|
@@ -13,6 +13,7 @@ import { AiChatMarkdown as AiChatMarkdownWC } from './esm/components/chat-markdo
|
|
|
13
13
|
import { AiFlowingWavesIndicator as AiFlowingWavesIndicatorWC } from './esm/components/flowing-waves-indicator.js';
|
|
14
14
|
import { AiHaloOverlay as AiHaloOverlayWC } from './esm/components/halo-overlay.js';
|
|
15
15
|
import { MessageFeedback as MessageFeedbackWC } from './esm/components/message-feedback/message-feedback.js';
|
|
16
|
+
import { AiNotificationLevel as AiNotificationLevelWC } from './esm/components/notification-level/notification-level.js';
|
|
16
17
|
import { AiPlasmaOrbIndicator as AiPlasmaOrbIndicatorWC } from './esm/components/plasma-orb-indicator.js';
|
|
17
18
|
import { FoundationAiPopoutManager as FoundationAiPopoutManagerWC } from './esm/components/popout-manager/popout-manager.js';
|
|
18
19
|
import { AiWavesIndicator as AiWavesIndicatorWC } from './esm/components/waves-indicator.js';
|
|
@@ -150,6 +151,11 @@ export const MessageFeedback = React.forwardRef(function MessageFeedback(props,
|
|
|
150
151
|
return React.createElement(customElements.getName(MessageFeedbackWC) ?? 'foundation-ai-message-feedback', { ...rest, ref }, children);
|
|
151
152
|
});
|
|
152
153
|
|
|
154
|
+
export const AiNotificationLevel = React.forwardRef(function AiNotificationLevel(props, ref) {
|
|
155
|
+
const { children, ...rest } = props;
|
|
156
|
+
return React.createElement(customElements.getName(AiNotificationLevelWC) ?? 'foundation-ai-notification-level', { ...rest, ref }, children);
|
|
157
|
+
});
|
|
158
|
+
|
|
153
159
|
export const FoundationAiPopoutManager = React.forwardRef(function FoundationAiPopoutManager(props, ref) {
|
|
154
160
|
const { children, ...rest } = props;
|
|
155
161
|
return React.createElement(customElements.getName(FoundationAiPopoutManagerWC) ?? 'foundation-ai-popout-manager', { ...rest, ref }, children);
|