@swirls/shuttle 0.0.0-stage → 0.1.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/CHANGELOG.md +10 -0
- package/LICENSE +190 -0
- package/NOTICE +5 -0
- package/README.md +42 -2
- package/dist/api/auth.d.ts +18 -0
- package/dist/api/auth.js +15 -0
- package/dist/api/common.d.ts +8 -0
- package/dist/api/common.js +4 -0
- package/dist/api/connections.d.ts +292 -0
- package/dist/api/connections.js +114 -0
- package/dist/api/github.d.ts +20 -0
- package/dist/api/github.js +13 -0
- package/dist/api/harness.d.ts +97 -0
- package/dist/api/harness.js +47 -0
- package/dist/api/index.d.ts +2059 -0
- package/dist/api/index.js +37 -0
- package/dist/api/runners.d.ts +93 -0
- package/dist/api/runners.js +45 -0
- package/dist/api/sandbox.d.ts +550 -0
- package/dist/api/sandbox.js +210 -0
- package/dist/api/sessions.d.ts +318 -0
- package/dist/api/sessions.js +154 -0
- package/dist/api/tenant.d.ts +54 -0
- package/dist/api/tenant.js +19 -0
- package/dist/api/timings.d.ts +36 -0
- package/dist/api/timings.js +48 -0
- package/dist/api/workspace.d.ts +738 -0
- package/dist/api/workspace.js +246 -0
- package/dist/core/pulls.d.ts +1001 -0
- package/dist/core/pulls.js +170 -0
- package/dist/core/workspace.d.ts +985 -0
- package/dist/core/workspace.js +174 -0
- package/dist/react/components/command-palette.d.ts +22 -0
- package/dist/react/components/command-palette.js +66 -0
- package/dist/react/components/follow-list.d.ts +20 -0
- package/dist/react/components/follow-list.js +98 -0
- package/dist/react/components/json-tree.d.ts +11 -0
- package/dist/react/components/json-tree.js +120 -0
- package/dist/react/components/markdown.d.ts +5 -0
- package/dist/react/components/markdown.js +29 -0
- package/dist/react/components/shuttle-mark.d.ts +7 -0
- package/dist/react/components/shuttle-mark.js +9 -0
- package/dist/react/components/status-dot.d.ts +9 -0
- package/dist/react/components/status-dot.js +27 -0
- package/dist/react/components/status.d.ts +6 -0
- package/dist/react/components/status.js +66 -0
- package/dist/react/components/ui/badge.d.ts +7 -0
- package/dist/react/components/ui/badge.js +19 -0
- package/dist/react/components/ui/button.d.ts +10 -0
- package/dist/react/components/ui/button.js +40 -0
- package/dist/react/components/ui/dialog.d.ts +19 -0
- package/dist/react/components/ui/dialog.js +34 -0
- package/dist/react/components/ui/dropdown-menu.d.ts +14 -0
- package/dist/react/components/ui/dropdown-menu.js +33 -0
- package/dist/react/components/ui/input.d.ts +3 -0
- package/dist/react/components/ui/input.js +6 -0
- package/dist/react/components/ui/panel.d.ts +18 -0
- package/dist/react/components/ui/panel.js +22 -0
- package/dist/react/components/ui/popover.d.ts +7 -0
- package/dist/react/components/ui/popover.js +16 -0
- package/dist/react/components/ui/resizable.d.ts +7 -0
- package/dist/react/components/ui/resizable.js +14 -0
- package/dist/react/components/ui/scroll-area.d.ts +14 -0
- package/dist/react/components/ui/scroll-area.js +12 -0
- package/dist/react/components/ui/select.d.ts +10 -0
- package/dist/react/components/ui/select.js +20 -0
- package/dist/react/components/ui/sheet.d.ts +8 -0
- package/dist/react/components/ui/sheet.js +20 -0
- package/dist/react/components/ui/tabs.d.ts +7 -0
- package/dist/react/components/ui/tabs.js +16 -0
- package/dist/react/components/ui/textarea.d.ts +3 -0
- package/dist/react/components/ui/textarea.js +6 -0
- package/dist/react/components/ui/tooltip.d.ts +8 -0
- package/dist/react/components/ui/tooltip.js +17 -0
- package/dist/react/features/artifacts/artifact-links.d.ts +9 -0
- package/dist/react/features/artifacts/artifact-links.js +38 -0
- package/dist/react/features/artifacts/artifact-pane.d.ts +19 -0
- package/dist/react/features/artifacts/artifact-pane.js +64 -0
- package/dist/react/features/artifacts/artifact-types.d.ts +59 -0
- package/dist/react/features/artifacts/artifact-types.js +69 -0
- package/dist/react/features/artifacts/browser-viewer.d.ts +5 -0
- package/dist/react/features/artifacts/browser-viewer.js +60 -0
- package/dist/react/features/artifacts/diff-style.d.ts +10 -0
- package/dist/react/features/artifacts/diff-style.js +21 -0
- package/dist/react/features/artifacts/file-pane.d.ts +13 -0
- package/dist/react/features/artifacts/file-pane.js +305 -0
- package/dist/react/features/artifacts/file-quick-open.d.ts +15 -0
- package/dist/react/features/artifacts/file-quick-open.js +74 -0
- package/dist/react/features/artifacts/file-search.d.ts +12 -0
- package/dist/react/features/artifacts/file-search.js +90 -0
- package/dist/react/features/artifacts/media-viewer.d.ts +8 -0
- package/dist/react/features/artifacts/media-viewer.js +41 -0
- package/dist/react/features/artifacts/review-diff.d.ts +19 -0
- package/dist/react/features/artifacts/review-diff.js +59 -0
- package/dist/react/features/artifacts/review-viewer.d.ts +4 -0
- package/dist/react/features/artifacts/review-viewer.js +337 -0
- package/dist/react/features/artifacts/sandbox.d.ts +43 -0
- package/dist/react/features/artifacts/sandbox.js +109 -0
- package/dist/react/features/artifacts/tab-strip.d.ts +11 -0
- package/dist/react/features/artifacts/tab-strip.js +55 -0
- package/dist/react/features/artifacts/terminal-theme.d.ts +34 -0
- package/dist/react/features/artifacts/terminal-theme.js +62 -0
- package/dist/react/features/artifacts/terminal-viewer.d.ts +5 -0
- package/dist/react/features/artifacts/terminal-viewer.js +209 -0
- package/dist/react/features/artifacts/unified-diff.d.ts +16 -0
- package/dist/react/features/artifacts/unified-diff.js +55 -0
- package/dist/react/features/artifacts/workspace-viewer.d.ts +16 -0
- package/dist/react/features/artifacts/workspace-viewer.js +275 -0
- package/dist/react/features/connections/agent-sign-in.d.ts +71 -0
- package/dist/react/features/connections/agent-sign-in.js +251 -0
- package/dist/react/features/connections/connections-panel.d.ts +8 -0
- package/dist/react/features/connections/connections-panel.js +42 -0
- package/dist/react/features/connections/login.d.ts +24 -0
- package/dist/react/features/connections/login.js +35 -0
- package/dist/react/features/connections/places.d.ts +20 -0
- package/dist/react/features/connections/places.js +27 -0
- package/dist/react/features/connections/queries.d.ts +28 -0
- package/dist/react/features/connections/queries.js +8 -0
- package/dist/react/features/events/event-cache.d.ts +4 -0
- package/dist/react/features/events/event-cache.js +29 -0
- package/dist/react/features/events/event-catalog.d.ts +17 -0
- package/dist/react/features/events/event-catalog.js +261 -0
- package/dist/react/features/events/event-inspector.d.ts +7 -0
- package/dist/react/features/events/event-inspector.js +29 -0
- package/dist/react/features/events/event-row.d.ts +21 -0
- package/dist/react/features/events/event-row.js +34 -0
- package/dist/react/features/events/event-stream.d.ts +18 -0
- package/dist/react/features/events/event-stream.js +58 -0
- package/dist/react/features/events/global-events.d.ts +122 -0
- package/dist/react/features/events/global-events.js +329 -0
- package/dist/react/features/events/shuttle-events.d.ts +7 -0
- package/dist/react/features/events/shuttle-events.js +1 -0
- package/dist/react/features/playbook/playbook-page.d.ts +2 -0
- package/dist/react/features/playbook/playbook-page.js +36 -0
- package/dist/react/features/playbook/playbook-query.d.ts +111 -0
- package/dist/react/features/playbook/playbook-query.js +17 -0
- package/dist/react/features/pulls/linked-session.d.ts +12 -0
- package/dist/react/features/pulls/linked-session.js +22 -0
- package/dist/react/features/pulls/pull-detail-sheet.d.ts +10 -0
- package/dist/react/features/pulls/pull-detail-sheet.js +41 -0
- package/dist/react/features/pulls/pull-fixtures.d.ts +8 -0
- package/dist/react/features/pulls/pull-fixtures.js +258 -0
- package/dist/react/features/pulls/pull-glyphs.d.ts +24 -0
- package/dist/react/features/pulls/pull-glyphs.js +89 -0
- package/dist/react/features/pulls/pull-inbox-list.d.ts +13 -0
- package/dist/react/features/pulls/pull-inbox-list.js +230 -0
- package/dist/react/features/pulls/pull-inbox-pref.d.ts +2 -0
- package/dist/react/features/pulls/pull-inbox-pref.js +19 -0
- package/dist/react/features/pulls/pull-inbox.d.ts +30 -0
- package/dist/react/features/pulls/pull-inbox.js +110 -0
- package/dist/react/features/pulls/pull-threads.d.ts +39 -0
- package/dist/react/features/pulls/pull-threads.js +145 -0
- package/dist/react/features/pulls/pulls.d.ts +120 -0
- package/dist/react/features/pulls/pulls.js +414 -0
- package/dist/react/features/pulls/session-pull-groups.d.ts +14 -0
- package/dist/react/features/pulls/session-pull-groups.js +29 -0
- package/dist/react/features/pulls/stack-ladder.d.ts +9 -0
- package/dist/react/features/pulls/stack-ladder.js +32 -0
- package/dist/react/features/sessions/agent-tree.d.ts +16 -0
- package/dist/react/features/sessions/agent-tree.js +100 -0
- package/dist/react/features/sessions/agents.d.ts +34 -0
- package/dist/react/features/sessions/agents.js +146 -0
- package/dist/react/features/sessions/attention.d.ts +32 -0
- package/dist/react/features/sessions/attention.js +42 -0
- package/dist/react/features/sessions/composer-attachments.d.ts +33 -0
- package/dist/react/features/sessions/composer-attachments.js +126 -0
- package/dist/react/features/sessions/composer.d.ts +15 -0
- package/dist/react/features/sessions/composer.js +327 -0
- package/dist/react/features/sessions/context-usage-meter.d.ts +5 -0
- package/dist/react/features/sessions/context-usage-meter.js +122 -0
- package/dist/react/features/sessions/context-usage.d.ts +54 -0
- package/dist/react/features/sessions/context-usage.js +206 -0
- package/dist/react/features/sessions/conversation.d.ts +21 -0
- package/dist/react/features/sessions/conversation.js +549 -0
- package/dist/react/features/sessions/harness-switcher.d.ts +26 -0
- package/dist/react/features/sessions/harness-switcher.js +118 -0
- package/dist/react/features/sessions/intake-heuristic.d.ts +5 -0
- package/dist/react/features/sessions/intake-heuristic.js +28 -0
- package/dist/react/features/sessions/interjection-routes.d.ts +13 -0
- package/dist/react/features/sessions/interjection-routes.js +72 -0
- package/dist/react/features/sessions/llm-models.d.ts +128 -0
- package/dist/react/features/sessions/llm-models.js +174 -0
- package/dist/react/features/sessions/media-strip.d.ts +25 -0
- package/dist/react/features/sessions/media-strip.js +56 -0
- package/dist/react/features/sessions/media.d.ts +43 -0
- package/dist/react/features/sessions/media.js +115 -0
- package/dist/react/features/sessions/model-search.d.ts +6 -0
- package/dist/react/features/sessions/model-search.js +16 -0
- package/dist/react/features/sessions/model-switcher.d.ts +16 -0
- package/dist/react/features/sessions/model-switcher.js +262 -0
- package/dist/react/features/sessions/open-pull-request.d.ts +20 -0
- package/dist/react/features/sessions/open-pull-request.js +92 -0
- package/dist/react/features/sessions/pull-publish-card.d.ts +14 -0
- package/dist/react/features/sessions/pull-publish-card.js +88 -0
- package/dist/react/features/sessions/recent-sessions.d.ts +11 -0
- package/dist/react/features/sessions/recent-sessions.js +29 -0
- package/dist/react/features/sessions/seen-sessions.d.ts +16 -0
- package/dist/react/features/sessions/seen-sessions.js +108 -0
- package/dist/react/features/sessions/session-activity.d.ts +95 -0
- package/dist/react/features/sessions/session-activity.js +785 -0
- package/dist/react/features/sessions/session-context.d.ts +8 -0
- package/dist/react/features/sessions/session-context.js +98 -0
- package/dist/react/features/sessions/session-feed.d.ts +243 -0
- package/dist/react/features/sessions/session-feed.js +883 -0
- package/dist/react/features/sessions/session-header.d.ts +24 -0
- package/dist/react/features/sessions/session-header.js +97 -0
- package/dist/react/features/sessions/session-layout.d.ts +7 -0
- package/dist/react/features/sessions/session-layout.js +87 -0
- package/dist/react/features/sessions/session-panes.d.ts +49 -0
- package/dist/react/features/sessions/session-panes.js +142 -0
- package/dist/react/features/sessions/session-parts.d.ts +35 -0
- package/dist/react/features/sessions/session-parts.js +74 -0
- package/dist/react/features/sessions/session-place.d.ts +9 -0
- package/dist/react/features/sessions/session-place.js +109 -0
- package/dist/react/features/sessions/session-pr-pills.d.ts +7 -0
- package/dist/react/features/sessions/session-pr-pills.js +28 -0
- package/dist/react/features/sessions/session-queries.d.ts +172 -0
- package/dist/react/features/sessions/session-queries.js +90 -0
- package/dist/react/features/sessions/session-repos.d.ts +8 -0
- package/dist/react/features/sessions/session-repos.js +15 -0
- package/dist/react/features/sessions/session-share.d.ts +8 -0
- package/dist/react/features/sessions/session-share.js +112 -0
- package/dist/react/features/sessions/session-tabs.d.ts +38 -0
- package/dist/react/features/sessions/session-tabs.js +191 -0
- package/dist/react/features/sessions/session.d.ts +103 -0
- package/dist/react/features/sessions/session.js +216 -0
- package/dist/react/features/sessions/signals.d.ts +13 -0
- package/dist/react/features/sessions/signals.js +34 -0
- package/dist/react/features/sessions/tab-set.d.ts +20 -0
- package/dist/react/features/sessions/tab-set.js +58 -0
- package/dist/react/features/sessions/team.d.ts +16 -0
- package/dist/react/features/sessions/team.js +35 -0
- package/dist/react/features/sessions/timeline.d.ts +53 -0
- package/dist/react/features/sessions/timeline.js +153 -0
- package/dist/react/features/sessions/use-session-tabs.d.ts +18 -0
- package/dist/react/features/sessions/use-session-tabs.js +119 -0
- package/dist/react/features/sessions/vendor-models.d.ts +23 -0
- package/dist/react/features/sessions/vendor-models.js +61 -0
- package/dist/react/features/workspace/activity-dot.d.ts +15 -0
- package/dist/react/features/workspace/activity-dot.js +36 -0
- package/dist/react/features/workspace/app-sidebar.d.ts +16 -0
- package/dist/react/features/workspace/app-sidebar.js +227 -0
- package/dist/react/features/workspace/fixture-toggle.d.ts +2 -0
- package/dist/react/features/workspace/fixture-toggle.js +72 -0
- package/dist/react/features/workspace/folder-group.d.ts +18 -0
- package/dist/react/features/workspace/folder-group.js +83 -0
- package/dist/react/features/workspace/inline-name-input.d.ts +10 -0
- package/dist/react/features/workspace/inline-name-input.js +33 -0
- package/dist/react/features/workspace/link-repo-dialog.d.ts +9 -0
- package/dist/react/features/workspace/link-repo-dialog.js +76 -0
- package/dist/react/features/workspace/repo-chip.d.ts +13 -0
- package/dist/react/features/workspace/repo-chip.js +15 -0
- package/dist/react/features/workspace/session-row.d.ts +20 -0
- package/dist/react/features/workspace/session-row.js +23 -0
- package/dist/react/features/workspace/use-debounced.d.ts +2 -0
- package/dist/react/features/workspace/use-debounced.js +10 -0
- package/dist/react/features/workspace/workspace-context.d.ts +45 -0
- package/dist/react/features/workspace/workspace-context.js +245 -0
- package/dist/react/features/workspace/workspace-fixtures.d.ts +16 -0
- package/dist/react/features/workspace/workspace-fixtures.js +175 -0
- package/dist/react/features/workspace/workspace-tree.d.ts +30 -0
- package/dist/react/features/workspace/workspace-tree.js +69 -0
- package/dist/react/features/workspace/workspace.d.ts +107 -0
- package/dist/react/features/workspace/workspace.js +458 -0
- package/dist/react/index.d.ts +33 -0
- package/dist/react/index.js +35 -0
- package/dist/react/lib/cn.d.ts +6 -0
- package/dist/react/lib/cn.js +20 -0
- package/dist/react/lib/initials.d.ts +6 -0
- package/dist/react/lib/initials.js +32 -0
- package/dist/react/lib/json.d.ts +33 -0
- package/dist/react/lib/json.js +101 -0
- package/dist/react/lib/time.d.ts +8 -0
- package/dist/react/lib/time.js +57 -0
- package/dist/react/lib/use-media-query.d.ts +1 -0
- package/dist/react/lib/use-media-query.js +9 -0
- package/dist/react/lib/use-now.d.ts +2 -0
- package/dist/react/lib/use-now.js +10 -0
- package/dist/react/lib/use-width-bucket.d.ts +6 -0
- package/dist/react/lib/use-width-bucket.js +28 -0
- package/dist/react/parts/index.d.ts +43 -0
- package/dist/react/parts/index.js +43 -0
- package/dist/react/shuttle/device.d.ts +42 -0
- package/dist/react/shuttle/device.js +10 -0
- package/dist/react/shuttle/host.d.ts +1126 -0
- package/dist/react/shuttle/host.js +93 -0
- package/dist/react/shuttle/identity.d.ts +31 -0
- package/dist/react/shuttle/identity.js +20 -0
- package/dist/react/shuttle/index.d.ts +14 -0
- package/dist/react/shuttle/index.js +13 -0
- package/dist/react/shuttle/provider.d.ts +41 -0
- package/dist/react/shuttle/provider.js +59 -0
- package/dist/react/shuttle/router.d.ts +43 -0
- package/dist/react/shuttle/router.js +1 -0
- package/dist/react/theme.css +456 -0
- package/dist/react/ui.d.ts +19 -0
- package/dist/react/ui.js +19 -0
- package/package.json +100 -4
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ArrowDownToLine, Search, SlidersHorizontal, X } from 'lucide-react';
|
|
3
|
+
import { useCallback, useDeferredValue, useMemo, useState } from 'react';
|
|
4
|
+
import { FollowList } from '../../components/follow-list.js';
|
|
5
|
+
import { Button } from '../../components/ui/button.js';
|
|
6
|
+
import { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuLabel, DropdownMenuTrigger, } from '../../components/ui/dropdown-menu.js';
|
|
7
|
+
import { Input } from '../../components/ui/input.js';
|
|
8
|
+
import { PanelHeader, PanelTitle } from '../../components/ui/panel.js';
|
|
9
|
+
import { cn, shortId } from '../../lib/cn.js';
|
|
10
|
+
import { eventFamilies, eventMeta, familyColor } from './event-catalog.js';
|
|
11
|
+
import { EventInspector } from './event-inspector.js';
|
|
12
|
+
import { EventRow } from './event-row.js';
|
|
13
|
+
const ROW_ESTIMATE = 26;
|
|
14
|
+
/** Streaming deltas and effect bookkeeping drown out the story; start with them hidden. */
|
|
15
|
+
const DEFAULT_HIDDEN = new Set(['effect']);
|
|
16
|
+
export function EventStream({ events, startedAt, threadId, threadLabel, labelFor, onClearThread, selectedSeq, onSelectSeq, toolbar = false, title = 'Events', split = false, onClose, }) {
|
|
17
|
+
const [query, setQuery] = useState('');
|
|
18
|
+
const [follow, setFollow] = useState(true);
|
|
19
|
+
const [showDeltas, setShowDeltas] = useState(false);
|
|
20
|
+
const [families, setFamilies] = useState(() => new Set(eventFamilies.filter((family) => !DEFAULT_HIDDEN.has(family))));
|
|
21
|
+
const deferredQuery = useDeferredValue(query);
|
|
22
|
+
const q = deferredQuery.trim().toLowerCase();
|
|
23
|
+
const visible = useMemo(() => events.filter((event) => {
|
|
24
|
+
if (threadId && event.threadId !== threadId) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
if (!showDeltas && event.ephemeral) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const meta = eventMeta(event);
|
|
31
|
+
if (!families.has(meta.family)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
return !q || meta.searchText.includes(q);
|
|
35
|
+
}), [events, threadId, showDeltas, families, q]);
|
|
36
|
+
const selected = useMemo(() => selectedSeq === undefined ? undefined : events.find((event) => event.seq === selectedSeq), [events, selectedSeq]);
|
|
37
|
+
const toggleFamily = useCallback((family) => {
|
|
38
|
+
setFamilies((prev) => {
|
|
39
|
+
const next = new Set(prev);
|
|
40
|
+
if (next.has(family)) {
|
|
41
|
+
next.delete(family);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
next.add(family);
|
|
45
|
+
}
|
|
46
|
+
return next;
|
|
47
|
+
});
|
|
48
|
+
}, []);
|
|
49
|
+
const hiddenCount = eventFamilies.length - families.size + (showDeltas ? 0 : 1);
|
|
50
|
+
const filtered = visible.length !== events.length;
|
|
51
|
+
return (_jsxs("div", { className: "event-stream flex h-full min-h-0 flex-col", children: [_jsxs(PanelHeader, { className: "gap-1.5 pr-2", children: [toolbar ? (_jsx("span", { className: "text-muted-foreground font-mono text-[11px] tabular-nums", children: filtered ? `${visible.length}/${events.length}` : events.length })) : (_jsx(PanelTitle, { meta: filtered ? `${visible.length}/${events.length}` : events.length, children: title })), _jsxs("div", { className: cn('relative min-w-0 flex-1 basis-24', toolbar ? '' : 'ml-auto'), children: [_jsx(Search, { "aria-hidden": true, className: "text-muted-foreground pointer-events-none absolute top-1/2 left-2 size-3 -translate-y-1/2" }), _jsx(Input, { value: query, onChange: (event) => setQuery(event.target.value), placeholder: "Search", "aria-label": "Search events", className: "h-7 w-full rounded-md pl-7 text-xs" })] }), _jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsxs(Button, { variant: "ghost", size: "icon-sm", className: "relative", "aria-label": "Filter event families", children: [_jsx(SlidersHorizontal, {}), hiddenCount > 0 ? (_jsx("span", { className: "bg-foreground text-background absolute top-0.5 right-0.5 flex size-3.5 items-center justify-center rounded-full font-mono text-[8px]", children: hiddenCount })) : null] }) }), _jsxs(DropdownMenuContent, { align: "end", children: [_jsx(DropdownMenuLabel, { children: "Event families" }), eventFamilies.map((family) => (_jsxs(DropdownMenuCheckboxItem, { checked: families.has(family), onCheckedChange: () => toggleFamily(family), onSelect: (event) => event.preventDefault(), className: "font-mono", children: [_jsx("span", { "aria-hidden": true, className: "size-1.5 rounded-full", style: { backgroundColor: familyColor(family) } }), family] }, family))), _jsx(DropdownMenuLabel, { children: "Live" }), _jsx(DropdownMenuCheckboxItem, { checked: showDeltas, onCheckedChange: (checked) => setShowDeltas(checked === true), onSelect: (event) => event.preventDefault(), children: "Ephemeral text deltas" })] })] }), _jsx(Button, { variant: "ghost", size: "icon-sm", "aria-pressed": follow, "aria-label": "Follow newest events", title: "Follow newest events", onClick: () => setFollow(!follow), className: "aria-pressed:bg-accent aria-pressed:text-foreground", children: _jsx(ArrowDownToLine, {}) }), onClose ? (_jsx(Button, { variant: "ghost", size: "icon-sm", "aria-label": `Close ${title}`, onClick: onClose, children: _jsx(X, {}) })) : null] }), threadId ? (_jsxs("div", { className: "flex h-8 shrink-0 items-center gap-2 border-b px-3 text-[11px]", children: [_jsx("span", { className: "text-muted-foreground", children: "Thread" }), _jsxs("span", { className: "bg-accent text-foreground inline-flex h-5 min-w-0 items-center gap-1 rounded-sm pr-0.5 pl-1.5", children: [_jsx("span", { className: "truncate", title: threadId, children: threadLabel ?? shortId(threadId) }), onClearThread ? (_jsx("button", { type: "button", "aria-label": "Show all threads", onClick: onClearThread, className: "text-muted-foreground hover:text-foreground hover:bg-background/60 flex size-4 items-center justify-center rounded-sm transition-colors", children: _jsx(X, { className: "size-3" }) })) : null] })] })) : null, _jsxs("div", { className: cn('flex min-h-0 flex-1', split ? 'flex-row' : 'flex-col'), children: [_jsx(FollowList, { items: visible, getKey: (event) => event.id, estimateSize: ROW_ESTIMATE, overscan: 16, follow: follow, onFollowChange: setFollow, className: "min-h-24", itemClassName: "px-1.5", empty: _jsx("p", { className: "text-muted-foreground p-6 text-center text-xs", children: events.length === 0 ? 'Waiting for events…' : 'No events match these filters.' }), renderItem: (event) => (_jsx(EventRow, { event: event, startedAt: startedAt, threadLabel: labelFor(event.threadId), selected: selectedSeq === event.seq, onSelectSeq: (seq) => {
|
|
52
|
+
// Keep the picked row in view instead of chasing new arrivals.
|
|
53
|
+
if (seq !== undefined) {
|
|
54
|
+
setFollow(false);
|
|
55
|
+
}
|
|
56
|
+
onSelectSeq(seq);
|
|
57
|
+
} })) }), selected ? (_jsx(EventInspector, { event: selected, threadLabel: labelFor(selected.threadId), onClose: () => onSelectSeq(undefined), className: split ? 'h-full w-[46%] min-w-72 border-t-0 border-l' : undefined }, selected.seq)) : null] })] }));
|
|
58
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* The firehose is Looms' own stream endpoint, not a route on the Worker's contract, so what it
|
|
4
|
+
* sends is checked here: each frame over the socket, and each page of older ones.
|
|
5
|
+
*/
|
|
6
|
+
declare const GlobalRunKind: z.ZodEnum<{
|
|
7
|
+
playbook: "playbook";
|
|
8
|
+
pulls: "pulls";
|
|
9
|
+
session: "session";
|
|
10
|
+
workspace: "workspace";
|
|
11
|
+
}>;
|
|
12
|
+
export type GlobalRunKind = z.infer<typeof GlobalRunKind>;
|
|
13
|
+
declare const GlobalEventFrame: z.ZodObject<{
|
|
14
|
+
cursor: z.ZodNumber;
|
|
15
|
+
runId: z.ZodString;
|
|
16
|
+
runKind: z.ZodEnum<{
|
|
17
|
+
playbook: "playbook";
|
|
18
|
+
pulls: "pulls";
|
|
19
|
+
session: "session";
|
|
20
|
+
workspace: "workspace";
|
|
21
|
+
}>;
|
|
22
|
+
event: z.ZodCustom<import("@swirls/looms/core").AnyEventEnvelope, import("@swirls/looms/core").AnyEventEnvelope>;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
export type GlobalEventFrame = Readonly<z.infer<typeof GlobalEventFrame>>;
|
|
25
|
+
/**
|
|
26
|
+
* The frames in one page of older events. A frame that cannot be read is left out, as one over
|
|
27
|
+
* the socket would be, so one bad event does not hide the rest of the page.
|
|
28
|
+
*/
|
|
29
|
+
export declare function framesOfPage(body: unknown): GlobalEventFrame[];
|
|
30
|
+
export interface GlobalEventsFilter {
|
|
31
|
+
readonly runKinds?: readonly GlobalRunKind[];
|
|
32
|
+
readonly runIds?: readonly string[];
|
|
33
|
+
}
|
|
34
|
+
export type GlobalEventsStatus = 'connecting' | 'live' | 'reconnecting' | 'paused' | 'error';
|
|
35
|
+
export interface GlobalEventsState {
|
|
36
|
+
readonly frames: readonly GlobalEventFrame[];
|
|
37
|
+
readonly pending: readonly GlobalEventFrame[];
|
|
38
|
+
readonly cursor: number;
|
|
39
|
+
readonly oldestCursor: number | null;
|
|
40
|
+
readonly paused: boolean;
|
|
41
|
+
readonly status: GlobalEventsStatus;
|
|
42
|
+
readonly error: string | null;
|
|
43
|
+
readonly hasMoreOlder: boolean;
|
|
44
|
+
}
|
|
45
|
+
export declare const CLIENT_BUFFER_CAP = 5000;
|
|
46
|
+
export declare const OLDER_PAGE_SIZE = 100;
|
|
47
|
+
type GlobalEventsAction = {
|
|
48
|
+
readonly type: 'reset';
|
|
49
|
+
} | {
|
|
50
|
+
readonly type: 'status';
|
|
51
|
+
readonly status: GlobalEventsStatus;
|
|
52
|
+
readonly error?: string | null;
|
|
53
|
+
} | {
|
|
54
|
+
readonly type: 'pause';
|
|
55
|
+
} | {
|
|
56
|
+
readonly type: 'resume';
|
|
57
|
+
} | {
|
|
58
|
+
readonly type: 'append';
|
|
59
|
+
readonly frames: readonly GlobalEventFrame[];
|
|
60
|
+
} | {
|
|
61
|
+
readonly type: 'prepend';
|
|
62
|
+
readonly frames: readonly GlobalEventFrame[];
|
|
63
|
+
readonly exhausted: boolean;
|
|
64
|
+
};
|
|
65
|
+
export declare function reduceGlobalEvents(state: GlobalEventsState, action: GlobalEventsAction): GlobalEventsState;
|
|
66
|
+
/** The filter the events page opens with: every kind of run, in every session. */
|
|
67
|
+
export declare const DEFAULT_EVENTS_FILTER: GlobalEventsFilter;
|
|
68
|
+
/**
|
|
69
|
+
* The most recent events, read over HTTP. The events page's loader waits for this, so the page
|
|
70
|
+
* opens on a full log instead of an empty one that says it is connecting. The socket then picks
|
|
71
|
+
* up from where this left off.
|
|
72
|
+
*/
|
|
73
|
+
export declare const latestEventsQuery: import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<Readonly<{
|
|
74
|
+
cursor: number;
|
|
75
|
+
runId: string;
|
|
76
|
+
runKind: "playbook" | "pulls" | "session" | "workspace";
|
|
77
|
+
event: import("@swirls/looms/core").AnyEventEnvelope;
|
|
78
|
+
}>[], Error, Readonly<{
|
|
79
|
+
cursor: number;
|
|
80
|
+
runId: string;
|
|
81
|
+
runKind: "playbook" | "pulls" | "session" | "workspace";
|
|
82
|
+
event: import("@swirls/looms/core").AnyEventEnvelope;
|
|
83
|
+
}>[], readonly ["firehose", "latest"]>, "queryFn"> & {
|
|
84
|
+
queryFn?: import("@tanstack/react-query").QueryFunction<Readonly<{
|
|
85
|
+
cursor: number;
|
|
86
|
+
runId: string;
|
|
87
|
+
runKind: "playbook" | "pulls" | "session" | "workspace";
|
|
88
|
+
event: import("@swirls/looms/core").AnyEventEnvelope;
|
|
89
|
+
}>[], readonly ["firehose", "latest"], never> | undefined;
|
|
90
|
+
} & import("@tanstack/react-query").QueryKeyWithDataTag<readonly ["firehose", "latest"], Readonly<{
|
|
91
|
+
cursor: number;
|
|
92
|
+
runId: string;
|
|
93
|
+
runKind: "playbook" | "pulls" | "session" | "workspace";
|
|
94
|
+
event: import("@swirls/looms/core").AnyEventEnvelope;
|
|
95
|
+
}>[], Error>;
|
|
96
|
+
/** Where the log starts when it already has events: showing them, and counted as live. */
|
|
97
|
+
export declare function seededState(frames: readonly GlobalEventFrame[]): GlobalEventsState;
|
|
98
|
+
/**
|
|
99
|
+
* Follows the organization's events. `seed` is what the page already has for `filter` when it
|
|
100
|
+
* first renders; the socket continues from its last event.
|
|
101
|
+
*/
|
|
102
|
+
export declare function useGlobalEvents(filter?: GlobalEventsFilter, seed?: readonly GlobalEventFrame[]): {
|
|
103
|
+
frames: readonly GlobalEventFrame[];
|
|
104
|
+
pending: readonly GlobalEventFrame[];
|
|
105
|
+
cursor: number;
|
|
106
|
+
oldestCursor: number | null;
|
|
107
|
+
paused: boolean;
|
|
108
|
+
status: GlobalEventsStatus;
|
|
109
|
+
error: string | null;
|
|
110
|
+
hasMoreOlder: boolean;
|
|
111
|
+
visible: readonly Readonly<{
|
|
112
|
+
cursor: number;
|
|
113
|
+
runId: string;
|
|
114
|
+
runKind: "playbook" | "pulls" | "session" | "workspace";
|
|
115
|
+
event: import("@swirls/looms/core").AnyEventEnvelope;
|
|
116
|
+
}>[];
|
|
117
|
+
pendingCount: number;
|
|
118
|
+
pause: () => void;
|
|
119
|
+
resume: () => void;
|
|
120
|
+
loadOlder: () => Promise<void>;
|
|
121
|
+
};
|
|
122
|
+
export {};
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import { queryOptions } from '@tanstack/react-query';
|
|
2
|
+
import { useCallback, useEffect, useMemo, useReducer, useRef } from 'react';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { isRecord } from '../../lib/json.js';
|
|
5
|
+
/**
|
|
6
|
+
* The firehose is Looms' own stream endpoint, not a route on the Worker's contract, so what it
|
|
7
|
+
* sends is checked here: each frame over the socket, and each page of older ones.
|
|
8
|
+
*/
|
|
9
|
+
const GlobalRunKind = z.enum(['session', 'workspace', 'playbook', 'pulls']);
|
|
10
|
+
const GlobalEventFrame = z.object({
|
|
11
|
+
cursor: z.number(),
|
|
12
|
+
runId: z.string(),
|
|
13
|
+
runKind: GlobalRunKind,
|
|
14
|
+
// The event is Looms' envelope, whatever kind it is. Views read its fields defensively.
|
|
15
|
+
event: z.custom(isRecord),
|
|
16
|
+
});
|
|
17
|
+
/** What the socket sends in place of a frame when it cannot go on. */
|
|
18
|
+
const SocketError = z.object({ type: z.literal('error'), error: z.unknown() });
|
|
19
|
+
const OlderPage = z.object({ events: z.array(z.unknown()).optional() });
|
|
20
|
+
/**
|
|
21
|
+
* The frames in one page of older events. A frame that cannot be read is left out, as one over
|
|
22
|
+
* the socket would be, so one bad event does not hide the rest of the page.
|
|
23
|
+
*/
|
|
24
|
+
export function framesOfPage(body) {
|
|
25
|
+
const page = OlderPage.safeParse(body);
|
|
26
|
+
return (page.data?.events ?? []).flatMap((item) => {
|
|
27
|
+
const frame = GlobalEventFrame.safeParse(item);
|
|
28
|
+
return frame.success ? [frame.data] : [];
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export const CLIENT_BUFFER_CAP = 5_000;
|
|
32
|
+
export const OLDER_PAGE_SIZE = 100;
|
|
33
|
+
const INITIAL_STATE = {
|
|
34
|
+
frames: [],
|
|
35
|
+
pending: [],
|
|
36
|
+
cursor: 0,
|
|
37
|
+
oldestCursor: null,
|
|
38
|
+
paused: false,
|
|
39
|
+
status: 'connecting',
|
|
40
|
+
error: null,
|
|
41
|
+
hasMoreOlder: true,
|
|
42
|
+
};
|
|
43
|
+
function capFrames(frames) {
|
|
44
|
+
if (frames.length <= CLIENT_BUFFER_CAP) {
|
|
45
|
+
return frames;
|
|
46
|
+
}
|
|
47
|
+
return frames.slice(frames.length - CLIENT_BUFFER_CAP);
|
|
48
|
+
}
|
|
49
|
+
function mergeUniqueByCursor(existing, incoming) {
|
|
50
|
+
if (incoming.length === 0) {
|
|
51
|
+
return [...existing];
|
|
52
|
+
}
|
|
53
|
+
const seen = new Set(existing.map((frame) => frame.cursor));
|
|
54
|
+
const next = [...existing];
|
|
55
|
+
for (const frame of incoming) {
|
|
56
|
+
if (seen.has(frame.cursor)) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
seen.add(frame.cursor);
|
|
60
|
+
next.push(frame);
|
|
61
|
+
}
|
|
62
|
+
next.sort((left, right) => left.cursor - right.cursor);
|
|
63
|
+
return next;
|
|
64
|
+
}
|
|
65
|
+
export function reduceGlobalEvents(state, action) {
|
|
66
|
+
switch (action.type) {
|
|
67
|
+
case 'reset':
|
|
68
|
+
return { ...INITIAL_STATE };
|
|
69
|
+
case 'status':
|
|
70
|
+
return {
|
|
71
|
+
...state,
|
|
72
|
+
status: state.paused && action.status === 'live' ? 'paused' : action.status,
|
|
73
|
+
error: action.error ?? null,
|
|
74
|
+
};
|
|
75
|
+
case 'pause':
|
|
76
|
+
return {
|
|
77
|
+
...state,
|
|
78
|
+
paused: true,
|
|
79
|
+
status: 'paused',
|
|
80
|
+
};
|
|
81
|
+
case 'resume': {
|
|
82
|
+
const frames = capFrames(mergeUniqueByCursor(state.frames, state.pending));
|
|
83
|
+
const cursor = frames.at(-1)?.cursor ?? state.cursor;
|
|
84
|
+
return {
|
|
85
|
+
...state,
|
|
86
|
+
paused: false,
|
|
87
|
+
pending: [],
|
|
88
|
+
frames,
|
|
89
|
+
cursor,
|
|
90
|
+
oldestCursor: frames[0]?.cursor ?? state.oldestCursor,
|
|
91
|
+
status: 'live',
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
case 'append': {
|
|
95
|
+
if (action.frames.length === 0) {
|
|
96
|
+
return state;
|
|
97
|
+
}
|
|
98
|
+
if (state.paused) {
|
|
99
|
+
const pending = mergeUniqueByCursor(state.pending, action.frames);
|
|
100
|
+
const cursor = pending.at(-1)?.cursor ?? state.cursor;
|
|
101
|
+
return { ...state, pending, cursor };
|
|
102
|
+
}
|
|
103
|
+
const frames = capFrames(mergeUniqueByCursor(state.frames, action.frames));
|
|
104
|
+
return {
|
|
105
|
+
...state,
|
|
106
|
+
frames,
|
|
107
|
+
cursor: frames.at(-1)?.cursor ?? state.cursor,
|
|
108
|
+
oldestCursor: frames[0]?.cursor ?? state.oldestCursor,
|
|
109
|
+
status: state.status === 'connecting' || state.status === 'reconnecting' ? 'live' : state.status,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
case 'prepend': {
|
|
113
|
+
if (action.frames.length === 0) {
|
|
114
|
+
return {
|
|
115
|
+
...state,
|
|
116
|
+
hasMoreOlder: action.exhausted ? false : state.hasMoreOlder,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const frames = capFrames(mergeUniqueByCursor(action.frames, state.frames));
|
|
120
|
+
return {
|
|
121
|
+
...state,
|
|
122
|
+
frames,
|
|
123
|
+
oldestCursor: frames[0]?.cursor ?? state.oldestCursor,
|
|
124
|
+
cursor: frames.at(-1)?.cursor ?? state.cursor,
|
|
125
|
+
hasMoreOlder: action.exhausted ? false : state.hasMoreOlder,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
default: {
|
|
129
|
+
const exhaustive = action;
|
|
130
|
+
return exhaustive;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function buildSocketUrl(filter, after) {
|
|
135
|
+
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
136
|
+
const url = new URL(`${protocol}//${window.location.host}/firehose/socket`);
|
|
137
|
+
if (after > 0) {
|
|
138
|
+
url.searchParams.set('after', String(after));
|
|
139
|
+
}
|
|
140
|
+
if (filter.runKinds && filter.runKinds.length > 0) {
|
|
141
|
+
url.searchParams.set('runKind', filter.runKinds.join(','));
|
|
142
|
+
}
|
|
143
|
+
if (filter.runIds && filter.runIds.length > 0) {
|
|
144
|
+
url.searchParams.set('runId', filter.runIds.join(','));
|
|
145
|
+
}
|
|
146
|
+
return url.toString();
|
|
147
|
+
}
|
|
148
|
+
function buildPageUrl(filter, before, limit) {
|
|
149
|
+
const url = new URL('/firehose/events', window.location.origin);
|
|
150
|
+
url.searchParams.set('before', String(before));
|
|
151
|
+
url.searchParams.set('limit', String(limit));
|
|
152
|
+
if (filter.runKinds && filter.runKinds.length > 0) {
|
|
153
|
+
url.searchParams.set('runKind', filter.runKinds.join(','));
|
|
154
|
+
}
|
|
155
|
+
if (filter.runIds && filter.runIds.length > 0) {
|
|
156
|
+
url.searchParams.set('runId', filter.runIds.join(','));
|
|
157
|
+
}
|
|
158
|
+
return url.toString();
|
|
159
|
+
}
|
|
160
|
+
/** The filter the events page opens with: every kind of run, in every session. */
|
|
161
|
+
export const DEFAULT_EVENTS_FILTER = {
|
|
162
|
+
runKinds: [...GlobalRunKind.options],
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* The most recent events, read over HTTP. The events page's loader waits for this, so the page
|
|
166
|
+
* opens on a full log instead of an empty one that says it is connecting. The socket then picks
|
|
167
|
+
* up from where this left off.
|
|
168
|
+
*/
|
|
169
|
+
export const latestEventsQuery = queryOptions({
|
|
170
|
+
queryKey: ['firehose', 'latest'],
|
|
171
|
+
queryFn: async ({ signal }) => {
|
|
172
|
+
const response = await fetch(buildPageUrl(DEFAULT_EVENTS_FILTER, Number.MAX_SAFE_INTEGER, OLDER_PAGE_SIZE), { signal });
|
|
173
|
+
if (!response.ok) {
|
|
174
|
+
throw new Error(`Could not load events (${response.status}).`);
|
|
175
|
+
}
|
|
176
|
+
return framesOfPage(await response.json());
|
|
177
|
+
},
|
|
178
|
+
// A log is only worth opening on if it is current.
|
|
179
|
+
staleTime: 5000,
|
|
180
|
+
gcTime: 30_000,
|
|
181
|
+
});
|
|
182
|
+
/** Where the log starts when it already has events: showing them, and counted as live. */
|
|
183
|
+
export function seededState(frames) {
|
|
184
|
+
if (frames.length === 0) {
|
|
185
|
+
return INITIAL_STATE;
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
...INITIAL_STATE,
|
|
189
|
+
frames: [...frames],
|
|
190
|
+
cursor: frames.at(-1)?.cursor ?? 0,
|
|
191
|
+
oldestCursor: frames[0]?.cursor ?? null,
|
|
192
|
+
status: 'live',
|
|
193
|
+
hasMoreOlder: frames.length >= OLDER_PAGE_SIZE,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Follows the organization's events. `seed` is what the page already has for `filter` when it
|
|
198
|
+
* first renders; the socket continues from its last event.
|
|
199
|
+
*/
|
|
200
|
+
export function useGlobalEvents(filter = {}, seed = []) {
|
|
201
|
+
const [state, dispatch] = useReducer(reduceGlobalEvents, seed, seededState);
|
|
202
|
+
const stateRef = useRef(state);
|
|
203
|
+
const socketRef = useRef(null);
|
|
204
|
+
const reconnectAttempt = useRef(0);
|
|
205
|
+
const runKindsKey = (filter.runKinds ?? []).join(',');
|
|
206
|
+
const runIdsKey = (filter.runIds ?? []).join(',');
|
|
207
|
+
const socketFilter = useMemo(() => ({
|
|
208
|
+
...(runKindsKey ? { runKinds: z.array(GlobalRunKind).parse(runKindsKey.split(',')) } : {}),
|
|
209
|
+
...(runIdsKey ? { runIds: runIdsKey.split(',') } : {}),
|
|
210
|
+
}), [runKindsKey, runIdsKey]);
|
|
211
|
+
useEffect(() => {
|
|
212
|
+
stateRef.current = state;
|
|
213
|
+
}, [state]);
|
|
214
|
+
// The filter the events on screen were read with. A different one means a different log.
|
|
215
|
+
const shownFilter = useRef(socketFilter);
|
|
216
|
+
useEffect(() => {
|
|
217
|
+
// Each run of this effect has its own sockets. One flag shared between runs would let a
|
|
218
|
+
// socket closed by an earlier run reconnect as if it belonged to this one.
|
|
219
|
+
let disposed = false;
|
|
220
|
+
if (shownFilter.current !== socketFilter) {
|
|
221
|
+
shownFilter.current = socketFilter;
|
|
222
|
+
stateRef.current = INITIAL_STATE;
|
|
223
|
+
dispatch({ type: 'reset' });
|
|
224
|
+
}
|
|
225
|
+
let timer;
|
|
226
|
+
let first = true;
|
|
227
|
+
function connect() {
|
|
228
|
+
if (disposed) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const after = stateRef.current.cursor;
|
|
232
|
+
// A log that opened with events already on it is not "reconnecting" the first time.
|
|
233
|
+
if (!(first && after > 0)) {
|
|
234
|
+
dispatch({
|
|
235
|
+
type: 'status',
|
|
236
|
+
status: after > 0 ? 'reconnecting' : 'connecting',
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
first = false;
|
|
240
|
+
const socket = new WebSocket(buildSocketUrl(socketFilter, after));
|
|
241
|
+
socketRef.current = socket;
|
|
242
|
+
socket.addEventListener('open', () => {
|
|
243
|
+
reconnectAttempt.current = 0;
|
|
244
|
+
dispatch({ type: 'status', status: 'live' });
|
|
245
|
+
});
|
|
246
|
+
socket.addEventListener('message', (message) => {
|
|
247
|
+
let payload;
|
|
248
|
+
try {
|
|
249
|
+
payload = JSON.parse(String(message.data));
|
|
250
|
+
}
|
|
251
|
+
catch {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const frame = GlobalEventFrame.safeParse(payload);
|
|
255
|
+
if (frame.success) {
|
|
256
|
+
dispatch({ type: 'append', frames: [frame.data] });
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const failure = SocketError.safeParse(payload);
|
|
260
|
+
if (failure.success) {
|
|
261
|
+
dispatch({
|
|
262
|
+
type: 'status',
|
|
263
|
+
status: 'error',
|
|
264
|
+
error: String(failure.data.error),
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
socket.addEventListener('close', () => {
|
|
269
|
+
if (disposed) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
socketRef.current = null;
|
|
273
|
+
const attempt = reconnectAttempt.current++;
|
|
274
|
+
const delay = Math.min(10_000, 500 * 2 ** attempt);
|
|
275
|
+
dispatch({ type: 'status', status: 'reconnecting' });
|
|
276
|
+
timer = setTimeout(connect, delay);
|
|
277
|
+
});
|
|
278
|
+
socket.addEventListener('error', () => {
|
|
279
|
+
socket.close();
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
connect();
|
|
283
|
+
return () => {
|
|
284
|
+
disposed = true;
|
|
285
|
+
if (timer) {
|
|
286
|
+
clearTimeout(timer);
|
|
287
|
+
}
|
|
288
|
+
socketRef.current?.close();
|
|
289
|
+
socketRef.current = null;
|
|
290
|
+
};
|
|
291
|
+
}, [socketFilter]);
|
|
292
|
+
const pause = useCallback(() => {
|
|
293
|
+
dispatch({ type: 'pause' });
|
|
294
|
+
}, []);
|
|
295
|
+
const resume = useCallback(() => {
|
|
296
|
+
dispatch({ type: 'resume' });
|
|
297
|
+
}, []);
|
|
298
|
+
const loadOlder = useCallback(async () => {
|
|
299
|
+
const current = stateRef.current;
|
|
300
|
+
const before = current.oldestCursor;
|
|
301
|
+
if (before === null || before <= 1 || !current.hasMoreOlder) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
const response = await fetch(buildPageUrl(socketFilter, before, OLDER_PAGE_SIZE));
|
|
305
|
+
if (!response.ok) {
|
|
306
|
+
dispatch({
|
|
307
|
+
type: 'status',
|
|
308
|
+
status: 'error',
|
|
309
|
+
error: `Failed to load older events: ${response.status}`,
|
|
310
|
+
});
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
const body = await response.json();
|
|
314
|
+
const frames = framesOfPage(body);
|
|
315
|
+
dispatch({
|
|
316
|
+
type: 'prepend',
|
|
317
|
+
frames,
|
|
318
|
+
exhausted: frames.length < OLDER_PAGE_SIZE,
|
|
319
|
+
});
|
|
320
|
+
}, [socketFilter]);
|
|
321
|
+
return {
|
|
322
|
+
...state,
|
|
323
|
+
visible: state.paused ? state.frames : state.frames,
|
|
324
|
+
pendingCount: state.pending.length,
|
|
325
|
+
pause,
|
|
326
|
+
resume,
|
|
327
|
+
loadOlder,
|
|
328
|
+
};
|
|
329
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { pullsCatalog } from '@swirls/shuttle/core/pulls';
|
|
2
|
+
import type { workspaceCatalog } from '@swirls/shuttle/core/workspace';
|
|
3
|
+
import type { EventsOfCatalog, ProtocolEvents } from '@swirls/looms/core';
|
|
4
|
+
/** Every event the workspace run can carry: the runtime's own plus the workspace catalog. */
|
|
5
|
+
export type WorkspaceEvent = ProtocolEvents | EventsOfCatalog<typeof workspaceCatalog>;
|
|
6
|
+
/** Every event the pulls run can carry. */
|
|
7
|
+
export type PullsEvent = ProtocolEvents | EventsOfCatalog<typeof pullsCatalog>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMutation, useQueryClient, useSuspenseQuery } from '@tanstack/react-query';
|
|
3
|
+
import { BookOpen, Check, Inbox, LoaderCircle, RefreshCw, Sparkles, X } from 'lucide-react';
|
|
4
|
+
import { Badge } from '../../components/ui/badge.js';
|
|
5
|
+
import { Button } from '../../components/ui/button.js';
|
|
6
|
+
import { EmptyState } from '../../components/ui/panel.js';
|
|
7
|
+
import { cn, shortId } from '../../lib/cn.js';
|
|
8
|
+
import { Link, useShuttleHost } from '../../shuttle/index.js';
|
|
9
|
+
import { decideApproval } from '../sessions/signals.js';
|
|
10
|
+
import { playbookQuery } from './playbook-query.js';
|
|
11
|
+
/** The playbook page. Its route's loader has read the playbook before this renders. */
|
|
12
|
+
export function PlaybookPage() {
|
|
13
|
+
const host = useShuttleHost();
|
|
14
|
+
const { data: { runId, playbook }, error, isFetching, refetch, } = useSuspenseQuery(playbookQuery(host));
|
|
15
|
+
const proposed = Object.entries(playbook.proposed ?? {});
|
|
16
|
+
const lessons = playbook.lessons;
|
|
17
|
+
return (_jsx("div", { className: "h-full overflow-y-auto", children: _jsxs("div", { className: "stagger mx-auto flex w-full max-w-2xl flex-col gap-10 px-6 pt-16 pb-24", children: [_jsxs("section", { className: "flex items-start gap-4", children: [_jsxs("div", { className: "min-w-0 flex-1", children: [_jsxs("div", { className: "flex items-center gap-2.5", children: [_jsx("h1", { className: "text-2xl font-semibold tracking-tight", children: "Playbook" }), _jsxs(Badge, { variant: "outline", children: ["v", playbook.version] })] }), _jsxs("p", { className: "text-muted-foreground mt-2 max-w-xl text-sm leading-relaxed text-pretty", children: ["When a session goes idle, the custom ", _jsx("code", { className: "text-foreground", children: "reflect" }), ' ', "module reads its event history, finds friction, and proposes lessons. Approved lessons load into the conductor and workers of the next session."] }), _jsx("p", { className: "text-muted-foreground mt-2 font-mono text-[11px]", children: runId })] }), _jsxs(Button, { variant: "outline", size: "sm", onClick: () => void refetch(), disabled: isFetching, children: [_jsx(RefreshCw, { className: cn(isFetching && 'animate-spin') }), "Refresh"] })] }), error ? _jsx("p", { className: "text-status-failed -mt-6 text-xs", children: error.message }) : null, _jsx(Section, { icon: _jsx(Inbox, {}), title: "Awaiting review", count: proposed.length, empty: _jsx(EmptyState, { icon: _jsx(Sparkles, {}), title: "Nothing to review", children: "Finish a session with a correction or a stop and the reflector will propose a lesson." }), children: proposed.map(([lessonId, lesson]) => (_jsx(ProposedLesson, { runId: runId, lessonId: lessonId, lesson: lesson }, lessonId))) }), _jsx(Section, { icon: _jsx(BookOpen, {}), title: "Active lessons", count: lessons.length, empty: _jsx(EmptyState, { icon: _jsx(BookOpen, {}), title: "No approved lessons yet", children: "Approved lessons appear here and ship with every new session." }), children: lessons.map((lesson) => (_jsx(LessonCard, { lesson: lesson }, lesson.id))) })] }) }));
|
|
18
|
+
}
|
|
19
|
+
/** A lesson waiting for review, with the buttons that approve or reject it. */
|
|
20
|
+
function ProposedLesson({ runId, lessonId, lesson, }) {
|
|
21
|
+
const host = useShuttleHost();
|
|
22
|
+
const queryClient = useQueryClient();
|
|
23
|
+
const decide = useMutation({
|
|
24
|
+
mutationFn: (decision) => decideApproval(host, runId, `lesson_${lessonId}`, decision),
|
|
25
|
+
// The buttons stay busy until the playbook has been read again and the lesson has moved.
|
|
26
|
+
onSuccess: () => queryClient.invalidateQueries({ queryKey: playbookQuery(host).queryKey }),
|
|
27
|
+
});
|
|
28
|
+
const deciding = decide.isPending ? decide.variables : undefined;
|
|
29
|
+
return (_jsx(LessonCard, { lesson: lesson, pending: true, error: decide.error?.message, actions: _jsxs(_Fragment, { children: [_jsxs(Button, { variant: "success", size: "sm", disabled: deciding !== undefined, onClick: () => decide.mutate('approve'), children: [deciding === 'approve' ? _jsx(LoaderCircle, { className: "animate-spin" }) : _jsx(Check, {}), "Approve"] }), _jsxs(Button, { variant: "ghost", size: "sm", disabled: deciding !== undefined, onClick: () => decide.mutate('reject'), children: [deciding === 'reject' ? _jsx(LoaderCircle, { className: "animate-spin" }) : _jsx(X, {}), "Reject"] })] }) }));
|
|
30
|
+
}
|
|
31
|
+
function Section({ icon, title, count, empty, children, }) {
|
|
32
|
+
return (_jsxs("section", { children: [_jsxs("div", { className: "mb-2 flex items-center gap-2", children: [_jsx("span", { className: "text-muted-foreground [&_svg]:size-3.5", children: icon }), _jsx("h2", { className: "text-[13px] font-medium", children: title }), _jsx("span", { className: "text-muted-foreground font-mono text-[11px] tabular-nums", children: count || '' })] }), count === 0 ? (_jsx("div", { className: "rounded-xl border border-dashed", children: empty })) : (_jsx("ul", { className: "flex flex-col gap-2", children: children }))] }));
|
|
33
|
+
}
|
|
34
|
+
function LessonCard({ lesson, pending = false, actions, error, }) {
|
|
35
|
+
return (_jsxs("li", { className: cn('bg-card/50 rounded-xl border p-4', pending && 'border-route-idea/25 bg-route-idea/[0.04]'), children: [_jsx("p", { className: "text-[13.5px] leading-relaxed", children: lesson.text }), _jsxs("div", { className: "mt-3 flex flex-wrap items-center gap-1.5", children: [lesson.scope ? _jsx(Badge, { variant: "outline", children: lesson.scope }) : null, lesson.evidence.map((item) => (_jsxs(Link, { to: { page: 'session', sessionId: item.runId }, className: "text-muted-foreground hover:text-foreground hover:bg-accent inline-flex h-5 items-center rounded-full border px-2 font-mono text-[10px] transition-colors duration-150", title: `${item.runId} · event #${item.seq}`, children: [shortId(item.runId), "#", item.seq] }, `${item.runId}_${item.seq}`))), actions ? _jsx("div", { className: "ml-auto flex gap-1.5", children: actions }) : null] }), error ? _jsx("p", { className: "text-status-failed mt-2 text-xs", children: error }) : null] }));
|
|
36
|
+
}
|