@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,785 @@
|
|
|
1
|
+
import { isRecord } from '../../lib/json.js';
|
|
2
|
+
const DEFAULT_THREAD_ID = '__default__';
|
|
3
|
+
export const initialSessionActivityState = {
|
|
4
|
+
runStatus: 'running',
|
|
5
|
+
rootThreadId: null,
|
|
6
|
+
conductorThreadId: null,
|
|
7
|
+
bindingSandbox: false,
|
|
8
|
+
queuedForConductor: false,
|
|
9
|
+
sessionError: false,
|
|
10
|
+
pendingUserMessages: [],
|
|
11
|
+
pendingApprovals: {},
|
|
12
|
+
threads: {},
|
|
13
|
+
activity: 'idle',
|
|
14
|
+
};
|
|
15
|
+
function asRecord(value) {
|
|
16
|
+
return isRecord(value) ? value : {};
|
|
17
|
+
}
|
|
18
|
+
function asString(value) {
|
|
19
|
+
return typeof value === 'string' && value.length > 0 ? value : null;
|
|
20
|
+
}
|
|
21
|
+
function asNumber(value) {
|
|
22
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : null;
|
|
23
|
+
}
|
|
24
|
+
function withoutKey(record, key) {
|
|
25
|
+
if (!(key in record)) {
|
|
26
|
+
return record;
|
|
27
|
+
}
|
|
28
|
+
const next = { ...record };
|
|
29
|
+
delete next[key];
|
|
30
|
+
return next;
|
|
31
|
+
}
|
|
32
|
+
function withoutApprovalsForThread(approvals, threadId) {
|
|
33
|
+
let changed = false;
|
|
34
|
+
const next = {};
|
|
35
|
+
for (const [approvalId, owner] of Object.entries(approvals)) {
|
|
36
|
+
if (owner === threadId) {
|
|
37
|
+
changed = true;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
next[approvalId] = owner;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return changed ? next : approvals;
|
|
44
|
+
}
|
|
45
|
+
function uniqueAppend(items, item) {
|
|
46
|
+
return items.includes(item) ? items : [...items, item];
|
|
47
|
+
}
|
|
48
|
+
function ensureAgentThread(threads, threadId) {
|
|
49
|
+
const existing = threads[threadId];
|
|
50
|
+
if (existing?.kind === 'agent') {
|
|
51
|
+
return existing;
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
kind: 'agent',
|
|
55
|
+
definitionName: existing?.definitionName ?? 'agent',
|
|
56
|
+
lineCount: 0,
|
|
57
|
+
midCallLines: 0,
|
|
58
|
+
inTurn: false,
|
|
59
|
+
needsLlmCall: false,
|
|
60
|
+
deferWake: false,
|
|
61
|
+
openToolCalls: {},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function threadHasPendingApproval(pendingApprovals, threadId) {
|
|
65
|
+
return Object.values(pendingApprovals).includes(threadId);
|
|
66
|
+
}
|
|
67
|
+
function isThreadActivelyWorking(state, threadId, thread) {
|
|
68
|
+
switch (thread.kind) {
|
|
69
|
+
case 'agent': {
|
|
70
|
+
if (thread.inTurn || thread.needsLlmCall) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
const blockedOnApproval = threadHasPendingApproval(state.pendingApprovals, threadId);
|
|
74
|
+
for (const callState of Object.values(thread.openToolCalls)) {
|
|
75
|
+
switch (callState) {
|
|
76
|
+
case 'executing':
|
|
77
|
+
return true;
|
|
78
|
+
case 'awaiting_effects':
|
|
79
|
+
if (!blockedOnApproval) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
83
|
+
case 'spawned_child':
|
|
84
|
+
break;
|
|
85
|
+
default: {
|
|
86
|
+
const exhaustive = callState;
|
|
87
|
+
return exhaustive;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
case 'evaluator':
|
|
94
|
+
return true;
|
|
95
|
+
case 'shuttle-session':
|
|
96
|
+
return (!thread.parkedOnMailbox ||
|
|
97
|
+
state.bindingSandbox ||
|
|
98
|
+
state.pendingUserMessages.length > 0 ||
|
|
99
|
+
state.queuedForConductor);
|
|
100
|
+
case 'other':
|
|
101
|
+
return thread.activeWaits.length === 0;
|
|
102
|
+
default: {
|
|
103
|
+
const exhaustive = thread;
|
|
104
|
+
return exhaustive;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
export function deriveSessionActivity(state) {
|
|
109
|
+
switch (state.runStatus) {
|
|
110
|
+
case 'completed':
|
|
111
|
+
case 'cancelled':
|
|
112
|
+
return 'idle';
|
|
113
|
+
case 'failed':
|
|
114
|
+
return 'error';
|
|
115
|
+
case 'running':
|
|
116
|
+
break;
|
|
117
|
+
default: {
|
|
118
|
+
const exhaustive = state.runStatus;
|
|
119
|
+
return exhaustive;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (Object.keys(state.pendingApprovals).length > 0) {
|
|
123
|
+
return 'needs_input';
|
|
124
|
+
}
|
|
125
|
+
for (const [threadId, thread] of Object.entries(state.threads)) {
|
|
126
|
+
if (isThreadActivelyWorking(state, threadId, thread)) {
|
|
127
|
+
return 'working';
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (state.bindingSandbox || state.pendingUserMessages.length > 0 || state.queuedForConductor) {
|
|
131
|
+
return 'working';
|
|
132
|
+
}
|
|
133
|
+
if (state.sessionError) {
|
|
134
|
+
return 'error';
|
|
135
|
+
}
|
|
136
|
+
return 'idle';
|
|
137
|
+
}
|
|
138
|
+
function withDerivedActivity(next) {
|
|
139
|
+
return {
|
|
140
|
+
...next,
|
|
141
|
+
activity: deriveSessionActivity(next),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function putThread(state, threadId, thread) {
|
|
145
|
+
return withDerivedActivity({
|
|
146
|
+
...state,
|
|
147
|
+
threads: {
|
|
148
|
+
...state.threads,
|
|
149
|
+
[threadId]: thread,
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/** Pure session activity fold — keep transitions in sync with apps/worker/src/workspace/activity-state.ts. */
|
|
154
|
+
export function reduceSessionActivity(state, event) {
|
|
155
|
+
const payload = asRecord(event.payload);
|
|
156
|
+
switch (event.type) {
|
|
157
|
+
case 'runtime.run.started':
|
|
158
|
+
return withDerivedActivity({
|
|
159
|
+
...state,
|
|
160
|
+
runStatus: 'running',
|
|
161
|
+
rootThreadId: asString(payload.rootThreadId) ?? state.rootThreadId,
|
|
162
|
+
});
|
|
163
|
+
case 'runtime.run.completed': {
|
|
164
|
+
const failed = Boolean(asString(payload.error));
|
|
165
|
+
return withDerivedActivity({
|
|
166
|
+
...state,
|
|
167
|
+
runStatus: failed ? 'failed' : 'completed',
|
|
168
|
+
bindingSandbox: false,
|
|
169
|
+
queuedForConductor: false,
|
|
170
|
+
sessionError: failed,
|
|
171
|
+
pendingUserMessages: [],
|
|
172
|
+
pendingApprovals: {},
|
|
173
|
+
threads: {},
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
case 'runtime.run.cancelled':
|
|
177
|
+
return withDerivedActivity({
|
|
178
|
+
...state,
|
|
179
|
+
runStatus: 'cancelled',
|
|
180
|
+
bindingSandbox: false,
|
|
181
|
+
queuedForConductor: false,
|
|
182
|
+
pendingUserMessages: [],
|
|
183
|
+
pendingApprovals: {},
|
|
184
|
+
threads: {},
|
|
185
|
+
});
|
|
186
|
+
case 'runtime.thread.started': {
|
|
187
|
+
const threadId = asString(payload.threadId) ?? asString(event.threadId);
|
|
188
|
+
if (!threadId) {
|
|
189
|
+
return state;
|
|
190
|
+
}
|
|
191
|
+
const kind = asString(payload.kind) ?? 'other';
|
|
192
|
+
const definitionName = asString(payload.definitionName) ?? '';
|
|
193
|
+
if (kind === 'shuttle-session') {
|
|
194
|
+
const input = asRecord(payload.input);
|
|
195
|
+
return withDerivedActivity({
|
|
196
|
+
...state,
|
|
197
|
+
rootThreadId: state.rootThreadId ?? threadId,
|
|
198
|
+
bindingSandbox: Boolean(asString(input.sandboxName)),
|
|
199
|
+
threads: {
|
|
200
|
+
...state.threads,
|
|
201
|
+
[threadId]: {
|
|
202
|
+
kind: 'shuttle-session',
|
|
203
|
+
definitionName,
|
|
204
|
+
parkedOnMailbox: false,
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
if (kind === 'agent') {
|
|
210
|
+
const hasInput = payload.input !== null;
|
|
211
|
+
return putThread(state, threadId, {
|
|
212
|
+
kind: 'agent',
|
|
213
|
+
definitionName,
|
|
214
|
+
lineCount: hasInput ? 1 : 0,
|
|
215
|
+
midCallLines: 0,
|
|
216
|
+
inTurn: false,
|
|
217
|
+
needsLlmCall: true,
|
|
218
|
+
deferWake: false,
|
|
219
|
+
openToolCalls: {},
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
if (kind === 'evaluator') {
|
|
223
|
+
return putThread(state, threadId, {
|
|
224
|
+
kind: 'evaluator',
|
|
225
|
+
definitionName,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
return putThread(state, threadId, {
|
|
229
|
+
kind: 'other',
|
|
230
|
+
definitionName,
|
|
231
|
+
activeWaits: [],
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
case 'runtime.thread.completed':
|
|
235
|
+
case 'runtime.thread.failed':
|
|
236
|
+
case 'runtime.thread.cancelled': {
|
|
237
|
+
const threadId = asString(payload.threadId) ?? asString(event.threadId);
|
|
238
|
+
if (!threadId) {
|
|
239
|
+
return withDerivedActivity({
|
|
240
|
+
...state,
|
|
241
|
+
bindingSandbox: false,
|
|
242
|
+
sessionError: event.type === 'runtime.thread.failed' ? true : state.sessionError,
|
|
243
|
+
pendingApprovals: {},
|
|
244
|
+
threads: {},
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
const nextThreads = withoutKey(state.threads, threadId);
|
|
248
|
+
const nextApprovals = withoutApprovalsForThread(state.pendingApprovals, threadId);
|
|
249
|
+
const isPrimaryThread = threadId === state.rootThreadId ||
|
|
250
|
+
threadId === state.conductorThreadId ||
|
|
251
|
+
(!state.conductorThreadId && Object.keys(nextThreads).length === 0);
|
|
252
|
+
return withDerivedActivity({
|
|
253
|
+
...state,
|
|
254
|
+
bindingSandbox: threadId === state.rootThreadId ? false : state.bindingSandbox,
|
|
255
|
+
sessionError: event.type === 'runtime.thread.failed' && isPrimaryThread ? true : state.sessionError,
|
|
256
|
+
pendingApprovals: nextApprovals,
|
|
257
|
+
threads: nextThreads,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
case 'runtime.wait.registered': {
|
|
261
|
+
const threadId = asString(event.threadId) ?? asString(payload.threadId);
|
|
262
|
+
const waitId = asString(payload.waitId);
|
|
263
|
+
if (!threadId || !waitId) {
|
|
264
|
+
return state;
|
|
265
|
+
}
|
|
266
|
+
const existing = state.threads[threadId];
|
|
267
|
+
if (!existing) {
|
|
268
|
+
return state;
|
|
269
|
+
}
|
|
270
|
+
if (existing.kind === 'shuttle-session') {
|
|
271
|
+
const tag = asRecord(payload.tag);
|
|
272
|
+
return tag.kind === 'shuttle-mailbox'
|
|
273
|
+
? putThread(state, threadId, { ...existing, parkedOnMailbox: true })
|
|
274
|
+
: state;
|
|
275
|
+
}
|
|
276
|
+
if (existing.kind === 'other') {
|
|
277
|
+
return putThread(state, threadId, {
|
|
278
|
+
...existing,
|
|
279
|
+
activeWaits: uniqueAppend(existing.activeWaits, waitId),
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
return state;
|
|
283
|
+
}
|
|
284
|
+
case 'runtime.wait.satisfied': {
|
|
285
|
+
const threadId = asString(event.threadId) ?? asString(payload.threadId);
|
|
286
|
+
const waitId = asString(payload.waitId);
|
|
287
|
+
if (!threadId) {
|
|
288
|
+
return state;
|
|
289
|
+
}
|
|
290
|
+
const existing = state.threads[threadId];
|
|
291
|
+
if (!existing) {
|
|
292
|
+
return state;
|
|
293
|
+
}
|
|
294
|
+
if (existing.kind === 'shuttle-session') {
|
|
295
|
+
const tag = asRecord(payload.tag);
|
|
296
|
+
return tag.kind === 'shuttle-mailbox'
|
|
297
|
+
? putThread(state, threadId, { ...existing, parkedOnMailbox: false })
|
|
298
|
+
: state;
|
|
299
|
+
}
|
|
300
|
+
if (existing.kind === 'other') {
|
|
301
|
+
return putThread(state, threadId, {
|
|
302
|
+
...existing,
|
|
303
|
+
activeWaits: waitId ? existing.activeWaits.filter((id) => id !== waitId) : [],
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
return state;
|
|
307
|
+
}
|
|
308
|
+
case 'runtime.effect.completed':
|
|
309
|
+
case 'runtime.effect.failed': {
|
|
310
|
+
const threadId = asString(event.threadId);
|
|
311
|
+
const effectId = asString(payload.effectId);
|
|
312
|
+
if ((threadId && threadId === state.rootThreadId) ||
|
|
313
|
+
(effectId && effectId.endsWith(':bind_sandbox'))) {
|
|
314
|
+
return withDerivedActivity({ ...state, bindingSandbox: false });
|
|
315
|
+
}
|
|
316
|
+
return state;
|
|
317
|
+
}
|
|
318
|
+
case 'shuttle.sandbox.bound':
|
|
319
|
+
return withDerivedActivity({ ...state, bindingSandbox: false });
|
|
320
|
+
case 'shuttle.conductor.spawned': {
|
|
321
|
+
const childThreadId = asString(payload.childThreadId);
|
|
322
|
+
return withDerivedActivity({
|
|
323
|
+
...state,
|
|
324
|
+
conductorThreadId: childThreadId ?? state.conductorThreadId,
|
|
325
|
+
queuedForConductor: false,
|
|
326
|
+
sessionError: false,
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
case 'shuttle.user.said': {
|
|
330
|
+
const messageId = asString(payload.messageId) ?? `msg_${event.seq}`;
|
|
331
|
+
return withDerivedActivity({
|
|
332
|
+
...state,
|
|
333
|
+
pendingUserMessages: uniqueAppend(state.pendingUserMessages, messageId),
|
|
334
|
+
sessionError: false,
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
case 'shuttle.reroute': {
|
|
338
|
+
const messageId = asString(payload.messageId) ?? `reroute_${event.seq}`;
|
|
339
|
+
return withDerivedActivity({
|
|
340
|
+
...state,
|
|
341
|
+
pendingUserMessages: uniqueAppend(state.pendingUserMessages, messageId),
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
case 'shuttle.routed': {
|
|
345
|
+
const messageId = asString(payload.messageId);
|
|
346
|
+
return withDerivedActivity({
|
|
347
|
+
...state,
|
|
348
|
+
pendingUserMessages: messageId
|
|
349
|
+
? state.pendingUserMessages.filter((id) => id !== messageId)
|
|
350
|
+
: [],
|
|
351
|
+
queuedForConductor: payload.queued === true,
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
case 'agent.turn.started': {
|
|
355
|
+
const threadId = asString(event.threadId) ?? DEFAULT_THREAD_ID;
|
|
356
|
+
const thread = ensureAgentThread(state.threads, threadId);
|
|
357
|
+
const messageCount = asNumber(payload.messageCount) ?? thread.lineCount;
|
|
358
|
+
const arrivedMidCall = thread.lineCount > messageCount;
|
|
359
|
+
return withDerivedActivity({
|
|
360
|
+
...state,
|
|
361
|
+
sessionError: false,
|
|
362
|
+
threads: {
|
|
363
|
+
...state.threads,
|
|
364
|
+
[threadId]: {
|
|
365
|
+
...thread,
|
|
366
|
+
inTurn: true,
|
|
367
|
+
needsLlmCall: false,
|
|
368
|
+
deferWake: arrivedMidCall,
|
|
369
|
+
midCallLines: arrivedMidCall ? thread.lineCount - messageCount : 0,
|
|
370
|
+
},
|
|
371
|
+
},
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
case 'agent.message': {
|
|
375
|
+
const threadId = asString(event.threadId) ?? DEFAULT_THREAD_ID;
|
|
376
|
+
const existing = state.threads[threadId];
|
|
377
|
+
if (existing?.kind !== 'agent') {
|
|
378
|
+
return state;
|
|
379
|
+
}
|
|
380
|
+
const message = asRecord(payload.message);
|
|
381
|
+
const toolCallsRaw = Array.isArray(message.toolCalls) ? message.toolCalls : [];
|
|
382
|
+
let openToolCalls = existing.openToolCalls;
|
|
383
|
+
for (const item of toolCallsRaw) {
|
|
384
|
+
const call = asRecord(item);
|
|
385
|
+
const callId = asString(call.id);
|
|
386
|
+
if (callId && !openToolCalls[callId]) {
|
|
387
|
+
openToolCalls = { ...openToolCalls, [callId]: 'executing' };
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
const hasOpenTools = Object.keys(openToolCalls).length > 0;
|
|
391
|
+
return putThread(state, threadId, {
|
|
392
|
+
...existing,
|
|
393
|
+
lineCount: existing.lineCount + 1,
|
|
394
|
+
inTurn: false,
|
|
395
|
+
needsLlmCall: (existing.needsLlmCall || existing.deferWake) && !hasOpenTools,
|
|
396
|
+
deferWake: false,
|
|
397
|
+
midCallLines: 0,
|
|
398
|
+
openToolCalls,
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
case 'agent.context.compacted': {
|
|
402
|
+
const threadId = asString(event.threadId) ?? DEFAULT_THREAD_ID;
|
|
403
|
+
const existing = state.threads[threadId];
|
|
404
|
+
if (existing?.kind !== 'agent') {
|
|
405
|
+
return state;
|
|
406
|
+
}
|
|
407
|
+
const compactedCount = asNumber(payload.compactedCount) ?? existing.lineCount;
|
|
408
|
+
return putThread(state, threadId, {
|
|
409
|
+
...existing,
|
|
410
|
+
lineCount: compactedCount + existing.midCallLines,
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
case 'agent.tool_call.requested': {
|
|
414
|
+
const threadId = asString(event.threadId) ?? DEFAULT_THREAD_ID;
|
|
415
|
+
const thread = ensureAgentThread(state.threads, threadId);
|
|
416
|
+
const toolCall = asRecord(payload.toolCall);
|
|
417
|
+
const callId = asString(toolCall.id) ?? `call_${event.seq}`;
|
|
418
|
+
return putThread(state, threadId, {
|
|
419
|
+
...thread,
|
|
420
|
+
needsLlmCall: false,
|
|
421
|
+
openToolCalls: {
|
|
422
|
+
...thread.openToolCalls,
|
|
423
|
+
[callId]: 'executing',
|
|
424
|
+
},
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
case 'agent.turn.settled':
|
|
428
|
+
case 'agent.turn.completed': {
|
|
429
|
+
const threadId = asString(event.threadId) ?? DEFAULT_THREAD_ID;
|
|
430
|
+
const thread = ensureAgentThread(state.threads, threadId);
|
|
431
|
+
const hasOpenTools = Object.keys(thread.openToolCalls).length > 0;
|
|
432
|
+
return putThread(state, threadId, {
|
|
433
|
+
...thread,
|
|
434
|
+
inTurn: false,
|
|
435
|
+
needsLlmCall: (thread.needsLlmCall || thread.deferWake) && !hasOpenTools,
|
|
436
|
+
deferWake: false,
|
|
437
|
+
midCallLines: 0,
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
case 'agent.spawn.requested': {
|
|
441
|
+
const threadId = asString(event.threadId) ?? DEFAULT_THREAD_ID;
|
|
442
|
+
const thread = ensureAgentThread(state.threads, threadId);
|
|
443
|
+
const toolCallId = asString(payload.toolCallId);
|
|
444
|
+
if (!toolCallId) {
|
|
445
|
+
return state;
|
|
446
|
+
}
|
|
447
|
+
return putThread(state, threadId, {
|
|
448
|
+
...thread,
|
|
449
|
+
openToolCalls: {
|
|
450
|
+
...thread.openToolCalls,
|
|
451
|
+
[toolCallId]: 'spawned_child',
|
|
452
|
+
},
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
case 'agent.effects.requested': {
|
|
456
|
+
const threadId = asString(event.threadId) ?? DEFAULT_THREAD_ID;
|
|
457
|
+
const thread = ensureAgentThread(state.threads, threadId);
|
|
458
|
+
const toolCallId = asString(payload.toolCallId);
|
|
459
|
+
if (!toolCallId) {
|
|
460
|
+
return state;
|
|
461
|
+
}
|
|
462
|
+
return putThread(state, threadId, {
|
|
463
|
+
...thread,
|
|
464
|
+
openToolCalls: {
|
|
465
|
+
...thread.openToolCalls,
|
|
466
|
+
[toolCallId]: 'awaiting_effects',
|
|
467
|
+
},
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
case 'agent.tool.result': {
|
|
471
|
+
const threadId = asString(event.threadId) ?? DEFAULT_THREAD_ID;
|
|
472
|
+
const thread = ensureAgentThread(state.threads, threadId);
|
|
473
|
+
const toolCallId = asString(payload.toolCallId);
|
|
474
|
+
const openToolCalls = toolCallId ? withoutKey(thread.openToolCalls, toolCallId) : {};
|
|
475
|
+
return putThread(state, threadId, {
|
|
476
|
+
...thread,
|
|
477
|
+
lineCount: thread.lineCount + 1,
|
|
478
|
+
openToolCalls,
|
|
479
|
+
needsLlmCall: Object.keys(openToolCalls).length === 0,
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
case 'agent.message.received': {
|
|
483
|
+
const threadId = asString(event.threadId) ?? DEFAULT_THREAD_ID;
|
|
484
|
+
const thread = ensureAgentThread(state.threads, threadId);
|
|
485
|
+
return putThread(state, threadId, {
|
|
486
|
+
...thread,
|
|
487
|
+
lineCount: thread.lineCount + 1,
|
|
488
|
+
needsLlmCall: Object.keys(thread.openToolCalls).length === 0,
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
case 'agent.steered': {
|
|
492
|
+
const threadId = asString(event.threadId) ?? DEFAULT_THREAD_ID;
|
|
493
|
+
const thread = ensureAgentThread(state.threads, threadId);
|
|
494
|
+
const interrupt = payload.interrupt === true;
|
|
495
|
+
if (interrupt) {
|
|
496
|
+
return withDerivedActivity({
|
|
497
|
+
...state,
|
|
498
|
+
pendingApprovals: withoutApprovalsForThread(state.pendingApprovals, threadId),
|
|
499
|
+
threads: {
|
|
500
|
+
...state.threads,
|
|
501
|
+
[threadId]: {
|
|
502
|
+
...thread,
|
|
503
|
+
lineCount: thread.lineCount + 1,
|
|
504
|
+
midCallLines: 0,
|
|
505
|
+
inTurn: false,
|
|
506
|
+
needsLlmCall: true,
|
|
507
|
+
deferWake: false,
|
|
508
|
+
openToolCalls: {},
|
|
509
|
+
},
|
|
510
|
+
},
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
return putThread(state, threadId, {
|
|
514
|
+
...thread,
|
|
515
|
+
lineCount: thread.lineCount + 1,
|
|
516
|
+
needsLlmCall: Object.keys(thread.openToolCalls).length === 0,
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
case 'agent.turn.stopped': {
|
|
520
|
+
const threadId = asString(event.threadId) ?? DEFAULT_THREAD_ID;
|
|
521
|
+
const existing = state.threads[threadId];
|
|
522
|
+
const nextApprovals = withoutApprovalsForThread(state.pendingApprovals, threadId);
|
|
523
|
+
if (existing?.kind !== 'agent') {
|
|
524
|
+
return nextApprovals === state.pendingApprovals
|
|
525
|
+
? state
|
|
526
|
+
: withDerivedActivity({ ...state, pendingApprovals: nextApprovals });
|
|
527
|
+
}
|
|
528
|
+
return withDerivedActivity({
|
|
529
|
+
...state,
|
|
530
|
+
pendingApprovals: nextApprovals,
|
|
531
|
+
threads: {
|
|
532
|
+
...state.threads,
|
|
533
|
+
[threadId]: {
|
|
534
|
+
...existing,
|
|
535
|
+
midCallLines: 0,
|
|
536
|
+
inTurn: false,
|
|
537
|
+
needsLlmCall: false,
|
|
538
|
+
deferWake: false,
|
|
539
|
+
openToolCalls: {},
|
|
540
|
+
},
|
|
541
|
+
},
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
case 'approval.requested': {
|
|
545
|
+
const approvalId = asString(payload.approvalId) ?? `approval_${event.seq}`;
|
|
546
|
+
const owner = asString(event.threadId) ?? DEFAULT_THREAD_ID;
|
|
547
|
+
return withDerivedActivity({
|
|
548
|
+
...state,
|
|
549
|
+
pendingApprovals: {
|
|
550
|
+
...state.pendingApprovals,
|
|
551
|
+
[approvalId]: owner,
|
|
552
|
+
},
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
case 'approval.decided':
|
|
556
|
+
case 'approval.timed_out': {
|
|
557
|
+
const approvalId = asString(payload.approvalId);
|
|
558
|
+
return withDerivedActivity({
|
|
559
|
+
...state,
|
|
560
|
+
pendingApprovals: approvalId ? withoutKey(state.pendingApprovals, approvalId) : {},
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
default:
|
|
564
|
+
return state;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
export const sessionActivity = {
|
|
568
|
+
name: 'shuttleSessionActivity',
|
|
569
|
+
initialState: initialSessionActivityState,
|
|
570
|
+
reduce(state, event) {
|
|
571
|
+
return reduceSessionActivity(state, event);
|
|
572
|
+
},
|
|
573
|
+
};
|
|
574
|
+
/** Resolve a single thread node's true live status for AgentTree. */
|
|
575
|
+
export function resolveThreadActivityTone(state, node) {
|
|
576
|
+
if (node.status === 'completed' || node.status === 'failed' || node.status === 'cancelled') {
|
|
577
|
+
return node.status;
|
|
578
|
+
}
|
|
579
|
+
if (state.runStatus === 'completed' ||
|
|
580
|
+
state.runStatus === 'failed' ||
|
|
581
|
+
state.runStatus === 'cancelled') {
|
|
582
|
+
return state.runStatus;
|
|
583
|
+
}
|
|
584
|
+
if (threadHasPendingApproval(state.pendingApprovals, node.threadId)) {
|
|
585
|
+
return 'needs_input';
|
|
586
|
+
}
|
|
587
|
+
const tracked = state.threads[node.threadId];
|
|
588
|
+
if (!tracked) {
|
|
589
|
+
return node.status === 'waiting' ? 'idle' : 'working';
|
|
590
|
+
}
|
|
591
|
+
switch (tracked.kind) {
|
|
592
|
+
case 'shuttle-session': {
|
|
593
|
+
switch (state.activity) {
|
|
594
|
+
case 'needs_input':
|
|
595
|
+
return 'needs_input';
|
|
596
|
+
case 'working':
|
|
597
|
+
return 'working';
|
|
598
|
+
case 'error':
|
|
599
|
+
return 'failed';
|
|
600
|
+
case 'idle':
|
|
601
|
+
return 'idle';
|
|
602
|
+
default: {
|
|
603
|
+
const exhaustive = state.activity;
|
|
604
|
+
return exhaustive;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
case 'agent': {
|
|
609
|
+
if (isThreadActivelyWorking(state, node.threadId, tracked)) {
|
|
610
|
+
return 'working';
|
|
611
|
+
}
|
|
612
|
+
if (Object.values(tracked.openToolCalls).includes('spawned_child')) {
|
|
613
|
+
return 'delegating';
|
|
614
|
+
}
|
|
615
|
+
return 'idle';
|
|
616
|
+
}
|
|
617
|
+
case 'evaluator':
|
|
618
|
+
return 'working';
|
|
619
|
+
case 'other':
|
|
620
|
+
return tracked.activeWaits.length > 0 ? 'idle' : 'working';
|
|
621
|
+
default: {
|
|
622
|
+
const exhaustive = tracked;
|
|
623
|
+
return exhaustive;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
export function resolveSessionIndicator(input) {
|
|
628
|
+
if (input.status === 'failed') {
|
|
629
|
+
return 'failed';
|
|
630
|
+
}
|
|
631
|
+
if (input.status === 'cancelled') {
|
|
632
|
+
return 'cancelled';
|
|
633
|
+
}
|
|
634
|
+
if (input.status === 'completed') {
|
|
635
|
+
return input.unread ? 'ready' : 'completed';
|
|
636
|
+
}
|
|
637
|
+
if (input.status === 'requested') {
|
|
638
|
+
return 'starting';
|
|
639
|
+
}
|
|
640
|
+
switch (input.activity) {
|
|
641
|
+
case 'needs_input':
|
|
642
|
+
return 'needs_input';
|
|
643
|
+
case 'working':
|
|
644
|
+
return 'working';
|
|
645
|
+
case 'error':
|
|
646
|
+
return 'failed';
|
|
647
|
+
default:
|
|
648
|
+
return input.unread ? 'ready' : 'idle';
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
const SESSION_INDICATOR_LABELS = {
|
|
652
|
+
starting: 'Starting',
|
|
653
|
+
working: 'Working',
|
|
654
|
+
needs_input: 'Needs input',
|
|
655
|
+
ready: 'Ready for review',
|
|
656
|
+
failed: 'Failed',
|
|
657
|
+
idle: 'Idle',
|
|
658
|
+
completed: 'Completed',
|
|
659
|
+
cancelled: 'Cancelled',
|
|
660
|
+
};
|
|
661
|
+
export function sessionIndicatorLabel(tone) {
|
|
662
|
+
return SESSION_INDICATOR_LABELS[tone];
|
|
663
|
+
}
|
|
664
|
+
const ROUTE_WAIT_FALLBACK_MS = 5_000;
|
|
665
|
+
/** An agent thread (not a narrator) that is mid-turn or executing a tool, for route wait UX. */
|
|
666
|
+
export function findInFlightToolCall(activity) {
|
|
667
|
+
let pick = null;
|
|
668
|
+
for (const [threadId, thread] of Object.entries(activity.threads)) {
|
|
669
|
+
if (thread.kind !== 'agent' || thread.definitionName === 'narrator') {
|
|
670
|
+
continue;
|
|
671
|
+
}
|
|
672
|
+
if (thread.inTurn) {
|
|
673
|
+
return { threadId, toolName: 'turn' };
|
|
674
|
+
}
|
|
675
|
+
if (!pick && Object.values(thread.openToolCalls).includes('executing')) {
|
|
676
|
+
pick = { threadId, toolName: 'tool' };
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
return pick;
|
|
680
|
+
}
|
|
681
|
+
/** Prefer feed tool rows when names and timestamps are available. */
|
|
682
|
+
export function findRunningToolInFeed(feed) {
|
|
683
|
+
for (let index = feed.items.length - 1; index >= 0; index -= 1) {
|
|
684
|
+
const item = feed.items[index];
|
|
685
|
+
if (item?.kind !== 'tools') {
|
|
686
|
+
continue;
|
|
687
|
+
}
|
|
688
|
+
const running = item.calls.filter((call) => call.status === 'running');
|
|
689
|
+
if (running.length === 0) {
|
|
690
|
+
continue;
|
|
691
|
+
}
|
|
692
|
+
return { threadId: item.threadId, call: running[running.length - 1] };
|
|
693
|
+
}
|
|
694
|
+
return null;
|
|
695
|
+
}
|
|
696
|
+
export function shouldShowRouteWaitFallback(messageTs, hasRoute, now) {
|
|
697
|
+
return !hasRoute && now - messageTs >= ROUTE_WAIT_FALLBACK_MS;
|
|
698
|
+
}
|
|
699
|
+
export function deriveRouteWaitFallback(input) {
|
|
700
|
+
if (!shouldShowRouteWaitFallback(input.messageTs, input.hasRoute, input.now)) {
|
|
701
|
+
return null;
|
|
702
|
+
}
|
|
703
|
+
const fromFeed = findRunningToolInFeed(input.feed);
|
|
704
|
+
if (fromFeed) {
|
|
705
|
+
const elapsedMs = Math.max(0, input.now - (fromFeed.call.startedAt ?? input.messageTs));
|
|
706
|
+
return {
|
|
707
|
+
threadId: fromFeed.threadId,
|
|
708
|
+
toolName: fromFeed.call.name,
|
|
709
|
+
elapsedMs,
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
const fromActivity = findInFlightToolCall(input.activity);
|
|
713
|
+
if (!fromActivity) {
|
|
714
|
+
return null;
|
|
715
|
+
}
|
|
716
|
+
return {
|
|
717
|
+
threadId: fromActivity.threadId,
|
|
718
|
+
toolName: fromActivity.toolName,
|
|
719
|
+
elapsedMs: Math.max(0, input.now - input.messageTs),
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
/**
|
|
723
|
+
* Summarize actionable session states inside a collapsed folder or hidden overflow slice.
|
|
724
|
+
* Returns `null` when every session is quiet (`idle`, `completed`, `cancelled`).
|
|
725
|
+
*/
|
|
726
|
+
export function resolveFolderIndicator(tones) {
|
|
727
|
+
let needsInput = 0;
|
|
728
|
+
let failed = 0;
|
|
729
|
+
let working = 0;
|
|
730
|
+
let ready = 0;
|
|
731
|
+
for (const tone of tones) {
|
|
732
|
+
switch (tone) {
|
|
733
|
+
case 'needs_input':
|
|
734
|
+
needsInput += 1;
|
|
735
|
+
break;
|
|
736
|
+
case 'failed':
|
|
737
|
+
failed += 1;
|
|
738
|
+
break;
|
|
739
|
+
case 'starting':
|
|
740
|
+
case 'working':
|
|
741
|
+
working += 1;
|
|
742
|
+
break;
|
|
743
|
+
case 'ready':
|
|
744
|
+
ready += 1;
|
|
745
|
+
break;
|
|
746
|
+
case 'idle':
|
|
747
|
+
case 'completed':
|
|
748
|
+
case 'cancelled':
|
|
749
|
+
break;
|
|
750
|
+
default: {
|
|
751
|
+
const exhaustive = tone;
|
|
752
|
+
void exhaustive;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
if (needsInput > 0) {
|
|
757
|
+
return {
|
|
758
|
+
tone: 'needs_input',
|
|
759
|
+
count: needsInput,
|
|
760
|
+
label: needsInput === 1 ? '1 session needs input' : `${needsInput} sessions need input`,
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
if (failed > 0) {
|
|
764
|
+
return {
|
|
765
|
+
tone: 'failed',
|
|
766
|
+
count: failed,
|
|
767
|
+
label: failed === 1 ? '1 session failed' : `${failed} sessions failed`,
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
if (working > 0) {
|
|
771
|
+
return {
|
|
772
|
+
tone: 'working',
|
|
773
|
+
count: working,
|
|
774
|
+
label: working === 1 ? '1 session working' : `${working} sessions working`,
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
if (ready > 0) {
|
|
778
|
+
return {
|
|
779
|
+
tone: 'ready',
|
|
780
|
+
count: ready,
|
|
781
|
+
label: ready === 1 ? '1 session ready for review' : `${ready} sessions ready for review`,
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
return null;
|
|
785
|
+
}
|