@swirls/shuttle 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/LICENSE +190 -0
- package/NOTICE +5 -0
- package/README.md +42 -2
- package/dist/api/auth.d.ts +18 -0
- package/dist/api/auth.js +15 -0
- package/dist/api/common.d.ts +8 -0
- package/dist/api/common.js +4 -0
- package/dist/api/connections.d.ts +292 -0
- package/dist/api/connections.js +114 -0
- package/dist/api/github.d.ts +20 -0
- package/dist/api/github.js +13 -0
- package/dist/api/harness.d.ts +97 -0
- package/dist/api/harness.js +47 -0
- package/dist/api/index.d.ts +2059 -0
- package/dist/api/index.js +37 -0
- package/dist/api/runners.d.ts +93 -0
- package/dist/api/runners.js +45 -0
- package/dist/api/sandbox.d.ts +550 -0
- package/dist/api/sandbox.js +210 -0
- package/dist/api/sessions.d.ts +318 -0
- package/dist/api/sessions.js +154 -0
- package/dist/api/tenant.d.ts +54 -0
- package/dist/api/tenant.js +19 -0
- package/dist/api/timings.d.ts +36 -0
- package/dist/api/timings.js +48 -0
- package/dist/api/workspace.d.ts +738 -0
- package/dist/api/workspace.js +246 -0
- package/dist/core/pulls.d.ts +1001 -0
- package/dist/core/pulls.js +170 -0
- package/dist/core/workspace.d.ts +985 -0
- package/dist/core/workspace.js +174 -0
- package/dist/react/components/command-palette.d.ts +22 -0
- package/dist/react/components/command-palette.js +66 -0
- package/dist/react/components/follow-list.d.ts +20 -0
- package/dist/react/components/follow-list.js +98 -0
- package/dist/react/components/json-tree.d.ts +11 -0
- package/dist/react/components/json-tree.js +120 -0
- package/dist/react/components/markdown.d.ts +5 -0
- package/dist/react/components/markdown.js +29 -0
- package/dist/react/components/shuttle-mark.d.ts +7 -0
- package/dist/react/components/shuttle-mark.js +9 -0
- package/dist/react/components/status-dot.d.ts +9 -0
- package/dist/react/components/status-dot.js +27 -0
- package/dist/react/components/status.d.ts +6 -0
- package/dist/react/components/status.js +66 -0
- package/dist/react/components/ui/badge.d.ts +7 -0
- package/dist/react/components/ui/badge.js +19 -0
- package/dist/react/components/ui/button.d.ts +10 -0
- package/dist/react/components/ui/button.js +40 -0
- package/dist/react/components/ui/dialog.d.ts +19 -0
- package/dist/react/components/ui/dialog.js +34 -0
- package/dist/react/components/ui/dropdown-menu.d.ts +14 -0
- package/dist/react/components/ui/dropdown-menu.js +33 -0
- package/dist/react/components/ui/input.d.ts +3 -0
- package/dist/react/components/ui/input.js +6 -0
- package/dist/react/components/ui/panel.d.ts +18 -0
- package/dist/react/components/ui/panel.js +22 -0
- package/dist/react/components/ui/popover.d.ts +7 -0
- package/dist/react/components/ui/popover.js +16 -0
- package/dist/react/components/ui/resizable.d.ts +7 -0
- package/dist/react/components/ui/resizable.js +14 -0
- package/dist/react/components/ui/scroll-area.d.ts +14 -0
- package/dist/react/components/ui/scroll-area.js +12 -0
- package/dist/react/components/ui/select.d.ts +10 -0
- package/dist/react/components/ui/select.js +20 -0
- package/dist/react/components/ui/sheet.d.ts +8 -0
- package/dist/react/components/ui/sheet.js +20 -0
- package/dist/react/components/ui/tabs.d.ts +7 -0
- package/dist/react/components/ui/tabs.js +16 -0
- package/dist/react/components/ui/textarea.d.ts +3 -0
- package/dist/react/components/ui/textarea.js +6 -0
- package/dist/react/components/ui/tooltip.d.ts +8 -0
- package/dist/react/components/ui/tooltip.js +17 -0
- package/dist/react/features/artifacts/artifact-links.d.ts +9 -0
- package/dist/react/features/artifacts/artifact-links.js +38 -0
- package/dist/react/features/artifacts/artifact-pane.d.ts +19 -0
- package/dist/react/features/artifacts/artifact-pane.js +64 -0
- package/dist/react/features/artifacts/artifact-types.d.ts +59 -0
- package/dist/react/features/artifacts/artifact-types.js +69 -0
- package/dist/react/features/artifacts/browser-viewer.d.ts +5 -0
- package/dist/react/features/artifacts/browser-viewer.js +60 -0
- package/dist/react/features/artifacts/diff-style.d.ts +10 -0
- package/dist/react/features/artifacts/diff-style.js +21 -0
- package/dist/react/features/artifacts/file-pane.d.ts +13 -0
- package/dist/react/features/artifacts/file-pane.js +305 -0
- package/dist/react/features/artifacts/file-quick-open.d.ts +15 -0
- package/dist/react/features/artifacts/file-quick-open.js +74 -0
- package/dist/react/features/artifacts/file-search.d.ts +12 -0
- package/dist/react/features/artifacts/file-search.js +90 -0
- package/dist/react/features/artifacts/media-viewer.d.ts +8 -0
- package/dist/react/features/artifacts/media-viewer.js +41 -0
- package/dist/react/features/artifacts/review-diff.d.ts +19 -0
- package/dist/react/features/artifacts/review-diff.js +59 -0
- package/dist/react/features/artifacts/review-viewer.d.ts +4 -0
- package/dist/react/features/artifacts/review-viewer.js +337 -0
- package/dist/react/features/artifacts/sandbox.d.ts +43 -0
- package/dist/react/features/artifacts/sandbox.js +109 -0
- package/dist/react/features/artifacts/tab-strip.d.ts +11 -0
- package/dist/react/features/artifacts/tab-strip.js +55 -0
- package/dist/react/features/artifacts/terminal-theme.d.ts +34 -0
- package/dist/react/features/artifacts/terminal-theme.js +62 -0
- package/dist/react/features/artifacts/terminal-viewer.d.ts +5 -0
- package/dist/react/features/artifacts/terminal-viewer.js +209 -0
- package/dist/react/features/artifacts/unified-diff.d.ts +16 -0
- package/dist/react/features/artifacts/unified-diff.js +55 -0
- package/dist/react/features/artifacts/workspace-viewer.d.ts +16 -0
- package/dist/react/features/artifacts/workspace-viewer.js +275 -0
- package/dist/react/features/connections/agent-sign-in.d.ts +71 -0
- package/dist/react/features/connections/agent-sign-in.js +251 -0
- package/dist/react/features/connections/connections-panel.d.ts +8 -0
- package/dist/react/features/connections/connections-panel.js +42 -0
- package/dist/react/features/connections/login.d.ts +24 -0
- package/dist/react/features/connections/login.js +35 -0
- package/dist/react/features/connections/places.d.ts +20 -0
- package/dist/react/features/connections/places.js +27 -0
- package/dist/react/features/connections/queries.d.ts +28 -0
- package/dist/react/features/connections/queries.js +8 -0
- package/dist/react/features/events/event-cache.d.ts +4 -0
- package/dist/react/features/events/event-cache.js +29 -0
- package/dist/react/features/events/event-catalog.d.ts +17 -0
- package/dist/react/features/events/event-catalog.js +261 -0
- package/dist/react/features/events/event-inspector.d.ts +7 -0
- package/dist/react/features/events/event-inspector.js +29 -0
- package/dist/react/features/events/event-row.d.ts +21 -0
- package/dist/react/features/events/event-row.js +34 -0
- package/dist/react/features/events/event-stream.d.ts +18 -0
- package/dist/react/features/events/event-stream.js +58 -0
- package/dist/react/features/events/global-events.d.ts +122 -0
- package/dist/react/features/events/global-events.js +329 -0
- package/dist/react/features/events/shuttle-events.d.ts +7 -0
- package/dist/react/features/events/shuttle-events.js +1 -0
- package/dist/react/features/playbook/playbook-page.d.ts +2 -0
- package/dist/react/features/playbook/playbook-page.js +36 -0
- package/dist/react/features/playbook/playbook-query.d.ts +111 -0
- package/dist/react/features/playbook/playbook-query.js +17 -0
- package/dist/react/features/pulls/linked-session.d.ts +12 -0
- package/dist/react/features/pulls/linked-session.js +22 -0
- package/dist/react/features/pulls/pull-detail-sheet.d.ts +10 -0
- package/dist/react/features/pulls/pull-detail-sheet.js +41 -0
- package/dist/react/features/pulls/pull-fixtures.d.ts +8 -0
- package/dist/react/features/pulls/pull-fixtures.js +258 -0
- package/dist/react/features/pulls/pull-glyphs.d.ts +24 -0
- package/dist/react/features/pulls/pull-glyphs.js +89 -0
- package/dist/react/features/pulls/pull-inbox-list.d.ts +13 -0
- package/dist/react/features/pulls/pull-inbox-list.js +230 -0
- package/dist/react/features/pulls/pull-inbox-pref.d.ts +2 -0
- package/dist/react/features/pulls/pull-inbox-pref.js +19 -0
- package/dist/react/features/pulls/pull-inbox.d.ts +30 -0
- package/dist/react/features/pulls/pull-inbox.js +110 -0
- package/dist/react/features/pulls/pull-threads.d.ts +39 -0
- package/dist/react/features/pulls/pull-threads.js +145 -0
- package/dist/react/features/pulls/pulls.d.ts +120 -0
- package/dist/react/features/pulls/pulls.js +414 -0
- package/dist/react/features/pulls/session-pull-groups.d.ts +14 -0
- package/dist/react/features/pulls/session-pull-groups.js +29 -0
- package/dist/react/features/pulls/stack-ladder.d.ts +9 -0
- package/dist/react/features/pulls/stack-ladder.js +32 -0
- package/dist/react/features/sessions/agent-tree.d.ts +16 -0
- package/dist/react/features/sessions/agent-tree.js +100 -0
- package/dist/react/features/sessions/agents.d.ts +34 -0
- package/dist/react/features/sessions/agents.js +146 -0
- package/dist/react/features/sessions/attention.d.ts +32 -0
- package/dist/react/features/sessions/attention.js +42 -0
- package/dist/react/features/sessions/composer-attachments.d.ts +33 -0
- package/dist/react/features/sessions/composer-attachments.js +126 -0
- package/dist/react/features/sessions/composer.d.ts +15 -0
- package/dist/react/features/sessions/composer.js +327 -0
- package/dist/react/features/sessions/context-usage-meter.d.ts +5 -0
- package/dist/react/features/sessions/context-usage-meter.js +122 -0
- package/dist/react/features/sessions/context-usage.d.ts +54 -0
- package/dist/react/features/sessions/context-usage.js +206 -0
- package/dist/react/features/sessions/conversation.d.ts +21 -0
- package/dist/react/features/sessions/conversation.js +549 -0
- package/dist/react/features/sessions/harness-switcher.d.ts +26 -0
- package/dist/react/features/sessions/harness-switcher.js +118 -0
- package/dist/react/features/sessions/intake-heuristic.d.ts +5 -0
- package/dist/react/features/sessions/intake-heuristic.js +28 -0
- package/dist/react/features/sessions/interjection-routes.d.ts +13 -0
- package/dist/react/features/sessions/interjection-routes.js +72 -0
- package/dist/react/features/sessions/llm-models.d.ts +128 -0
- package/dist/react/features/sessions/llm-models.js +174 -0
- package/dist/react/features/sessions/media-strip.d.ts +25 -0
- package/dist/react/features/sessions/media-strip.js +56 -0
- package/dist/react/features/sessions/media.d.ts +43 -0
- package/dist/react/features/sessions/media.js +115 -0
- package/dist/react/features/sessions/model-search.d.ts +6 -0
- package/dist/react/features/sessions/model-search.js +16 -0
- package/dist/react/features/sessions/model-switcher.d.ts +16 -0
- package/dist/react/features/sessions/model-switcher.js +262 -0
- package/dist/react/features/sessions/open-pull-request.d.ts +20 -0
- package/dist/react/features/sessions/open-pull-request.js +92 -0
- package/dist/react/features/sessions/pull-publish-card.d.ts +14 -0
- package/dist/react/features/sessions/pull-publish-card.js +88 -0
- package/dist/react/features/sessions/recent-sessions.d.ts +11 -0
- package/dist/react/features/sessions/recent-sessions.js +29 -0
- package/dist/react/features/sessions/seen-sessions.d.ts +16 -0
- package/dist/react/features/sessions/seen-sessions.js +108 -0
- package/dist/react/features/sessions/session-activity.d.ts +95 -0
- package/dist/react/features/sessions/session-activity.js +785 -0
- package/dist/react/features/sessions/session-context.d.ts +8 -0
- package/dist/react/features/sessions/session-context.js +98 -0
- package/dist/react/features/sessions/session-feed.d.ts +243 -0
- package/dist/react/features/sessions/session-feed.js +883 -0
- package/dist/react/features/sessions/session-header.d.ts +24 -0
- package/dist/react/features/sessions/session-header.js +97 -0
- package/dist/react/features/sessions/session-layout.d.ts +7 -0
- package/dist/react/features/sessions/session-layout.js +87 -0
- package/dist/react/features/sessions/session-panes.d.ts +49 -0
- package/dist/react/features/sessions/session-panes.js +142 -0
- package/dist/react/features/sessions/session-parts.d.ts +35 -0
- package/dist/react/features/sessions/session-parts.js +74 -0
- package/dist/react/features/sessions/session-place.d.ts +9 -0
- package/dist/react/features/sessions/session-place.js +109 -0
- package/dist/react/features/sessions/session-pr-pills.d.ts +7 -0
- package/dist/react/features/sessions/session-pr-pills.js +28 -0
- package/dist/react/features/sessions/session-queries.d.ts +172 -0
- package/dist/react/features/sessions/session-queries.js +90 -0
- package/dist/react/features/sessions/session-repos.d.ts +8 -0
- package/dist/react/features/sessions/session-repos.js +15 -0
- package/dist/react/features/sessions/session-share.d.ts +8 -0
- package/dist/react/features/sessions/session-share.js +112 -0
- package/dist/react/features/sessions/session-tabs.d.ts +38 -0
- package/dist/react/features/sessions/session-tabs.js +191 -0
- package/dist/react/features/sessions/session.d.ts +103 -0
- package/dist/react/features/sessions/session.js +216 -0
- package/dist/react/features/sessions/signals.d.ts +13 -0
- package/dist/react/features/sessions/signals.js +34 -0
- package/dist/react/features/sessions/tab-set.d.ts +20 -0
- package/dist/react/features/sessions/tab-set.js +58 -0
- package/dist/react/features/sessions/team.d.ts +16 -0
- package/dist/react/features/sessions/team.js +35 -0
- package/dist/react/features/sessions/timeline.d.ts +53 -0
- package/dist/react/features/sessions/timeline.js +153 -0
- package/dist/react/features/sessions/use-session-tabs.d.ts +18 -0
- package/dist/react/features/sessions/use-session-tabs.js +119 -0
- package/dist/react/features/sessions/vendor-models.d.ts +23 -0
- package/dist/react/features/sessions/vendor-models.js +61 -0
- package/dist/react/features/workspace/activity-dot.d.ts +15 -0
- package/dist/react/features/workspace/activity-dot.js +36 -0
- package/dist/react/features/workspace/app-sidebar.d.ts +16 -0
- package/dist/react/features/workspace/app-sidebar.js +227 -0
- package/dist/react/features/workspace/fixture-toggle.d.ts +2 -0
- package/dist/react/features/workspace/fixture-toggle.js +72 -0
- package/dist/react/features/workspace/folder-group.d.ts +18 -0
- package/dist/react/features/workspace/folder-group.js +83 -0
- package/dist/react/features/workspace/inline-name-input.d.ts +10 -0
- package/dist/react/features/workspace/inline-name-input.js +33 -0
- package/dist/react/features/workspace/link-repo-dialog.d.ts +9 -0
- package/dist/react/features/workspace/link-repo-dialog.js +76 -0
- package/dist/react/features/workspace/repo-chip.d.ts +13 -0
- package/dist/react/features/workspace/repo-chip.js +15 -0
- package/dist/react/features/workspace/session-row.d.ts +20 -0
- package/dist/react/features/workspace/session-row.js +23 -0
- package/dist/react/features/workspace/use-debounced.d.ts +2 -0
- package/dist/react/features/workspace/use-debounced.js +10 -0
- package/dist/react/features/workspace/workspace-context.d.ts +45 -0
- package/dist/react/features/workspace/workspace-context.js +245 -0
- package/dist/react/features/workspace/workspace-fixtures.d.ts +16 -0
- package/dist/react/features/workspace/workspace-fixtures.js +175 -0
- package/dist/react/features/workspace/workspace-tree.d.ts +30 -0
- package/dist/react/features/workspace/workspace-tree.js +69 -0
- package/dist/react/features/workspace/workspace.d.ts +107 -0
- package/dist/react/features/workspace/workspace.js +458 -0
- package/dist/react/index.d.ts +33 -0
- package/dist/react/index.js +35 -0
- package/dist/react/lib/cn.d.ts +6 -0
- package/dist/react/lib/cn.js +20 -0
- package/dist/react/lib/initials.d.ts +6 -0
- package/dist/react/lib/initials.js +32 -0
- package/dist/react/lib/json.d.ts +33 -0
- package/dist/react/lib/json.js +101 -0
- package/dist/react/lib/time.d.ts +8 -0
- package/dist/react/lib/time.js +57 -0
- package/dist/react/lib/use-media-query.d.ts +1 -0
- package/dist/react/lib/use-media-query.js +9 -0
- package/dist/react/lib/use-now.d.ts +2 -0
- package/dist/react/lib/use-now.js +10 -0
- package/dist/react/lib/use-width-bucket.d.ts +6 -0
- package/dist/react/lib/use-width-bucket.js +28 -0
- package/dist/react/parts/index.d.ts +43 -0
- package/dist/react/parts/index.js +43 -0
- package/dist/react/shuttle/device.d.ts +42 -0
- package/dist/react/shuttle/device.js +10 -0
- package/dist/react/shuttle/host.d.ts +1126 -0
- package/dist/react/shuttle/host.js +93 -0
- package/dist/react/shuttle/identity.d.ts +31 -0
- package/dist/react/shuttle/identity.js +20 -0
- package/dist/react/shuttle/index.d.ts +14 -0
- package/dist/react/shuttle/index.js +13 -0
- package/dist/react/shuttle/provider.d.ts +41 -0
- package/dist/react/shuttle/provider.js +59 -0
- package/dist/react/shuttle/router.d.ts +43 -0
- package/dist/react/shuttle/router.js +1 -0
- package/dist/react/theme.css +456 -0
- package/dist/react/ui.d.ts +19 -0
- package/dist/react/ui.js +19 -0
- package/package.json +100 -4
|
@@ -0,0 +1,883 @@
|
|
|
1
|
+
import { jsonFields, jsonNumber, jsonText } from '../../lib/json.js';
|
|
2
|
+
import { mediaAssetsOf, sharedAssetOf } from './media.js';
|
|
3
|
+
export const interjectionKinds = [
|
|
4
|
+
'question',
|
|
5
|
+
'idea',
|
|
6
|
+
'constraint',
|
|
7
|
+
'correction',
|
|
8
|
+
'task',
|
|
9
|
+
'stop',
|
|
10
|
+
];
|
|
11
|
+
export function isInterjectionKind(value) {
|
|
12
|
+
return interjectionKinds.some((kind) => kind === value);
|
|
13
|
+
}
|
|
14
|
+
function reviewVerdict(value) {
|
|
15
|
+
return value === 'approve' || value === 'request_changes' || value === 'comment'
|
|
16
|
+
? value
|
|
17
|
+
: undefined;
|
|
18
|
+
}
|
|
19
|
+
function messageAuthor(value) {
|
|
20
|
+
if (!value || typeof value !== 'object') {
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
23
|
+
const { id, name } = value;
|
|
24
|
+
return typeof id === 'string' && typeof name === 'string' ? { author: { id, name } } : {};
|
|
25
|
+
}
|
|
26
|
+
const initialFeed = {
|
|
27
|
+
media: [],
|
|
28
|
+
publishedPulls: [],
|
|
29
|
+
draftReviewComments: [],
|
|
30
|
+
items: [],
|
|
31
|
+
routes: {},
|
|
32
|
+
deliveries: {},
|
|
33
|
+
narratorFor: {},
|
|
34
|
+
classifying: {},
|
|
35
|
+
messageText: {},
|
|
36
|
+
brief: [],
|
|
37
|
+
playbook: { version: 0, lessons: [] },
|
|
38
|
+
narrators: {},
|
|
39
|
+
toolIndex: {},
|
|
40
|
+
questionIndex: {},
|
|
41
|
+
pendingThoughts: {},
|
|
42
|
+
openTurns: {},
|
|
43
|
+
queued: {},
|
|
44
|
+
vendorAgents: {},
|
|
45
|
+
};
|
|
46
|
+
function withoutKey(record, key) {
|
|
47
|
+
const next = { ...record };
|
|
48
|
+
delete next[key];
|
|
49
|
+
return next;
|
|
50
|
+
}
|
|
51
|
+
function schemaDefaults(schema) {
|
|
52
|
+
const properties = jsonFields(jsonFields(schema).properties);
|
|
53
|
+
const defaults = {};
|
|
54
|
+
for (const [key, property] of Object.entries(properties)) {
|
|
55
|
+
const value = jsonFields(property).default;
|
|
56
|
+
if (value !== undefined) {
|
|
57
|
+
defaults[key] = value;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return defaults;
|
|
61
|
+
}
|
|
62
|
+
function withPublishOutcome(feed, index, publish) {
|
|
63
|
+
const question = index === undefined ? undefined : feed.items[index];
|
|
64
|
+
if (index === undefined || question?.kind !== 'question') {
|
|
65
|
+
return feed;
|
|
66
|
+
}
|
|
67
|
+
const items = [...feed.items];
|
|
68
|
+
items[index] = { ...question, publish };
|
|
69
|
+
return { ...feed, items };
|
|
70
|
+
}
|
|
71
|
+
function appendItem(feed, item) {
|
|
72
|
+
return { ...feed, items: [...feed.items, item] };
|
|
73
|
+
}
|
|
74
|
+
function takePendingThought(feed, threadId, turn) {
|
|
75
|
+
const pending = feed.pendingThoughts[threadId];
|
|
76
|
+
if (!pending || (turn !== undefined && pending.turn !== turn)) {
|
|
77
|
+
return { feed };
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
feed: { ...feed, pendingThoughts: withoutKey(feed.pendingThoughts, threadId) },
|
|
81
|
+
thought: pending,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** Flush an unclaimed thought when a turn settles without messages, tools, or approvals. */
|
|
85
|
+
function flushPendingThought(feed, threadId) {
|
|
86
|
+
if (!threadId) {
|
|
87
|
+
return feed;
|
|
88
|
+
}
|
|
89
|
+
const pending = feed.pendingThoughts[threadId];
|
|
90
|
+
if (!pending) {
|
|
91
|
+
return feed;
|
|
92
|
+
}
|
|
93
|
+
const cleared = {
|
|
94
|
+
...feed,
|
|
95
|
+
pendingThoughts: withoutKey(feed.pendingThoughts, threadId),
|
|
96
|
+
};
|
|
97
|
+
const last = cleared.items.at(-1);
|
|
98
|
+
if (last?.kind === 'tools' && last.threadId === threadId) {
|
|
99
|
+
const items = [...cleared.items];
|
|
100
|
+
items[items.length - 1] = {
|
|
101
|
+
...last,
|
|
102
|
+
thoughts: [...last.thoughts, pending],
|
|
103
|
+
steps: [...last.steps, { kind: 'thought', thought: pending }],
|
|
104
|
+
};
|
|
105
|
+
return { ...cleared, items };
|
|
106
|
+
}
|
|
107
|
+
return appendItem(cleared, {
|
|
108
|
+
kind: 'thought',
|
|
109
|
+
id: pending.id,
|
|
110
|
+
seq: pending.seq,
|
|
111
|
+
ts: pending.ts,
|
|
112
|
+
threadId,
|
|
113
|
+
turn: pending.turn,
|
|
114
|
+
text: pending.text,
|
|
115
|
+
durationMs: pending.durationMs,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/** Looms runs each model turn of a thread as the effect `<threadId>:llm_turn_<n>`. */
|
|
119
|
+
const MODEL_TURN_EFFECT = /^(.+):llm_turn_\d+$/;
|
|
120
|
+
function mapValues(record, map) {
|
|
121
|
+
return Object.fromEntries(Object.entries(record).map(([key, value]) => [key, map(value)]));
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Ends a thread's turn. A turn is recorded when it ends, so messages sent while it ran would sit
|
|
125
|
+
* above what it did. The agent reads them next, so they move below it.
|
|
126
|
+
*/
|
|
127
|
+
function endTurn(feed, threadId) {
|
|
128
|
+
if (!threadId || !feed.openTurns[threadId]) {
|
|
129
|
+
return feed;
|
|
130
|
+
}
|
|
131
|
+
const ended = { ...feed, openTurns: withoutKey(feed.openTurns, threadId) };
|
|
132
|
+
const waiting = new Set(Object.entries(feed.queued).flatMap(([messageId, waitsFor]) => waitsFor === threadId ? [messageId] : []));
|
|
133
|
+
if (waiting.size === 0) {
|
|
134
|
+
return ended;
|
|
135
|
+
}
|
|
136
|
+
const isWaiting = (item) => item.kind === 'user' && waiting.has(item.messageId);
|
|
137
|
+
const items = [...feed.items.filter((item) => !isWaiting(item)), ...feed.items.filter(isWaiting)];
|
|
138
|
+
const position = new Map(items.map((item, index) => [item, index]));
|
|
139
|
+
const moved = (index) => {
|
|
140
|
+
const item = feed.items[index];
|
|
141
|
+
return (item && position.get(item)) ?? index;
|
|
142
|
+
};
|
|
143
|
+
return {
|
|
144
|
+
...ended,
|
|
145
|
+
items,
|
|
146
|
+
queued: Object.fromEntries(Object.entries(feed.queued).filter(([messageId]) => !waiting.has(messageId))),
|
|
147
|
+
toolIndex: mapValues(feed.toolIndex, moved),
|
|
148
|
+
questionIndex: mapValues(feed.questionIndex, moved),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function onToolCall(feed, event) {
|
|
152
|
+
const payload = jsonFields(event.payload);
|
|
153
|
+
const call = jsonFields(payload.toolCall);
|
|
154
|
+
const toolCallId = jsonText(call.id);
|
|
155
|
+
const threadId = event.threadId;
|
|
156
|
+
const name = jsonText(call.name) ?? 'tool';
|
|
157
|
+
// `ask_user` surfaces as a question card from its approval gate instead.
|
|
158
|
+
if (!toolCallId || !threadId || name === 'ask_user' || feed.toolIndex[toolCallId] !== undefined) {
|
|
159
|
+
return feed;
|
|
160
|
+
}
|
|
161
|
+
const turn = jsonNumber(payload.turn);
|
|
162
|
+
const taken = takePendingThought(feed, threadId, turn);
|
|
163
|
+
const baseFeed = taken.feed;
|
|
164
|
+
const thought = taken.thought;
|
|
165
|
+
const item = {
|
|
166
|
+
toolCallId,
|
|
167
|
+
name,
|
|
168
|
+
args: call.arguments ?? null,
|
|
169
|
+
seq: event.seq,
|
|
170
|
+
status: 'running',
|
|
171
|
+
startedAt: event.ts,
|
|
172
|
+
};
|
|
173
|
+
const newSteps = thought
|
|
174
|
+
? [
|
|
175
|
+
{ kind: 'thought', thought },
|
|
176
|
+
{ kind: 'call', call: item },
|
|
177
|
+
]
|
|
178
|
+
: [{ kind: 'call', call: item }];
|
|
179
|
+
const last = baseFeed.items.at(-1);
|
|
180
|
+
// Consecutive silent work from one agent collapses into a single activity card.
|
|
181
|
+
if (last?.kind === 'tools' && last.threadId === threadId) {
|
|
182
|
+
const index = baseFeed.items.length - 1;
|
|
183
|
+
const items = [...baseFeed.items];
|
|
184
|
+
items[index] = {
|
|
185
|
+
...last,
|
|
186
|
+
calls: [...last.calls, item],
|
|
187
|
+
thoughts: thought ? [...last.thoughts, thought] : last.thoughts,
|
|
188
|
+
steps: [...last.steps, ...newSteps],
|
|
189
|
+
};
|
|
190
|
+
return { ...baseFeed, items, toolIndex: { ...baseFeed.toolIndex, [toolCallId]: index } };
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
...appendItem(baseFeed, {
|
|
194
|
+
kind: 'tools',
|
|
195
|
+
id: event.id,
|
|
196
|
+
seq: event.seq,
|
|
197
|
+
ts: event.ts,
|
|
198
|
+
threadId,
|
|
199
|
+
calls: [item],
|
|
200
|
+
thoughts: thought ? [thought] : [],
|
|
201
|
+
steps: newSteps,
|
|
202
|
+
}),
|
|
203
|
+
toolIndex: { ...baseFeed.toolIndex, [toolCallId]: baseFeed.items.length },
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function onToolResult(feed, event) {
|
|
207
|
+
const payload = jsonFields(event.payload);
|
|
208
|
+
const toolCallId = jsonText(payload.toolCallId);
|
|
209
|
+
const index = toolCallId ? feed.toolIndex[toolCallId] : undefined;
|
|
210
|
+
const group = index === undefined ? undefined : feed.items[index];
|
|
211
|
+
if (index === undefined || group?.kind !== 'tools') {
|
|
212
|
+
return feed;
|
|
213
|
+
}
|
|
214
|
+
const error = jsonText(payload.error) ?? undefined;
|
|
215
|
+
const items = [...feed.items];
|
|
216
|
+
const updateCall = (call) => call.toolCallId === toolCallId
|
|
217
|
+
? {
|
|
218
|
+
...call,
|
|
219
|
+
status: error ? 'error' : 'ok',
|
|
220
|
+
result: payload.result ?? null,
|
|
221
|
+
error,
|
|
222
|
+
}
|
|
223
|
+
: call;
|
|
224
|
+
items[index] = {
|
|
225
|
+
...group,
|
|
226
|
+
calls: group.calls.map(updateCall),
|
|
227
|
+
steps: group.steps.map((step) => step.kind === 'call' ? { kind: 'call', call: updateCall(step.call) } : step),
|
|
228
|
+
};
|
|
229
|
+
const call = group.calls.find((candidate) => candidate.toolCallId === toolCallId);
|
|
230
|
+
const shared = call?.name === SHARE_FILE_TOOL && !error ? sharedAssetOf(payload.result) : undefined;
|
|
231
|
+
return shared
|
|
232
|
+
? withSharedMedia({ ...feed, items }, event, group.threadId, shared)
|
|
233
|
+
: { ...feed, items };
|
|
234
|
+
}
|
|
235
|
+
/** The tool an agent calls to show a file. Its result carries the file. */
|
|
236
|
+
const SHARE_FILE_TOOL = 'share_file';
|
|
237
|
+
/** Shows a file an agent shared. Files shared one after another by one agent share a row. */
|
|
238
|
+
function withSharedMedia(feed, event, threadId, asset) {
|
|
239
|
+
const media = [
|
|
240
|
+
...feed.media,
|
|
241
|
+
{ asset, source: 'agent', seq: event.seq, ts: event.ts, threadId },
|
|
242
|
+
];
|
|
243
|
+
// Each share is a tool call of its own, so the row for the previous file sits just behind the
|
|
244
|
+
// calls that shared the later ones.
|
|
245
|
+
const isShareCalls = (item) => item.kind === 'tools' &&
|
|
246
|
+
item.threadId === threadId &&
|
|
247
|
+
item.calls.every((call) => call.name === SHARE_FILE_TOOL);
|
|
248
|
+
const index = feed.items.findLastIndex((item) => !isShareCalls(item));
|
|
249
|
+
const previous = feed.items[index];
|
|
250
|
+
if (previous?.kind === 'media' && previous.threadId === threadId) {
|
|
251
|
+
const items = [...feed.items];
|
|
252
|
+
items[index] = { ...previous, assets: [...previous.assets, asset] };
|
|
253
|
+
return { ...feed, media, items };
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
...appendItem(feed, {
|
|
257
|
+
kind: 'media',
|
|
258
|
+
id: event.id,
|
|
259
|
+
seq: event.seq,
|
|
260
|
+
ts: event.ts,
|
|
261
|
+
threadId,
|
|
262
|
+
assets: [asset],
|
|
263
|
+
}),
|
|
264
|
+
media,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
function reduceFeed(feed, event) {
|
|
268
|
+
const payload = jsonFields(event.payload);
|
|
269
|
+
switch (event.type) {
|
|
270
|
+
case 'runtime.thread.started': {
|
|
271
|
+
if (feed.rootThreadId || event.parentThreadId) {
|
|
272
|
+
return feed;
|
|
273
|
+
}
|
|
274
|
+
const goal = jsonText(jsonFields(payload.input).goal);
|
|
275
|
+
if (!goal || !event.threadId) {
|
|
276
|
+
return { ...feed, rootThreadId: event.threadId ?? undefined };
|
|
277
|
+
}
|
|
278
|
+
return {
|
|
279
|
+
...appendItem(feed, {
|
|
280
|
+
kind: 'user',
|
|
281
|
+
id: event.id,
|
|
282
|
+
seq: event.seq,
|
|
283
|
+
ts: event.ts,
|
|
284
|
+
messageId: `goal_${event.id}`,
|
|
285
|
+
text: goal,
|
|
286
|
+
goal: true,
|
|
287
|
+
}),
|
|
288
|
+
rootThreadId: event.threadId,
|
|
289
|
+
brief: [{ version: 1, text: goal, ts: event.ts }],
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
case 'shuttle.user.said': {
|
|
293
|
+
const messageId = jsonText(payload.messageId);
|
|
294
|
+
const text = jsonText(payload.text) ?? '';
|
|
295
|
+
const attachments = mediaAssetsOf(payload.attachments);
|
|
296
|
+
// A message may be files alone.
|
|
297
|
+
if (!messageId || (!text && attachments.length === 0)) {
|
|
298
|
+
return feed;
|
|
299
|
+
}
|
|
300
|
+
const forced = jsonText(payload.forceKind);
|
|
301
|
+
const author = messageAuthor(payload.author);
|
|
302
|
+
return {
|
|
303
|
+
...appendItem(feed, {
|
|
304
|
+
kind: 'user',
|
|
305
|
+
id: event.id,
|
|
306
|
+
seq: event.seq,
|
|
307
|
+
ts: event.ts,
|
|
308
|
+
messageId,
|
|
309
|
+
text,
|
|
310
|
+
goal: false,
|
|
311
|
+
forced: isInterjectionKind(forced) ? forced : undefined,
|
|
312
|
+
...author,
|
|
313
|
+
...(attachments.length > 0 ? { attachments } : {}),
|
|
314
|
+
}),
|
|
315
|
+
messageText: { ...feed.messageText, [messageId]: text },
|
|
316
|
+
media: [
|
|
317
|
+
...feed.media,
|
|
318
|
+
...attachments.map((asset) => ({
|
|
319
|
+
asset,
|
|
320
|
+
source: 'upload',
|
|
321
|
+
seq: event.seq,
|
|
322
|
+
ts: event.ts,
|
|
323
|
+
...(author.author ? { authorName: author.author.name } : {}),
|
|
324
|
+
})),
|
|
325
|
+
],
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
case 'shuttle.intake.started': {
|
|
329
|
+
const messageId = jsonText(payload.messageId);
|
|
330
|
+
return messageId ? { ...feed, classifying: { ...feed.classifying, [messageId]: true } } : feed;
|
|
331
|
+
}
|
|
332
|
+
case 'shuttle.routed': {
|
|
333
|
+
const messageId = jsonText(payload.messageId);
|
|
334
|
+
const kind = jsonText(payload.kind);
|
|
335
|
+
if (!messageId || !isInterjectionKind(kind)) {
|
|
336
|
+
return feed;
|
|
337
|
+
}
|
|
338
|
+
return {
|
|
339
|
+
...feed,
|
|
340
|
+
classifying: withoutKey(feed.classifying, messageId),
|
|
341
|
+
routes: {
|
|
342
|
+
...feed.routes,
|
|
343
|
+
[messageId]: {
|
|
344
|
+
kind,
|
|
345
|
+
summary: jsonText(payload.summary) ?? '',
|
|
346
|
+
targetThreadId: jsonText(payload.targetThreadId) ?? null,
|
|
347
|
+
briefVersion: jsonNumber(payload.briefVersion),
|
|
348
|
+
},
|
|
349
|
+
},
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
case 'shuttle.narrator.spawned': {
|
|
353
|
+
const messageId = jsonText(payload.messageId);
|
|
354
|
+
const childThreadId = jsonText(payload.childThreadId);
|
|
355
|
+
if (!messageId || !childThreadId) {
|
|
356
|
+
return feed;
|
|
357
|
+
}
|
|
358
|
+
return {
|
|
359
|
+
...feed,
|
|
360
|
+
narrators: { ...feed.narrators, [childThreadId]: messageId },
|
|
361
|
+
narratorFor: { ...feed.narratorFor, [messageId]: childThreadId },
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
case 'shuttle.brief.amended': {
|
|
365
|
+
const version = jsonNumber(payload.version);
|
|
366
|
+
const text = jsonText(payload.text);
|
|
367
|
+
if (version === undefined || text === undefined) {
|
|
368
|
+
return feed;
|
|
369
|
+
}
|
|
370
|
+
return {
|
|
371
|
+
...feed,
|
|
372
|
+
brief: [
|
|
373
|
+
...feed.brief.filter((revision) => revision.version !== version),
|
|
374
|
+
{ version, text, ts: event.ts, sourceMessageId: jsonText(payload.sourceMessageId) },
|
|
375
|
+
],
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
case 'shuttle.playbook.loaded': {
|
|
379
|
+
const lessons = Array.isArray(payload.lessons) ? payload.lessons : [];
|
|
380
|
+
return {
|
|
381
|
+
...feed,
|
|
382
|
+
playbook: {
|
|
383
|
+
version: jsonNumber(payload.version) ?? 0,
|
|
384
|
+
lessons: lessons.flatMap((lesson) => {
|
|
385
|
+
const fields = jsonFields(lesson);
|
|
386
|
+
const id = jsonText(fields.id);
|
|
387
|
+
const text = jsonText(fields.text);
|
|
388
|
+
return id && text ? [{ id, text, scope: jsonText(fields.scope) }] : [];
|
|
389
|
+
}),
|
|
390
|
+
},
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
case 'shuttle.conductor.spawned': {
|
|
394
|
+
const generation = jsonNumber(payload.generation) ?? 0;
|
|
395
|
+
const reason = jsonText(payload.reason);
|
|
396
|
+
if (generation <= 0) {
|
|
397
|
+
return feed;
|
|
398
|
+
}
|
|
399
|
+
const reasonLabel = reason && reason !== 'initial' ? ` after ${reason}` : '';
|
|
400
|
+
return appendItem(feed, {
|
|
401
|
+
kind: 'notice',
|
|
402
|
+
id: event.id,
|
|
403
|
+
seq: event.seq,
|
|
404
|
+
ts: event.ts,
|
|
405
|
+
tone: 'info',
|
|
406
|
+
text: `Conductor restarted (generation ${generation})${reasonLabel}.`,
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
case 'shuttle.reflection.launched': {
|
|
410
|
+
const runId = jsonText(payload.runId);
|
|
411
|
+
if (!runId) {
|
|
412
|
+
return feed;
|
|
413
|
+
}
|
|
414
|
+
return {
|
|
415
|
+
...appendItem(feed, {
|
|
416
|
+
kind: 'notice',
|
|
417
|
+
id: event.id,
|
|
418
|
+
seq: event.seq,
|
|
419
|
+
ts: event.ts,
|
|
420
|
+
tone: 'info',
|
|
421
|
+
text: 'Session idle. Reflection run launched to mine lessons from this history.',
|
|
422
|
+
runId,
|
|
423
|
+
}),
|
|
424
|
+
reflectionRunId: runId,
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
case 'agent.steered': {
|
|
428
|
+
const messageId = jsonText(payload.messageId);
|
|
429
|
+
if (!messageId || !event.threadId) {
|
|
430
|
+
return feed;
|
|
431
|
+
}
|
|
432
|
+
const delivery = {
|
|
433
|
+
threadId: event.threadId,
|
|
434
|
+
interrupt: payload.interrupt === true,
|
|
435
|
+
};
|
|
436
|
+
const waits = !delivery.interrupt && feed.openTurns[event.threadId] === true;
|
|
437
|
+
return {
|
|
438
|
+
...feed,
|
|
439
|
+
deliveries: {
|
|
440
|
+
...feed.deliveries,
|
|
441
|
+
[messageId]: [...(feed.deliveries[messageId] ?? []), delivery],
|
|
442
|
+
},
|
|
443
|
+
...(waits && feed.queued[messageId] === undefined
|
|
444
|
+
? { queued: { ...feed.queued, [messageId]: event.threadId } }
|
|
445
|
+
: {}),
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
case 'runtime.effect.attempt.started': {
|
|
449
|
+
const threadId = MODEL_TURN_EFFECT.exec(jsonText(payload.effectId) ?? '')?.[1];
|
|
450
|
+
return threadId && !feed.openTurns[threadId]
|
|
451
|
+
? { ...feed, openTurns: { ...feed.openTurns, [threadId]: true } }
|
|
452
|
+
: feed;
|
|
453
|
+
}
|
|
454
|
+
case 'shuttle.turn.thought': {
|
|
455
|
+
const text = jsonText(payload.text)?.trim();
|
|
456
|
+
const turn = jsonNumber(payload.turn);
|
|
457
|
+
if (!text || turn === undefined || !event.threadId) {
|
|
458
|
+
return feed;
|
|
459
|
+
}
|
|
460
|
+
const flushed = flushPendingThought(feed, event.threadId);
|
|
461
|
+
return {
|
|
462
|
+
...flushed,
|
|
463
|
+
pendingThoughts: {
|
|
464
|
+
...flushed.pendingThoughts,
|
|
465
|
+
[event.threadId]: {
|
|
466
|
+
id: event.id,
|
|
467
|
+
text,
|
|
468
|
+
durationMs: jsonNumber(payload.durationMs),
|
|
469
|
+
seq: event.seq,
|
|
470
|
+
ts: event.ts,
|
|
471
|
+
turn,
|
|
472
|
+
},
|
|
473
|
+
},
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
case 'shuttle.sandbox.moved': {
|
|
477
|
+
const machine = typeof payload.device === 'string' ? payload.device : 'a local machine';
|
|
478
|
+
const place = (end) => (end === 'local' ? machine : 'the cloud');
|
|
479
|
+
return appendItem(feed, {
|
|
480
|
+
kind: 'notice',
|
|
481
|
+
id: event.id,
|
|
482
|
+
seq: event.seq,
|
|
483
|
+
ts: event.ts,
|
|
484
|
+
tone: 'info',
|
|
485
|
+
text: payload.fromSave === true
|
|
486
|
+
? `Moved from ${place(payload.from)} to ${place(payload.to)} using its last save, because ${machine} was not connected. Anything changed there since is still on it.`
|
|
487
|
+
: `Moved from ${place(payload.from)} to ${place(payload.to)}, with its branches and uncommitted files.`,
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
case 'shuttle.team.changed': {
|
|
491
|
+
const members = [
|
|
492
|
+
payload.workers === true ? 'Shuttle workers' : null,
|
|
493
|
+
payload.codex === true ? 'Codex' : null,
|
|
494
|
+
payload.claudeCode === true ? 'Claude Code' : null,
|
|
495
|
+
payload.cursor === true ? 'Cursor' : null,
|
|
496
|
+
].filter(Boolean);
|
|
497
|
+
return appendItem(feed, {
|
|
498
|
+
kind: 'notice',
|
|
499
|
+
id: event.id,
|
|
500
|
+
seq: event.seq,
|
|
501
|
+
ts: event.ts,
|
|
502
|
+
tone: 'info',
|
|
503
|
+
text: `Team is now ${members.join(', ')}. This applies from the conductor's next turn.`,
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
case 'shuttle.vendor.turn_started': {
|
|
507
|
+
const label = jsonText(payload.label);
|
|
508
|
+
const harness = jsonText(payload.harness);
|
|
509
|
+
if (!label || !harness || !event.threadId) {
|
|
510
|
+
return feed;
|
|
511
|
+
}
|
|
512
|
+
const model = jsonText(payload.model);
|
|
513
|
+
const billedTo = jsonText(payload.billedTo);
|
|
514
|
+
return {
|
|
515
|
+
...feed,
|
|
516
|
+
vendorAgents: {
|
|
517
|
+
...feed.vendorAgents,
|
|
518
|
+
[event.threadId]: {
|
|
519
|
+
harness,
|
|
520
|
+
label,
|
|
521
|
+
...(model ? { model } : {}),
|
|
522
|
+
...(billedTo ? { billedTo } : {}),
|
|
523
|
+
},
|
|
524
|
+
},
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
// A vendor agent says several things in one turn. Each is its own message in the feed.
|
|
528
|
+
case 'shuttle.vendor.message': {
|
|
529
|
+
const text = jsonText(payload.text)?.trim();
|
|
530
|
+
if (!text || !event.threadId) {
|
|
531
|
+
return feed;
|
|
532
|
+
}
|
|
533
|
+
const taken = takePendingThought(feed, event.threadId, jsonNumber(payload.turn));
|
|
534
|
+
return appendItem(taken.feed, {
|
|
535
|
+
kind: 'agent',
|
|
536
|
+
id: event.id,
|
|
537
|
+
seq: event.seq,
|
|
538
|
+
ts: event.ts,
|
|
539
|
+
threadId: event.threadId,
|
|
540
|
+
text,
|
|
541
|
+
replyTo: taken.feed.narrators[event.threadId],
|
|
542
|
+
...(taken.thought ? { thought: taken.thought } : {}),
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
case 'agent.message': {
|
|
546
|
+
const message = jsonFields(payload.message);
|
|
547
|
+
const text = jsonText(message.content)?.trim();
|
|
548
|
+
if (message.role !== 'assistant' || !text || !event.threadId) {
|
|
549
|
+
return feed;
|
|
550
|
+
}
|
|
551
|
+
const turn = jsonNumber(payload.turn);
|
|
552
|
+
const taken = takePendingThought(feed, event.threadId, turn);
|
|
553
|
+
return appendItem(taken.feed, {
|
|
554
|
+
kind: 'agent',
|
|
555
|
+
id: event.id,
|
|
556
|
+
seq: event.seq,
|
|
557
|
+
ts: event.ts,
|
|
558
|
+
threadId: event.threadId,
|
|
559
|
+
text,
|
|
560
|
+
replyTo: taken.feed.narrators[event.threadId],
|
|
561
|
+
...(taken.thought ? { thought: taken.thought } : {}),
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
case 'agent.tool_call.requested':
|
|
565
|
+
// A vendor agent's own tools are recorded in the same shape as Shuttle's.
|
|
566
|
+
case 'shuttle.vendor.tool_started':
|
|
567
|
+
return onToolCall(feed, event);
|
|
568
|
+
case 'approval.requested': {
|
|
569
|
+
const approvalId = jsonText(payload.approvalId);
|
|
570
|
+
if (!approvalId || !event.threadId || feed.questionIndex[approvalId] !== undefined) {
|
|
571
|
+
return feed;
|
|
572
|
+
}
|
|
573
|
+
const taken = takePendingThought(feed, event.threadId);
|
|
574
|
+
const defaults = schemaDefaults(payload.schema);
|
|
575
|
+
return {
|
|
576
|
+
...appendItem(taken.feed, {
|
|
577
|
+
kind: 'question',
|
|
578
|
+
id: event.id,
|
|
579
|
+
seq: event.seq,
|
|
580
|
+
ts: event.ts,
|
|
581
|
+
threadId: event.threadId,
|
|
582
|
+
approvalId,
|
|
583
|
+
title: jsonText(payload.title) ?? 'The agent needs your input',
|
|
584
|
+
...(Object.keys(defaults).length > 0 ? { defaults } : {}),
|
|
585
|
+
...(taken.thought ? { thought: taken.thought } : {}),
|
|
586
|
+
}),
|
|
587
|
+
questionIndex: { ...taken.feed.questionIndex, [approvalId]: taken.feed.items.length },
|
|
588
|
+
...(approvalId.startsWith('pr_review_')
|
|
589
|
+
? {
|
|
590
|
+
pendingReviewApprovalId: approvalId,
|
|
591
|
+
reviewOutcome: undefined,
|
|
592
|
+
reviewProposal: {
|
|
593
|
+
...(jsonText(defaults.summary) ? { summary: jsonText(defaults.summary) } : {}),
|
|
594
|
+
...(reviewVerdict(defaults.verdict)
|
|
595
|
+
? { verdict: reviewVerdict(defaults.verdict) }
|
|
596
|
+
: {}),
|
|
597
|
+
},
|
|
598
|
+
}
|
|
599
|
+
: {}),
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
case 'shuttle.review.submitted': {
|
|
603
|
+
return {
|
|
604
|
+
...feed,
|
|
605
|
+
reviewOutcome: {
|
|
606
|
+
status: 'submitted',
|
|
607
|
+
verdict: reviewVerdict(payload.verdict) ?? 'comment',
|
|
608
|
+
commentCount: jsonNumber(payload.commentCount) ?? 0,
|
|
609
|
+
unanchoredCount: jsonNumber(payload.unanchoredCount) ?? 0,
|
|
610
|
+
},
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
case 'shuttle.review.submit_failed': {
|
|
614
|
+
return {
|
|
615
|
+
...feed,
|
|
616
|
+
reviewOutcome: {
|
|
617
|
+
status: 'failed',
|
|
618
|
+
error: jsonText(payload.error) ?? 'The review could not be sent.',
|
|
619
|
+
},
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
case 'approval.decided': {
|
|
623
|
+
const approvalId = jsonText(payload.approvalId);
|
|
624
|
+
const index = approvalId ? feed.questionIndex[approvalId] : undefined;
|
|
625
|
+
const question = index === undefined ? undefined : feed.items[index];
|
|
626
|
+
if (index === undefined || question?.kind !== 'question') {
|
|
627
|
+
return feed;
|
|
628
|
+
}
|
|
629
|
+
const answer = payload.outcome === 'approve'
|
|
630
|
+
? (jsonText(jsonFields(payload.payload).answer) ?? 'Approved')
|
|
631
|
+
: null;
|
|
632
|
+
const items = [...feed.items];
|
|
633
|
+
items[index] = { ...question, decision: { answer, ts: event.ts } };
|
|
634
|
+
return {
|
|
635
|
+
...feed,
|
|
636
|
+
items,
|
|
637
|
+
...(approvalId && approvalId === feed.pendingReviewApprovalId
|
|
638
|
+
? { pendingReviewApprovalId: undefined }
|
|
639
|
+
: {}),
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
case 'shuttle.pr.published': {
|
|
643
|
+
const pullsRaw = Array.isArray(payload.pulls) ? payload.pulls : [];
|
|
644
|
+
const approvalId = jsonText(payload.approvalId);
|
|
645
|
+
const index = approvalId ? feed.questionIndex[approvalId] : undefined;
|
|
646
|
+
const question = index === undefined ? undefined : feed.items[index];
|
|
647
|
+
const proposedBy = question?.kind === 'question' ? question.threadId : undefined;
|
|
648
|
+
const threadId = jsonText(payload.threadId) ?? proposedBy;
|
|
649
|
+
const stackId = jsonNumber(payload.stackId) ?? 1;
|
|
650
|
+
const published = pullsRaw.flatMap((entry) => {
|
|
651
|
+
const pull = jsonFields(entry);
|
|
652
|
+
const fullName = jsonText(pull.fullName);
|
|
653
|
+
const number = jsonNumber(pull.number);
|
|
654
|
+
const url = jsonText(pull.url);
|
|
655
|
+
const layer = jsonNumber(pull.layer);
|
|
656
|
+
if (!fullName || number === undefined || !url) {
|
|
657
|
+
return [];
|
|
658
|
+
}
|
|
659
|
+
return [
|
|
660
|
+
{
|
|
661
|
+
fullName,
|
|
662
|
+
number,
|
|
663
|
+
url,
|
|
664
|
+
draft: pull.draft === true,
|
|
665
|
+
...(threadId ? { threadId } : {}),
|
|
666
|
+
...(layer !== undefined ? { stack: { id: stackId, layer } } : {}),
|
|
667
|
+
},
|
|
668
|
+
];
|
|
669
|
+
});
|
|
670
|
+
if (published.length === 0) {
|
|
671
|
+
return feed;
|
|
672
|
+
}
|
|
673
|
+
return {
|
|
674
|
+
...withPublishOutcome(feed, index, { status: 'published', pulls: published }),
|
|
675
|
+
publishedPulls: [...feed.publishedPulls, ...published],
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
case 'shuttle.pr.publish_failed': {
|
|
679
|
+
const approvalId = jsonText(payload.approvalId);
|
|
680
|
+
const index = approvalId ? feed.questionIndex[approvalId] : undefined;
|
|
681
|
+
return withPublishOutcome(feed, index, {
|
|
682
|
+
status: 'failed',
|
|
683
|
+
error: jsonText(payload.error) ?? 'Publishing failed',
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
case 'shuttle.review.comment.drafted': {
|
|
687
|
+
const commentId = jsonText(payload.commentId);
|
|
688
|
+
const path = jsonText(payload.path);
|
|
689
|
+
const line = jsonNumber(payload.line);
|
|
690
|
+
const body = jsonText(payload.body);
|
|
691
|
+
if (!commentId || !path || line === undefined || !body) {
|
|
692
|
+
return feed;
|
|
693
|
+
}
|
|
694
|
+
const severityRaw = jsonText(payload.severity);
|
|
695
|
+
const severity = severityRaw === 'warning' || severityRaw === 'error' ? severityRaw : 'info';
|
|
696
|
+
const side = payload.side === 'LEFT' ? 'LEFT' : 'RIGHT';
|
|
697
|
+
const suggestion = jsonText(payload.suggestion);
|
|
698
|
+
return {
|
|
699
|
+
...feed,
|
|
700
|
+
draftReviewComments: [
|
|
701
|
+
...feed.draftReviewComments.filter((comment) => comment.commentId !== commentId),
|
|
702
|
+
{
|
|
703
|
+
commentId,
|
|
704
|
+
path,
|
|
705
|
+
line,
|
|
706
|
+
side,
|
|
707
|
+
severity,
|
|
708
|
+
body,
|
|
709
|
+
...(suggestion ? { suggestion } : {}),
|
|
710
|
+
},
|
|
711
|
+
],
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
case 'agent.tool.result':
|
|
715
|
+
case 'shuttle.vendor.tool_finished':
|
|
716
|
+
return onToolResult(feed, event);
|
|
717
|
+
case 'agent.turn.settled':
|
|
718
|
+
case 'runtime.thread.completed':
|
|
719
|
+
case 'runtime.thread.cancelled':
|
|
720
|
+
return endTurn(flushPendingThought(feed, event.threadId), event.threadId);
|
|
721
|
+
case 'runtime.thread.failed':
|
|
722
|
+
return endTurn(appendItem(flushPendingThought(feed, event.threadId), {
|
|
723
|
+
kind: 'notice',
|
|
724
|
+
id: event.id,
|
|
725
|
+
seq: event.seq,
|
|
726
|
+
ts: event.ts,
|
|
727
|
+
tone: 'error',
|
|
728
|
+
text: jsonText(payload.error) ?? 'Thread failed',
|
|
729
|
+
threadId: event.threadId ?? undefined,
|
|
730
|
+
}), event.threadId);
|
|
731
|
+
case 'agent.turn.stopped':
|
|
732
|
+
return endTurn(appendItem(flushPendingThought(feed, event.threadId), {
|
|
733
|
+
kind: 'notice',
|
|
734
|
+
id: event.id,
|
|
735
|
+
seq: event.seq,
|
|
736
|
+
ts: event.ts,
|
|
737
|
+
tone: 'info',
|
|
738
|
+
text: 'Stopped',
|
|
739
|
+
threadId: event.threadId ?? undefined,
|
|
740
|
+
}), event.threadId);
|
|
741
|
+
default:
|
|
742
|
+
return feed;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
export const sessionFeed = {
|
|
746
|
+
name: 'shuttleSessionFeed',
|
|
747
|
+
initialState: initialFeed,
|
|
748
|
+
// Live copies of a vendor agent's steps are folded by `vendorLiveFeed`; the durable copies
|
|
749
|
+
// that arrive with the turn's result are the ones that belong here.
|
|
750
|
+
reduce: (feed, event) => (event.ephemeral ? feed : reduceFeed(feed, event)),
|
|
751
|
+
};
|
|
752
|
+
const VENDOR_STEP_TYPES = new Set([
|
|
753
|
+
'shuttle.vendor.turn_started',
|
|
754
|
+
'shuttle.vendor.message',
|
|
755
|
+
'shuttle.vendor.tool_started',
|
|
756
|
+
'shuttle.vendor.tool_finished',
|
|
757
|
+
'shuttle.turn.thought',
|
|
758
|
+
]);
|
|
759
|
+
const TURN_ENDED_TYPES = new Set([
|
|
760
|
+
'agent.message',
|
|
761
|
+
'agent.turn.settled',
|
|
762
|
+
'agent.turn.stopped',
|
|
763
|
+
'runtime.thread.completed',
|
|
764
|
+
'runtime.thread.failed',
|
|
765
|
+
'runtime.thread.cancelled',
|
|
766
|
+
]);
|
|
767
|
+
/**
|
|
768
|
+
* What each vendor agent has done so far in a turn that is still running, as a small feed per
|
|
769
|
+
* thread. A vendor turn's steps only become durable when the turn ends, so this is what shows
|
|
770
|
+
* the agent working in the meantime. It empties for a thread once that turn's result lands.
|
|
771
|
+
*/
|
|
772
|
+
export const vendorLiveFeed = {
|
|
773
|
+
kind: 'liveFold',
|
|
774
|
+
name: 'shuttleVendorLiveFeed',
|
|
775
|
+
initialState: {},
|
|
776
|
+
reduce(state, event) {
|
|
777
|
+
const threadId = event.threadId;
|
|
778
|
+
if (!threadId) {
|
|
779
|
+
return state;
|
|
780
|
+
}
|
|
781
|
+
if (event.ephemeral && VENDOR_STEP_TYPES.has(event.type)) {
|
|
782
|
+
return { ...state, [threadId]: reduceFeed(state[threadId] ?? initialFeed, event) };
|
|
783
|
+
}
|
|
784
|
+
const durableStep = !event.ephemeral && VENDOR_STEP_TYPES.has(event.type);
|
|
785
|
+
if ((durableStep || TURN_ENDED_TYPES.has(event.type)) && threadId in state) {
|
|
786
|
+
return withoutKey(state, threadId);
|
|
787
|
+
}
|
|
788
|
+
return state;
|
|
789
|
+
},
|
|
790
|
+
};
|
|
791
|
+
/** The durable feed with every running vendor turn's steps so far appended. */
|
|
792
|
+
export function withLiveVendorSteps(feed, live) {
|
|
793
|
+
const threads = Object.entries(live);
|
|
794
|
+
if (threads.length === 0) {
|
|
795
|
+
return feed;
|
|
796
|
+
}
|
|
797
|
+
let items = feed.items;
|
|
798
|
+
let vendorAgents = feed.vendorAgents;
|
|
799
|
+
for (const [threadId, steps] of threads) {
|
|
800
|
+
// A thought with nothing after it yet still shows, as its own row.
|
|
801
|
+
items = [...items, ...flushPendingThought(steps, threadId).items];
|
|
802
|
+
vendorAgents = { ...vendorAgents, ...steps.vendorAgents };
|
|
803
|
+
}
|
|
804
|
+
return { ...feed, items, vendorAgents };
|
|
805
|
+
}
|
|
806
|
+
function clearStreamingTurn(state, threadId) {
|
|
807
|
+
return threadId in state ? withoutKey(state, threadId) : state;
|
|
808
|
+
}
|
|
809
|
+
/** Live thinking + reply text each agent has streamed since its last durable message. */
|
|
810
|
+
export const streamingTurns = {
|
|
811
|
+
kind: 'liveFold',
|
|
812
|
+
name: 'shuttleStreamingTurns',
|
|
813
|
+
initialState: {},
|
|
814
|
+
reduce(state, event) {
|
|
815
|
+
const threadId = event.threadId;
|
|
816
|
+
if (!threadId) {
|
|
817
|
+
return state;
|
|
818
|
+
}
|
|
819
|
+
if (event.type === 'agent.message' ||
|
|
820
|
+
event.type === 'agent.turn.settled' ||
|
|
821
|
+
event.type === 'agent.turn.stopped' ||
|
|
822
|
+
event.type === 'runtime.thread.completed' ||
|
|
823
|
+
event.type === 'runtime.thread.failed' ||
|
|
824
|
+
event.type === 'runtime.thread.cancelled') {
|
|
825
|
+
return clearStreamingTurn(state, threadId);
|
|
826
|
+
}
|
|
827
|
+
const payload = jsonFields(event.payload);
|
|
828
|
+
const turn = jsonNumber(payload.turn) ?? state[threadId]?.turn ?? 0;
|
|
829
|
+
const current = state[threadId];
|
|
830
|
+
// A vendor agent's turn has several messages and thoughts. Once one is recorded as a step,
|
|
831
|
+
// it stops being streamed text and the next one starts from empty.
|
|
832
|
+
if (current && event.ephemeral && event.type === 'shuttle.vendor.message') {
|
|
833
|
+
return { ...state, [threadId]: { ...current, text: '' } };
|
|
834
|
+
}
|
|
835
|
+
if (current && event.ephemeral && event.type === 'shuttle.turn.thought') {
|
|
836
|
+
return { ...state, [threadId]: { turn: current.turn, thinking: '', text: current.text } };
|
|
837
|
+
}
|
|
838
|
+
const base = current ?? {
|
|
839
|
+
turn,
|
|
840
|
+
thinking: '',
|
|
841
|
+
text: '',
|
|
842
|
+
};
|
|
843
|
+
if (event.type === 'shuttle.turn.thinking_delta') {
|
|
844
|
+
const delta = jsonText(payload.delta);
|
|
845
|
+
if (!delta) {
|
|
846
|
+
return state;
|
|
847
|
+
}
|
|
848
|
+
const nextTurn = current && current.turn !== turn
|
|
849
|
+
? { turn, thinking: '', text: '', thinkingStartedAt: event.ts }
|
|
850
|
+
: base;
|
|
851
|
+
return {
|
|
852
|
+
...state,
|
|
853
|
+
[threadId]: {
|
|
854
|
+
...nextTurn,
|
|
855
|
+
turn,
|
|
856
|
+
thinking: `${nextTurn.thinking}${delta}`,
|
|
857
|
+
thinkingStartedAt: nextTurn.thinkingStartedAt ?? event.ts,
|
|
858
|
+
thinkingEndedAt: event.ts,
|
|
859
|
+
},
|
|
860
|
+
};
|
|
861
|
+
}
|
|
862
|
+
if (event.type === 'agent.turn.text_delta') {
|
|
863
|
+
const delta = jsonText(payload.delta);
|
|
864
|
+
if (!delta) {
|
|
865
|
+
return state;
|
|
866
|
+
}
|
|
867
|
+
const nextTurn = current && current.turn !== turn ? { turn, thinking: '', text: '' } : base;
|
|
868
|
+
return {
|
|
869
|
+
...state,
|
|
870
|
+
[threadId]: {
|
|
871
|
+
...nextTurn,
|
|
872
|
+
turn,
|
|
873
|
+
text: `${nextTurn.text}${delta}`,
|
|
874
|
+
thinkingEndedAt: nextTurn.thinking ? (nextTurn.thinkingEndedAt ?? event.ts) : undefined,
|
|
875
|
+
},
|
|
876
|
+
};
|
|
877
|
+
}
|
|
878
|
+
return state;
|
|
879
|
+
},
|
|
880
|
+
};
|
|
881
|
+
export function currentBrief(feed) {
|
|
882
|
+
return feed.brief.toSorted((left, right) => right.version - left.version)[0];
|
|
883
|
+
}
|