@agent-native/dispatch 0.27.21 → 0.28.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.
Files changed (36) hide show
  1. package/dist/actions/update-workspace-app-metadata.js +1 -1
  2. package/dist/actions/update-workspace-app-metadata.js.map +1 -1
  3. package/dist/components/layout/Layout.d.ts.map +1 -1
  4. package/dist/components/layout/Layout.js +2 -7
  5. package/dist/components/layout/Layout.js.map +1 -1
  6. package/dist/components/workspace-app-host.d.ts +17 -0
  7. package/dist/components/workspace-app-host.d.ts.map +1 -1
  8. package/dist/components/workspace-app-host.js +90 -8
  9. package/dist/components/workspace-app-host.js.map +1 -1
  10. package/dist/server/lib/app-creation-store.d.ts.map +1 -1
  11. package/dist/server/lib/app-creation-store.js +0 -1
  12. package/dist/server/lib/app-creation-store.js.map +1 -1
  13. package/dist/server/lib/workspace-app-chat-proxy.d.ts +52 -0
  14. package/dist/server/lib/workspace-app-chat-proxy.d.ts.map +1 -0
  15. package/dist/server/lib/workspace-app-chat-proxy.js +306 -0
  16. package/dist/server/lib/workspace-app-chat-proxy.js.map +1 -0
  17. package/dist/server/plugins/core-routes.d.ts +3 -2
  18. package/dist/server/plugins/core-routes.d.ts.map +1 -1
  19. package/dist/server/plugins/core-routes.js +12 -4
  20. package/dist/server/plugins/core-routes.js.map +1 -1
  21. package/dist/shared/workspace-app-chat.d.ts +23 -0
  22. package/dist/shared/workspace-app-chat.d.ts.map +1 -0
  23. package/dist/shared/workspace-app-chat.js +45 -0
  24. package/dist/shared/workspace-app-chat.js.map +1 -0
  25. package/package.json +2 -2
  26. package/src/actions/update-workspace-app-metadata.ts +1 -1
  27. package/src/components/layout/Layout.app-chat.spec.ts +22 -13
  28. package/src/components/layout/Layout.tsx +5 -18
  29. package/src/components/workspace-app-chat-rail.spec.tsx +182 -0
  30. package/src/components/workspace-app-host.tsx +172 -21
  31. package/src/server/lib/app-creation-store.spec.ts +32 -20
  32. package/src/server/lib/app-creation-store.ts +0 -1
  33. package/src/server/lib/workspace-app-chat-proxy.spec.ts +322 -0
  34. package/src/server/lib/workspace-app-chat-proxy.ts +389 -0
  35. package/src/server/plugins/core-routes.ts +21 -4
  36. package/src/shared/workspace-app-chat.ts +45 -0
@@ -1,12 +1,29 @@
1
- import { createCoreRoutesPlugin } from "@agent-native/core/server";
1
+ import {
2
+ createCoreRoutesPlugin,
3
+ getH3App,
4
+ type NitroPluginDef,
5
+ } from "@agent-native/core/server";
2
6
 
7
+ import { WORKSPACE_APP_CHAT_PROXY_PREFIX } from "../../shared/workspace-app-chat.js";
3
8
  import { envKeys } from "../lib/env-config.js";
4
9
  import { registerDispatchOnboardingSteps } from "../lib/onboarding-steps.js";
10
+ import { createWorkspaceAppChatProxyHandler } from "../lib/workspace-app-chat-proxy.js";
5
11
 
6
12
  // Register before the core plugin so "create your first app" (order 5) appears
7
13
  // above the auto-generated Slack/Telegram steps (order 60). Idempotent.
8
14
  registerDispatchOnboardingSteps();
9
15
 
10
- export default createCoreRoutesPlugin({
11
- envKeys,
12
- });
16
+ const corePlugin = createCoreRoutesPlugin({ envKeys });
17
+
18
+ const dispatchCoreRoutesPlugin: NitroPluginDef = (nitroApp) => {
19
+ const coreInit = corePlugin(nitroApp);
20
+ // `getH3App` installs the framework CSRF middleware on its first call for
21
+ // this app, so any route registered through it is already behind that check.
22
+ getH3App(nitroApp).use(
23
+ WORKSPACE_APP_CHAT_PROXY_PREFIX,
24
+ createWorkspaceAppChatProxyHandler(),
25
+ );
26
+ return coreInit;
27
+ };
28
+
29
+ export default dispatchCoreRoutesPlugin;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Route contract for the Dispatch → workspace app agent-chat proxy.
3
+ *
4
+ * When an app is open in Dispatch, its chat rail must talk to that app's own
5
+ * agent (its tools, its AGENTS.md and skills, its org resources, its dev-mode
6
+ * surface) instead of to Dispatch's agent. The rail points `apiUrl` at this
7
+ * Dispatch-side prefix and the server forwards the whole agent-chat subtree to
8
+ * the app's `/_agent-native/agent-chat`, exactly as the Desktop loopback relay
9
+ * does. Shared so the browser can build the URL without importing server code.
10
+ */
11
+
12
+ export const WORKSPACE_APP_CHAT_PROXY_PREFIX =
13
+ "/_agent-native/workspace-app-chat";
14
+
15
+ /** Dispatch-relative base URL the chat rail uses as its `apiUrl`. */
16
+ export function workspaceAppChatProxyPath(appId: string): string {
17
+ return `${WORKSPACE_APP_CHAT_PROXY_PREFIX}/${encodeURIComponent(appId.trim())}`;
18
+ }
19
+
20
+ /**
21
+ * Split `/<appId>[/rest]` off a request that already matched the prefix.
22
+ * Returns null when there is no app segment, so the route fails loudly instead
23
+ * of proxying to an unresolved target.
24
+ */
25
+ export function parseWorkspaceAppChatProxyPath(
26
+ pathname: string,
27
+ ): { appId: string; targetSubPath: string } | null {
28
+ const index = pathname.indexOf(WORKSPACE_APP_CHAT_PROXY_PREFIX);
29
+ if (index < 0) return null;
30
+ const rest = pathname.slice(index + WORKSPACE_APP_CHAT_PROXY_PREFIX.length);
31
+ if (!rest.startsWith("/")) return null;
32
+ const segments = rest.slice(1).split("/");
33
+ const rawAppId = segments.shift() ?? "";
34
+ let appId: string;
35
+ try {
36
+ appId = decodeURIComponent(rawAppId).trim();
37
+ } catch {
38
+ // coercion-ok: malformed percent-encoding names no workspace app.
39
+ return null;
40
+ }
41
+ if (!appId) return null;
42
+ const targetSubPath = segments.length > 0 ? `/${segments.join("/")}` : "";
43
+ if (targetSubPath.includes("..")) return null;
44
+ return { appId, targetSubPath };
45
+ }