@swirls/shuttle 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -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 +75 -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,100 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMutation } from '@tanstack/react-query';
|
|
3
|
+
import { ChevronRight, Cog, Layers, LoaderCircle, Square } from 'lucide-react';
|
|
4
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
5
|
+
import { statusLabel } from '../../components/status.js';
|
|
6
|
+
import { StatusDot } from '../../components/status-dot.js';
|
|
7
|
+
import { ScrollArea } from '../../components/ui/scroll-area.js';
|
|
8
|
+
import { cn } from '../../lib/cn.js';
|
|
9
|
+
import { useApi } from '../../shuttle/index.js';
|
|
10
|
+
import { agentRole, isSystemAgent } from './agents.js';
|
|
11
|
+
import { resolveThreadActivityTone } from './session-activity.js';
|
|
12
|
+
const INDENT = 14;
|
|
13
|
+
/**
|
|
14
|
+
* The rows under `root`, in tree order. Housekeeping agents are left out when `system` is given,
|
|
15
|
+
* and collected into it instead, so the tree can show them as one group.
|
|
16
|
+
*/
|
|
17
|
+
function flatten(root, collapsed, baseDepth = 0, system) {
|
|
18
|
+
const rows = [];
|
|
19
|
+
if (!root) {
|
|
20
|
+
return rows;
|
|
21
|
+
}
|
|
22
|
+
const stack = [{ node: root, depth: baseDepth }];
|
|
23
|
+
while (stack.length > 0) {
|
|
24
|
+
const next = stack.pop();
|
|
25
|
+
if (!next) {
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
if (system && next.depth > baseDepth && isSystemAgent(next.node.definitionName)) {
|
|
29
|
+
system.push(next.node);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
rows.push(next);
|
|
33
|
+
if (!collapsed.has(next.node.threadId)) {
|
|
34
|
+
for (const child of next.node.children.toReversed()) {
|
|
35
|
+
stack.push({ node: child, depth: next.depth + 1 });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return rows;
|
|
40
|
+
}
|
|
41
|
+
export function AgentTree({ root, activityState, identities, eventCounts, totalEventCount, selectedThreadId, showCounts = false, onSelect, stopIn, }) {
|
|
42
|
+
const [collapsed, setCollapsed] = useState(() => new Set());
|
|
43
|
+
const [systemOpen, setSystemOpen] = useState(false);
|
|
44
|
+
// Intake, narrators and the reflector run for every message. They are most of the tree and
|
|
45
|
+
// rarely what the reader came for, so they sit in one group that starts closed.
|
|
46
|
+
const { rows, systemRows } = useMemo(() => {
|
|
47
|
+
const system = [];
|
|
48
|
+
const main = flatten(root, collapsed, 0, system);
|
|
49
|
+
return {
|
|
50
|
+
rows: main,
|
|
51
|
+
systemRows: system.flatMap((node) => flatten(node, collapsed, 2)),
|
|
52
|
+
};
|
|
53
|
+
}, [root, collapsed]);
|
|
54
|
+
const systemCount = systemRows.filter((row) => row.depth === 2).length;
|
|
55
|
+
// A selected housekeeping agent stays in view even while its group is closed.
|
|
56
|
+
const showSystem = systemOpen || systemRows.some((row) => row.node.threadId === selectedThreadId);
|
|
57
|
+
const toggle = useCallback((id) => {
|
|
58
|
+
setCollapsed((prev) => {
|
|
59
|
+
const next = new Set(prev);
|
|
60
|
+
if (next.has(id)) {
|
|
61
|
+
next.delete(id);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
next.add(id);
|
|
65
|
+
}
|
|
66
|
+
return next;
|
|
67
|
+
});
|
|
68
|
+
}, []);
|
|
69
|
+
const renderRow = (row) => (_jsx(TreeRow, { row: row, activityState: activityState, identity: identities.get(row.node.threadId), count: showCounts ? (eventCounts.get(row.node.threadId) ?? 0) : undefined, selected: selectedThreadId === row.node.threadId, collapsed: collapsed.has(row.node.threadId), onToggle: toggle, onSelect: onSelect,
|
|
70
|
+
// The session's own thread is not an agent to stop.
|
|
71
|
+
stopIn: row.depth > 0 ? stopIn : undefined }, row.node.threadId));
|
|
72
|
+
return (_jsx(ScrollArea, { className: "min-h-0 flex-1", children: _jsxs("div", { className: "flex flex-col gap-px p-2", children: [_jsxs("button", { type: "button", onClick: () => onSelect(undefined), className: cn('flex h-8 w-full items-center gap-2 rounded-md px-2 text-left text-xs transition-colors duration-100', selectedThreadId === undefined
|
|
73
|
+
? 'bg-accent text-foreground'
|
|
74
|
+
: 'text-muted-foreground hover:bg-accent/50'), children: [_jsx(Layers, { className: "size-3.5 shrink-0" }), _jsx("span", { children: "All threads" }), showCounts ? (_jsx("span", { className: "text-muted-foreground ml-auto font-mono text-[10px] tabular-nums", children: totalEventCount })) : null] }), rows.length === 0 ? (_jsx("p", { className: "text-muted-foreground px-2 py-3 text-xs", children: "Waiting for threads\u2026" })) : (_jsxs(_Fragment, { children: [rows.map(renderRow), systemCount > 0 ? (_jsxs(_Fragment, { children: [_jsxs("button", { type: "button", onClick: () => setSystemOpen(!showSystem), "aria-expanded": showSystem, title: "Agents that route and answer messages, and learn from the session", className: "text-muted-foreground hover:bg-accent/50 hover:text-foreground relative flex h-8 w-full items-center rounded-md pr-2 text-left text-xs transition-colors duration-100", style: { paddingLeft: 4 + INDENT }, children: [_jsx("span", { "aria-hidden": true, className: "bg-border absolute inset-y-0 w-px", style: { left: 12 } }), _jsx("span", { className: "flex size-4 shrink-0 items-center justify-center", children: _jsx(ChevronRight, { className: cn('ease-snappy size-3 transition-transform duration-150', showSystem && 'rotate-90') }) }), _jsxs("span", { className: "flex min-w-0 items-center gap-2 pl-1", children: [_jsx(Cog, { className: "size-3.5 shrink-0" }), _jsx("span", { className: "truncate font-medium", children: "System" })] }), _jsx("span", { className: "ml-auto shrink-0 font-mono text-[10px] tabular-nums", children: systemCount })] }), showSystem ? systemRows.map(renderRow) : null] })) : null] }))] }) }));
|
|
75
|
+
}
|
|
76
|
+
function TreeRow({ row, activityState, identity, count, selected, collapsed, onToggle, onSelect, stopIn, }) {
|
|
77
|
+
const api = useApi();
|
|
78
|
+
const { node, depth } = row;
|
|
79
|
+
// Stops the thread and everything beneath it.
|
|
80
|
+
const stopThread = useMutation(api.sessions.stopThread.mutationOptions());
|
|
81
|
+
const stopping = stopThread.isPending;
|
|
82
|
+
const stopError = stopThread.error?.message;
|
|
83
|
+
const role = identity?.role ?? agentRole(node.definitionName);
|
|
84
|
+
const Icon = role.icon;
|
|
85
|
+
const hasChildren = node.children.length > 0;
|
|
86
|
+
const tone = resolveThreadActivityTone(activityState, node);
|
|
87
|
+
const label = identity?.label ?? role.label;
|
|
88
|
+
// A thread that has already ended has nothing left to stop.
|
|
89
|
+
const stoppable = stopIn && node.status !== 'completed' && node.status !== 'failed' && node.status !== 'cancelled';
|
|
90
|
+
const stop = () => {
|
|
91
|
+
if (stopIn && !stopping) {
|
|
92
|
+
stopThread.mutate({ id: stopIn, threadId: node.threadId });
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
return (_jsxs("div", { className: cn('group/row relative flex h-8 items-center rounded-md pr-2 text-xs transition-colors duration-100', selected ? 'bg-accent text-foreground' : 'hover:bg-accent/50'), style: { paddingLeft: 4 + depth * INDENT }, title: `${role.blurb}\n${node.kind}:${node.definitionName} · ${statusLabel(tone)}`, children: [Array.from({ length: depth }, (_, level) => (_jsx("span", { "aria-hidden": true, className: "bg-border absolute inset-y-0 w-px", style: { left: 12 + level * INDENT } }, level))), hasChildren ? (_jsx("button", { type: "button", className: "text-muted-foreground hover:text-foreground hover:bg-background/40 flex size-4 shrink-0 items-center justify-center rounded-sm", onClick: () => onToggle(node.threadId), "aria-label": collapsed ? 'Expand thread' : 'Collapse thread', "aria-expanded": !collapsed, children: _jsx(ChevronRight, { className: cn('ease-snappy size-3 transition-transform duration-150', !collapsed && 'rotate-90') }) })) : (_jsx("span", { className: "size-4 shrink-0" })), _jsxs("button", { type: "button", className: "flex h-full min-w-0 flex-1 items-center gap-2 pl-1 text-left", onClick: () => onSelect(node.threadId), children: [_jsx(Icon, { className: cn('size-3.5 shrink-0', role.tone) }), _jsx("span", { className: "min-w-0 truncate font-medium", children: label }), _jsx(StatusDot, { status: tone, className: "ml-0.5" }), count === undefined ? null : (_jsx("span", { className: cn('text-muted-foreground ml-auto shrink-0 font-mono text-[10px] tabular-nums',
|
|
96
|
+
// The stop button takes the count's place while the row is hovered or focused.
|
|
97
|
+
stoppable && 'group-focus-within/row:invisible group-hover/row:invisible', stopping && 'invisible'), children: count }))] }), stoppable ? (_jsx("button", { type: "button", onClick: stop, disabled: stopping, "aria-label": hasChildren ? `Stop ${label} and the agents under it` : `Stop ${label}`, title: stopError ?? (hasChildren ? `Stop ${label} and the agents under it` : `Stop ${label}`), className: cn('hover:bg-destructive/15 hover:text-destructive focus-visible:ring-ring/50 absolute right-1.5 flex size-5 items-center justify-center rounded-sm outline-none focus-visible:ring-2', stopError ? 'text-destructive' : 'text-muted-foreground', stopping
|
|
98
|
+
? 'opacity-100'
|
|
99
|
+
: 'opacity-0 group-hover/row:opacity-100 focus-visible:opacity-100'), children: stopping ? (_jsx(LoaderCircle, { className: "size-3 animate-spin" })) : (_jsx(Square, { className: "size-2.5 fill-current" })) })) : null] }));
|
|
100
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type LucideIcon } from 'lucide-react';
|
|
2
|
+
import type { ThreadNode } from '@swirls/looms/core';
|
|
3
|
+
export interface AgentRole {
|
|
4
|
+
readonly label: string;
|
|
5
|
+
readonly icon: LucideIcon;
|
|
6
|
+
/** Tailwind text color class; backgrounds derive from `currentColor`. */
|
|
7
|
+
readonly tone: string;
|
|
8
|
+
readonly blurb: string;
|
|
9
|
+
}
|
|
10
|
+
/** Whether a thread is one of the session's own housekeeping agents. */
|
|
11
|
+
export declare function isSystemAgent(definitionName: string | undefined): boolean;
|
|
12
|
+
export declare function agentRole(definitionName: string | undefined): AgentRole;
|
|
13
|
+
export interface AgentIdentity {
|
|
14
|
+
readonly threadId: string;
|
|
15
|
+
readonly definitionName: string;
|
|
16
|
+
readonly label: string;
|
|
17
|
+
readonly role: AgentRole;
|
|
18
|
+
}
|
|
19
|
+
/** Repeated definitions get ordinal suffixes ("Worker 2") in tree order. */
|
|
20
|
+
export declare function agentIdentities(root: ThreadNode | null): ReadonlyMap<string, AgentIdentity>;
|
|
21
|
+
/**
|
|
22
|
+
* Renames threads that a vendor agent runs. A Codex or Claude Code session is still driven
|
|
23
|
+
* through Shuttle's conductor thread, but it is that agent doing the work, so it carries its name.
|
|
24
|
+
*
|
|
25
|
+
* `vendorAgents` records what actually ran each thread. Before a thread's first step there is no
|
|
26
|
+
* record yet, so `sessionHarness`, the agent the session is set to, names it in the meantime.
|
|
27
|
+
*/
|
|
28
|
+
export declare function withVendorAgents(identities: ReadonlyMap<string, AgentIdentity>, vendorAgents: Readonly<Record<string, {
|
|
29
|
+
label: string;
|
|
30
|
+
model?: string;
|
|
31
|
+
billedTo?: string;
|
|
32
|
+
}>>, sessionHarness?: string,
|
|
33
|
+
/** Says whose subscription a turn ran on, such as "your" or "Alice's". */
|
|
34
|
+
whose?: (userId: string) => string): ReadonlyMap<string, AgentIdentity>;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { Bot, Compass, Filter, Hammer, MessageCircleQuestion, Orbit, Sparkles, Workflow, } from 'lucide-react';
|
|
2
|
+
const roles = {
|
|
3
|
+
coding: {
|
|
4
|
+
label: 'Session',
|
|
5
|
+
icon: Orbit,
|
|
6
|
+
tone: 'text-brand',
|
|
7
|
+
blurb: 'Root mailbox that routes every interjection.',
|
|
8
|
+
},
|
|
9
|
+
conductor: {
|
|
10
|
+
label: 'Conductor',
|
|
11
|
+
icon: Compass,
|
|
12
|
+
tone: 'text-route-task',
|
|
13
|
+
blurb: 'Plans the work and delegates to workers.',
|
|
14
|
+
},
|
|
15
|
+
worker: {
|
|
16
|
+
label: 'Worker',
|
|
17
|
+
icon: Hammer,
|
|
18
|
+
tone: 'text-route-idea',
|
|
19
|
+
blurb: 'Edits code inside the sandbox.',
|
|
20
|
+
},
|
|
21
|
+
// Vendor agents the conductor delegates to in a hybrid session.
|
|
22
|
+
codex: {
|
|
23
|
+
label: 'Codex',
|
|
24
|
+
icon: Bot,
|
|
25
|
+
tone: 'text-route-idea',
|
|
26
|
+
blurb: 'Codex on your subscription, taking tasks from the conductor.',
|
|
27
|
+
},
|
|
28
|
+
'claude-code': {
|
|
29
|
+
label: 'Claude Code',
|
|
30
|
+
icon: Bot,
|
|
31
|
+
tone: 'text-route-question',
|
|
32
|
+
blurb: 'Claude Code on your subscription, taking tasks from the conductor.',
|
|
33
|
+
},
|
|
34
|
+
cursor: {
|
|
35
|
+
label: 'Cursor',
|
|
36
|
+
icon: Bot,
|
|
37
|
+
tone: 'text-route-idea',
|
|
38
|
+
blurb: 'Cursor on your subscription, taking tasks from the conductor.',
|
|
39
|
+
},
|
|
40
|
+
narrator: {
|
|
41
|
+
label: 'Narrator',
|
|
42
|
+
icon: MessageCircleQuestion,
|
|
43
|
+
tone: 'text-route-question',
|
|
44
|
+
blurb: 'Answers questions without interrupting the work.',
|
|
45
|
+
},
|
|
46
|
+
intake: {
|
|
47
|
+
label: 'Intake',
|
|
48
|
+
icon: Filter,
|
|
49
|
+
tone: 'text-route-constraint',
|
|
50
|
+
blurb: 'Classifies each message before routing.',
|
|
51
|
+
},
|
|
52
|
+
reflector: {
|
|
53
|
+
label: 'Reflector',
|
|
54
|
+
icon: Sparkles,
|
|
55
|
+
tone: 'text-route-constraint',
|
|
56
|
+
blurb: 'Mines the event history for lessons.',
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
const fallbackRole = {
|
|
60
|
+
label: 'Thread',
|
|
61
|
+
icon: Workflow,
|
|
62
|
+
tone: 'text-muted-foreground',
|
|
63
|
+
blurb: 'Looms thread.',
|
|
64
|
+
};
|
|
65
|
+
/** Agents that keep the session running rather than doing the work someone asked for. */
|
|
66
|
+
const SYSTEM_DEFINITIONS = new Set(['intake', 'narrator', 'reflector']);
|
|
67
|
+
/** Whether a thread is one of the session's own housekeeping agents. */
|
|
68
|
+
export function isSystemAgent(definitionName) {
|
|
69
|
+
return definitionName !== undefined && SYSTEM_DEFINITIONS.has(definitionName);
|
|
70
|
+
}
|
|
71
|
+
export function agentRole(definitionName) {
|
|
72
|
+
return (definitionName ? roles[definitionName] : undefined) ?? fallbackRole;
|
|
73
|
+
}
|
|
74
|
+
/** Repeated definitions get ordinal suffixes ("Worker 2") in tree order. */
|
|
75
|
+
export function agentIdentities(root) {
|
|
76
|
+
const identities = new Map();
|
|
77
|
+
const seen = new Map();
|
|
78
|
+
function visit(node) {
|
|
79
|
+
const role = agentRole(node.definitionName);
|
|
80
|
+
const count = (seen.get(node.definitionName) ?? 0) + 1;
|
|
81
|
+
seen.set(node.definitionName, count);
|
|
82
|
+
const base = role === fallbackRole ? node.definitionName || 'thread' : role.label;
|
|
83
|
+
identities.set(node.threadId, {
|
|
84
|
+
threadId: node.threadId,
|
|
85
|
+
definitionName: node.definitionName,
|
|
86
|
+
label: count > 1 ? `${base} ${count}` : base,
|
|
87
|
+
role,
|
|
88
|
+
});
|
|
89
|
+
for (const child of node.children) {
|
|
90
|
+
visit(child);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (root) {
|
|
94
|
+
visit(root);
|
|
95
|
+
}
|
|
96
|
+
return identities;
|
|
97
|
+
}
|
|
98
|
+
const HARNESS_LABELS = {
|
|
99
|
+
codex: 'Codex',
|
|
100
|
+
'claude-code': 'Claude Code',
|
|
101
|
+
cursor: 'Cursor',
|
|
102
|
+
};
|
|
103
|
+
/** Thread definitions whose turns run on the session's vendor agent. */
|
|
104
|
+
const VENDOR_RUN_DEFINITIONS = new Set(['conductor']);
|
|
105
|
+
function renamed(identity, label, model, whose = 'your') {
|
|
106
|
+
return {
|
|
107
|
+
...identity,
|
|
108
|
+
label,
|
|
109
|
+
role: {
|
|
110
|
+
...identity.role,
|
|
111
|
+
label,
|
|
112
|
+
blurb: model
|
|
113
|
+
? `${label} on ${whose} subscription, running ${model}.`
|
|
114
|
+
: `${label} on ${whose} subscription.`,
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Renames threads that a vendor agent runs. A Codex or Claude Code session is still driven
|
|
120
|
+
* through Shuttle's conductor thread, but it is that agent doing the work, so it carries its name.
|
|
121
|
+
*
|
|
122
|
+
* `vendorAgents` records what actually ran each thread. Before a thread's first step there is no
|
|
123
|
+
* record yet, so `sessionHarness`, the agent the session is set to, names it in the meantime.
|
|
124
|
+
*/
|
|
125
|
+
export function withVendorAgents(identities, vendorAgents, sessionHarness,
|
|
126
|
+
/** Says whose subscription a turn ran on, such as "your" or "Alice's". */
|
|
127
|
+
whose) {
|
|
128
|
+
const pendingLabel = sessionHarness ? HARNESS_LABELS[sessionHarness] : undefined;
|
|
129
|
+
if (Object.keys(vendorAgents).length === 0 && !pendingLabel) {
|
|
130
|
+
return identities;
|
|
131
|
+
}
|
|
132
|
+
const next = new Map();
|
|
133
|
+
for (const [threadId, identity] of identities) {
|
|
134
|
+
const agent = vendorAgents[threadId];
|
|
135
|
+
if (agent) {
|
|
136
|
+
next.set(threadId, renamed(identity, agent.label, agent.model, agent.billedTo && whose ? whose(agent.billedTo) : undefined));
|
|
137
|
+
}
|
|
138
|
+
else if (pendingLabel && VENDOR_RUN_DEFINITIONS.has(identity.definitionName)) {
|
|
139
|
+
next.set(threadId, renamed(identity, pendingLabel));
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
next.set(threadId, identity);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return next;
|
|
146
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which sessions want the person back, for the desktop app's Dock badge and notifications.
|
|
3
|
+
*
|
|
4
|
+
* Only a person's own sessions count: ones they started or were added to. An organization's
|
|
5
|
+
* public sessions are someone else's work, and are not theirs to be called back to.
|
|
6
|
+
*/
|
|
7
|
+
export interface AttentionSession {
|
|
8
|
+
readonly runId: string;
|
|
9
|
+
readonly title: string;
|
|
10
|
+
readonly activity: string;
|
|
11
|
+
readonly archived: boolean;
|
|
12
|
+
readonly ownerId?: string | null;
|
|
13
|
+
readonly memberIds?: readonly string[];
|
|
14
|
+
}
|
|
15
|
+
export type AttentionKind = 'needs_input' | 'finished' | 'failed';
|
|
16
|
+
export interface AttentionChange {
|
|
17
|
+
readonly runId: string;
|
|
18
|
+
readonly title: string;
|
|
19
|
+
readonly kind: AttentionKind;
|
|
20
|
+
}
|
|
21
|
+
/** How many of the person's sessions are stopped, waiting for them. */
|
|
22
|
+
export declare function attentionCount(sessions: Readonly<Record<string, AttentionSession>>, userId: string,
|
|
23
|
+
/** The session on screen, which they can already see. Null when the window is elsewhere. */
|
|
24
|
+
watching: string | null): number;
|
|
25
|
+
/** What each watched session was doing, to compare the next reading against. */
|
|
26
|
+
export declare function activitySnapshot(sessions: Readonly<Record<string, AttentionSession>>, userId: string): Record<string, string>;
|
|
27
|
+
/**
|
|
28
|
+
* Sessions that stopped working since `previous`. A session seen for the first time is not a
|
|
29
|
+
* change: it was already in that state when the page opened.
|
|
30
|
+
*/
|
|
31
|
+
export declare function attentionChanges(previous: Readonly<Record<string, string>>, sessions: Readonly<Record<string, AttentionSession>>, userId: string): AttentionChange[];
|
|
32
|
+
export declare function attentionMessage(kind: AttentionKind): string;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
function isMine(session, userId) {
|
|
2
|
+
return session.ownerId === userId || (session.memberIds?.includes(userId) ?? false);
|
|
3
|
+
}
|
|
4
|
+
function watched(sessions, userId) {
|
|
5
|
+
return Object.values(sessions).filter((session) => !session.archived && isMine(session, userId));
|
|
6
|
+
}
|
|
7
|
+
/** How many of the person's sessions are stopped, waiting for them. */
|
|
8
|
+
export function attentionCount(sessions, userId,
|
|
9
|
+
/** The session on screen, which they can already see. Null when the window is elsewhere. */
|
|
10
|
+
watching) {
|
|
11
|
+
return watched(sessions, userId).filter((session) => session.runId !== watching &&
|
|
12
|
+
(session.activity === 'needs_input' || session.activity === 'error')).length;
|
|
13
|
+
}
|
|
14
|
+
/** What each watched session was doing, to compare the next reading against. */
|
|
15
|
+
export function activitySnapshot(sessions, userId) {
|
|
16
|
+
return Object.fromEntries(watched(sessions, userId).map((session) => [session.runId, session.activity]));
|
|
17
|
+
}
|
|
18
|
+
const ARRIVED = {
|
|
19
|
+
needs_input: 'needs_input',
|
|
20
|
+
idle: 'finished',
|
|
21
|
+
error: 'failed',
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Sessions that stopped working since `previous`. A session seen for the first time is not a
|
|
25
|
+
* change: it was already in that state when the page opened.
|
|
26
|
+
*/
|
|
27
|
+
export function attentionChanges(previous, sessions, userId) {
|
|
28
|
+
return watched(sessions, userId).flatMap((session) => {
|
|
29
|
+
const kind = ARRIVED[session.activity];
|
|
30
|
+
return previous[session.runId] === 'working' && kind
|
|
31
|
+
? [{ runId: session.runId, title: session.title, kind }]
|
|
32
|
+
: [];
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const MESSAGES = {
|
|
36
|
+
needs_input: 'Needs your answer',
|
|
37
|
+
finished: 'Finished working',
|
|
38
|
+
failed: 'Stopped on an error',
|
|
39
|
+
};
|
|
40
|
+
export function attentionMessage(kind) {
|
|
41
|
+
return MESSAGES[kind];
|
|
42
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type MediaAsset } from './media.js';
|
|
2
|
+
/** A file chosen for the message being written. It uploads as soon as it is chosen. */
|
|
3
|
+
export interface PendingAttachment {
|
|
4
|
+
readonly key: string;
|
|
5
|
+
readonly file: File;
|
|
6
|
+
/** A local preview, for images. */
|
|
7
|
+
readonly previewUrl?: string;
|
|
8
|
+
readonly status: 'uploading' | 'ready' | 'error';
|
|
9
|
+
/** Upload progress from 0 to 1. */
|
|
10
|
+
readonly progress: number;
|
|
11
|
+
readonly error?: string;
|
|
12
|
+
/** Settles when the upload does. A message sent meanwhile waits on it. */
|
|
13
|
+
readonly uploaded: Promise<MediaAsset>;
|
|
14
|
+
readonly cancel: () => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The files attached to the message being written. Each uploads on its own while the person
|
|
18
|
+
* keeps typing, so sending rarely has to wait.
|
|
19
|
+
*/
|
|
20
|
+
export declare function useComposerAttachments(runId: string): {
|
|
21
|
+
attachments: readonly PendingAttachment[];
|
|
22
|
+
rejection: string | null;
|
|
23
|
+
add: (files: readonly File[]) => void;
|
|
24
|
+
remove: (key: string) => void;
|
|
25
|
+
take: () => readonly PendingAttachment[];
|
|
26
|
+
restore: (returned: readonly PendingAttachment[]) => void;
|
|
27
|
+
};
|
|
28
|
+
/** Releases the previews of files whose message has been sent. */
|
|
29
|
+
export declare function releaseAttachments(attachments: readonly PendingAttachment[]): void;
|
|
30
|
+
export declare function AttachmentTray({ attachments, onRemove, }: {
|
|
31
|
+
attachments: readonly PendingAttachment[];
|
|
32
|
+
onRemove: (key: string) => void;
|
|
33
|
+
}): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { AlertCircle, FileAudio, FileText, FileVideo, Paperclip, X } from 'lucide-react';
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { cn, errorMessage } from '../../lib/cn.js';
|
|
5
|
+
import { useShuttleHost } from '../../shuttle/index.js';
|
|
6
|
+
import { MAX_ATTACHMENTS, MAX_ATTACHMENT_BYTES, formatBytes, mediaKind, uploadAsset, } from './media.js';
|
|
7
|
+
/**
|
|
8
|
+
* The files attached to the message being written. Each uploads on its own while the person
|
|
9
|
+
* keeps typing, so sending rarely has to wait.
|
|
10
|
+
*/
|
|
11
|
+
export function useComposerAttachments(runId) {
|
|
12
|
+
const host = useShuttleHost();
|
|
13
|
+
const [attachments, setAttachments] = useState([]);
|
|
14
|
+
const [rejection, setRejection] = useState(null);
|
|
15
|
+
/** The latest files, for callbacks that must not change identity as files come and go. */
|
|
16
|
+
const live = useRef(attachments);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
live.current = attachments;
|
|
19
|
+
}, [attachments]);
|
|
20
|
+
// Previews are object URLs, which the browser keeps until they are released.
|
|
21
|
+
useEffect(() => () => {
|
|
22
|
+
for (const attachment of live.current) {
|
|
23
|
+
attachment.cancel();
|
|
24
|
+
if (attachment.previewUrl) {
|
|
25
|
+
URL.revokeObjectURL(attachment.previewUrl);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}, []);
|
|
29
|
+
const patch = useCallback((key, change) => {
|
|
30
|
+
setAttachments((current) => current.map((attachment) => attachment.key === key ? { ...attachment, ...change } : attachment));
|
|
31
|
+
}, []);
|
|
32
|
+
const add = useCallback((files) => {
|
|
33
|
+
if (files.length === 0) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const room = MAX_ATTACHMENTS - live.current.length;
|
|
37
|
+
const accepted = [];
|
|
38
|
+
let refused = null;
|
|
39
|
+
for (const file of files) {
|
|
40
|
+
if (accepted.length >= room) {
|
|
41
|
+
refused = `A message can carry up to ${MAX_ATTACHMENTS} files.`;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
if (file.size > MAX_ATTACHMENT_BYTES) {
|
|
45
|
+
refused = `${file.name} is ${formatBytes(file.size)}. Files can be up to ${formatBytes(MAX_ATTACHMENT_BYTES)}.`;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (file.size === 0) {
|
|
49
|
+
refused = `${file.name} is empty.`;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const key = crypto.randomUUID();
|
|
53
|
+
const controller = new AbortController();
|
|
54
|
+
const uploaded = uploadAsset(host, runId, file, {
|
|
55
|
+
signal: controller.signal,
|
|
56
|
+
onProgress: (progress) => patch(key, { progress }),
|
|
57
|
+
});
|
|
58
|
+
uploaded.then(() => patch(key, { status: 'ready', progress: 1 }), (cause) => {
|
|
59
|
+
if (!controller.signal.aborted) {
|
|
60
|
+
patch(key, { status: 'error', error: errorMessage(cause) });
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
accepted.push({
|
|
64
|
+
key,
|
|
65
|
+
file,
|
|
66
|
+
...(file.type.startsWith('image/') ? { previewUrl: URL.createObjectURL(file) } : {}),
|
|
67
|
+
status: 'uploading',
|
|
68
|
+
progress: 0,
|
|
69
|
+
uploaded,
|
|
70
|
+
cancel: () => controller.abort(),
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
setRejection(refused);
|
|
74
|
+
if (accepted.length > 0) {
|
|
75
|
+
setAttachments((current) => [...current, ...accepted]);
|
|
76
|
+
}
|
|
77
|
+
}, [host, runId, patch]);
|
|
78
|
+
const remove = useCallback((key) => {
|
|
79
|
+
setAttachments((current) => {
|
|
80
|
+
const removed = current.find((attachment) => attachment.key === key);
|
|
81
|
+
removed?.cancel();
|
|
82
|
+
if (removed?.previewUrl) {
|
|
83
|
+
URL.revokeObjectURL(removed.previewUrl);
|
|
84
|
+
}
|
|
85
|
+
return current.filter((attachment) => attachment.key !== key);
|
|
86
|
+
});
|
|
87
|
+
setRejection(null);
|
|
88
|
+
}, []);
|
|
89
|
+
/** Hands the current files to a message being sent and empties the composer. */
|
|
90
|
+
const take = useCallback(() => {
|
|
91
|
+
const taken = live.current;
|
|
92
|
+
setAttachments([]);
|
|
93
|
+
setRejection(null);
|
|
94
|
+
return taken;
|
|
95
|
+
}, []);
|
|
96
|
+
/** Puts files back, for a message that could not be sent. */
|
|
97
|
+
const restore = useCallback((returned) => {
|
|
98
|
+
setAttachments((current) => [...returned, ...current]);
|
|
99
|
+
}, []);
|
|
100
|
+
return { attachments, rejection, add, remove, take, restore };
|
|
101
|
+
}
|
|
102
|
+
/** Releases the previews of files whose message has been sent. */
|
|
103
|
+
export function releaseAttachments(attachments) {
|
|
104
|
+
for (const attachment of attachments) {
|
|
105
|
+
if (attachment.previewUrl) {
|
|
106
|
+
URL.revokeObjectURL(attachment.previewUrl);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export function AttachmentTray({ attachments, onRemove, }) {
|
|
111
|
+
if (attachments.length === 0) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
return (_jsx("ul", { "aria-label": "Attached files", className: "flex flex-wrap gap-2 px-3 pt-3", children: attachments.map((attachment) => (_jsx(AttachmentChip, { attachment: attachment, onRemove: onRemove }, attachment.key))) }));
|
|
115
|
+
}
|
|
116
|
+
function AttachmentChip({ attachment, onRemove, }) {
|
|
117
|
+
const { file, status } = attachment;
|
|
118
|
+
const kind = mediaKind(file.type);
|
|
119
|
+
const percent = Math.round(attachment.progress * 100);
|
|
120
|
+
const detail = status === 'error'
|
|
121
|
+
? (attachment.error ?? 'Could not upload')
|
|
122
|
+
: status === 'uploading'
|
|
123
|
+
? `Uploading ${percent}%`
|
|
124
|
+
: formatBytes(file.size);
|
|
125
|
+
return (_jsxs("li", { title: status === 'error' ? attachment.error : file.name, className: cn('bg-secondary/60 relative flex h-12 max-w-56 min-w-0 items-center gap-2 overflow-hidden rounded-lg border pr-7 pl-1.5', status === 'error' && 'border-status-failed/50'), children: [_jsx("span", { className: "bg-background text-muted-foreground flex size-9 shrink-0 items-center justify-center overflow-hidden rounded-md [&_svg]:size-4", children: status === 'error' ? (_jsx(AlertCircle, { className: "text-status-failed" })) : attachment.previewUrl ? (_jsx("img", { src: attachment.previewUrl, alt: "", className: "size-full object-cover" })) : kind === 'video' ? (_jsx(FileVideo, {})) : kind === 'audio' ? (_jsx(FileAudio, {})) : kind === 'pdf' ? (_jsx(FileText, {})) : (_jsx(Paperclip, {})) }), _jsxs("span", { className: "min-w-0 flex-1", children: [_jsx("span", { className: "block truncate text-[12px] font-medium", dir: "auto", children: file.name }), _jsx("span", { role: status === 'error' ? 'alert' : undefined, className: cn('block truncate text-[11px] tabular-nums', status === 'error' ? 'text-status-failed' : 'text-muted-foreground'), children: detail })] }), _jsx("button", { type: "button", onClick: () => onRemove(attachment.key), "aria-label": `Remove ${file.name}`, className: "text-muted-foreground hover:bg-accent hover:text-foreground focus-visible:ring-ring/50 absolute top-1 right-1 flex size-5 items-center justify-center rounded outline-none focus-visible:ring-[3px]", children: _jsx(X, { className: "size-3" }) }), status === 'uploading' ? (_jsx("span", { "aria-hidden": true, className: "bg-brand absolute bottom-0 left-0 h-0.5 origin-left transition-[width] duration-150 ease-out", style: { width: `${Math.max(4, percent)}%` } })) : null] }));
|
|
126
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { AgentIdentity } from './agents.js';
|
|
3
|
+
export declare function Composer({ runId, identities, disabled, showExamples, context, targetThreadId, }: {
|
|
4
|
+
runId: string;
|
|
5
|
+
identities: ReadonlyMap<string, AgentIdentity>;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
showExamples?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* The agent whose timeline is open. Messages go to it while it is, unless the sender picks
|
|
10
|
+
* someone else.
|
|
11
|
+
*/
|
|
12
|
+
targetThreadId?: string;
|
|
13
|
+
/** What the session works from (repos, brief), shown under the composer on the left. */
|
|
14
|
+
context?: ReactNode;
|
|
15
|
+
}): import("react").JSX.Element;
|