@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,191 @@
|
|
|
1
|
+
import { reduceTabMutation } from './tab-set.js';
|
|
2
|
+
export const emptyTabSet = {
|
|
3
|
+
order: [],
|
|
4
|
+
tabs: {},
|
|
5
|
+
};
|
|
6
|
+
export function hasTabEvents(set) {
|
|
7
|
+
return Boolean(set && (set.order.length > 0 || Object.keys(set.tabs).length > 0));
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The tabs a session shows. Event history is no longer a tab — it opens as a drawer under the
|
|
11
|
+
* session — so Events tabs saved by older sessions are left out. A session with nothing open
|
|
12
|
+
* has no tabs.
|
|
13
|
+
*/
|
|
14
|
+
export function resolveTabSet(projected) {
|
|
15
|
+
const set = projected ?? emptyTabSet;
|
|
16
|
+
if (!Object.values(set.tabs).some((tab) => tab.kind === 'events')) {
|
|
17
|
+
return set;
|
|
18
|
+
}
|
|
19
|
+
const tabs = {};
|
|
20
|
+
for (const [tabId, tab] of Object.entries(set.tabs)) {
|
|
21
|
+
if (tab.kind !== 'events') {
|
|
22
|
+
tabs[tabId] = tab;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return { order: set.order.filter((tabId) => tabs[tabId]), tabs };
|
|
26
|
+
}
|
|
27
|
+
function pendingToMutation(op) {
|
|
28
|
+
switch (op.kind) {
|
|
29
|
+
case 'open':
|
|
30
|
+
return { type: 'open', tab: op.tab };
|
|
31
|
+
case 'close':
|
|
32
|
+
return { type: 'close', tabId: op.tabId };
|
|
33
|
+
case 'reorder':
|
|
34
|
+
return { type: 'reorder', tabIds: op.tabIds };
|
|
35
|
+
case 'retarget':
|
|
36
|
+
return { type: 'retarget', tabId: op.tabId, title: op.title, target: op.target };
|
|
37
|
+
default: {
|
|
38
|
+
const exhaustive = op;
|
|
39
|
+
return exhaustive;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export function applyPendingOps(base, pending) {
|
|
44
|
+
let next = base;
|
|
45
|
+
for (const op of pending) {
|
|
46
|
+
next = reduceTabMutation(next, pendingToMutation(op));
|
|
47
|
+
}
|
|
48
|
+
return next;
|
|
49
|
+
}
|
|
50
|
+
function tabSetsEqual(left, right) {
|
|
51
|
+
if (left.order.join('\0') !== right.order.join('\0')) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
for (const id of left.order) {
|
|
55
|
+
const a = left.tabs[id];
|
|
56
|
+
const b = right.tabs[id];
|
|
57
|
+
if (!a || !b) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
if (a.kind !== b.kind || a.title !== b.title || a.target !== b.target || a.tabId !== b.tabId) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Drop the whole pending queue once the projection matches what those ops would
|
|
68
|
+
* produce. Partial absorption keeps the queue so optimistic UI stays coherent.
|
|
69
|
+
*/
|
|
70
|
+
export function prunePendingOps(projected, pending) {
|
|
71
|
+
if (pending.length === 0) {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
if (!hasTabEvents(projected)) {
|
|
75
|
+
return [...pending];
|
|
76
|
+
}
|
|
77
|
+
const base = projected ?? emptyTabSet;
|
|
78
|
+
const overlay = applyPendingOps(base, pending);
|
|
79
|
+
return tabSetsEqual(overlay, base) ? [] : [...pending];
|
|
80
|
+
}
|
|
81
|
+
const ACTIVE_KEY_PREFIX = 'shuttle.active-tab:';
|
|
82
|
+
export function activeTabStorageKey(runId) {
|
|
83
|
+
return `${ACTIVE_KEY_PREFIX}${runId}`;
|
|
84
|
+
}
|
|
85
|
+
export function readActiveTabId(runId) {
|
|
86
|
+
try {
|
|
87
|
+
return sessionStorage.getItem(activeTabStorageKey(runId));
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export function writeActiveTabId(runId, tabId) {
|
|
94
|
+
try {
|
|
95
|
+
const key = activeTabStorageKey(runId);
|
|
96
|
+
if (tabId) {
|
|
97
|
+
sessionStorage.setItem(key, tabId);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
sessionStorage.removeItem(key);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// Private mode / quota — active tab is ephemeral anyway.
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/** Prefer the remembered tab when still open; otherwise the neighbour of a closed tab, else first. */
|
|
108
|
+
export function resolveActiveTabId(set, preferred, closedTabId) {
|
|
109
|
+
if (set.order.length === 0) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
if (preferred && set.tabs[preferred]) {
|
|
113
|
+
return preferred;
|
|
114
|
+
}
|
|
115
|
+
if (closedTabId) {
|
|
116
|
+
const index = set.order.indexOf(closedTabId);
|
|
117
|
+
if (index >= 0) {
|
|
118
|
+
return set.order[Math.min(index, set.order.length - 1)] ?? null;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return set.order[0] ?? null;
|
|
122
|
+
}
|
|
123
|
+
export function neighborAfterClose(previousOrder, closedTabId) {
|
|
124
|
+
const index = previousOrder.indexOf(closedTabId);
|
|
125
|
+
if (index < 0) {
|
|
126
|
+
return previousOrder[0] ?? null;
|
|
127
|
+
}
|
|
128
|
+
if (index + 1 < previousOrder.length) {
|
|
129
|
+
return previousOrder[index + 1] ?? null;
|
|
130
|
+
}
|
|
131
|
+
if (index - 1 >= 0) {
|
|
132
|
+
return previousOrder[index - 1] ?? null;
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
export function tabTitleForKind(kind, target) {
|
|
137
|
+
switch (kind) {
|
|
138
|
+
case 'events':
|
|
139
|
+
return 'Events';
|
|
140
|
+
case 'files':
|
|
141
|
+
return 'Workspace';
|
|
142
|
+
case 'file':
|
|
143
|
+
return target?.split('/').pop() || 'File';
|
|
144
|
+
case 'changes':
|
|
145
|
+
return 'Changes';
|
|
146
|
+
case 'terminal':
|
|
147
|
+
return 'Terminal';
|
|
148
|
+
case 'browser':
|
|
149
|
+
return target ? browserTitle(target) : 'Browser';
|
|
150
|
+
case 'review':
|
|
151
|
+
return 'Review';
|
|
152
|
+
case 'media':
|
|
153
|
+
return 'Media';
|
|
154
|
+
// A host's own kind: the part of its name after the namespace, until its type says better.
|
|
155
|
+
default:
|
|
156
|
+
return kind.slice(kind.indexOf(':') + 1);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function browserTitle(target) {
|
|
160
|
+
if (/^\d+$/.test(target)) {
|
|
161
|
+
return `:${target}`;
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
const url = new URL(target);
|
|
165
|
+
return url.host || 'Browser';
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
return target.slice(0, 24) || 'Browser';
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
export function singletonTabId(kind) {
|
|
172
|
+
switch (kind) {
|
|
173
|
+
case 'events':
|
|
174
|
+
return 'events';
|
|
175
|
+
case 'files':
|
|
176
|
+
return 'files';
|
|
177
|
+
case 'changes':
|
|
178
|
+
return 'changes';
|
|
179
|
+
case 'review':
|
|
180
|
+
return 'review';
|
|
181
|
+
case 'media':
|
|
182
|
+
return 'media';
|
|
183
|
+
case 'file':
|
|
184
|
+
case 'terminal':
|
|
185
|
+
case 'browser':
|
|
186
|
+
return null;
|
|
187
|
+
// A host's own kind has as many tabs as are opened, unless its type says there is one.
|
|
188
|
+
default:
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { ThreadNode } from '@swirls/looms/core';
|
|
3
|
+
import { type RunSummary } from '@swirls/looms/react';
|
|
4
|
+
import { type ArtifactType } from '../artifacts/artifact-types.js';
|
|
5
|
+
import type { SessionEvent } from '../events/event-catalog.js';
|
|
6
|
+
import type { ArtifactTabKind, WorkspaceFolder } from '../workspace/workspace.js';
|
|
7
|
+
import { type AgentIdentity } from './agents.js';
|
|
8
|
+
import { type SessionActivityState } from './session-activity.js';
|
|
9
|
+
import { type SessionFeed, type StreamingTurn } from './session-feed.js';
|
|
10
|
+
import { type SessionTabsController } from './use-session-tabs.js';
|
|
11
|
+
/**
|
|
12
|
+
* One session, as everything that shows a part of it reads it. `<Shuttle.Session>` follows the
|
|
13
|
+
* run and folds it once; the parts under it (conversation, composer, agents, artifacts, event
|
|
14
|
+
* history, header) each take what they need from here, so they can be put anywhere, left out,
|
|
15
|
+
* or replaced with something that reads the same thing.
|
|
16
|
+
*/
|
|
17
|
+
export interface SessionValue {
|
|
18
|
+
readonly runId: string;
|
|
19
|
+
/** The session's name: the one it was given, else what it was asked to do. */
|
|
20
|
+
readonly title: string;
|
|
21
|
+
/** What the session was first asked to do. */
|
|
22
|
+
readonly goal: string | undefined;
|
|
23
|
+
/** How the run ended, or what it is doing now. */
|
|
24
|
+
readonly status: string;
|
|
25
|
+
readonly summary: RunSummary;
|
|
26
|
+
/** The folder the session is in, where what hosts it keeps folders. */
|
|
27
|
+
readonly folder: WorkspaceFolder | undefined;
|
|
28
|
+
/** The conversation, folded from the run's events. */
|
|
29
|
+
readonly feed: SessionFeed;
|
|
30
|
+
readonly activity: SessionActivityState;
|
|
31
|
+
/** The turns agents are writing right now, by thread. */
|
|
32
|
+
readonly streaming: Readonly<Record<string, StreamingTurn>>;
|
|
33
|
+
readonly events: readonly SessionEvent[];
|
|
34
|
+
readonly eventCounts: ReadonlyMap<string, number>;
|
|
35
|
+
/** The session's agents, as a tree of threads. */
|
|
36
|
+
readonly root: ThreadNode | null;
|
|
37
|
+
readonly identities: ReadonlyMap<string, AgentIdentity>;
|
|
38
|
+
readonly labelFor: (threadId: string | null) => string | undefined;
|
|
39
|
+
/** The agent whose own timeline is open. Undefined at the session's top level. */
|
|
40
|
+
readonly openThreadId: string | undefined;
|
|
41
|
+
/** The agents above the open thread, top down, ending with it. Empty at the top level. */
|
|
42
|
+
readonly threadPath: readonly string[];
|
|
43
|
+
readonly openThread: (threadId: string | undefined) => void;
|
|
44
|
+
/** Goes up one level from the open thread. */
|
|
45
|
+
readonly leaveThread: () => void;
|
|
46
|
+
/** What event history is looking at: one agent's events, and one event among them. */
|
|
47
|
+
readonly inspected: {
|
|
48
|
+
readonly threadId: string | undefined;
|
|
49
|
+
readonly seq: number | undefined;
|
|
50
|
+
};
|
|
51
|
+
readonly selectThread: (threadId: string | undefined) => void;
|
|
52
|
+
readonly selectEvent: (seq: number | undefined) => void;
|
|
53
|
+
/** Opens event history on an agent, or on one of its steps. */
|
|
54
|
+
readonly inspect: (threadId: string, seq?: number) => void;
|
|
55
|
+
/** The kinds of tab the artifacts pane can show. */
|
|
56
|
+
readonly artifactTypes: readonly ArtifactType[];
|
|
57
|
+
readonly tabs: SessionTabsController;
|
|
58
|
+
/** Shows something in the artifacts pane, bringing the pane out if it is away. */
|
|
59
|
+
readonly openArtifact: (kind: ArtifactTabKind, target?: string) => void;
|
|
60
|
+
/**
|
|
61
|
+
* Which panes the reader wants out. These are wishes, not layout: an arrangement decides
|
|
62
|
+
* what it does with each, and one that has no such pane ignores it.
|
|
63
|
+
*/
|
|
64
|
+
readonly panes: {
|
|
65
|
+
readonly agents: boolean;
|
|
66
|
+
readonly setAgents: (open: boolean) => void;
|
|
67
|
+
readonly events: boolean;
|
|
68
|
+
readonly setEvents: (open: boolean) => void;
|
|
69
|
+
/** Beside the conversation. Follows whether anything is open in it until the reader says. */
|
|
70
|
+
readonly artifacts: boolean;
|
|
71
|
+
readonly setArtifacts: (open: boolean) => void;
|
|
72
|
+
/** Over the conversation, where there is no room beside it. */
|
|
73
|
+
readonly artifactsOverlay: boolean;
|
|
74
|
+
readonly setArtifactsOverlay: (open: boolean) => void;
|
|
75
|
+
/** Brings the artifacts pane out, wherever the arrangement shows it. */
|
|
76
|
+
readonly revealArtifacts: () => void;
|
|
77
|
+
readonly palette: boolean;
|
|
78
|
+
readonly setPalette: (open: boolean) => void;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/** The session the nearest `<Shuttle.Session>` is following. */
|
|
82
|
+
export declare function useSession(): SessionValue;
|
|
83
|
+
export interface SessionProps {
|
|
84
|
+
/** The session's run. */
|
|
85
|
+
readonly id: string;
|
|
86
|
+
/**
|
|
87
|
+
* The agent whose own timeline is open. Pass it with `onThreadChange` to keep it somewhere
|
|
88
|
+
* of the host's, such as the address, so a timeline can be linked to and Back leaves it.
|
|
89
|
+
* Without `onThreadChange` the session keeps it itself.
|
|
90
|
+
*/
|
|
91
|
+
readonly thread?: string | undefined;
|
|
92
|
+
readonly onThreadChange?: (threadId: string | undefined) => void;
|
|
93
|
+
/** An agent to open event history on when the session first shows, such as a link's. */
|
|
94
|
+
readonly focusThread?: string | undefined;
|
|
95
|
+
/** The kinds of tab the artifacts pane can show. Shuttle's own, unless given others. */
|
|
96
|
+
readonly artifactTypes?: readonly ArtifactType[];
|
|
97
|
+
readonly children: ReactNode;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Follows one session and gives it to the parts inside. The session's run should already be
|
|
101
|
+
* synced and its queries read (see the session page's loader) for it to arrive whole.
|
|
102
|
+
*/
|
|
103
|
+
export declare function Session(props: SessionProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useSuspenseQuery } from '@tanstack/react-query';
|
|
3
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, } from 'react';
|
|
4
|
+
import { useEventCounts, useLiveFold, useProjection, useRunEvents, useRunStore, useRunSummary, useThreadTree, } from '@swirls/looms/react';
|
|
5
|
+
import { possessive, useOrgPeople, useShuttleHost, useTenant } from '../../shuttle/index.js';
|
|
6
|
+
import { defaultArtifactTypes } from '../artifacts/artifact-types.js';
|
|
7
|
+
import { pullInbox, reviewedPullForSession, usePullsRunId } from '../pulls/pulls.js';
|
|
8
|
+
import { useOptionalWorkspace, useReportLiveSession } from '../workspace/workspace-context.js';
|
|
9
|
+
import { agentIdentities, withVendorAgents } from './agents.js';
|
|
10
|
+
import { rememberSession } from './recent-sessions.js';
|
|
11
|
+
import { sessionActivity } from './session-activity.js';
|
|
12
|
+
import { sessionFeed, streamingTurns, vendorLiveFeed, withLiveVendorSteps, } from './session-feed.js';
|
|
13
|
+
import { useAgentsOpen, useArtifactsChoice, useEventsOpen } from './session-panes.js';
|
|
14
|
+
import { sessionQueries } from './session-queries.js';
|
|
15
|
+
import { threadParents, threadPath } from './timeline.js';
|
|
16
|
+
import { useSessionTabs } from './use-session-tabs.js';
|
|
17
|
+
const SessionContext = createContext(null);
|
|
18
|
+
/** The session the nearest `<Shuttle.Session>` is following. */
|
|
19
|
+
export function useSession() {
|
|
20
|
+
const value = useContext(SessionContext);
|
|
21
|
+
if (!value) {
|
|
22
|
+
throw new Error('Session parts must be used inside <Shuttle.Session>');
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Follows one session and gives it to the parts inside. The session's run should already be
|
|
28
|
+
* synced and its queries read (see the session page's loader) for it to arrive whole.
|
|
29
|
+
*/
|
|
30
|
+
export function Session(props) {
|
|
31
|
+
// Everything kept here is about one session, so another session starts afresh.
|
|
32
|
+
return _jsx(SessionRoot, { ...props }, props.id);
|
|
33
|
+
}
|
|
34
|
+
function SessionRoot({ id: runId, thread, onThreadChange, focusThread, artifactTypes = defaultArtifactTypes, children, }) {
|
|
35
|
+
const host = useShuttleHost();
|
|
36
|
+
const store = useRunStore(runId);
|
|
37
|
+
const summary = useRunSummary(store);
|
|
38
|
+
const tree = useThreadTree(store);
|
|
39
|
+
const events = useRunEvents(store);
|
|
40
|
+
const eventCounts = useEventCounts(store);
|
|
41
|
+
const durableFeed = useProjection(store, sessionFeed);
|
|
42
|
+
const liveVendorSteps = useLiveFold(store, vendorLiveFeed);
|
|
43
|
+
const feed = useMemo(() => withLiveVendorSteps(durableFeed, liveVendorSteps), [durableFeed, liveVendorSteps]);
|
|
44
|
+
const activity = useProjection(store, sessionActivity);
|
|
45
|
+
const streaming = useLiveFold(store, streamingTurns);
|
|
46
|
+
const reportLiveSession = useReportLiveSession();
|
|
47
|
+
const [selectedThreadId, setSelectedThreadId] = useState();
|
|
48
|
+
const [selectedSeq, setSelectedSeq] = useState();
|
|
49
|
+
// The default view is the conversation alone. Agents and event history stay closed until
|
|
50
|
+
// asked for; artifacts show once the session has something open in them, unless the reader
|
|
51
|
+
// has opened or closed the pane themself.
|
|
52
|
+
const tabs = useSessionTabs(runId, artifactTypes);
|
|
53
|
+
const [agentsOpen, setAgentsOpen] = useAgentsOpen();
|
|
54
|
+
const [eventsOpen, setEventsOpen] = useEventsOpen();
|
|
55
|
+
const [artifactsChoice, setArtifactsChoice] = useArtifactsChoice(runId);
|
|
56
|
+
const artifactsDocked = artifactsChoice ?? tabs.tabs.order.length > 0;
|
|
57
|
+
const [artifactsOverlay, setArtifactsOverlay] = useState(false);
|
|
58
|
+
const [paletteOpen, setPaletteOpen] = useState(false);
|
|
59
|
+
const revealArtifacts = useCallback(() => {
|
|
60
|
+
setArtifactsOverlay(true);
|
|
61
|
+
setArtifactsChoice(true);
|
|
62
|
+
}, [setArtifactsChoice]);
|
|
63
|
+
// Opens what a message points at. A preview that is already open comes forward instead of
|
|
64
|
+
// opening a second time.
|
|
65
|
+
const { tabs: tabSet, openTab, setActiveTabId } = tabs;
|
|
66
|
+
const openArtifact = useCallback((kind, target) => {
|
|
67
|
+
revealArtifacts();
|
|
68
|
+
const existing = kind === 'browser'
|
|
69
|
+
? Object.values(tabSet.tabs).find((tab) => tab.kind === 'browser' && tab.target === target)
|
|
70
|
+
: undefined;
|
|
71
|
+
if (existing) {
|
|
72
|
+
setActiveTabId(existing.tabId);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
void openTab({ kind, target });
|
|
76
|
+
}
|
|
77
|
+
}, [revealArtifacts, tabSet, openTab, setActiveTabId]);
|
|
78
|
+
// A review session is about its review, so that tab is open when the session first is. Once
|
|
79
|
+
// per session and browser: closing the tab afterwards keeps it closed.
|
|
80
|
+
const reviewing = Boolean(reviewedPullForSession(useProjection(useRunStore(usePullsRunId()), pullInbox), runId));
|
|
81
|
+
const reviewTabOffered = useRef(null);
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
if (!reviewing || reviewTabOffered.current === runId) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
reviewTabOffered.current = runId;
|
|
87
|
+
const key = `shuttle:review-tab-opened:${runId}`;
|
|
88
|
+
try {
|
|
89
|
+
if (window.localStorage.getItem(key)) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
window.localStorage.setItem(key, '1');
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
// Storage is unavailable; opening the tab once per visit is the best that can be done.
|
|
96
|
+
}
|
|
97
|
+
// The pane shows itself once it has a tab, unless it was deliberately hidden.
|
|
98
|
+
void openTab({ kind: 'review' });
|
|
99
|
+
}, [reviewing, runId, openTab]);
|
|
100
|
+
// The open timeline is the host's to keep when it asks to hear of changes, and otherwise ours.
|
|
101
|
+
const [ownThread, setOwnThread] = useState();
|
|
102
|
+
const wantedThread = onThreadChange ? thread : ownThread;
|
|
103
|
+
const openThread = onThreadChange ?? setOwnThread;
|
|
104
|
+
// The conversation shows one timeline at a time: the session's top level, or one agent's.
|
|
105
|
+
// The session's own thread is the top level.
|
|
106
|
+
const openThreadId = wantedThread && wantedThread !== tree.root?.threadId ? wantedThread : undefined;
|
|
107
|
+
const path = useMemo(() => (openThreadId ? threadPath(openThreadId, threadParents(tree.root)) : []), [openThreadId, tree.root]);
|
|
108
|
+
const leaveThread = useCallback(() => {
|
|
109
|
+
// One level up. From an agent the top level delegated to, that is the session itself,
|
|
110
|
+
// which already shows the delegating agent's side of the work.
|
|
111
|
+
openThread(path.length > 2 ? path.at(-2) : undefined);
|
|
112
|
+
}, [openThread, path]);
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
if (!openThreadId) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const onKeyDown = (event) => {
|
|
118
|
+
const target = event.target;
|
|
119
|
+
// Escape belongs first to whatever is open or being typed into.
|
|
120
|
+
if (event.key !== 'Escape' ||
|
|
121
|
+
event.defaultPrevented ||
|
|
122
|
+
(target instanceof HTMLElement &&
|
|
123
|
+
(target.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(target.tagName))) ||
|
|
124
|
+
document.querySelector('[role="dialog"], [role="menu"], [role="listbox"]')) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
leaveThread();
|
|
128
|
+
};
|
|
129
|
+
window.addEventListener('keydown', onKeyDown);
|
|
130
|
+
return () => window.removeEventListener('keydown', onKeyDown);
|
|
131
|
+
}, [openThreadId, leaveThread]);
|
|
132
|
+
// Which agent runs the session is known before its first step, so the thread carries the
|
|
133
|
+
// agent's name from the start and never shows as Shuttle's conductor first. The composer's
|
|
134
|
+
// agent picker writes to the same query, so a change there renames the thread at once.
|
|
135
|
+
const { harness } = useSuspenseQuery(sessionQueries(host, runId).harness).data;
|
|
136
|
+
const me = useTenant().user.id;
|
|
137
|
+
const people = useOrgPeople();
|
|
138
|
+
const identities = useMemo(() => withVendorAgents(agentIdentities(tree.root), feed.vendorAgents, harness, (userId) => possessive(userId, me, people)), [tree.root, feed.vendorAgents, harness, me, people]);
|
|
139
|
+
const firstMessage = feed.items.find((item) => item.kind === 'user' && item.goal);
|
|
140
|
+
const goal = firstMessage?.kind === 'user' ? firstMessage.text : undefined;
|
|
141
|
+
const workspaceTree = useOptionalWorkspace()?.tree;
|
|
142
|
+
const listed = workspaceTree?.sessions[runId];
|
|
143
|
+
const folder = listed?.folderId ? workspaceTree?.folders[listed.folderId] : undefined;
|
|
144
|
+
const title = listed?.title ?? goal ?? 'Coding session';
|
|
145
|
+
// A finished run says how it ended; a live one says what it is doing now.
|
|
146
|
+
const status = summary.status === 'completed' || summary.status === 'failed' || summary.status === 'cancelled'
|
|
147
|
+
? summary.status
|
|
148
|
+
: summary.startedAt !== undefined
|
|
149
|
+
? activity.activity
|
|
150
|
+
: 'working';
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
if (goal) {
|
|
153
|
+
rememberSession({ runId, goal });
|
|
154
|
+
}
|
|
155
|
+
}, [runId, goal]);
|
|
156
|
+
useEffect(() => {
|
|
157
|
+
if (summary.startedAt !== undefined) {
|
|
158
|
+
reportLiveSession(runId, { status: summary.status, activity: activity.activity });
|
|
159
|
+
}
|
|
160
|
+
}, [runId, summary.startedAt, summary.status, activity.activity, reportLiveSession]);
|
|
161
|
+
const labelFor = useCallback((threadId) => (threadId ? identities.get(threadId)?.label : undefined), [identities]);
|
|
162
|
+
const inspect = useCallback((threadId, seq) => {
|
|
163
|
+
setSelectedThreadId(threadId);
|
|
164
|
+
setSelectedSeq(seq);
|
|
165
|
+
setEventsOpen(true);
|
|
166
|
+
}, [setEventsOpen]);
|
|
167
|
+
const focusThreadKnown = focusThread !== undefined && identities.has(focusThread);
|
|
168
|
+
const [focusedThreadId, setFocusedThreadId] = useState();
|
|
169
|
+
if (focusThreadKnown && focusedThreadId !== focusThread) {
|
|
170
|
+
setFocusedThreadId(focusThread);
|
|
171
|
+
setSelectedThreadId(focusThread);
|
|
172
|
+
setSelectedSeq(undefined);
|
|
173
|
+
setEventsOpen(true);
|
|
174
|
+
}
|
|
175
|
+
const value = {
|
|
176
|
+
runId,
|
|
177
|
+
title,
|
|
178
|
+
goal,
|
|
179
|
+
status,
|
|
180
|
+
summary,
|
|
181
|
+
folder,
|
|
182
|
+
feed,
|
|
183
|
+
activity,
|
|
184
|
+
streaming,
|
|
185
|
+
events,
|
|
186
|
+
eventCounts,
|
|
187
|
+
root: tree.root,
|
|
188
|
+
identities,
|
|
189
|
+
labelFor,
|
|
190
|
+
openThreadId,
|
|
191
|
+
threadPath: path,
|
|
192
|
+
openThread,
|
|
193
|
+
leaveThread,
|
|
194
|
+
inspected: { threadId: selectedThreadId, seq: selectedSeq },
|
|
195
|
+
selectThread: setSelectedThreadId,
|
|
196
|
+
selectEvent: setSelectedSeq,
|
|
197
|
+
inspect,
|
|
198
|
+
artifactTypes,
|
|
199
|
+
tabs,
|
|
200
|
+
openArtifact,
|
|
201
|
+
panes: {
|
|
202
|
+
agents: agentsOpen,
|
|
203
|
+
setAgents: setAgentsOpen,
|
|
204
|
+
events: eventsOpen,
|
|
205
|
+
setEvents: setEventsOpen,
|
|
206
|
+
artifacts: artifactsDocked,
|
|
207
|
+
setArtifacts: setArtifactsChoice,
|
|
208
|
+
artifactsOverlay,
|
|
209
|
+
setArtifactsOverlay,
|
|
210
|
+
revealArtifacts,
|
|
211
|
+
palette: paletteOpen,
|
|
212
|
+
setPalette: setPaletteOpen,
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
return _jsx(SessionContext, { value: value, children: children });
|
|
216
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { InterjectionKind } from '@swirls/shuttle/api';
|
|
2
|
+
import { type ShuttleHost } from '../../shuttle/index.js';
|
|
3
|
+
/** Sends a message the session already has down a different route. */
|
|
4
|
+
export declare function reroute(host: ShuttleHost, runId: string, messageId: string, kind: InterjectionKind, targetThreadId?: string): Promise<void>;
|
|
5
|
+
/** Resolves an agent's `ask_user` gate; `null` lets the agent use its own judgment. */
|
|
6
|
+
export declare function answerQuestion(host: ShuttleHost, runId: string, approvalId: string, answer: string | null): Promise<void>;
|
|
7
|
+
export declare function decideApproval(host: ShuttleHost, runId: string, approvalId: string, outcome: 'approve' | 'reject'): Promise<void>;
|
|
8
|
+
/** Resolve a structured approval gate (PR publish / review submit). */
|
|
9
|
+
export declare function decideStructuredApproval(host: ShuttleHost, runId: string, approvalId: string, choice: {
|
|
10
|
+
readonly actionId: string;
|
|
11
|
+
readonly outcome: 'approve' | 'reject';
|
|
12
|
+
readonly payload?: Record<string, unknown>;
|
|
13
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { SignalError } from '../../shuttle/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Sends a signal and, when the run refuses it, says what the person was trying to do ahead of
|
|
4
|
+
* the run's own reason.
|
|
5
|
+
*/
|
|
6
|
+
async function signal(host, runId, name, input, failure) {
|
|
7
|
+
try {
|
|
8
|
+
await host.signalRun(runId, name, input);
|
|
9
|
+
}
|
|
10
|
+
catch (cause) {
|
|
11
|
+
if (cause instanceof SignalError) {
|
|
12
|
+
throw new SignalError(`${failure}: ${cause.message}`, cause.status);
|
|
13
|
+
}
|
|
14
|
+
throw cause;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** Sends a message the session already has down a different route. */
|
|
18
|
+
export function reroute(host, runId, messageId, kind, targetThreadId) {
|
|
19
|
+
return signal(host, runId, 'shuttle/reroute', { messageId, kind, ...(targetThreadId ? { targetThreadId } : {}) }, 'Failed to reroute');
|
|
20
|
+
}
|
|
21
|
+
/** Resolves an agent's `ask_user` gate; `null` lets the agent use its own judgment. */
|
|
22
|
+
export function answerQuestion(host, runId, approvalId, answer) {
|
|
23
|
+
const choice = answer === null
|
|
24
|
+
? { actionId: 'defer', outcome: 'reject' }
|
|
25
|
+
: { actionId: 'answer', outcome: 'approve', payload: { answer } };
|
|
26
|
+
return signal(host, runId, 'approval/decision', { approvalId, choice }, 'Failed to answer');
|
|
27
|
+
}
|
|
28
|
+
export function decideApproval(host, runId, approvalId, outcome) {
|
|
29
|
+
return signal(host, runId, 'approval/decision', { approvalId, choice: outcome }, 'Failed to decide approval');
|
|
30
|
+
}
|
|
31
|
+
/** Resolve a structured approval gate (PR publish / review submit). */
|
|
32
|
+
export function decideStructuredApproval(host, runId, approvalId, choice) {
|
|
33
|
+
return signal(host, runId, 'approval/decision', { approvalId, choice }, 'Failed to decide approval');
|
|
34
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ArtifactTab, SessionTabSet } from '../workspace/workspace.js';
|
|
2
|
+
export type TabMutation = {
|
|
3
|
+
readonly type: 'open';
|
|
4
|
+
readonly tab: ArtifactTab;
|
|
5
|
+
} | {
|
|
6
|
+
readonly type: 'close';
|
|
7
|
+
readonly tabId: string;
|
|
8
|
+
} | {
|
|
9
|
+
readonly type: 'reorder';
|
|
10
|
+
readonly tabIds: readonly string[];
|
|
11
|
+
} | {
|
|
12
|
+
readonly type: 'retarget';
|
|
13
|
+
readonly tabId: string;
|
|
14
|
+
readonly title: string;
|
|
15
|
+
readonly target: string;
|
|
16
|
+
};
|
|
17
|
+
/** Pure tab-set transitions shared by the web projection and optimistic overlay. */
|
|
18
|
+
export declare function reduceTabMutation(base: SessionTabSet, mutation: TabMutation): SessionTabSet;
|
|
19
|
+
/** Applies one tab mutation to a session's tab set. Only `open` creates a missing tab set. */
|
|
20
|
+
export declare function mutateSessionTabs(state: Readonly<Record<string, SessionTabSet>>, runId: string, mutation: TabMutation): Readonly<Record<string, SessionTabSet>>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** Pure tab-set transitions shared by the web projection and optimistic overlay. */
|
|
2
|
+
export function reduceTabMutation(base, mutation) {
|
|
3
|
+
switch (mutation.type) {
|
|
4
|
+
case 'open': {
|
|
5
|
+
if (base.tabs[mutation.tab.tabId]) {
|
|
6
|
+
return base;
|
|
7
|
+
}
|
|
8
|
+
return {
|
|
9
|
+
order: [...base.order, mutation.tab.tabId],
|
|
10
|
+
tabs: { ...base.tabs, [mutation.tab.tabId]: mutation.tab },
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
case 'close': {
|
|
14
|
+
if (!base.tabs[mutation.tabId]) {
|
|
15
|
+
return base;
|
|
16
|
+
}
|
|
17
|
+
const tabs = { ...base.tabs };
|
|
18
|
+
delete tabs[mutation.tabId];
|
|
19
|
+
return {
|
|
20
|
+
order: base.order.filter((id) => id !== mutation.tabId),
|
|
21
|
+
tabs,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
case 'reorder': {
|
|
25
|
+
const known = new Set(base.order);
|
|
26
|
+
const order = mutation.tabIds.filter((id) => known.has(id));
|
|
27
|
+
const missing = base.order.filter((id) => !order.includes(id));
|
|
28
|
+
return { ...base, order: [...order, ...missing] };
|
|
29
|
+
}
|
|
30
|
+
case 'retarget': {
|
|
31
|
+
const tab = base.tabs[mutation.tabId];
|
|
32
|
+
if (!tab) {
|
|
33
|
+
return base;
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
...base,
|
|
37
|
+
tabs: {
|
|
38
|
+
...base.tabs,
|
|
39
|
+
[mutation.tabId]: { ...tab, title: mutation.title, target: mutation.target },
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
default: {
|
|
44
|
+
const exhaustive = mutation;
|
|
45
|
+
return exhaustive;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** Applies one tab mutation to a session's tab set. Only `open` creates a missing tab set. */
|
|
50
|
+
export function mutateSessionTabs(state, runId, mutation) {
|
|
51
|
+
const existing = state[runId];
|
|
52
|
+
if (!existing && mutation.type !== 'open') {
|
|
53
|
+
return state;
|
|
54
|
+
}
|
|
55
|
+
const base = existing ?? { order: [], tabs: {} };
|
|
56
|
+
const next = reduceTabMutation(base, mutation);
|
|
57
|
+
return next === base ? state : { ...state, [runId]: next };
|
|
58
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Connection, Team } from '@swirls/shuttle/api';
|
|
2
|
+
import { type SignInPlace } from '../connections/places.js';
|
|
3
|
+
/** The team a session has before anyone chooses one: Shuttle's own workers and nobody else. */
|
|
4
|
+
export declare const DEFAULT_TEAM: Team;
|
|
5
|
+
/** A team always has someone to do the work, and a preset needs both agents it names. */
|
|
6
|
+
export declare function withTeamChange(team: Team, change: Partial<Team>): Team;
|
|
7
|
+
/**
|
|
8
|
+
* Whether an agent can run where the session does. Where that place is unknown, or the agent's
|
|
9
|
+
* sign-in there cannot be checked from here, being signed in anywhere is enough.
|
|
10
|
+
*/
|
|
11
|
+
export declare function canRunAt(connection: Connection, place?: SignInPlace | null): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* The team as it will actually run: a saved team can name a vendor agent whose sign-in is gone,
|
|
14
|
+
* or was never this person's, and the worker leaves that agent out.
|
|
15
|
+
*/
|
|
16
|
+
export declare function effectiveTeam(team: Team, connections: readonly Connection[], place?: SignInPlace | null): Team;
|