@agent-native/core 0.35.3 → 0.37.0
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/cli/index.js +1 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/skills.d.ts.map +1 -1
- package/dist/cli/skills.js +249 -11
- package/dist/cli/skills.js.map +1 -1
- package/dist/client/AssistantChat.d.ts.map +1 -1
- package/dist/client/AssistantChat.js +25 -25
- package/dist/client/AssistantChat.js.map +1 -1
- package/dist/client/MultiTabAssistantChat.d.ts.map +1 -1
- package/dist/client/MultiTabAssistantChat.js +32 -15
- package/dist/client/MultiTabAssistantChat.js.map +1 -1
- package/dist/client/agent-chat-adapter.d.ts.map +1 -1
- package/dist/client/agent-chat-adapter.js +68 -24
- package/dist/client/agent-chat-adapter.js.map +1 -1
- package/dist/client/composer/ComposerPlusMenu.d.ts.map +1 -1
- package/dist/client/composer/ComposerPlusMenu.js +174 -8
- package/dist/client/composer/ComposerPlusMenu.js.map +1 -1
- package/dist/client/composer/PromptComposer.d.ts +2 -0
- package/dist/client/composer/PromptComposer.d.ts.map +1 -1
- package/dist/client/composer/PromptComposer.js +2 -2
- package/dist/client/composer/PromptComposer.js.map +1 -1
- package/dist/client/composer/TiptapComposer.js +1 -1
- package/dist/client/composer/TiptapComposer.js.map +1 -1
- package/dist/client/context-xray/ContextMeter.d.ts +2 -1
- package/dist/client/context-xray/ContextMeter.d.ts.map +1 -1
- package/dist/client/context-xray/ContextMeter.js +19 -25
- package/dist/client/context-xray/ContextMeter.js.map +1 -1
- package/dist/client/context-xray/ContextXRayPanel.d.ts +1 -3
- package/dist/client/context-xray/ContextXRayPanel.d.ts.map +1 -1
- package/dist/client/context-xray/ContextXRayPanel.js +27 -24
- package/dist/client/context-xray/ContextXRayPanel.js.map +1 -1
- package/dist/client/conversation/AgentConversation.d.ts.map +1 -1
- package/dist/client/conversation/AgentConversation.js +2 -1
- package/dist/client/conversation/AgentConversation.js.map +1 -1
- package/dist/client/dynamic-suggestions.d.ts +13 -7
- package/dist/client/dynamic-suggestions.d.ts.map +1 -1
- package/dist/client/dynamic-suggestions.js +23 -12
- package/dist/client/dynamic-suggestions.js.map +1 -1
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -0
- package/dist/client/index.js.map +1 -1
- package/dist/client/route-state.d.ts +116 -0
- package/dist/client/route-state.d.ts.map +1 -0
- package/dist/client/route-state.js +205 -0
- package/dist/client/route-state.js.map +1 -0
- package/dist/client/sse-event-processor.d.ts +1 -0
- package/dist/client/sse-event-processor.d.ts.map +1 -1
- package/dist/client/sse-event-processor.js +62 -15
- package/dist/client/sse-event-processor.js.map +1 -1
- package/dist/client/tool-display.d.ts +4 -0
- package/dist/client/tool-display.d.ts.map +1 -0
- package/dist/client/tool-display.js +28 -0
- package/dist/client/tool-display.js.map +1 -0
- package/dist/client/use-chat-threads.d.ts.map +1 -1
- package/dist/client/use-chat-threads.js +40 -31
- package/dist/client/use-chat-threads.js.map +1 -1
- package/dist/client/use-external-value.d.ts.map +1 -1
- package/dist/client/use-external-value.js +14 -7
- package/dist/client/use-external-value.js.map +1 -1
- package/dist/extensions/html-shell.d.ts +3 -2
- package/dist/extensions/html-shell.d.ts.map +1 -1
- package/dist/extensions/html-shell.js +12 -2
- package/dist/extensions/html-shell.js.map +1 -1
- package/dist/extensions/routes.js +2 -7
- package/dist/extensions/routes.js.map +1 -1
- package/dist/server/core-routes-plugin.js +2 -2
- package/dist/server/core-routes-plugin.js.map +1 -1
- package/dist/server/security-headers.d.ts +16 -19
- package/dist/server/security-headers.d.ts.map +1 -1
- package/dist/server/security-headers.js +24 -25
- package/dist/server/security-headers.js.map +1 -1
- package/dist/templates/default/AGENTS.md +7 -1
- package/dist/templates/default/app/hooks/use-navigation-state.ts +10 -76
- package/docs/content/context-awareness.md +90 -48
- package/docs/content/creating-templates.md +22 -1
- package/docs/content/external-agents.md +1 -1
- package/package.json +2 -1
- package/src/templates/default/AGENTS.md +7 -1
- package/src/templates/default/app/hooks/use-navigation-state.ts +10 -76
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Sets a baseline set of "no-brainer" security headers on every framework HTTP
|
|
5
5
|
* response. These headers are layered defenses: each one mitigates a specific
|
|
6
|
-
* class of attack, and together they harden the surface against
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* class of attack, and together they harden the surface against MIME-sniffing,
|
|
7
|
+
* referrer leakage, mixed-content downgrades, and cross-origin window/embed
|
|
8
|
+
* access.
|
|
9
9
|
*
|
|
10
10
|
* The headers we emit:
|
|
11
11
|
*
|
|
@@ -16,15 +16,6 @@
|
|
|
16
16
|
* - `X-Content-Type-Options: nosniff` — disables browser MIME sniffing so
|
|
17
17
|
* a tool /render route serving user-authored HTML can't be misinterpreted
|
|
18
18
|
* as some other content type by a clever Accept header.
|
|
19
|
-
* - `X-Frame-Options: DENY` — prevents the entire app from being iframed by
|
|
20
|
-
* other origins (clickjacking the agent chat, booking pages, etc.). The
|
|
21
|
-
* tool /render endpoint and any other route that legitimately needs to be
|
|
22
|
-
* embedded in the same-origin app shell can opt out by setting its own
|
|
23
|
-
* header inside the route handler — h3's `setResponseHeader` overwrites,
|
|
24
|
-
* so a route emitting `SAMEORIGIN` wins over our middleware default.
|
|
25
|
-
* We skip this header entirely in dev (NODE_ENV !== "production") so the
|
|
26
|
-
* desktop app's local dev frame (localhost:3334) can iframe templates
|
|
27
|
-
* running on other localhost ports (e.g. mail at 8085).
|
|
28
19
|
* - `Referrer-Policy: strict-origin-when-cross-origin` — strips path/query
|
|
29
20
|
* from outbound Referer headers when the request crosses origin, so a
|
|
30
21
|
* public-share viewer's outbound link clicks never leak the share token.
|
|
@@ -36,25 +27,31 @@
|
|
|
36
27
|
* - `Cross-Origin-Opener-Policy: same-origin` — isolates window.opener so
|
|
37
28
|
* a popup-window opener reference can't read or modify our document.
|
|
38
29
|
* - `Cross-Origin-Embedder-Policy: require-corp` — emitted only for
|
|
39
|
-
* validated MCP embed-session page loads
|
|
40
|
-
* Apps proxy require framed cross-origin
|
|
30
|
+
* validated MCP embed-session page loads and browser iframe navigations.
|
|
31
|
+
* COEP hosts such as Claude's MCP Apps proxy require framed cross-origin
|
|
32
|
+
* documents to opt in explicitly.
|
|
41
33
|
* - `Cross-Origin-Resource-Policy: same-site` — prevents other origins from
|
|
42
34
|
* embedding our endpoints as `<img>` / `<script>` / `<audio>`, blocking
|
|
43
35
|
* the simplest data-leak chain when combined with auth cookies. Validated
|
|
44
|
-
* MCP embed-session page loads
|
|
45
|
-
*
|
|
36
|
+
* MCP embed-session page loads and browser iframe navigations use
|
|
37
|
+
* `cross-origin` so COEP hosts can frame app documents.
|
|
46
38
|
*
|
|
47
39
|
* NOTE: `Cross-Origin-Embedder-Policy` is NOT set by default because it
|
|
48
40
|
* requires every embedded subresource to opt in via CORP/CORS, which would
|
|
49
41
|
* break Builder's iframe editor and template embed use cases. COOP + CORP
|
|
50
42
|
* without COEP gives us most of the protection on normal responses; COEP is
|
|
51
|
-
* only added for validated MCP embed-session page loads
|
|
43
|
+
* only added for validated MCP embed-session page loads and browser iframe
|
|
44
|
+
* navigations (see above).
|
|
45
|
+
*
|
|
46
|
+
* NOTE: `X-Frame-Options` is intentionally not set globally. Agent-native apps
|
|
47
|
+
* are expected to run inside iframe hosts such as Builder, Design, and MCP app
|
|
48
|
+
* shells. Routes that render especially sensitive iframe-only documents should
|
|
49
|
+
* set their own route-specific CSP / frame policy.
|
|
52
50
|
*/
|
|
53
51
|
/**
|
|
54
52
|
* Create the security-headers h3 middleware. Mount this BEFORE other route
|
|
55
53
|
* handlers so the headers are present on every response (including 4xx/5xx
|
|
56
|
-
* error pages). Route handlers that need to
|
|
57
|
-
* `X-Frame-Options: SAMEORIGIN` on the tool render route) can call
|
|
54
|
+
* error pages). Route handlers that need to tighten a specific header can call
|
|
58
55
|
* `setResponseHeader` after this runs — the latest write wins.
|
|
59
56
|
*/
|
|
60
57
|
export declare function createSecurityHeadersMiddleware(): import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"security-headers.d.ts","sourceRoot":"","sources":["../../src/server/security-headers.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"security-headers.d.ts","sourceRoot":"","sources":["../../src/server/security-headers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AA+CH;;;;;GAKG;AACH,wBAAgB,+BAA+B,8EA4C9C"}
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Sets a baseline set of "no-brainer" security headers on every framework HTTP
|
|
5
5
|
* response. These headers are layered defenses: each one mitigates a specific
|
|
6
|
-
* class of attack, and together they harden the surface against
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* class of attack, and together they harden the surface against MIME-sniffing,
|
|
7
|
+
* referrer leakage, mixed-content downgrades, and cross-origin window/embed
|
|
8
|
+
* access.
|
|
9
9
|
*
|
|
10
10
|
* The headers we emit:
|
|
11
11
|
*
|
|
@@ -16,15 +16,6 @@
|
|
|
16
16
|
* - `X-Content-Type-Options: nosniff` — disables browser MIME sniffing so
|
|
17
17
|
* a tool /render route serving user-authored HTML can't be misinterpreted
|
|
18
18
|
* as some other content type by a clever Accept header.
|
|
19
|
-
* - `X-Frame-Options: DENY` — prevents the entire app from being iframed by
|
|
20
|
-
* other origins (clickjacking the agent chat, booking pages, etc.). The
|
|
21
|
-
* tool /render endpoint and any other route that legitimately needs to be
|
|
22
|
-
* embedded in the same-origin app shell can opt out by setting its own
|
|
23
|
-
* header inside the route handler — h3's `setResponseHeader` overwrites,
|
|
24
|
-
* so a route emitting `SAMEORIGIN` wins over our middleware default.
|
|
25
|
-
* We skip this header entirely in dev (NODE_ENV !== "production") so the
|
|
26
|
-
* desktop app's local dev frame (localhost:3334) can iframe templates
|
|
27
|
-
* running on other localhost ports (e.g. mail at 8085).
|
|
28
19
|
* - `Referrer-Policy: strict-origin-when-cross-origin` — strips path/query
|
|
29
20
|
* from outbound Referer headers when the request crosses origin, so a
|
|
30
21
|
* public-share viewer's outbound link clicks never leak the share token.
|
|
@@ -36,19 +27,26 @@
|
|
|
36
27
|
* - `Cross-Origin-Opener-Policy: same-origin` — isolates window.opener so
|
|
37
28
|
* a popup-window opener reference can't read or modify our document.
|
|
38
29
|
* - `Cross-Origin-Embedder-Policy: require-corp` — emitted only for
|
|
39
|
-
* validated MCP embed-session page loads
|
|
40
|
-
* Apps proxy require framed cross-origin
|
|
30
|
+
* validated MCP embed-session page loads and browser iframe navigations.
|
|
31
|
+
* COEP hosts such as Claude's MCP Apps proxy require framed cross-origin
|
|
32
|
+
* documents to opt in explicitly.
|
|
41
33
|
* - `Cross-Origin-Resource-Policy: same-site` — prevents other origins from
|
|
42
34
|
* embedding our endpoints as `<img>` / `<script>` / `<audio>`, blocking
|
|
43
35
|
* the simplest data-leak chain when combined with auth cookies. Validated
|
|
44
|
-
* MCP embed-session page loads
|
|
45
|
-
*
|
|
36
|
+
* MCP embed-session page loads and browser iframe navigations use
|
|
37
|
+
* `cross-origin` so COEP hosts can frame app documents.
|
|
46
38
|
*
|
|
47
39
|
* NOTE: `Cross-Origin-Embedder-Policy` is NOT set by default because it
|
|
48
40
|
* requires every embedded subresource to opt in via CORP/CORS, which would
|
|
49
41
|
* break Builder's iframe editor and template embed use cases. COOP + CORP
|
|
50
42
|
* without COEP gives us most of the protection on normal responses; COEP is
|
|
51
|
-
* only added for validated MCP embed-session page loads
|
|
43
|
+
* only added for validated MCP embed-session page loads and browser iframe
|
|
44
|
+
* navigations (see above).
|
|
45
|
+
*
|
|
46
|
+
* NOTE: `X-Frame-Options` is intentionally not set globally. Agent-native apps
|
|
47
|
+
* are expected to run inside iframe hosts such as Builder, Design, and MCP app
|
|
48
|
+
* shells. Routes that render especially sensitive iframe-only documents should
|
|
49
|
+
* set their own route-specific CSP / frame policy.
|
|
52
50
|
*/
|
|
53
51
|
import { defineEventHandler, getHeader, setResponseHeader } from "h3";
|
|
54
52
|
import { requestHasEmbedAuthMarker } from "./embed-session.js";
|
|
@@ -82,30 +80,31 @@ function isMcpEndpointRequest(event) {
|
|
|
82
80
|
String(event?.node?.req?.url ?? event?.path ?? "/").split("?")[0];
|
|
83
81
|
return (pathname === "/_agent-native/mcp" || pathname.endsWith("/_agent-native/mcp"));
|
|
84
82
|
}
|
|
83
|
+
function isIframeNavigationRequest(event) {
|
|
84
|
+
return getHeader(event, "sec-fetch-dest") === "iframe";
|
|
85
|
+
}
|
|
85
86
|
/**
|
|
86
87
|
* Create the security-headers h3 middleware. Mount this BEFORE other route
|
|
87
88
|
* handlers so the headers are present on every response (including 4xx/5xx
|
|
88
|
-
* error pages). Route handlers that need to
|
|
89
|
-
* `X-Frame-Options: SAMEORIGIN` on the tool render route) can call
|
|
89
|
+
* error pages). Route handlers that need to tighten a specific header can call
|
|
90
90
|
* `setResponseHeader` after this runs — the latest write wins.
|
|
91
91
|
*/
|
|
92
92
|
export function createSecurityHeadersMiddleware() {
|
|
93
|
-
const isProduction = process.env.NODE_ENV === "production";
|
|
94
93
|
return defineEventHandler((event) => {
|
|
95
94
|
const embedFrameRequest = requestHasEmbedAuthMarker(event);
|
|
96
95
|
const mcpEndpointRequest = isMcpEndpointRequest(event);
|
|
96
|
+
const iframeNavigationRequest = isIframeNavigationRequest(event);
|
|
97
97
|
const requestOrigin = getHeader(event, "origin");
|
|
98
98
|
setResponseHeader(event, "X-Content-Type-Options", "nosniff");
|
|
99
|
-
if (isProduction && !embedFrameRequest) {
|
|
100
|
-
setResponseHeader(event, "X-Frame-Options", "DENY");
|
|
101
|
-
}
|
|
102
99
|
setResponseHeader(event, "Referrer-Policy", embedFrameRequest ? "no-referrer" : "strict-origin-when-cross-origin");
|
|
103
100
|
setResponseHeader(event, "Permissions-Policy", PERMISSIONS_POLICY);
|
|
104
101
|
setResponseHeader(event, "Cross-Origin-Opener-Policy", "same-origin");
|
|
105
|
-
if (embedFrameRequest) {
|
|
102
|
+
if (embedFrameRequest || iframeNavigationRequest) {
|
|
106
103
|
setResponseHeader(event, "Cross-Origin-Embedder-Policy", "require-corp");
|
|
107
104
|
}
|
|
108
|
-
setResponseHeader(event, "Cross-Origin-Resource-Policy", embedFrameRequest || mcpEndpointRequest
|
|
105
|
+
setResponseHeader(event, "Cross-Origin-Resource-Policy", embedFrameRequest || mcpEndpointRequest || iframeNavigationRequest
|
|
106
|
+
? "cross-origin"
|
|
107
|
+
: "same-site");
|
|
109
108
|
if (embedFrameRequest && isMcpEmbedCorsOrigin(requestOrigin)) {
|
|
110
109
|
setResponseHeader(event, "Access-Control-Allow-Origin", requestOrigin);
|
|
111
110
|
setResponseHeader(event, "Vary", "Origin");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"security-headers.js","sourceRoot":"","sources":["../../src/server/security-headers.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"security-headers.js","sourceRoot":"","sources":["../../src/server/security-headers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAEH,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAC;AACtE,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EACL,oBAAoB,EACpB,4BAA4B,GAC7B,MAAM,gCAAgC,CAAC;AAExC,MAAM,IAAI,GAAG,8CAA8C,CAAC;AAC5D,MAAM,kBAAkB,GACtB,mEAAmE,CAAC;AAEtE;;;;;GAKG;AACH,SAAS,cAAc,CAAC,KAAU;IAChC,MAAM,GAAG,GACP,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,mBAAmB,CAAC;QAChD,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,mBAAmB,CAAC,CAAC;IAC7C,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,OAAO;QACjE,OAAO,IAAI,CAAC;IACd,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,OAAO;QAAE,OAAO,IAAI,CAAC;IAC1D,uDAAuD;IACvD,MAAM,KAAK,GAAG,KAAK,EAAE,GAAG,EAAE,QAAQ,CAAC;IACnC,IAAI,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACpC,2DAA2D;IAC3D,IAAI,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,SAAS;QAAE,OAAO,IAAI,CAAC;IACzD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,oBAAoB,CAAC,KAAU;IACtC,MAAM,QAAQ,GACZ,KAAK,EAAE,GAAG,EAAE,QAAQ;QACpB,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,KAAK,EAAE,IAAI,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACpE,OAAO,CACL,QAAQ,KAAK,oBAAoB,IAAI,QAAQ,CAAC,QAAQ,CAAC,oBAAoB,CAAC,CAC7E,CAAC;AACJ,CAAC;AAED,SAAS,yBAAyB,CAAC,KAAU;IAC3C,OAAO,SAAS,CAAC,KAAK,EAAE,gBAAgB,CAAC,KAAK,QAAQ,CAAC;AACzD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,+BAA+B;IAC7C,OAAO,kBAAkB,CAAC,CAAC,KAAK,EAAE,EAAE;QAClC,MAAM,iBAAiB,GAAG,yBAAyB,CAAC,KAAK,CAAC,CAAC;QAC3D,MAAM,kBAAkB,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;QACvD,MAAM,uBAAuB,GAAG,yBAAyB,CAAC,KAAK,CAAC,CAAC;QACjE,MAAM,aAAa,GAAG,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QACjD,iBAAiB,CAAC,KAAK,EAAE,wBAAwB,EAAE,SAAS,CAAC,CAAC;QAC9D,iBAAiB,CACf,KAAK,EACL,iBAAiB,EACjB,iBAAiB,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,iCAAiC,CACtE,CAAC;QACF,iBAAiB,CAAC,KAAK,EAAE,oBAAoB,EAAE,kBAAkB,CAAC,CAAC;QACnE,iBAAiB,CAAC,KAAK,EAAE,4BAA4B,EAAE,aAAa,CAAC,CAAC;QACtE,IAAI,iBAAiB,IAAI,uBAAuB,EAAE,CAAC;YACjD,iBAAiB,CAAC,KAAK,EAAE,8BAA8B,EAAE,cAAc,CAAC,CAAC;QAC3E,CAAC;QACD,iBAAiB,CACf,KAAK,EACL,8BAA8B,EAC9B,iBAAiB,IAAI,kBAAkB,IAAI,uBAAuB;YAChE,CAAC,CAAC,cAAc;YAChB,CAAC,CAAC,WAAW,CAChB,CAAC;QACF,IAAI,iBAAiB,IAAI,oBAAoB,CAAC,aAAa,CAAC,EAAE,CAAC;YAC7D,iBAAiB,CAAC,KAAK,EAAE,6BAA6B,EAAE,aAAa,CAAC,CAAC;YACvE,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;YAC3C,iBAAiB,CACf,KAAK,EACL,8BAA8B,EAC9B,wCAAwC,CACzC,CAAC;YACF,iBAAiB,CACf,KAAK,EACL,8BAA8B,EAC9B,4BAA4B,CAC7B,CAAC;QACJ,CAAC;QACD,IAAI,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,iBAAiB,CAAC,KAAK,EAAE,2BAA2B,EAAE,IAAI,CAAC,CAAC;QAC9D,CAAC;QACD,2EAA2E;QAC3E,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * Security response headers middleware.\n *\n * Sets a baseline set of \"no-brainer\" security headers on every framework HTTP\n * response. These headers are layered defenses: each one mitigates a specific\n * class of attack, and together they harden the surface against MIME-sniffing,\n * referrer leakage, mixed-content downgrades, and cross-origin window/embed\n * access.\n *\n * The headers we emit:\n *\n * - `Strict-Transport-Security` — forces HTTPS for the browser's lifetime\n * of the cached value, preventing SSL-strip MITM. Only emitted when the\n * request scheme is `https` (we don't want to break local-dev HTTP, and\n * emitting HSTS over HTTP is a no-op per the spec but causes confusion).\n * - `X-Content-Type-Options: nosniff` — disables browser MIME sniffing so\n * a tool /render route serving user-authored HTML can't be misinterpreted\n * as some other content type by a clever Accept header.\n * - `Referrer-Policy: strict-origin-when-cross-origin` — strips path/query\n * from outbound Referer headers when the request crosses origin, so a\n * public-share viewer's outbound link clicks never leak the share token.\n * - `Permissions-Policy: camera=(), microphone=(self), geolocation=(),\n * screen-wake-lock=()` — allows the app shell to request microphone access\n * for composer dictation while keeping camera/location/wake-lock blocked\n * by default. Templates that need broader media capture for recording UI\n * override this on their own routes.\n * - `Cross-Origin-Opener-Policy: same-origin` — isolates window.opener so\n * a popup-window opener reference can't read or modify our document.\n * - `Cross-Origin-Embedder-Policy: require-corp` — emitted only for\n * validated MCP embed-session page loads and browser iframe navigations.\n * COEP hosts such as Claude's MCP Apps proxy require framed cross-origin\n * documents to opt in explicitly.\n * - `Cross-Origin-Resource-Policy: same-site` — prevents other origins from\n * embedding our endpoints as `<img>` / `<script>` / `<audio>`, blocking\n * the simplest data-leak chain when combined with auth cookies. Validated\n * MCP embed-session page loads and browser iframe navigations use\n * `cross-origin` so COEP hosts can frame app documents.\n *\n * NOTE: `Cross-Origin-Embedder-Policy` is NOT set by default because it\n * requires every embedded subresource to opt in via CORP/CORS, which would\n * break Builder's iframe editor and template embed use cases. COOP + CORP\n * without COEP gives us most of the protection on normal responses; COEP is\n * only added for validated MCP embed-session page loads and browser iframe\n * navigations (see above).\n *\n * NOTE: `X-Frame-Options` is intentionally not set globally. Agent-native apps\n * are expected to run inside iframe hosts such as Builder, Design, and MCP app\n * shells. Routes that render especially sensitive iframe-only documents should\n * set their own route-specific CSP / frame policy.\n */\n\nimport { defineEventHandler, getHeader, setResponseHeader } from \"h3\";\nimport { requestHasEmbedAuthMarker } from \"./embed-session.js\";\nimport {\n isMcpEmbedCorsOrigin,\n MCP_EMBED_CORS_ALLOW_HEADERS,\n} from \"../shared/mcp-embed-headers.js\";\n\nconst HSTS = \"max-age=31536000; includeSubDomains; preload\";\nconst PERMISSIONS_POLICY =\n \"camera=(), microphone=(self), geolocation=(), screen-wake-lock=()\";\n\n/**\n * Returns true when the request was received over HTTPS. We trust both the\n * underlying connection (when the server is terminating TLS itself) and the\n * `x-forwarded-proto` header (set by Netlify, Vercel, Cloudflare, and any\n * other reverse proxy that fronts the framework).\n */\nfunction isHttpsRequest(event: any): boolean {\n const xfp =\n event?.node?.req?.headers?.[\"x-forwarded-proto\"] ??\n event?.headers?.get?.(\"x-forwarded-proto\");\n if (typeof xfp === \"string\" && xfp.split(\",\")[0].trim() === \"https\")\n return true;\n if (Array.isArray(xfp) && xfp[0] === \"https\") return true;\n // h3 sets `event.url.protocol` to \"http:\" or \"https:\".\n const proto = event?.url?.protocol;\n if (proto === \"https:\") return true;\n // Direct Node `req.connection.encrypted` (older runtimes).\n if (event?.node?.req?.connection?.encrypted) return true;\n return false;\n}\n\nfunction isMcpEndpointRequest(event: any): boolean {\n const pathname =\n event?.url?.pathname ??\n String(event?.node?.req?.url ?? event?.path ?? \"/\").split(\"?\")[0];\n return (\n pathname === \"/_agent-native/mcp\" || pathname.endsWith(\"/_agent-native/mcp\")\n );\n}\n\nfunction isIframeNavigationRequest(event: any): boolean {\n return getHeader(event, \"sec-fetch-dest\") === \"iframe\";\n}\n\n/**\n * Create the security-headers h3 middleware. Mount this BEFORE other route\n * handlers so the headers are present on every response (including 4xx/5xx\n * error pages). Route handlers that need to tighten a specific header can call\n * `setResponseHeader` after this runs — the latest write wins.\n */\nexport function createSecurityHeadersMiddleware() {\n return defineEventHandler((event) => {\n const embedFrameRequest = requestHasEmbedAuthMarker(event);\n const mcpEndpointRequest = isMcpEndpointRequest(event);\n const iframeNavigationRequest = isIframeNavigationRequest(event);\n const requestOrigin = getHeader(event, \"origin\");\n setResponseHeader(event, \"X-Content-Type-Options\", \"nosniff\");\n setResponseHeader(\n event,\n \"Referrer-Policy\",\n embedFrameRequest ? \"no-referrer\" : \"strict-origin-when-cross-origin\",\n );\n setResponseHeader(event, \"Permissions-Policy\", PERMISSIONS_POLICY);\n setResponseHeader(event, \"Cross-Origin-Opener-Policy\", \"same-origin\");\n if (embedFrameRequest || iframeNavigationRequest) {\n setResponseHeader(event, \"Cross-Origin-Embedder-Policy\", \"require-corp\");\n }\n setResponseHeader(\n event,\n \"Cross-Origin-Resource-Policy\",\n embedFrameRequest || mcpEndpointRequest || iframeNavigationRequest\n ? \"cross-origin\"\n : \"same-site\",\n );\n if (embedFrameRequest && isMcpEmbedCorsOrigin(requestOrigin)) {\n setResponseHeader(event, \"Access-Control-Allow-Origin\", requestOrigin);\n setResponseHeader(event, \"Vary\", \"Origin\");\n setResponseHeader(\n event,\n \"Access-Control-Allow-Methods\",\n \"GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS\",\n );\n setResponseHeader(\n event,\n \"Access-Control-Allow-Headers\",\n MCP_EMBED_CORS_ALLOW_HEADERS,\n );\n }\n if (isHttpsRequest(event)) {\n setResponseHeader(event, \"Strict-Transport-Security\", HSTS);\n }\n // Continue to the next handler — we only set headers, don't return a body.\n return undefined;\n });\n}\n"]}
|
|
@@ -57,6 +57,12 @@ Ephemeral UI state is stored in the SQL `application_state` table, accessed via
|
|
|
57
57
|
|
|
58
58
|
The `navigation` key is written by the UI whenever the route changes. The `navigate` key is a one-shot command: the agent writes it, the UI reads and executes the navigation, then deletes it.
|
|
59
59
|
|
|
60
|
+
UI code should use `useAgentRouteState` / `useSemanticNavigationState` from
|
|
61
|
+
`@agent-native/core/client` for navigation sync instead of hand-written
|
|
62
|
+
`fetch("/_agent-native/application-state/...")` calls. Keep shareable filters
|
|
63
|
+
in URL query params; the framework exposes them as `<current-url>` and the
|
|
64
|
+
built-in agent can update them with `set-search-params`.
|
|
65
|
+
|
|
60
66
|
## Mounted Workspace Routing
|
|
61
67
|
|
|
62
68
|
This app may be mounted under `/<app-id>` in a workspace. Inside app source, React Router paths are app-local: use `<Link to="/review">` and `navigate("/review")`, not `/<app-id>/review`. The workspace gateway and `APP_BASE_PATH` add the mounted prefix in the browser; hardcoding it inside React Router links causes doubled URLs such as `/<app-id>/<app-id>/review`.
|
|
@@ -123,7 +129,7 @@ Skills in `.agents/skills/` provide detailed guidance for each architectural rul
|
|
|
123
129
|
|
|
124
130
|
**Read the `adding-a-feature` skill first** — it has the full four-area checklist (UI / Action / Skills / App-State). Quick summary:
|
|
125
131
|
|
|
126
|
-
1. **Add navigation state entries** — extend `app/hooks/use-navigation-state.ts` to track new routes
|
|
132
|
+
1. **Add navigation state entries** — extend `app/hooks/use-navigation-state.ts` to track new routes with `useAgentRouteState`
|
|
127
133
|
2. **Enhance view-screen** — make the view-screen script return relevant context for the new view
|
|
128
134
|
3. **Create domain actions** — add actions in `actions/` for CRUD operations on new data models; do not create REST wrappers around those actions
|
|
129
135
|
4. **Wire UI for auto-refresh** — use `useActionQuery` / `useActionMutation` for normal CRUD. If a raw `useQuery` is unavoidable, fold `useChangeVersions([<source>, "action"])` into its key with `placeholderData`. When the agent mutates this data, the UI must reflect the change without a manual refresh. See `real-time-sync` skill.
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { useEffect, useRef } from "react";
|
|
2
|
-
import { useLocation, useNavigate } from "react-router";
|
|
3
|
-
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
4
1
|
import {
|
|
5
|
-
agentNativePath,
|
|
6
2
|
appBasePath,
|
|
7
3
|
appPath,
|
|
4
|
+
useAgentRouteState,
|
|
8
5
|
} from "@agent-native/core/client";
|
|
9
6
|
import { TAB_ID } from "../lib/tab-id";
|
|
10
7
|
|
|
@@ -18,79 +15,16 @@ export interface NavigationState {
|
|
|
18
15
|
}
|
|
19
16
|
|
|
20
17
|
export function useNavigationState() {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
fetch(agentNativePath("/_agent-native/application-state/navigation"), {
|
|
32
|
-
method: "PUT",
|
|
33
|
-
keepalive: true,
|
|
34
|
-
headers: {
|
|
35
|
-
"Content-Type": "application/json",
|
|
36
|
-
"X-Request-Source": TAB_ID,
|
|
37
|
-
},
|
|
38
|
-
body: JSON.stringify(state),
|
|
39
|
-
}).catch(() => {});
|
|
40
|
-
}, [location.pathname]);
|
|
41
|
-
|
|
42
|
-
// Default React Query structuralSharing reuses the previous reference when
|
|
43
|
-
// the JSON is unchanged, so repeated invalidations driven by `useDbSync`
|
|
44
|
-
// (which fire on every relevant app-state event) don't re-fire the
|
|
45
|
-
// useEffect with a brand-new object containing the same command.
|
|
46
|
-
const { data: navCommand } = useQuery<NavigationState | null>({
|
|
47
|
-
queryKey: ["navigate-command"],
|
|
48
|
-
queryFn: async () => {
|
|
49
|
-
const res = await fetch(
|
|
50
|
-
agentNativePath("/_agent-native/application-state/navigate"),
|
|
51
|
-
);
|
|
52
|
-
if (!res.ok) return null;
|
|
53
|
-
const data = await res.json();
|
|
54
|
-
return data ?? null;
|
|
55
|
-
},
|
|
56
|
-
refetchInterval: 2_000,
|
|
18
|
+
useAgentRouteState<NavigationState>({
|
|
19
|
+
browserTabId: TAB_ID,
|
|
20
|
+
requestSource: TAB_ID,
|
|
21
|
+
getNavigationState: ({ pathname, search, hash }) => ({
|
|
22
|
+
view: viewFromPath(pathname),
|
|
23
|
+
path: appPath(`${pathname}${search}${hash}`),
|
|
24
|
+
}),
|
|
25
|
+
getCommandPath: (command) =>
|
|
26
|
+
routerPath(command.path || pathFromView(command.view)),
|
|
57
27
|
});
|
|
58
|
-
|
|
59
|
-
const lastProcessedDedupKeyRef = useRef<string | null>(null);
|
|
60
|
-
|
|
61
|
-
useEffect(() => {
|
|
62
|
-
if (!navCommand) return;
|
|
63
|
-
const cmd = navCommand;
|
|
64
|
-
const dedupKey =
|
|
65
|
-
cmd._writeId ?? JSON.stringify({ view: cmd.view, path: cmd.path });
|
|
66
|
-
if (lastProcessedDedupKeyRef.current === dedupKey) {
|
|
67
|
-
// Same command we already handled — the consume-DELETE races against
|
|
68
|
-
// the next polling refetch, so when it loses the same command can show
|
|
69
|
-
// up again. Re-fire DELETE and bail rather than navigate again.
|
|
70
|
-
fetch(agentNativePath("/_agent-native/application-state/navigate"), {
|
|
71
|
-
method: "DELETE",
|
|
72
|
-
headers: {
|
|
73
|
-
"X-Agent-Native-CSRF": "1",
|
|
74
|
-
"X-Request-Source": TAB_ID,
|
|
75
|
-
},
|
|
76
|
-
}).catch(() => {});
|
|
77
|
-
qc.setQueryData(["navigate-command"], null);
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
lastProcessedDedupKeyRef.current = dedupKey;
|
|
81
|
-
|
|
82
|
-
fetch(agentNativePath("/_agent-native/application-state/navigate"), {
|
|
83
|
-
method: "DELETE",
|
|
84
|
-
headers: {
|
|
85
|
-
"X-Agent-Native-CSRF": "1",
|
|
86
|
-
"X-Request-Source": TAB_ID,
|
|
87
|
-
},
|
|
88
|
-
}).catch(() => {});
|
|
89
|
-
|
|
90
|
-
const path = routerPath(cmd.path || pathFromView(cmd.view));
|
|
91
|
-
navigate(path);
|
|
92
|
-
qc.setQueryData(["navigate-command"], null);
|
|
93
|
-
}, [navCommand, navigate, qc]);
|
|
94
28
|
}
|
|
95
29
|
|
|
96
30
|
function viewFromPath(pathname: string): string {
|
|
@@ -11,13 +11,14 @@ How the agent knows what the user is looking at -- and how the agent can control
|
|
|
11
11
|
|
|
12
12
|
Without context awareness, the agent is blind. It asks "which email?" when the user is staring at one. It cannot act on the current selection, cannot provide relevant suggestions, and cannot modify what the user sees. With context awareness, the user can click a row, highlight a paragraph, select a slide element, or press Cmd+I, then say "summarize this" and the agent already knows what "this" means.
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
Six patterns solve this:
|
|
15
15
|
|
|
16
16
|
1. **Navigation state** -- the UI writes a `navigation` key to application-state on every route change
|
|
17
|
-
2. **
|
|
18
|
-
3.
|
|
19
|
-
4.
|
|
20
|
-
5.
|
|
17
|
+
2. **Current URL** -- the framework writes `__url__` so query params are visible and editable by the agent
|
|
18
|
+
3. **Selection state** -- the UI writes a `selection` key when the user focuses, selects, or multi-selects something meaningful
|
|
19
|
+
4. **`view-screen`** -- an action that reads application state, fetches contextual data, and returns a snapshot of what the user sees
|
|
20
|
+
5. **Prompt handoff** -- UI controls call `sendToAgentChat()` when a click should become an agent turn
|
|
21
|
+
6. **`navigate`** -- a one-shot command from the agent that tells the UI where to go
|
|
21
22
|
|
|
22
23
|
## Context layers {#context-layers}
|
|
23
24
|
|
|
@@ -25,25 +26,26 @@ Use different context channels for different jobs:
|
|
|
25
26
|
|
|
26
27
|
| Layer | Owner | Use it for |
|
|
27
28
|
| ----------------------------------------- | ----------------- | -------------------------------------------------------------------------- |
|
|
28
|
-
| `navigation` app-state key | UI |
|
|
29
|
+
| `navigation` app-state key | UI | Semantic route state: current view, open record, active tab, stable IDs |
|
|
30
|
+
| `__url__` app-state key | Framework UI | Current pathname, search string, hash, and parsed URL query params |
|
|
31
|
+
| `__set_url__` app-state key | Agent / framework | One-shot URL edits from `set-search-params` and `set-url-path` |
|
|
29
32
|
| `selection` app-state key | UI | Durable semantic selection: rows, blocks, shapes, assets, messages |
|
|
30
33
|
| `pending-selection-context` app-state key | UI / `AgentPanel` | One-shot selected text attached to the next chat turn, usually from Cmd+I |
|
|
31
34
|
| `view-screen` action | Agent | Hydrating the app-state keys into real records and screen summaries |
|
|
32
35
|
| `sendToAgentChat()` | UI | Turning a click, command, comment pin, or selected item into a chat prompt |
|
|
33
36
|
| `navigate` app-state key | Agent | Asking the UI to move to another route or focus another object |
|
|
34
37
|
|
|
35
|
-
The short version:
|
|
38
|
+
The short version: URL query params are the source of truth for shareable filters, `navigation` stores semantic IDs and view names, `view-screen` turns those state layers into useful data, and `sendToAgentChat()` turns UI intent into a chat message when the user clicks a command.
|
|
36
39
|
|
|
37
40
|
## Navigation state {#navigation-state}
|
|
38
41
|
|
|
39
|
-
The UI writes a `navigation` key to application-state on every route change. This tells the agent what view the user is on, what item is open, and which
|
|
42
|
+
The UI writes a `navigation` key to application-state on every route change. This tells the agent what view the user is on, what item is open, and which semantic UI state matters.
|
|
40
43
|
|
|
41
44
|
```json
|
|
42
45
|
{
|
|
43
46
|
"view": "inbox",
|
|
44
47
|
"threadId": "thread-123",
|
|
45
48
|
"focusedEmailId": "msg-456",
|
|
46
|
-
"search": "budget",
|
|
47
49
|
"label": "important"
|
|
48
50
|
}
|
|
49
51
|
```
|
|
@@ -52,10 +54,10 @@ What to include in navigation state:
|
|
|
52
54
|
|
|
53
55
|
- `view` -- the current page/section, such as "inbox", "form-builder", or "dashboard"
|
|
54
56
|
- Item IDs -- the selected/open item, such as `threadId` or `formId`
|
|
55
|
-
-
|
|
57
|
+
- Semantic aliases -- active tab, label name, or other stable app concepts that help the agent reason
|
|
56
58
|
- Light focus state -- focused row, active tab, current panel
|
|
57
59
|
|
|
58
|
-
Keep `navigation` small and
|
|
60
|
+
Keep `navigation` small and semantic. It should identify the current screen, not duplicate whole records or mirror every query param. Fetch records in `view-screen` so the agent always gets fresh data.
|
|
59
61
|
|
|
60
62
|
The agent reads this before acting:
|
|
61
63
|
|
|
@@ -66,6 +68,44 @@ const navigation = await readAppState("navigation");
|
|
|
66
68
|
// { view: "inbox", threadId: "thread-123", label: "important" }
|
|
67
69
|
```
|
|
68
70
|
|
|
71
|
+
## Current URL and filters {#current-url}
|
|
72
|
+
|
|
73
|
+
`AgentPanel` automatically syncs the current React Router URL into the `__url__` application-state key. The built-in agent includes it in every turn as a `<current-url>` block:
|
|
74
|
+
|
|
75
|
+
```txt
|
|
76
|
+
<current-url>
|
|
77
|
+
pathname: /adhoc/revenue
|
|
78
|
+
search: ?f_region=west&q=renewal
|
|
79
|
+
searchParams:
|
|
80
|
+
f_region: west
|
|
81
|
+
q: renewal
|
|
82
|
+
</current-url>
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
This is the canonical layer for shareable filter state. If the user can copy a URL and come back to the same filtered list, the filter belongs in the query string. The agent can change those filters with the built-in `set-search-params` tool:
|
|
86
|
+
|
|
87
|
+
```txt
|
|
88
|
+
set-search-params({ "params": { "f_region": "east", "q": null } })
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Use `navigation` only for semantic aliases that help `view-screen` fetch or summarize the right data. A dashboard might keep `navigation.dashboardId` while `__url__.searchParams` owns `f_region`, `f_dateStart`, and `q`.
|
|
92
|
+
|
|
93
|
+
When `view-screen` returns a richer snapshot, it can copy important URL filters into a friendly `activeFilters` object:
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
const url = (await readAppState("__url__")) as {
|
|
97
|
+
searchParams?: Record<string, string>;
|
|
98
|
+
} | null;
|
|
99
|
+
|
|
100
|
+
if (url?.searchParams) {
|
|
101
|
+
screen.activeFilters = Object.fromEntries(
|
|
102
|
+
Object.entries(url.searchParams).filter(
|
|
103
|
+
([key, value]) => key.startsWith("f_") && value,
|
|
104
|
+
),
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
69
109
|
## Selection state {#selection-state}
|
|
70
110
|
|
|
71
111
|
Selection is semantic UI state. It is how "the chart I clicked", "these three rows", "this slide title", or "the current email draft range" becomes model-visible context.
|
|
@@ -257,58 +297,60 @@ import { writeAppState } from "@agent-native/core/application-state";
|
|
|
257
297
|
await writeAppState("navigate", { view: "inbox", threadId: "thread-123" });
|
|
258
298
|
```
|
|
259
299
|
|
|
260
|
-
The UI
|
|
300
|
+
The UI should consume these commands through `useAgentRouteState`, which handles command polling, tab-scoped fallback keys, duplicate-command protection, and delete-after-read:
|
|
261
301
|
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
import {
|
|
265
|
-
deleteClientAppState,
|
|
266
|
-
readClientAppState,
|
|
267
|
-
} from "@agent-native/core/client";
|
|
268
|
-
|
|
269
|
-
const { data: navCommand } = useQuery({
|
|
270
|
-
queryKey: ["navigate-command"],
|
|
271
|
-
queryFn: async () => {
|
|
272
|
-
const data = await readClientAppState<NavigateCommand>("navigate");
|
|
273
|
-
if (data) {
|
|
274
|
-
await deleteClientAppState("navigate");
|
|
275
|
-
return data;
|
|
276
|
-
}
|
|
277
|
-
return null;
|
|
278
|
-
},
|
|
279
|
-
staleTime: 2_000,
|
|
280
|
-
});
|
|
302
|
+
```tsx
|
|
303
|
+
import { useAgentRouteState } from "@agent-native/core/client";
|
|
304
|
+
import { TAB_ID } from "@/lib/tab-id";
|
|
281
305
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
306
|
+
interface NavigationState {
|
|
307
|
+
view: "inbox" | "thread";
|
|
308
|
+
threadId?: string;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export function useNavigationState() {
|
|
312
|
+
useAgentRouteState<NavigationState>({
|
|
313
|
+
browserTabId: TAB_ID,
|
|
314
|
+
requestSource: TAB_ID,
|
|
315
|
+
getNavigationState: ({ pathname }) => {
|
|
316
|
+
const match = pathname.match(/^\/thread\/([^/]+)/);
|
|
317
|
+
return match ? { view: "thread", threadId: match[1] } : { view: "inbox" };
|
|
318
|
+
},
|
|
319
|
+
getCommandPath: (command) =>
|
|
320
|
+
command.view === "thread" && command.threadId
|
|
321
|
+
? `/thread/${command.threadId}`
|
|
322
|
+
: "/",
|
|
323
|
+
});
|
|
324
|
+
}
|
|
287
325
|
```
|
|
288
326
|
|
|
289
327
|
The `navigation` key belongs to the UI -- the agent should never write to it directly. Instead, the agent writes to `navigate`, and the UI performs the actual navigation, which then updates `navigation`.
|
|
290
328
|
|
|
291
329
|
## useNavigationState hook {#use-navigation-state}
|
|
292
330
|
|
|
293
|
-
The `use-navigation-state.ts` hook
|
|
331
|
+
The `use-navigation-state.ts` hook is usually a thin wrapper around `useAgentRouteState`. Template code supplies the app-specific route mapping; core owns application-state writes, command reads/deletes, request-source headers, and duplicate-command prevention.
|
|
294
332
|
|
|
295
|
-
```
|
|
333
|
+
```tsx
|
|
296
334
|
// app/hooks/use-navigation-state.ts
|
|
297
|
-
import {
|
|
298
|
-
import {
|
|
299
|
-
import { setClientAppState } from "@agent-native/core/client";
|
|
335
|
+
import { useAgentRouteState } from "@agent-native/core/client";
|
|
336
|
+
import { TAB_ID } from "@/lib/tab-id";
|
|
300
337
|
|
|
301
338
|
export function useNavigationState() {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
339
|
+
useAgentRouteState({
|
|
340
|
+
browserTabId: TAB_ID,
|
|
341
|
+
requestSource: TAB_ID,
|
|
342
|
+
getNavigationState: ({ pathname, searchParams }) => ({
|
|
343
|
+
view: pathname === "/" ? "home" : pathname.slice(1),
|
|
344
|
+
// Optional semantic alias. Raw query params are still visible in
|
|
345
|
+
// <current-url> and controllable with set-search-params.
|
|
346
|
+
label: searchParams.get("label"),
|
|
347
|
+
}),
|
|
348
|
+
getCommandPath: (command: any) => command.path ?? "/",
|
|
349
|
+
});
|
|
308
350
|
}
|
|
309
351
|
```
|
|
310
352
|
|
|
311
|
-
|
|
353
|
+
For non-router state channels, use the lower-level `useSemanticNavigationState`. It takes a ready-made `state`, an ordered list of `navigationKeys`/`commandKeys`, and an `onCommand` callback, but does not import or assume React Router.
|
|
312
354
|
|
|
313
355
|
## Jitter prevention {#jitter-prevention}
|
|
314
356
|
|
|
@@ -215,10 +215,31 @@ Common sources: `"action"` (every successful agent action — the reliable fallb
|
|
|
215
215
|
|
|
216
216
|
Application state is how the agent knows what the user is seeing. At minimum, add:
|
|
217
217
|
|
|
218
|
-
- A UI hook that writes `navigation` state when routes, selected records,
|
|
218
|
+
- A UI hook that writes semantic `navigation` state when routes, selected records, active tabs, or editor selections change.
|
|
219
219
|
- A `view-screen` action that reads that state and returns the current screen snapshot.
|
|
220
220
|
- A `navigate` action that writes a one-shot `navigate` command for the UI to consume.
|
|
221
221
|
|
|
222
|
+
Use `useAgentRouteState` for the UI hook so application-state writes, tab-scoped command reads, delete-after-read, and duplicate-command protection stay consistent:
|
|
223
|
+
|
|
224
|
+
```tsx
|
|
225
|
+
import { useAgentRouteState } from "@agent-native/core/client";
|
|
226
|
+
import { TAB_ID } from "@/lib/tab-id";
|
|
227
|
+
|
|
228
|
+
export function useNavigationState() {
|
|
229
|
+
useAgentRouteState({
|
|
230
|
+
browserTabId: TAB_ID,
|
|
231
|
+
requestSource: TAB_ID,
|
|
232
|
+
getNavigationState: ({ pathname, searchParams }) => ({
|
|
233
|
+
view: pathname === "/" ? "home" : pathname.slice(1),
|
|
234
|
+
selectedId: searchParams.get("id"),
|
|
235
|
+
}),
|
|
236
|
+
getCommandPath: (command: any) => command.path ?? "/",
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Keep shareable filters in URL query params. The framework exposes them to the agent as `<current-url>` and the built-in agent can change them with `set-search-params`; `navigation` should hold semantic IDs and aliases, not a second copy of the full query string.
|
|
242
|
+
|
|
222
243
|
```ts
|
|
223
244
|
// actions/navigate.ts
|
|
224
245
|
import { defineAction } from "@agent-native/core";
|
|
@@ -616,7 +616,7 @@ If `connect dev` cannot infer your local owner identity from an existing connect
|
|
|
616
616
|
|
|
617
617
|
The standard OAuth path never exposes tokens to MCP Apps: the host stores OAuth access/refresh tokens and mediates tool calls and `resources/read` over the authenticated MCP connection. Embedded iframes receive app data and tool results, not bearer secrets.
|
|
618
618
|
|
|
619
|
-
Full-app embeds also avoid handing the MCP bearer token to the browser. The MCP caller mints a one-time embed ticket in SQL; the iframe launch route consumes it and sets a short-lived, iframe-safe browser session cookie. The landing URL carries a temporary `__an_embed_token` query param only long enough for the client to capture it, remove it from the address bar, and attach it to same-origin `fetch` calls when third-party cookies are blocked. Embed sessions are route-scoped; app fetches include the current embedded target, and the server rejects token reuse outside the minted route.
|
|
619
|
+
Full-app embeds also avoid handing the MCP bearer token to the browser. The MCP caller mints a one-time embed ticket in SQL; the iframe launch route consumes it and sets a short-lived, iframe-safe browser session cookie. The landing URL carries a temporary `__an_embed_token` query param only long enough for the client to capture it, remove it from the address bar, and attach it to same-origin `fetch` calls when third-party cookies are blocked. Embed sessions are route-scoped; app fetches include the current embedded target, and the server rejects token reuse outside the minted route. App pages intentionally do not emit `X-Frame-Options` or CSP `frame-ancestors`, so Builder, Design, and MCP app hosts can iframe them. Browser iframe navigations also opt into COEP/CORP when needed for cross-origin isolated hosts.
|
|
620
620
|
|
|
621
621
|
The fallback hosted `connect` flow never copies the deployment's shared secret. Instead:
|
|
622
622
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-native/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22"
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"./client/AgentPanel": "./dist/client/AgentPanel.js",
|
|
44
44
|
"./client/application-state": "./dist/client/application-state.js",
|
|
45
45
|
"./client/api-path": "./dist/client/api-path.js",
|
|
46
|
+
"./client/route-state": "./dist/client/route-state.js",
|
|
46
47
|
"./client/observability": "./dist/client/observability/index.js",
|
|
47
48
|
"./client/onboarding": "./dist/client/onboarding/index.js",
|
|
48
49
|
"./client/settings/useBuilderStatus": "./dist/client/settings/useBuilderStatus.js",
|