@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,206 @@
|
|
|
1
|
+
import { jsonFields, jsonNumber } from '../../lib/json.js';
|
|
2
|
+
import { currentBrief } from './session-feed.js';
|
|
3
|
+
const CATEGORY_META = {
|
|
4
|
+
brief: { label: 'Brief', color: 'oklch(0.72 0.04 265)' },
|
|
5
|
+
playbook: { label: 'Playbook', color: 'oklch(0.76 0.13 155)' },
|
|
6
|
+
tools: { label: 'Tool activity', color: 'oklch(0.74 0.12 300)' },
|
|
7
|
+
conversation: { label: 'Conversation', color: 'oklch(0.7 0.16 25)' },
|
|
8
|
+
other: { label: 'System & tools', color: 'oklch(0.74 0.13 245)' },
|
|
9
|
+
};
|
|
10
|
+
const initialUsage = {
|
|
11
|
+
lastTurn: null,
|
|
12
|
+
totals: { input: 0, output: 0 },
|
|
13
|
+
};
|
|
14
|
+
/** ~4 chars per token — good enough for relative segment sizing. */
|
|
15
|
+
export function estimateTokens(text) {
|
|
16
|
+
const trimmed = text.trim();
|
|
17
|
+
if (!trimmed) {
|
|
18
|
+
return 0;
|
|
19
|
+
}
|
|
20
|
+
return Math.max(1, Math.ceil(trimmed.length / 4));
|
|
21
|
+
}
|
|
22
|
+
export function formatTokenCount(tokens) {
|
|
23
|
+
if (tokens < 1_000) {
|
|
24
|
+
return String(Math.round(tokens));
|
|
25
|
+
}
|
|
26
|
+
if (tokens < 1_000_000) {
|
|
27
|
+
return `${(tokens / 1_000).toFixed(1).replace(/\.0$/, '')}K`;
|
|
28
|
+
}
|
|
29
|
+
return `${(tokens / 1_000_000).toFixed(1).replace(/\.0$/, '')}M`;
|
|
30
|
+
}
|
|
31
|
+
export function formatTokenTotal(tokens) {
|
|
32
|
+
if (tokens < 1_000) {
|
|
33
|
+
return String(Math.round(tokens));
|
|
34
|
+
}
|
|
35
|
+
if (tokens < 1_000_000) {
|
|
36
|
+
return `${Math.round(tokens / 1_000)}K`;
|
|
37
|
+
}
|
|
38
|
+
const millions = tokens / 1_000_000;
|
|
39
|
+
return Number.isInteger(millions) ? `${millions}M` : `${millions.toFixed(1)}M`;
|
|
40
|
+
}
|
|
41
|
+
function estimateFromFeed(feed) {
|
|
42
|
+
const brief = currentBrief(feed);
|
|
43
|
+
const briefTokens = brief ? estimateTokens(brief.text) : 0;
|
|
44
|
+
const playbookTokens = estimateTokens(feed.playbook.lessons.map((lesson) => lesson.text).join('\n'));
|
|
45
|
+
let conversationTokens = 0;
|
|
46
|
+
let toolTokens = 0;
|
|
47
|
+
for (const item of feed.items) {
|
|
48
|
+
switch (item.kind) {
|
|
49
|
+
case 'user': {
|
|
50
|
+
// Goal text is already counted under Brief.
|
|
51
|
+
if (!item.goal) {
|
|
52
|
+
conversationTokens += estimateTokens(item.text);
|
|
53
|
+
}
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
case 'agent': {
|
|
57
|
+
conversationTokens += estimateTokens(item.text);
|
|
58
|
+
if (item.thought) {
|
|
59
|
+
conversationTokens += estimateTokens(item.thought.text);
|
|
60
|
+
}
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
case 'thought': {
|
|
64
|
+
conversationTokens += estimateTokens(item.text);
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
case 'tools': {
|
|
68
|
+
for (const thought of item.thoughts) {
|
|
69
|
+
conversationTokens += estimateTokens(thought.text);
|
|
70
|
+
}
|
|
71
|
+
for (const call of item.calls) {
|
|
72
|
+
toolTokens += estimateTokens(JSON.stringify(call.args ?? null));
|
|
73
|
+
if (call.result !== undefined) {
|
|
74
|
+
toolTokens += estimateTokens(JSON.stringify(call.result));
|
|
75
|
+
}
|
|
76
|
+
if (call.error) {
|
|
77
|
+
toolTokens += estimateTokens(call.error);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
case 'question': {
|
|
83
|
+
conversationTokens += estimateTokens(item.title);
|
|
84
|
+
if (item.thought) {
|
|
85
|
+
conversationTokens += estimateTokens(item.thought.text);
|
|
86
|
+
}
|
|
87
|
+
if (item.decision?.answer) {
|
|
88
|
+
conversationTokens += estimateTokens(item.decision.answer);
|
|
89
|
+
}
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
case 'media':
|
|
93
|
+
case 'notice': {
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
default: {
|
|
97
|
+
const exhaustive = item;
|
|
98
|
+
return exhaustive;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
brief: briefTokens,
|
|
104
|
+
playbook: playbookTokens,
|
|
105
|
+
tools: toolTokens,
|
|
106
|
+
conversation: conversationTokens,
|
|
107
|
+
other: 0,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function toSegments(counts) {
|
|
111
|
+
const order = ['other', 'brief', 'playbook', 'tools', 'conversation'];
|
|
112
|
+
return order
|
|
113
|
+
.filter((id) => counts[id] > 0)
|
|
114
|
+
.map((id) => ({
|
|
115
|
+
id,
|
|
116
|
+
label: CATEGORY_META[id].label,
|
|
117
|
+
tokens: counts[id],
|
|
118
|
+
color: CATEGORY_META[id].color,
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Build a Cursor-style context report.
|
|
123
|
+
*
|
|
124
|
+
* Prefers billed last-turn input when present; otherwise falls back to char-based
|
|
125
|
+
* estimates from the session feed so the meter still works while streaming usage
|
|
126
|
+
* reports `input: 0`.
|
|
127
|
+
*/
|
|
128
|
+
export function buildContextUsageReport(usage, feed, window) {
|
|
129
|
+
const estimates = estimateFromFeed(feed);
|
|
130
|
+
const estimatedSum = estimates.brief + estimates.playbook + estimates.tools + estimates.conversation;
|
|
131
|
+
const billedInput = usage.lastTurn?.input ?? 0;
|
|
132
|
+
let counts;
|
|
133
|
+
let used;
|
|
134
|
+
let estimated;
|
|
135
|
+
if (billedInput > 0) {
|
|
136
|
+
estimated = false;
|
|
137
|
+
used = billedInput;
|
|
138
|
+
if (estimatedSum === 0) {
|
|
139
|
+
counts = { brief: 0, playbook: 0, tools: 0, conversation: 0, other: billedInput };
|
|
140
|
+
}
|
|
141
|
+
else if (estimatedSum <= billedInput) {
|
|
142
|
+
counts = { ...estimates, other: billedInput - estimatedSum };
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
const scale = billedInput / estimatedSum;
|
|
146
|
+
counts = {
|
|
147
|
+
brief: Math.round(estimates.brief * scale),
|
|
148
|
+
playbook: Math.round(estimates.playbook * scale),
|
|
149
|
+
tools: Math.round(estimates.tools * scale),
|
|
150
|
+
conversation: Math.round(estimates.conversation * scale),
|
|
151
|
+
other: 0,
|
|
152
|
+
};
|
|
153
|
+
const scaledSum = counts.brief + counts.playbook + counts.tools + counts.conversation;
|
|
154
|
+
const drift = billedInput - scaledSum;
|
|
155
|
+
if (drift !== 0) {
|
|
156
|
+
const anchor = counts.conversation > 0 ? 'conversation' : counts.tools > 0 ? 'tools' : 'other';
|
|
157
|
+
counts = { ...counts, [anchor]: counts[anchor] + drift };
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
estimated = estimatedSum > 0;
|
|
163
|
+
used = estimatedSum;
|
|
164
|
+
counts = estimates;
|
|
165
|
+
}
|
|
166
|
+
const safeWindow = Math.max(1, window);
|
|
167
|
+
const percent = Math.min(100, Math.round((used / safeWindow) * 100));
|
|
168
|
+
return {
|
|
169
|
+
used,
|
|
170
|
+
window: safeWindow,
|
|
171
|
+
percent,
|
|
172
|
+
estimated,
|
|
173
|
+
segments: toSegments(counts),
|
|
174
|
+
lastTurn: usage.lastTurn,
|
|
175
|
+
totals: usage.totals,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function reduceUsage(state, event) {
|
|
179
|
+
if (event.type !== 'agent.turn.usage') {
|
|
180
|
+
return state;
|
|
181
|
+
}
|
|
182
|
+
const payload = jsonFields(event.payload);
|
|
183
|
+
const input = jsonNumber(payload.input) ?? 0;
|
|
184
|
+
const output = jsonNumber(payload.output) ?? 0;
|
|
185
|
+
const turn = jsonNumber(payload.turn) ?? 0;
|
|
186
|
+
const lastTurn = {
|
|
187
|
+
threadId: event.threadId,
|
|
188
|
+
turn,
|
|
189
|
+
input,
|
|
190
|
+
output,
|
|
191
|
+
ts: event.ts,
|
|
192
|
+
};
|
|
193
|
+
return {
|
|
194
|
+
lastTurn,
|
|
195
|
+
totals: {
|
|
196
|
+
input: state.totals.input + input,
|
|
197
|
+
output: state.totals.output + output,
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
/** Client-side fold of `agent.turn.usage` for the context meter. */
|
|
202
|
+
export const contextUsage = {
|
|
203
|
+
name: 'shuttleContextUsage',
|
|
204
|
+
initialState: initialUsage,
|
|
205
|
+
reduce: reduceUsage,
|
|
206
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ThreadNode } from '@swirls/looms/core';
|
|
2
|
+
import type { AgentIdentity } from './agents.js';
|
|
3
|
+
import { type SessionActivityState } from './session-activity.js';
|
|
4
|
+
import { type SessionFeed, type StreamingTurn } from './session-feed.js';
|
|
5
|
+
/** Shows something in the artifacts pane, such as the workspace or a preview by port. */
|
|
6
|
+
export type OpenArtifact = (kind: 'files' | 'browser' | 'terminal' | 'review' | 'media', target?: string) => void;
|
|
7
|
+
export declare function Conversation({ runId, feed, activity, streaming, identities, onInspect, onOpenArtifact, root, openThreadId, onOpenThread, }: {
|
|
8
|
+
runId: string;
|
|
9
|
+
feed: SessionFeed;
|
|
10
|
+
activity: SessionActivityState;
|
|
11
|
+
streaming: Readonly<Record<string, StreamingTurn>>;
|
|
12
|
+
identities: ReadonlyMap<string, AgentIdentity>;
|
|
13
|
+
onInspect: (threadId: string, seq?: number) => void;
|
|
14
|
+
/** Left out, messages carry no links into the artifacts pane. */
|
|
15
|
+
onOpenArtifact?: OpenArtifact;
|
|
16
|
+
/** The session's threads, which decide what the timeline folds away. */
|
|
17
|
+
root: ThreadNode | null;
|
|
18
|
+
/** The agent whose own timeline is open. Left out, it is the session's top level. */
|
|
19
|
+
openThreadId?: string;
|
|
20
|
+
onOpenThread: (threadId: string) => void;
|
|
21
|
+
}): import("react").JSX.Element;
|