@agent-native/dispatch 0.31.14 → 0.31.15

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 (29) hide show
  1. package/dist/actions/provider-api-register.d.ts +1 -1
  2. package/dist/components/dispatch-control-plane.d.ts.map +1 -1
  3. package/dist/components/dispatch-control-plane.js +2 -2
  4. package/dist/components/dispatch-control-plane.js.map +1 -1
  5. package/dist/components/layout/Layout.d.ts +17 -4
  6. package/dist/components/layout/Layout.d.ts.map +1 -1
  7. package/dist/components/layout/Layout.js +45 -20
  8. package/dist/components/layout/Layout.js.map +1 -1
  9. package/dist/components/workspace-app-card.d.ts.map +1 -1
  10. package/dist/components/workspace-app-card.js +18 -1
  11. package/dist/components/workspace-app-card.js.map +1 -1
  12. package/dist/lib/catch-all-target.d.ts.map +1 -1
  13. package/dist/lib/catch-all-target.js +4 -2
  14. package/dist/lib/catch-all-target.js.map +1 -1
  15. package/dist/routes/pages/automations.d.ts.map +1 -1
  16. package/dist/routes/pages/automations.js +19 -16
  17. package/dist/routes/pages/automations.js.map +1 -1
  18. package/package.json +3 -3
  19. package/src/components/dispatch-control-plane.spec.tsx +3 -1
  20. package/src/components/dispatch-control-plane.tsx +2 -1
  21. package/src/components/layout/Layout.spec.tsx +143 -25
  22. package/src/components/layout/Layout.tsx +79 -47
  23. package/src/components/workspace-app-card.tsx +27 -1
  24. package/src/lib/catch-all-target.spec.ts +8 -0
  25. package/src/lib/catch-all-target.ts +4 -2
  26. package/src/routes/pages/automations.spec.tsx +240 -0
  27. package/src/routes/pages/automations.tsx +22 -16
  28. package/src/styles/dispatch-css.spec.ts +3 -0
  29. package/src/styles/dispatch.css +5 -0
@@ -0,0 +1,240 @@
1
+ // @vitest-environment happy-dom
2
+ import { act, type ReactNode } from "react";
3
+ import { createRoot, type Root } from "react-dom/client";
4
+ import { MemoryRouter, useLocation, useNavigate } from "react-router";
5
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
6
+
7
+ import { automationIdentity } from "../../lib/automation-display";
8
+ import type { DispatchAutomationItem } from "../../lib/automations";
9
+ import AutomationsRoute from "./automations";
10
+
11
+ const automationA: DispatchAutomationItem = {
12
+ id: "auto-a",
13
+ name: "Nightly digest",
14
+ path: "jobs/nightly-digest.md",
15
+ owner: "user@example.com",
16
+ appId: "dispatch",
17
+ scope: "personal",
18
+ enabled: true,
19
+ triggerType: "schedule",
20
+ schedule: "0 6 * * *",
21
+ scheduleDescription: "Every day at 6am",
22
+ lastStatus: "success",
23
+ };
24
+
25
+ const automationB: DispatchAutomationItem = {
26
+ id: "auto-b",
27
+ name: "Error triage",
28
+ path: "jobs/error-triage.md",
29
+ owner: "user@example.com",
30
+ appId: "dispatch",
31
+ scope: "personal",
32
+ enabled: true,
33
+ triggerType: "event",
34
+ event: "issue.created",
35
+ lastStatus: "success",
36
+ };
37
+
38
+ // Real @tanstack/react-query is not exercised here — the route reads its
39
+ // list straight from useQuery, so the hook itself is stubbed with a fixed
40
+ // two-item list rather than standing up a QueryClient + network mock.
41
+ vi.mock("@tanstack/react-query", () => ({
42
+ useQuery: ({ queryKey }: { queryKey: readonly unknown[] }) => {
43
+ if (String(queryKey[0]).includes("automations")) {
44
+ return {
45
+ data: [automationA, automationB],
46
+ isLoading: false,
47
+ isError: false,
48
+ error: null,
49
+ };
50
+ }
51
+ return { data: undefined, isLoading: false, isError: false, error: null };
52
+ },
53
+ useMutation: () => ({
54
+ mutate: vi.fn(),
55
+ isPending: false,
56
+ variables: undefined,
57
+ }),
58
+ useQueryClient: () => ({
59
+ cancelQueries: vi.fn(),
60
+ getQueriesData: vi.fn(() => []),
61
+ setQueriesData: vi.fn(),
62
+ invalidateQueries: vi.fn(),
63
+ }),
64
+ }));
65
+
66
+ vi.mock("@agent-native/core/client/hooks", () => ({
67
+ useChangeVersions: () => 0,
68
+ }));
69
+
70
+ vi.mock("@agent-native/core/client/agent-chat", () => ({
71
+ sendToAgentChat: vi.fn(),
72
+ }));
73
+
74
+ vi.mock("@agent-native/core/client/composer", () => ({
75
+ PromptComposer: () => null,
76
+ }));
77
+
78
+ vi.mock("../../components/dispatch-shell", () => ({
79
+ DispatchShell: ({ children }: { children: ReactNode }) => (
80
+ <main>{children}</main>
81
+ ),
82
+ }));
83
+
84
+ vi.mock("../../components/automation-details-panel", () => ({
85
+ AutomationDetailsPanel: ({
86
+ automation,
87
+ }: {
88
+ automation: DispatchAutomationItem;
89
+ }) => <div data-testid="details-panel">{automation.name}</div>,
90
+ }));
91
+
92
+ function LocationProbe() {
93
+ const location = useLocation();
94
+ return (
95
+ <div data-testid="location">{location.pathname + location.search}</div>
96
+ );
97
+ }
98
+
99
+ function GoBackProbe() {
100
+ const navigate = useNavigate();
101
+ return (
102
+ <button type="button" data-testid="go-back" onClick={() => navigate(-1)}>
103
+ Back
104
+ </button>
105
+ );
106
+ }
107
+
108
+ describe("AutomationsRoute", () => {
109
+ let container: HTMLDivElement;
110
+ let root: Root;
111
+
112
+ beforeEach(() => {
113
+ vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
114
+ container = document.createElement("div");
115
+ document.body.appendChild(container);
116
+ root = createRoot(container);
117
+ });
118
+
119
+ afterEach(() => {
120
+ act(() => root.unmount());
121
+ container.remove();
122
+ vi.unstubAllGlobals();
123
+ });
124
+
125
+ function locationText() {
126
+ return container.querySelector('[data-testid="location"]')?.textContent;
127
+ }
128
+
129
+ function findRowButton(name: string) {
130
+ return [...container.querySelectorAll("button")].find((button) =>
131
+ button.textContent?.includes(name),
132
+ );
133
+ }
134
+
135
+ it("writes the selected automation into the URL so it survives reload and back navigation", async () => {
136
+ await act(async () => {
137
+ root.render(
138
+ <MemoryRouter initialEntries={["/automations"]}>
139
+ <AutomationsRoute />
140
+ <LocationProbe />
141
+ </MemoryRouter>,
142
+ );
143
+ });
144
+
145
+ expect(locationText()).toBe("/automations");
146
+
147
+ const row = findRowButton(automationA.name);
148
+ expect(row).toBeTruthy();
149
+
150
+ await act(async () => {
151
+ row?.click();
152
+ });
153
+
154
+ expect(
155
+ container.querySelector('[data-testid="details-panel"]')?.textContent,
156
+ ).toBe(automationA.name);
157
+ // Selecting a row must push the identity into the address bar — a plain
158
+ // local-state selection leaves the URL unchanged, which is exactly the
159
+ // bug this test guards against (no way to link/reload/Back to a row).
160
+ expect(locationText()).toBe(
161
+ `/automations?automationId=${encodeURIComponent(automationIdentity(automationA))}`,
162
+ );
163
+
164
+ const otherRow = findRowButton(automationB.name);
165
+ await act(async () => {
166
+ otherRow?.click();
167
+ });
168
+
169
+ expect(locationText()).toBe(
170
+ `/automations?automationId=${encodeURIComponent(automationIdentity(automationB))}`,
171
+ );
172
+ });
173
+
174
+ it("pushes a history entry per row selection so Back steps through prior selections", async () => {
175
+ await act(async () => {
176
+ root.render(
177
+ <MemoryRouter initialEntries={["/automations"]}>
178
+ <AutomationsRoute />
179
+ <LocationProbe />
180
+ <GoBackProbe />
181
+ </MemoryRouter>,
182
+ );
183
+ });
184
+
185
+ const goBack = container.querySelector<HTMLButtonElement>(
186
+ '[data-testid="go-back"]',
187
+ );
188
+ expect(goBack).toBeTruthy();
189
+
190
+ await act(async () => {
191
+ findRowButton(automationA.name)?.click();
192
+ });
193
+ expect(locationText()).toBe(
194
+ `/automations?automationId=${encodeURIComponent(automationIdentity(automationA))}`,
195
+ );
196
+
197
+ await act(async () => {
198
+ findRowButton(automationB.name)?.click();
199
+ });
200
+ expect(locationText()).toBe(
201
+ `/automations?automationId=${encodeURIComponent(automationIdentity(automationB))}`,
202
+ );
203
+
204
+ // A row click is an explicit user selection, not URL canonicalization —
205
+ // it must push a new history entry so Back steps back through the prior
206
+ // selection (A) instead of skipping past the whole page's history in one
207
+ // jump. Replacing on every click (the bug this guards against) collapses
208
+ // all selections into a single entry.
209
+ await act(async () => {
210
+ goBack?.click();
211
+ });
212
+ expect(locationText()).toBe(
213
+ `/automations?automationId=${encodeURIComponent(automationIdentity(automationA))}`,
214
+ );
215
+
216
+ await act(async () => {
217
+ goBack?.click();
218
+ });
219
+ expect(locationText()).toBe("/automations");
220
+ });
221
+
222
+ it("reopens the matching detail panel when automationId is already in the URL", async () => {
223
+ const targetId = automationIdentity(automationB);
224
+ await act(async () => {
225
+ root.render(
226
+ <MemoryRouter
227
+ initialEntries={[
228
+ `/automations?automationId=${encodeURIComponent(targetId)}`,
229
+ ]}
230
+ >
231
+ <AutomationsRoute />
232
+ </MemoryRouter>,
233
+ );
234
+ });
235
+
236
+ expect(
237
+ container.querySelector('[data-testid="details-panel"]')?.textContent,
238
+ ).toBe(automationB.name);
239
+ });
240
+ });
@@ -9,8 +9,8 @@ import {
9
9
  IconSettingsAutomation,
10
10
  } from "@tabler/icons-react";
11
11
  import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
12
- import { useEffect, useMemo, useState } from "react";
13
- import { Link } from "react-router";
12
+ import { useMemo, useState } from "react";
13
+ import { Link, useSearchParams } from "react-router";
14
14
  import { toast } from "sonner";
15
15
 
16
16
  import { AutomationDetailsPanel } from "../../components/automation-details-panel";
@@ -189,10 +189,9 @@ function CreateAutomationButton() {
189
189
  }
190
190
 
191
191
  export default function AutomationsRoute() {
192
+ const [searchParams, setSearchParams] = useSearchParams();
192
193
  const [view, setView] = useState<"dispatch" | "all">("dispatch");
193
194
  const [query, setQuery] = useState("");
194
- const [detailsTarget, setDetailsTarget] =
195
- useState<DispatchAutomationItem | null>(null);
196
195
  const automationsQuery = useAutomations();
197
196
  const toggleAutomation = useToggleAutomation();
198
197
  const automations = automationsQuery.data ?? [];
@@ -238,17 +237,24 @@ export default function AutomationsRoute() {
238
237
  : null
239
238
  : null;
240
239
 
241
- useEffect(() => {
242
- if (!detailsTarget) return;
243
- const current = filtered.find(
244
- (item) => automationIdentity(item) === automationIdentity(detailsTarget),
245
- );
246
- if (current) {
247
- if (current !== detailsTarget) setDetailsTarget(current);
248
- } else {
249
- setDetailsTarget(null);
250
- }
251
- }, [detailsTarget, filtered]);
240
+ // URL-backed selection (mirrors dreams.tsx's `?dreamId=`): the currently
241
+ // open automation lives in `automationId` so it survives reload, Back, and
242
+ // sharing a link, instead of vanishing local state.
243
+ const selectedAutomationId = searchParams.get("automationId");
244
+ const detailsTarget = selectedAutomationId
245
+ ? (filtered.find(
246
+ (item) => automationIdentity(item) === selectedAutomationId,
247
+ ) ?? null)
248
+ : null;
249
+
250
+ function selectAutomation(item: DispatchAutomationItem) {
251
+ // Push, don't replace: each row click is an explicit selection the user
252
+ // should be able to Back out of one step at a time, not a URL
253
+ // canonicalization that should collapse into the current entry.
254
+ const next = new URLSearchParams(searchParams);
255
+ next.set("automationId", automationIdentity(item));
256
+ setSearchParams(next);
257
+ }
252
258
 
253
259
  return (
254
260
  <DispatchShell
@@ -334,7 +340,7 @@ export default function AutomationsRoute() {
334
340
  type="button"
335
341
  className="w-full min-w-0 cursor-pointer text-left outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-card"
336
342
  aria-pressed={isSelected}
337
- onClick={() => setDetailsTarget(item)}
343
+ onClick={() => selectAutomation(item)}
338
344
  >
339
345
  <div className="flex min-w-0 items-center gap-2">
340
346
  <StatusDot tone={status.tone} />
@@ -27,6 +27,9 @@ describe("dispatch Tailwind styles", () => {
27
27
  '@source "../components/**/*.{js,mjs,ts,tsx}"',
28
28
  );
29
29
  expect(stylesheet).toContain('@source "../routes/**/*.{js,mjs,ts,tsx}"');
30
+ expect(stylesheet).toContain(
31
+ "body:has(.fixed.bottom-3.left-3) [data-dispatch-sidebar-footer]",
32
+ );
30
33
  });
31
34
 
32
35
  it("imports package source directives from the Dispatch template", () => {
@@ -40,6 +40,11 @@
40
40
  font-weight: 600;
41
41
  }
42
42
 
43
+ body:has(.fixed.bottom-3.left-3) [data-dispatch-sidebar-footer] {
44
+ /* The fixed environment badge only needs this space when it is rendered. */
45
+ padding-bottom: 2.5rem;
46
+ }
47
+
43
48
  @media (max-width: 767px) {
44
49
  .dispatch-chat-first-surface {
45
50
  position: relative;