@agent-native/core 0.161.10 → 0.161.14
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/corpus/README.md +1 -1
- package/corpus/templates/analytics/actions/clear-selected-dashboard-object.ts +71 -0
- package/corpus/templates/analytics/actions/view-screen.ts +68 -4
- package/corpus/templates/analytics/app/hooks/use-dashboard-chat-context.ts +41 -66
- package/corpus/templates/analytics/app/lib/selected-object.ts +53 -0
- package/corpus/templates/analytics/app/pages/Ask.tsx +21 -0
- package/corpus/templates/analytics/changelog/2026-08-18-ask-no-stale-dashboard-context.md +6 -0
- package/corpus/templates/calendar/app/root.tsx +12 -4
- package/corpus/templates/calendar/changelog/2026-08-18-calendar-stays-responsive-in-the-desktop-app-without-focus-t.md +6 -0
- package/corpus/templates/clips/app/components/library/recording-card.tsx +19 -3
- package/corpus/templates/clips/changelog/2026-08-18-deleting-a-recording-no-longer-freezes-clips.md +6 -0
- package/corpus/templates/clips/desktop/src/app.tsx +9 -10
- package/corpus/templates/clips/desktop/src/lib/recorder.ts +4 -3
- package/corpus/templates/clips/desktop/src/lib/recording-start-guard.ts +26 -0
- package/corpus/templates/content/actions/export-document.ts +68 -3
- package/corpus/templates/content/changelog/2026-08-06-database-exports-now-include-their-pages.md +6 -0
- package/corpus/templates/content/shared/document-export.ts +25 -0
- package/corpus/templates/design/.agents/skills/creative-context/SKILL.md +3 -0
- package/corpus/templates/design/app/components/editor/PromptDialog.tsx +66 -0
- package/corpus/templates/design/app/pages/Index.tsx +45 -1
- package/corpus/templates/design/app/pages/design-editor/creative-context-precedent.ts +233 -0
- package/corpus/templates/design/changelog/2026-08-11-new-designs-now-skip-the-intake-questions-and-follow-your-ex.md +6 -0
- package/corpus/templates/dispatch/app/chat-first-pages.ts +40 -40
- package/corpus/templates/dispatch/app/i18n-data.ts +5 -5
- package/corpus/templates/factory/AGENTS.md +30 -29
- package/corpus/templates/slides/app/components/layout/AgentWorkIndicator.tsx +56 -9
- package/dist/action.js +68 -2
- package/dist/agent/chat-health-alert.js +10 -1
- package/dist/client/AssistantChat.js +1 -0
- package/dist/client/chat-first/app-open-actions.js +1 -1
- package/dist/client/chat-first/copy.js +2 -2
- package/dist/client/conversation/use-near-bottom-autoscroll.js +34 -4
- package/dist/client/embed-auth.js +40 -3
- package/dist/client/mcp-apps/McpAppRenderer.js +7 -2
- package/dist/client/route-state.js +42 -5
- package/dist/client/use-change-version.js +71 -25
- package/dist/client/use-db-sync.d.ts +1 -0
- package/dist/client/use-db-sync.js +223 -45
- package/dist/collab/awareness.js +37 -4
- package/dist/collab/client.js +17 -1
- package/dist/collab/struct-routes.d.ts +1 -1
- package/dist/mcp/embed-app.js +71 -2
- package/dist/notifications/routes.d.ts +1 -1
- package/dist/observability/routes.d.ts +3 -3
- package/dist/secrets/routes.d.ts +9 -9
- package/dist/server/poll.d.ts +22 -14
- package/dist/server/poll.js +243 -67
- package/dist/styles/agent-conversation.css +25 -4
- package/package.json +1 -1
|
@@ -11,6 +11,7 @@ const GUARDED_METHODS = new Set(["GET", "HEAD"]);
|
|
|
11
11
|
const AUTH_FAILURE_HEADER = "x-agent-native-auth-circuit-breaker";
|
|
12
12
|
const MCP_CHAT_BRIDGE_VIEWPORT_STYLE_ID = "agent-native-mcp-chat-bridge-viewport";
|
|
13
13
|
const MCP_CHAT_BRIDGE_VIEWPORT_HEIGHT = 560;
|
|
14
|
+
let pendingMcpChatBridgeViewportNotification = null;
|
|
14
15
|
const authFailureCache = new Map();
|
|
15
16
|
let embedAuthFailure = null;
|
|
16
17
|
function browserWindow() {
|
|
@@ -211,11 +212,38 @@ function notifyMcpChatBridgeViewportHeight(win) {
|
|
|
211
212
|
// Cross-host embeds can deny parent messaging in tests or strict sandboxes.
|
|
212
213
|
}
|
|
213
214
|
};
|
|
215
|
+
const pending = pendingMcpChatBridgeViewportNotification;
|
|
216
|
+
pendingMcpChatBridgeViewportNotification = null;
|
|
217
|
+
if (pending) {
|
|
218
|
+
if (pending.animationFrameId !== null) {
|
|
219
|
+
pending.win.cancelAnimationFrame?.(pending.animationFrameId);
|
|
220
|
+
}
|
|
221
|
+
for (const id of pending.timeoutIds)
|
|
222
|
+
pending.win.clearTimeout(id);
|
|
223
|
+
}
|
|
214
224
|
notify();
|
|
225
|
+
const nextPending = {
|
|
226
|
+
win,
|
|
227
|
+
animationFrameId: null,
|
|
228
|
+
timeoutIds: [],
|
|
229
|
+
};
|
|
230
|
+
pendingMcpChatBridgeViewportNotification = nextPending;
|
|
231
|
+
const notifyIfCurrent = () => {
|
|
232
|
+
// Some hosts expose requestAnimationFrame/timers from a different clock
|
|
233
|
+
// than the one used by clearTimeout. The identity guard keeps a superseded
|
|
234
|
+
// setup from notifying even when cancellation cannot reach that clock.
|
|
235
|
+
if (pendingMcpChatBridgeViewportNotification !== nextPending)
|
|
236
|
+
return;
|
|
237
|
+
notify();
|
|
238
|
+
};
|
|
215
239
|
try {
|
|
216
|
-
win.requestAnimationFrame
|
|
217
|
-
|
|
218
|
-
|
|
240
|
+
if (win.requestAnimationFrame) {
|
|
241
|
+
nextPending.animationFrameId = win.requestAnimationFrame(notifyIfCurrent);
|
|
242
|
+
}
|
|
243
|
+
if (win.setTimeout) {
|
|
244
|
+
nextPending.timeoutIds.push(win.setTimeout(notifyIfCurrent, 250));
|
|
245
|
+
nextPending.timeoutIds.push(win.setTimeout(notifyIfCurrent, 1000));
|
|
246
|
+
}
|
|
219
247
|
}
|
|
220
248
|
catch {
|
|
221
249
|
// Timers are a progressive enhancement for late host bridge initialization.
|
|
@@ -223,6 +251,15 @@ function notifyMcpChatBridgeViewportHeight(win) {
|
|
|
223
251
|
}
|
|
224
252
|
/** Internal test helper. Do not use in app code. */
|
|
225
253
|
export function _resetEmbedAuthForTests() {
|
|
254
|
+
if (pendingMcpChatBridgeViewportNotification) {
|
|
255
|
+
const pending = pendingMcpChatBridgeViewportNotification;
|
|
256
|
+
pendingMcpChatBridgeViewportNotification = null;
|
|
257
|
+
if (pending.animationFrameId !== null) {
|
|
258
|
+
pending.win.cancelAnimationFrame?.(pending.animationFrameId);
|
|
259
|
+
}
|
|
260
|
+
for (const id of pending.timeoutIds)
|
|
261
|
+
pending.win.clearTimeout(id);
|
|
262
|
+
}
|
|
226
263
|
installed = false;
|
|
227
264
|
memoryToken = null;
|
|
228
265
|
mcpChatBridgeActive = false;
|
|
@@ -55,6 +55,11 @@ export function McpAppRenderer({ app, className }) {
|
|
|
55
55
|
setReady(true);
|
|
56
56
|
setError(null);
|
|
57
57
|
}, []);
|
|
58
|
+
const handleIframeError = useCallback(() => {
|
|
59
|
+
readyRef.current = false;
|
|
60
|
+
setReady(false);
|
|
61
|
+
setError("MCP App iframe failed to load.");
|
|
62
|
+
}, []);
|
|
58
63
|
const applyHeight = useCallback((desiredHeight) => {
|
|
59
64
|
if (typeof desiredHeight === "number" &&
|
|
60
65
|
Number.isFinite(desiredHeight) &&
|
|
@@ -228,9 +233,9 @@ export function McpAppRenderer({ app, className }) {
|
|
|
228
233
|
// new-but-equal `app` object reference does not tear down a live bridge.
|
|
229
234
|
}, [applyHeight, markReady, srcDoc]);
|
|
230
235
|
if (!resourceHtml) {
|
|
231
|
-
return (_jsxs("div", { className: cn("agent-mcp-app agent-mcp-app--error", className), children: [_jsx(IconAlertTriangle, { size: 15 }), _jsx("span", { children: "MCP App resource was not available." })] }));
|
|
236
|
+
return (_jsxs("div", { className: cn("agent-mcp-app agent-mcp-app--error", className), children: [_jsx(IconAlertTriangle, { size: 15 }), _jsx("span", { children: "MCP App resource was not available." }), externalOpenUrl && (_jsx("button", { type: "button", className: "agent-mcp-app__open", onClick: () => window.open(externalOpenUrl, "_blank", "noopener,noreferrer"), children: "Open in new tab" }))] }));
|
|
232
237
|
}
|
|
233
|
-
return (_jsxs("div", { className: cn("agent-mcp-app", uiMeta.prefersBorder === false && "agent-mcp-app--flush", className), children: [!ready && !error && (_jsxs("div", { className: "agent-mcp-app__loading", children: [_jsx(IconLoader2, { size: 14, className: "agent-conversation-spin" }), _jsx("span", { children: "Loading MCP App" })] })), error && (_jsxs("div", { className: "agent-mcp-app__error", children: [_jsx(IconAlertTriangle, { size: 15 }), _jsx("span", { children: error }), externalOpenUrl && (_jsx("button", { type: "button", className: "agent-mcp-app__open", onClick: () => window.open(externalOpenUrl, "_blank", "noopener,noreferrer"), children: "Open in new tab" }))] })), _jsx("iframe", { ref: iframeRef, title: app.tool?.title ?? app.originalToolName, srcDoc: srcDoc, sandbox: SANDBOX_FLAGS, allow: buildAllowAttribute(supportedPermissions), style: { height } })] }));
|
|
238
|
+
return (_jsxs("div", { className: cn("agent-mcp-app", uiMeta.prefersBorder === false && "agent-mcp-app--flush", className), children: [!ready && !error && (_jsxs("div", { className: "agent-mcp-app__loading", children: [_jsx(IconLoader2, { size: 14, className: "agent-conversation-spin" }), _jsx("span", { children: "Loading MCP App" })] })), error && (_jsx("div", { className: "agent-mcp-app__error", role: "alert", children: _jsxs("div", { className: "agent-mcp-app__error-box", children: [_jsx(IconAlertTriangle, { size: 15 }), _jsx("span", { children: error }), externalOpenUrl && (_jsx("button", { type: "button", className: "agent-mcp-app__open", onClick: () => window.open(externalOpenUrl, "_blank", "noopener,noreferrer"), children: "Open in new tab" }))] }) })), _jsx("iframe", { ref: iframeRef, title: app.tool?.title ?? app.originalToolName, srcDoc: srcDoc, sandbox: SANDBOX_FLAGS, allow: buildAllowAttribute(supportedPermissions), style: { height }, onError: handleIframeError })] }));
|
|
234
239
|
}
|
|
235
240
|
function messageTextFromMcpUiMessage(params) {
|
|
236
241
|
return textPartsFromMcpContent(params.content).join("\n\n").trim();
|
|
@@ -37,12 +37,39 @@ function defaultCommandDedupKey(command) {
|
|
|
37
37
|
function currentRouterPath(location) {
|
|
38
38
|
return `${location.pathname}${location.search}${location.hash}`;
|
|
39
39
|
}
|
|
40
|
+
function shallowEqualNavigationState(left, right) {
|
|
41
|
+
if (Object.is(left, right))
|
|
42
|
+
return true;
|
|
43
|
+
if (!left ||
|
|
44
|
+
!right ||
|
|
45
|
+
typeof left !== "object" ||
|
|
46
|
+
typeof right !== "object") {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
const leftKeys = Object.keys(left);
|
|
50
|
+
const rightKeys = Object.keys(right);
|
|
51
|
+
if (leftKeys.length !== rightKeys.length)
|
|
52
|
+
return false;
|
|
53
|
+
for (const key of leftKeys) {
|
|
54
|
+
if (!Object.prototype.hasOwnProperty.call(right, key) ||
|
|
55
|
+
!Object.is(left[key], right[key])) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
40
61
|
function stringifyForWriteDedup(value) {
|
|
41
62
|
try {
|
|
42
|
-
|
|
63
|
+
const serialized = JSON.stringify(value);
|
|
64
|
+
return typeof serialized === "string"
|
|
65
|
+
? serialized
|
|
66
|
+
: Symbol("unserializable navigation state");
|
|
43
67
|
}
|
|
44
68
|
catch {
|
|
45
|
-
|
|
69
|
+
// Do not turn a serialization failure into a reusable string key. A
|
|
70
|
+
// distinct token lets a changed unserializable state reach the write path
|
|
71
|
+
// and surface its real error instead of being silently deduplicated.
|
|
72
|
+
return Symbol("unserializable navigation state");
|
|
46
73
|
}
|
|
47
74
|
}
|
|
48
75
|
function resolveAgentChatViewTransitionOption(option, command, path) {
|
|
@@ -65,10 +92,10 @@ export function useSemanticNavigationState(options) {
|
|
|
65
92
|
const commandKeys = useMemo(() => uniqueKeys(options.commandKeys ?? ["navigate"]), [options.commandKeys]);
|
|
66
93
|
const commandQueryKey = useMemo(() => options.commandQueryKey ?? ["navigate-command"], [options.commandQueryKey]);
|
|
67
94
|
const navigationState = options.state ?? null;
|
|
68
|
-
const navigationWriteDedup = stringifyForWriteDedup({
|
|
95
|
+
const navigationWriteDedup = useMemo(() => stringifyForWriteDedup({
|
|
69
96
|
keys: navigationKeys,
|
|
70
97
|
state: navigationState,
|
|
71
|
-
});
|
|
98
|
+
}), [navigationKeys, navigationState]);
|
|
72
99
|
const getCommandDedupKeyRef = useRef(options.getCommandDedupKey);
|
|
73
100
|
const onCommandRef = useRef(options.onCommand);
|
|
74
101
|
const onErrorRef = useRef(options.onError);
|
|
@@ -184,7 +211,17 @@ export function useAgentRouteState(options) {
|
|
|
184
211
|
browserTabId ?? "global",
|
|
185
212
|
], [browserTabId, commandKey, options.commandQueryKey]);
|
|
186
213
|
const routeLocation = useMemo(() => routeLocationFromReactRouter(location), [location]);
|
|
187
|
-
|
|
214
|
+
// Callers may include app-local state in this callback in addition to the
|
|
215
|
+
// router location. Derive on every render so those values are not frozen at
|
|
216
|
+
// the last route change, then retain the previous object when its shallow
|
|
217
|
+
// values are unchanged. This keeps the write-dedup serialization off the
|
|
218
|
+
// unrelated-render path without hiding captured state updates.
|
|
219
|
+
const derivedNavigationState = options.getNavigationState(routeLocation) ?? null;
|
|
220
|
+
const navigationStateRef = useRef(derivedNavigationState);
|
|
221
|
+
if (!shallowEqualNavigationState(navigationStateRef.current, derivedNavigationState)) {
|
|
222
|
+
navigationStateRef.current = derivedNavigationState;
|
|
223
|
+
}
|
|
224
|
+
const navigationState = navigationStateRef.current;
|
|
188
225
|
return useSemanticNavigationState({
|
|
189
226
|
state: navigationState,
|
|
190
227
|
navigationKeys,
|
|
@@ -31,11 +31,13 @@
|
|
|
31
31
|
* refetch when that source fires. A poll heartbeat with no event does
|
|
32
32
|
* nothing.
|
|
33
33
|
*/
|
|
34
|
-
import { useSyncExternalStore } from "react";
|
|
34
|
+
import { useCallback, useMemo, useSyncExternalStore } from "react";
|
|
35
|
+
const MAX_TRACKED_SOURCES = 1_000;
|
|
36
|
+
const ZERO_SNAPSHOT = () => 0;
|
|
35
37
|
class ChangeVersionStore {
|
|
36
38
|
versions = new Map();
|
|
37
|
-
listeners = new
|
|
38
|
-
|
|
39
|
+
listeners = new Map();
|
|
40
|
+
activeSources = new Map();
|
|
39
41
|
/**
|
|
40
42
|
* Advance the counter for `source` to at least `version`. Returns true if
|
|
41
43
|
* the counter actually moved (so callers can avoid spurious work).
|
|
@@ -46,31 +48,60 @@ class ChangeVersionStore {
|
|
|
46
48
|
const current = this.versions.get(source) ?? 0;
|
|
47
49
|
if (version > current) {
|
|
48
50
|
this.versions.set(source, version);
|
|
49
|
-
this.
|
|
50
|
-
this.
|
|
51
|
+
this.evictUnobservedSources();
|
|
52
|
+
for (const listener of this.listeners.get(source) ?? [])
|
|
53
|
+
listener();
|
|
51
54
|
return true;
|
|
52
55
|
}
|
|
53
56
|
return false;
|
|
54
57
|
}
|
|
55
58
|
get(source) {
|
|
56
|
-
|
|
57
|
-
// values, so we serve from a cached map that we only update inside
|
|
58
|
-
// `bump`.
|
|
59
|
-
const cached = this.cachedSnapshots.get(source);
|
|
60
|
-
if (cached !== undefined)
|
|
61
|
-
return cached;
|
|
62
|
-
this.cachedSnapshots.set(source, 0);
|
|
63
|
-
return 0;
|
|
59
|
+
return this.versions.get(source) ?? 0;
|
|
64
60
|
}
|
|
65
|
-
subscribe(listener) {
|
|
66
|
-
|
|
61
|
+
subscribe(sources, listener) {
|
|
62
|
+
const uniqueSources = new Set(sources.filter(Boolean));
|
|
63
|
+
for (const source of uniqueSources) {
|
|
64
|
+
this.activeSources.set(source, (this.activeSources.get(source) ?? 0) + 1);
|
|
65
|
+
let listeners = this.listeners.get(source);
|
|
66
|
+
if (!listeners) {
|
|
67
|
+
listeners = new Set();
|
|
68
|
+
this.listeners.set(source, listeners);
|
|
69
|
+
}
|
|
70
|
+
listeners.add(listener);
|
|
71
|
+
}
|
|
67
72
|
return () => {
|
|
68
|
-
|
|
73
|
+
for (const source of uniqueSources) {
|
|
74
|
+
const listeners = this.listeners.get(source);
|
|
75
|
+
listeners?.delete(listener);
|
|
76
|
+
if (listeners?.size === 0)
|
|
77
|
+
this.listeners.delete(source);
|
|
78
|
+
const count = (this.activeSources.get(source) ?? 1) - 1;
|
|
79
|
+
if (count > 0)
|
|
80
|
+
this.activeSources.set(source, count);
|
|
81
|
+
else
|
|
82
|
+
this.activeSources.delete(source);
|
|
83
|
+
}
|
|
84
|
+
this.evictUnobservedSources();
|
|
69
85
|
};
|
|
70
86
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
87
|
+
reset() {
|
|
88
|
+
this.versions.clear();
|
|
89
|
+
this.listeners.clear();
|
|
90
|
+
this.activeSources.clear();
|
|
91
|
+
}
|
|
92
|
+
evictUnobservedSources() {
|
|
93
|
+
while (this.versions.size > MAX_TRACKED_SOURCES) {
|
|
94
|
+
let evicted = false;
|
|
95
|
+
for (const source of this.versions.keys()) {
|
|
96
|
+
if (this.activeSources.has(source))
|
|
97
|
+
continue;
|
|
98
|
+
this.versions.delete(source);
|
|
99
|
+
evicted = true;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
if (!evicted)
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
74
105
|
}
|
|
75
106
|
}
|
|
76
107
|
const store = new ChangeVersionStore();
|
|
@@ -110,7 +141,9 @@ export function getChangeVersion(source) {
|
|
|
110
141
|
* ```
|
|
111
142
|
*/
|
|
112
143
|
export function useChangeVersion(source) {
|
|
113
|
-
|
|
144
|
+
const subscribe = useCallback((listener) => store.subscribe([source], listener), [source]);
|
|
145
|
+
const getSnapshot = useCallback(() => store.get(source), [source]);
|
|
146
|
+
return useSyncExternalStore(subscribe, getSnapshot, ZERO_SNAPSHOT);
|
|
114
147
|
}
|
|
115
148
|
/**
|
|
116
149
|
* Convenience for queries that should refetch on multiple sources — returns
|
|
@@ -123,12 +156,25 @@ export function useChangeVersion(source) {
|
|
|
123
156
|
* ```
|
|
124
157
|
*/
|
|
125
158
|
export function useChangeVersions(sources) {
|
|
126
|
-
|
|
159
|
+
const sourceKey = sources
|
|
160
|
+
.map((source) => `${source.length}:${source}`)
|
|
161
|
+
.join("\u0001");
|
|
162
|
+
const stableSources = useMemo(() => {
|
|
163
|
+
const uniqueSources = [];
|
|
164
|
+
const seen = new Set();
|
|
165
|
+
for (const source of sources) {
|
|
166
|
+
if (seen.has(source))
|
|
167
|
+
continue;
|
|
168
|
+
seen.add(source);
|
|
169
|
+
uniqueSources.push(source);
|
|
170
|
+
}
|
|
171
|
+
return uniqueSources;
|
|
172
|
+
}, [sourceKey]);
|
|
173
|
+
const subscribe = useCallback((listener) => store.subscribe(stableSources, listener), [stableSources]);
|
|
174
|
+
const getSnapshot = useCallback(() => stableSources.reduce((sum, src) => sum + store.get(src), 0), [stableSources]);
|
|
175
|
+
return useSyncExternalStore(subscribe, getSnapshot, ZERO_SNAPSHOT);
|
|
127
176
|
}
|
|
128
177
|
/** Internal test helper — reset all counters. Do not use in app code. */
|
|
129
178
|
export function _resetChangeVersionStoreForTests() {
|
|
130
|
-
|
|
131
|
-
store.versions.clear();
|
|
132
|
-
// @ts-expect-error reaching past private to clear state in tests
|
|
133
|
-
store.cachedSnapshots.clear();
|
|
179
|
+
store.reset();
|
|
134
180
|
}
|