@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.
Files changed (80) hide show
  1. package/dist/cli/index.js +1 -1
  2. package/dist/cli/index.js.map +1 -1
  3. package/dist/cli/skills.d.ts.map +1 -1
  4. package/dist/cli/skills.js +249 -11
  5. package/dist/cli/skills.js.map +1 -1
  6. package/dist/client/AssistantChat.d.ts.map +1 -1
  7. package/dist/client/AssistantChat.js +25 -25
  8. package/dist/client/AssistantChat.js.map +1 -1
  9. package/dist/client/MultiTabAssistantChat.d.ts.map +1 -1
  10. package/dist/client/MultiTabAssistantChat.js +32 -15
  11. package/dist/client/MultiTabAssistantChat.js.map +1 -1
  12. package/dist/client/agent-chat-adapter.d.ts.map +1 -1
  13. package/dist/client/agent-chat-adapter.js +68 -24
  14. package/dist/client/agent-chat-adapter.js.map +1 -1
  15. package/dist/client/composer/ComposerPlusMenu.d.ts.map +1 -1
  16. package/dist/client/composer/ComposerPlusMenu.js +174 -8
  17. package/dist/client/composer/ComposerPlusMenu.js.map +1 -1
  18. package/dist/client/composer/PromptComposer.d.ts +2 -0
  19. package/dist/client/composer/PromptComposer.d.ts.map +1 -1
  20. package/dist/client/composer/PromptComposer.js +2 -2
  21. package/dist/client/composer/PromptComposer.js.map +1 -1
  22. package/dist/client/composer/TiptapComposer.js +1 -1
  23. package/dist/client/composer/TiptapComposer.js.map +1 -1
  24. package/dist/client/context-xray/ContextMeter.d.ts +2 -1
  25. package/dist/client/context-xray/ContextMeter.d.ts.map +1 -1
  26. package/dist/client/context-xray/ContextMeter.js +19 -25
  27. package/dist/client/context-xray/ContextMeter.js.map +1 -1
  28. package/dist/client/context-xray/ContextXRayPanel.d.ts +1 -3
  29. package/dist/client/context-xray/ContextXRayPanel.d.ts.map +1 -1
  30. package/dist/client/context-xray/ContextXRayPanel.js +27 -24
  31. package/dist/client/context-xray/ContextXRayPanel.js.map +1 -1
  32. package/dist/client/conversation/AgentConversation.d.ts.map +1 -1
  33. package/dist/client/conversation/AgentConversation.js +2 -1
  34. package/dist/client/conversation/AgentConversation.js.map +1 -1
  35. package/dist/client/dynamic-suggestions.d.ts +13 -7
  36. package/dist/client/dynamic-suggestions.d.ts.map +1 -1
  37. package/dist/client/dynamic-suggestions.js +23 -12
  38. package/dist/client/dynamic-suggestions.js.map +1 -1
  39. package/dist/client/index.d.ts +1 -0
  40. package/dist/client/index.d.ts.map +1 -1
  41. package/dist/client/index.js +1 -0
  42. package/dist/client/index.js.map +1 -1
  43. package/dist/client/route-state.d.ts +116 -0
  44. package/dist/client/route-state.d.ts.map +1 -0
  45. package/dist/client/route-state.js +205 -0
  46. package/dist/client/route-state.js.map +1 -0
  47. package/dist/client/sse-event-processor.d.ts +1 -0
  48. package/dist/client/sse-event-processor.d.ts.map +1 -1
  49. package/dist/client/sse-event-processor.js +62 -15
  50. package/dist/client/sse-event-processor.js.map +1 -1
  51. package/dist/client/tool-display.d.ts +4 -0
  52. package/dist/client/tool-display.d.ts.map +1 -0
  53. package/dist/client/tool-display.js +28 -0
  54. package/dist/client/tool-display.js.map +1 -0
  55. package/dist/client/use-chat-threads.d.ts.map +1 -1
  56. package/dist/client/use-chat-threads.js +40 -31
  57. package/dist/client/use-chat-threads.js.map +1 -1
  58. package/dist/client/use-external-value.d.ts.map +1 -1
  59. package/dist/client/use-external-value.js +14 -7
  60. package/dist/client/use-external-value.js.map +1 -1
  61. package/dist/extensions/html-shell.d.ts +3 -2
  62. package/dist/extensions/html-shell.d.ts.map +1 -1
  63. package/dist/extensions/html-shell.js +12 -2
  64. package/dist/extensions/html-shell.js.map +1 -1
  65. package/dist/extensions/routes.js +2 -7
  66. package/dist/extensions/routes.js.map +1 -1
  67. package/dist/server/core-routes-plugin.js +2 -2
  68. package/dist/server/core-routes-plugin.js.map +1 -1
  69. package/dist/server/security-headers.d.ts +16 -19
  70. package/dist/server/security-headers.d.ts.map +1 -1
  71. package/dist/server/security-headers.js +24 -25
  72. package/dist/server/security-headers.js.map +1 -1
  73. package/dist/templates/default/AGENTS.md +7 -1
  74. package/dist/templates/default/app/hooks/use-navigation-state.ts +10 -76
  75. package/docs/content/context-awareness.md +90 -48
  76. package/docs/content/creating-templates.md +22 -1
  77. package/docs/content/external-agents.md +1 -1
  78. package/package.json +2 -1
  79. package/src/templates/default/AGENTS.md +7 -1
  80. package/src/templates/default/app/hooks/use-navigation-state.ts +10 -76
@@ -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
- const location = useLocation();
22
- const navigate = useNavigate();
23
- const qc = useQueryClient();
24
-
25
- useEffect(() => {
26
- const state: NavigationState = {
27
- view: viewFromPath(location.pathname),
28
- path: appPath(location.pathname),
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 {