@myrialabs/clopen 0.2.16 → 0.2.17
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/.env.example +4 -4
- package/backend/utils/env.ts +5 -5
- package/bin/clopen.ts +21 -298
- package/dist/assets/addon-clipboard-wHJhZAA4.js +1 -0
- package/dist/assets/addon-fit-DX4qG4td.js +1 -0
- package/dist/assets/addon-ligatures-DpDY8N_X.js +2 -0
- package/dist/assets/addon-unicode11-Bt8F3D7-.js +7 -0
- package/dist/assets/addon-web-links-DIbG5aQx.js +1 -0
- package/dist/assets/index-C-eR9PGW.js +2 -0
- package/dist/assets/main-D1IISCsM.js +247 -0
- package/dist/assets/main-DzSwlujO.css +1 -0
- package/dist/assets/xterm-B-qIQCd3.js +16 -0
- package/{index.html → dist/index.html} +2 -1
- package/package.json +11 -2
- package/scripts/start.ts +3 -3
- package/shared/utils/logger.ts +1 -1
- package/.dockerignore +0 -5
- package/.github/workflows/ci.yml +0 -86
- package/CONTRIBUTING.md +0 -188
- package/bun.lock +0 -1127
- package/docker-compose.yml +0 -31
- package/frontend/App.svelte +0 -77
- package/frontend/app-environment.ts +0 -10
- package/frontend/app.css +0 -313
- package/frontend/components/auth/InvitePage.svelte +0 -215
- package/frontend/components/auth/LoginPage.svelte +0 -129
- package/frontend/components/auth/SetupPage.svelte +0 -1054
- package/frontend/components/chat/ChatInterface.svelte +0 -426
- package/frontend/components/chat/formatters/ErrorMessage.svelte +0 -57
- package/frontend/components/chat/formatters/MessageFormatter.svelte +0 -244
- package/frontend/components/chat/formatters/TextMessage.svelte +0 -383
- package/frontend/components/chat/formatters/Tools.svelte +0 -79
- package/frontend/components/chat/formatters/index.ts +0 -3
- package/frontend/components/chat/input/ChatInput.svelte +0 -492
- package/frontend/components/chat/input/components/ChatInputActions.svelte +0 -88
- package/frontend/components/chat/input/components/DragDropOverlay.svelte +0 -30
- package/frontend/components/chat/input/components/EditModeIndicator.svelte +0 -33
- package/frontend/components/chat/input/components/EngineModelPicker.svelte +0 -642
- package/frontend/components/chat/input/components/FileAttachmentPreview.svelte +0 -48
- package/frontend/components/chat/input/components/LoadingIndicator.svelte +0 -43
- package/frontend/components/chat/input/composables/use-animations.svelte.ts +0 -217
- package/frontend/components/chat/input/composables/use-chat-actions.svelte.ts +0 -152
- package/frontend/components/chat/input/composables/use-file-handling.svelte.ts +0 -216
- package/frontend/components/chat/input/composables/use-input-state.svelte.ts +0 -357
- package/frontend/components/chat/input/composables/use-textarea-resize.svelte.ts +0 -69
- package/frontend/components/chat/message/ChatMessage.svelte +0 -509
- package/frontend/components/chat/message/ChatMessages.svelte +0 -553
- package/frontend/components/chat/message/DateSeparator.svelte +0 -86
- package/frontend/components/chat/message/MessageBubble.svelte +0 -114
- package/frontend/components/chat/message/MessageHeader.svelte +0 -143
- package/frontend/components/chat/modal/DebugModal.svelte +0 -59
- package/frontend/components/chat/shared/index.ts +0 -2
- package/frontend/components/chat/shared/utils.ts +0 -116
- package/frontend/components/chat/tools/AgentTool.svelte +0 -96
- package/frontend/components/chat/tools/AskUserQuestionTool.svelte +0 -391
- package/frontend/components/chat/tools/BashOutputTool.svelte +0 -35
- package/frontend/components/chat/tools/BashTool.svelte +0 -51
- package/frontend/components/chat/tools/CustomMcpTool.svelte +0 -141
- package/frontend/components/chat/tools/EditTool.svelte +0 -48
- package/frontend/components/chat/tools/EnterPlanModeTool.svelte +0 -24
- package/frontend/components/chat/tools/ExitPlanModeTool.svelte +0 -29
- package/frontend/components/chat/tools/GlobTool.svelte +0 -51
- package/frontend/components/chat/tools/GrepTool.svelte +0 -90
- package/frontend/components/chat/tools/ListMcpResourcesTool.svelte +0 -31
- package/frontend/components/chat/tools/NotebookEditTool.svelte +0 -38
- package/frontend/components/chat/tools/ReadMcpResourceTool.svelte +0 -34
- package/frontend/components/chat/tools/ReadTool.svelte +0 -41
- package/frontend/components/chat/tools/SkillTool.svelte +0 -21
- package/frontend/components/chat/tools/TaskStopTool.svelte +0 -26
- package/frontend/components/chat/tools/TaskTool.svelte +0 -64
- package/frontend/components/chat/tools/TodoWriteTool.svelte +0 -75
- package/frontend/components/chat/tools/WebFetchTool.svelte +0 -35
- package/frontend/components/chat/tools/WebSearchTool.svelte +0 -84
- package/frontend/components/chat/tools/WriteTool.svelte +0 -33
- package/frontend/components/chat/tools/components/CodeBlock.svelte +0 -79
- package/frontend/components/chat/tools/components/DiffBlock.svelte +0 -408
- package/frontend/components/chat/tools/components/FileHeader.svelte +0 -59
- package/frontend/components/chat/tools/components/InfoLine.svelte +0 -19
- package/frontend/components/chat/tools/components/StatsBadges.svelte +0 -27
- package/frontend/components/chat/tools/components/TerminalCommand.svelte +0 -61
- package/frontend/components/chat/tools/components/index.ts +0 -7
- package/frontend/components/chat/tools/index.ts +0 -30
- package/frontend/components/chat/widgets/ContextIndicator.svelte +0 -186
- package/frontend/components/chat/widgets/FloatingTodoList.svelte +0 -367
- package/frontend/components/checkpoint/ConflictResolutionModal.svelte +0 -189
- package/frontend/components/checkpoint/TimelineModal.svelte +0 -447
- package/frontend/components/checkpoint/timeline/TimelineEdge.svelte +0 -26
- package/frontend/components/checkpoint/timeline/TimelineGraph.svelte +0 -87
- package/frontend/components/checkpoint/timeline/TimelineNode.svelte +0 -119
- package/frontend/components/checkpoint/timeline/TimelineVersionGroup.svelte +0 -59
- package/frontend/components/checkpoint/timeline/animation.ts +0 -168
- package/frontend/components/checkpoint/timeline/config.ts +0 -44
- package/frontend/components/checkpoint/timeline/graph-builder.ts +0 -304
- package/frontend/components/checkpoint/timeline/types.ts +0 -69
- package/frontend/components/checkpoint/timeline/utils.ts +0 -53
- package/frontend/components/common/display/AvatarBubble.svelte +0 -56
- package/frontend/components/common/display/Button.svelte +0 -71
- package/frontend/components/common/display/Card.svelte +0 -102
- package/frontend/components/common/display/Icon.svelte +0 -58
- package/frontend/components/common/display/PageTemplate.svelte +0 -76
- package/frontend/components/common/display/ProjectUserAvatars.svelte +0 -79
- package/frontend/components/common/display/ThemeToggle.svelte +0 -44
- package/frontend/components/common/editor/MonacoEditor.svelte +0 -583
- package/frontend/components/common/feedback/Alert.svelte +0 -139
- package/frontend/components/common/feedback/ConnectionBanner.svelte +0 -55
- package/frontend/components/common/feedback/LoadingScreen.svelte +0 -52
- package/frontend/components/common/feedback/LoadingSpinner.svelte +0 -48
- package/frontend/components/common/feedback/NotificationToast.svelte +0 -128
- package/frontend/components/common/feedback/RestartRequiredModal.svelte +0 -53
- package/frontend/components/common/feedback/UpdateBanner.svelte +0 -99
- package/frontend/components/common/form/Checkbox.svelte +0 -48
- package/frontend/components/common/form/FolderBrowser.svelte +0 -856
- package/frontend/components/common/form/Input.svelte +0 -72
- package/frontend/components/common/form/ModelSelector.svelte +0 -110
- package/frontend/components/common/form/Select.svelte +0 -98
- package/frontend/components/common/form/Textarea.svelte +0 -80
- package/frontend/components/common/lucide-icons.ts +0 -1642
- package/frontend/components/common/material-icons.ts +0 -1082
- package/frontend/components/common/media/MediaPreview.svelte +0 -187
- package/frontend/components/common/overlay/Dialog.svelte +0 -251
- package/frontend/components/common/overlay/Lightbox.svelte +0 -233
- package/frontend/components/common/overlay/Modal.svelte +0 -177
- package/frontend/components/common/overlay/ModalProvider.svelte +0 -28
- package/frontend/components/common/xterm/XTerm.svelte +0 -743
- package/frontend/components/common/xterm/index.ts +0 -16
- package/frontend/components/common/xterm/terminal-config.ts +0 -68
- package/frontend/components/common/xterm/types.ts +0 -32
- package/frontend/components/common/xterm/xterm-service.ts +0 -437
- package/frontend/components/files/FileNode.svelte +0 -327
- package/frontend/components/files/FileTree.svelte +0 -690
- package/frontend/components/files/FileViewer.svelte +0 -551
- package/frontend/components/files/SearchResults.svelte +0 -303
- package/frontend/components/git/BranchManager.svelte +0 -446
- package/frontend/components/git/ChangesSection.svelte +0 -196
- package/frontend/components/git/CommitForm.svelte +0 -128
- package/frontend/components/git/ConflictResolver.svelte +0 -158
- package/frontend/components/git/DiffViewer.svelte +0 -298
- package/frontend/components/git/FileChangeItem.svelte +0 -119
- package/frontend/components/git/GitButton.svelte +0 -33
- package/frontend/components/git/GitLog.svelte +0 -401
- package/frontend/components/git/GitModal.svelte +0 -80
- package/frontend/components/history/HistoryModal.svelte +0 -602
- package/frontend/components/history/HistoryView.svelte +0 -561
- package/frontend/components/index.ts +0 -34
- package/frontend/components/preview/browser/BrowserPreview.svelte +0 -558
- package/frontend/components/preview/browser/components/Canvas.svelte +0 -1523
- package/frontend/components/preview/browser/components/ConsolePanel.svelte +0 -757
- package/frontend/components/preview/browser/components/Container.svelte +0 -507
- package/frontend/components/preview/browser/components/ContextMenu.svelte +0 -236
- package/frontend/components/preview/browser/components/SelectDropdown.svelte +0 -224
- package/frontend/components/preview/browser/components/Toolbar.svelte +0 -358
- package/frontend/components/preview/browser/components/VirtualCursor.svelte +0 -36
- package/frontend/components/preview/browser/core/cleanup.svelte.ts +0 -155
- package/frontend/components/preview/browser/core/coordinator.svelte.ts +0 -885
- package/frontend/components/preview/browser/core/interactions.svelte.ts +0 -113
- package/frontend/components/preview/browser/core/mcp-handlers.svelte.ts +0 -331
- package/frontend/components/preview/browser/core/native-ui-handlers.svelte.ts +0 -391
- package/frontend/components/preview/browser/core/stream-handler.svelte.ts +0 -288
- package/frontend/components/preview/browser/core/tab-manager.svelte.ts +0 -210
- package/frontend/components/preview/browser/core/tab-operations.svelte.ts +0 -241
- package/frontend/components/preview/index.ts +0 -2
- package/frontend/components/settings/SettingsModal.svelte +0 -268
- package/frontend/components/settings/SettingsView.svelte +0 -54
- package/frontend/components/settings/account/AccountSettings.svelte +0 -5
- package/frontend/components/settings/admin/InviteManagement.svelte +0 -239
- package/frontend/components/settings/admin/UserManagement.svelte +0 -127
- package/frontend/components/settings/appearance/AppearanceSettings.svelte +0 -104
- package/frontend/components/settings/appearance/LayoutPresetSettings.svelte +0 -160
- package/frontend/components/settings/appearance/LayoutPreview.svelte +0 -76
- package/frontend/components/settings/engines/AIEnginesSettings.svelte +0 -917
- package/frontend/components/settings/general/AdvancedSettings.svelte +0 -193
- package/frontend/components/settings/general/AuthModeSettings.svelte +0 -229
- package/frontend/components/settings/general/DataManagementSettings.svelte +0 -89
- package/frontend/components/settings/general/GeneralSettings.svelte +0 -20
- package/frontend/components/settings/general/UpdateSettings.svelte +0 -130
- package/frontend/components/settings/git/GitSettings.svelte +0 -392
- package/frontend/components/settings/model/EngineModelPicker.svelte +0 -284
- package/frontend/components/settings/model/ModelSettings.svelte +0 -240
- package/frontend/components/settings/notifications/NotificationSettings.svelte +0 -205
- package/frontend/components/settings/security/SecuritySettings.svelte +0 -10
- package/frontend/components/settings/system/SystemSettings.svelte +0 -10
- package/frontend/components/settings/tunnel/TunnelSettings.svelte +0 -1060
- package/frontend/components/settings/user/UserSettings.svelte +0 -270
- package/frontend/components/terminal/Terminal.svelte +0 -338
- package/frontend/components/terminal/TerminalTabs.svelte +0 -88
- package/frontend/components/terminal/TerminalView.svelte +0 -55
- package/frontend/components/tunnel/TunnelActive.svelte +0 -218
- package/frontend/components/tunnel/TunnelButton.svelte +0 -60
- package/frontend/components/tunnel/TunnelInactive.svelte +0 -260
- package/frontend/components/tunnel/TunnelModal.svelte +0 -101
- package/frontend/components/tunnel/TunnelQRCode.svelte +0 -49
- package/frontend/components/workspace/DesktopNavigator.svelte +0 -445
- package/frontend/components/workspace/MobileNavigator.svelte +0 -427
- package/frontend/components/workspace/PanelContainer.svelte +0 -100
- package/frontend/components/workspace/PanelHeader.svelte +0 -664
- package/frontend/components/workspace/ViewMenu.svelte +0 -146
- package/frontend/components/workspace/WorkspaceLayout.svelte +0 -199
- package/frontend/components/workspace/layout/DesktopLayout.svelte +0 -15
- package/frontend/components/workspace/layout/MobileLayout.svelte +0 -17
- package/frontend/components/workspace/layout/split-pane/Container.svelte +0 -42
- package/frontend/components/workspace/layout/split-pane/Handle.svelte +0 -85
- package/frontend/components/workspace/layout/split-pane/Layout.svelte +0 -62
- package/frontend/components/workspace/panels/ChatPanel.svelte +0 -282
- package/frontend/components/workspace/panels/FilesPanel.svelte +0 -1376
- package/frontend/components/workspace/panels/GitPanel.svelte +0 -1601
- package/frontend/components/workspace/panels/PreviewPanel.svelte +0 -153
- package/frontend/components/workspace/panels/TerminalPanel.svelte +0 -73
- package/frontend/main.ts +0 -17
- package/frontend/services/chat/chat.service.ts +0 -975
- package/frontend/services/chat/index.ts +0 -7
- package/frontend/services/favicon.service.ts +0 -103
- package/frontend/services/notification/global-stream-monitor.ts +0 -120
- package/frontend/services/notification/index.ts +0 -8
- package/frontend/services/notification/push.service.ts +0 -144
- package/frontend/services/notification/sound.service.ts +0 -127
- package/frontend/services/preview/browser/browser-console.service.ts +0 -61
- package/frontend/services/preview/browser/browser-webcodecs.service.ts +0 -1643
- package/frontend/services/preview/browser/mcp-integration.svelte.ts +0 -67
- package/frontend/services/preview/index.ts +0 -23
- package/frontend/services/project/index.ts +0 -8
- package/frontend/services/project/status.service.ts +0 -170
- package/frontend/services/snapshot/snapshot.service.ts +0 -86
- package/frontend/services/terminal/background/index.ts +0 -130
- package/frontend/services/terminal/background/session-restore.ts +0 -274
- package/frontend/services/terminal/background/stream-manager.ts +0 -286
- package/frontend/services/terminal/index.ts +0 -14
- package/frontend/services/terminal/persistence.service.ts +0 -260
- package/frontend/services/terminal/project.service.ts +0 -1004
- package/frontend/services/terminal/session.service.ts +0 -364
- package/frontend/services/terminal/terminal.service.ts +0 -379
- package/frontend/stores/core/app.svelte.ts +0 -296
- package/frontend/stores/core/files.svelte.ts +0 -87
- package/frontend/stores/core/presence.svelte.ts +0 -128
- package/frontend/stores/core/projects.svelte.ts +0 -325
- package/frontend/stores/core/sessions.svelte.ts +0 -452
- package/frontend/stores/features/auth.svelte.ts +0 -336
- package/frontend/stores/features/claude-accounts.svelte.ts +0 -58
- package/frontend/stores/features/models.svelte.ts +0 -89
- package/frontend/stores/features/settings.svelte.ts +0 -151
- package/frontend/stores/features/terminal.svelte.ts +0 -747
- package/frontend/stores/features/tunnel-config.svelte.ts +0 -205
- package/frontend/stores/features/tunnel.svelte.ts +0 -277
- package/frontend/stores/features/user.svelte.ts +0 -54
- package/frontend/stores/ui/chat-input.svelte.ts +0 -57
- package/frontend/stores/ui/chat-model.svelte.ts +0 -61
- package/frontend/stores/ui/connection.svelte.ts +0 -40
- package/frontend/stores/ui/dialog.svelte.ts +0 -59
- package/frontend/stores/ui/edit-mode.svelte.ts +0 -214
- package/frontend/stores/ui/notification.svelte.ts +0 -169
- package/frontend/stores/ui/settings-modal.svelte.ts +0 -116
- package/frontend/stores/ui/theme.svelte.ts +0 -179
- package/frontend/stores/ui/todo-panel.svelte.ts +0 -39
- package/frontend/stores/ui/update.svelte.ts +0 -159
- package/frontend/stores/ui/workspace.svelte.ts +0 -798
- package/frontend/utils/chat/date-separator.ts +0 -39
- package/frontend/utils/chat/message-grouper.ts +0 -329
- package/frontend/utils/chat/message-processor.ts +0 -169
- package/frontend/utils/chat/tool-handler.ts +0 -287
- package/frontend/utils/chat/virtual-scroll.svelte.ts +0 -142
- package/frontend/utils/click-outside.ts +0 -20
- package/frontend/utils/context-manager.ts +0 -55
- package/frontend/utils/file-icon-mappings.ts +0 -769
- package/frontend/utils/file-type.ts +0 -68
- package/frontend/utils/folder-icon-mappings.ts +0 -1030
- package/frontend/utils/git-status.ts +0 -68
- package/frontend/utils/native-ui.ts +0 -73
- package/frontend/utils/platform.ts +0 -113
- package/frontend/utils/port-check.ts +0 -65
- package/frontend/utils/preview-constants.ts +0 -45
- package/frontend/utils/terminal-formatter.ts +0 -207
- package/frontend/utils/theme.ts +0 -6
- package/frontend/utils/tree-visualizer.ts +0 -320
- package/frontend/utils/ws.ts +0 -90
- package/scripts/dev.ts +0 -46
- package/scripts/generate-icons.ts +0 -87
- package/svelte.config.js +0 -20
- package/tsconfig.json +0 -41
- package/vite.config.ts +0 -51
- /package/{static → dist}/audio/notification.ogg +0 -0
- /package/{static → dist}/favicon.svg +0 -0
- /package/{static → dist}/fonts/dm-sans/dm-sans-italic-latin-ext.woff2 +0 -0
- /package/{static → dist}/fonts/dm-sans/dm-sans-italic-latin.woff2 +0 -0
- /package/{static → dist}/fonts/dm-sans/dm-sans-normal-latin-ext.woff2 +0 -0
- /package/{static → dist}/fonts/dm-sans/dm-sans-normal-latin.woff2 +0 -0
- /package/{static → dist}/fonts/dm-sans.css +0 -0
- /package/{static → dist}/manifest.json +0 -0
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
shouldEmbedResult,
|
|
3
|
-
shouldHideTool
|
|
4
|
-
} from './message-processor';
|
|
5
|
-
import type {
|
|
6
|
-
ProcessedMessage,
|
|
7
|
-
ToolGroup,
|
|
8
|
-
BackgroundBashData
|
|
9
|
-
} from './message-grouper';
|
|
10
|
-
import type { SDKMessageFormatter } from '$shared/types/database/schema';
|
|
11
|
-
import type { SubAgentActivity } from '$shared/types/messaging';
|
|
12
|
-
|
|
13
|
-
// Extended ToolUse with embedded result and metadata
|
|
14
|
-
export interface ToolUseWithResult {
|
|
15
|
-
type: 'tool_use';
|
|
16
|
-
id: string;
|
|
17
|
-
name: string;
|
|
18
|
-
input: any;
|
|
19
|
-
$result?: any;
|
|
20
|
-
$subMessages?: SubAgentActivity[];
|
|
21
|
-
$skillPrompt?: string;
|
|
22
|
-
metadata?: Record<string, unknown>;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Process a tool message with embedded results
|
|
26
|
-
export function processToolMessage(
|
|
27
|
-
message: ProcessedMessage,
|
|
28
|
-
toolUseMap: Map<string, ToolGroup>,
|
|
29
|
-
backgroundBashMap: Map<string, BackgroundBashData>,
|
|
30
|
-
subAgentMap: Map<string, SDKMessageFormatter[]>,
|
|
31
|
-
skillPromptMap: Map<string, string> = new Map()
|
|
32
|
-
): ProcessedMessage {
|
|
33
|
-
const messageAny = message as any;
|
|
34
|
-
const content = messageAny.message?.content ?
|
|
35
|
-
(Array.isArray(messageAny.message.content) ? messageAny.message.content : [messageAny.message.content]) : [];
|
|
36
|
-
|
|
37
|
-
// Check if parent message is marked as interrupted
|
|
38
|
-
const isInterrupted = !!(messageAny.metadata?.interrupted);
|
|
39
|
-
|
|
40
|
-
// Create modified content with embedded tool_result in tool_use objects
|
|
41
|
-
const modifiedContent = content
|
|
42
|
-
.map((item: any): any => {
|
|
43
|
-
if (typeof item === 'object' && item && 'type' in item && item.type === 'tool_use') {
|
|
44
|
-
const processed = processToolUse(item, toolUseMap, backgroundBashMap, subAgentMap, skillPromptMap);
|
|
45
|
-
// Propagate message-level interrupted flag to ALL tool_use blocks
|
|
46
|
-
if (processed && isInterrupted) {
|
|
47
|
-
return { ...processed, metadata: { ...processed.metadata, interrupted: true } };
|
|
48
|
-
}
|
|
49
|
-
return processed;
|
|
50
|
-
}
|
|
51
|
-
return item;
|
|
52
|
-
})
|
|
53
|
-
.filter((item: any) => item !== null); // Remove null items (hidden tools)
|
|
54
|
-
|
|
55
|
-
// Return modified message with embedded tool_results
|
|
56
|
-
return {
|
|
57
|
-
...message,
|
|
58
|
-
message: {
|
|
59
|
-
...messageAny.message,
|
|
60
|
-
content: modifiedContent
|
|
61
|
-
}
|
|
62
|
-
} as ProcessedMessage;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Process individual tool_use item
|
|
66
|
-
function processToolUse(
|
|
67
|
-
item: any,
|
|
68
|
-
toolUseMap: Map<string, ToolGroup>,
|
|
69
|
-
backgroundBashMap: Map<string, BackgroundBashData>,
|
|
70
|
-
subAgentMap: Map<string, SDKMessageFormatter[]>,
|
|
71
|
-
skillPromptMap: Map<string, string>
|
|
72
|
-
): ToolUseWithResult | null {
|
|
73
|
-
// Hide certain tools completely
|
|
74
|
-
if (shouldHideTool(item.name)) {
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Special handling for Bash with run_in_background
|
|
79
|
-
if (item.name === 'Bash' && item.input &&
|
|
80
|
-
typeof item.input === 'object' &&
|
|
81
|
-
'run_in_background' in item.input &&
|
|
82
|
-
item.input.run_in_background && item.id) {
|
|
83
|
-
return handleBackgroundBash(item, toolUseMap, backgroundBashMap);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Special handling for Agent tool — embed sub-agent activities
|
|
87
|
-
if (item.name === 'Agent' && item.id && subAgentMap.has(item.id)) {
|
|
88
|
-
return handleAgentTool(item, toolUseMap, subAgentMap);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Special handling for Skill tool — embed expanded skill prompt
|
|
92
|
-
if (item.name === 'Skill' && item.id && skillPromptMap.has(item.id)) {
|
|
93
|
-
return handleSkillTool(item, toolUseMap, skillPromptMap);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Regular tool handling
|
|
97
|
-
if (item.id && item.name && shouldEmbedResult(item.name) && toolUseMap.has(item.id)) {
|
|
98
|
-
return handleRegularTool(item, toolUseMap);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return item;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Handle Agent tool — process sub-agent messages into activities
|
|
105
|
-
function handleAgentTool(
|
|
106
|
-
item: any,
|
|
107
|
-
toolUseMap: Map<string, ToolGroup>,
|
|
108
|
-
subAgentMap: Map<string, SDKMessageFormatter[]>
|
|
109
|
-
): ToolUseWithResult {
|
|
110
|
-
const subMessages = subAgentMap.get(item.id) || [];
|
|
111
|
-
const activities = processSubAgentMessages(subMessages);
|
|
112
|
-
|
|
113
|
-
// Also embed the $result if available
|
|
114
|
-
let result: any = undefined;
|
|
115
|
-
if (item.id && toolUseMap.has(item.id)) {
|
|
116
|
-
const group = toolUseMap.get(item.id);
|
|
117
|
-
if (group?.toolResultMessage) {
|
|
118
|
-
const resultMessage = group.toolResultMessage as any;
|
|
119
|
-
const resultContent = resultMessage.message ?
|
|
120
|
-
(Array.isArray(resultMessage.message.content) ? resultMessage.message.content : [resultMessage.message.content]) : [];
|
|
121
|
-
result = findToolResult(resultContent, item.id);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return {
|
|
126
|
-
...item,
|
|
127
|
-
...(result ? { $result: result } : {}),
|
|
128
|
-
...(activities.length > 0 ? { $subMessages: activities } : {})
|
|
129
|
-
} as ToolUseWithResult;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Process sub-agent messages into a flat activity list
|
|
133
|
-
function processSubAgentMessages(messages: SDKMessageFormatter[]): SubAgentActivity[] {
|
|
134
|
-
const activities: SubAgentActivity[] = [];
|
|
135
|
-
const toolResultMap = new Map<string, any>();
|
|
136
|
-
|
|
137
|
-
// First pass: collect all tool_results from user messages
|
|
138
|
-
for (const msg of messages) {
|
|
139
|
-
if (msg.type === 'user' && 'message' in msg && msg.message?.content) {
|
|
140
|
-
const content = Array.isArray(msg.message.content) ? msg.message.content : [msg.message.content];
|
|
141
|
-
for (const item of content) {
|
|
142
|
-
if (typeof item === 'object' && item && item.type === 'tool_result' && item.tool_use_id) {
|
|
143
|
-
toolResultMap.set(item.tool_use_id, item);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Second pass: build activity list from assistant messages
|
|
150
|
-
for (const msg of messages) {
|
|
151
|
-
if (msg.type === 'assistant' && 'message' in msg && msg.message?.content) {
|
|
152
|
-
const content = Array.isArray(msg.message.content) ? msg.message.content : [msg.message.content];
|
|
153
|
-
for (const item of content) {
|
|
154
|
-
if (typeof item === 'object' && item) {
|
|
155
|
-
if (item.type === 'tool_use') {
|
|
156
|
-
activities.push({
|
|
157
|
-
type: 'tool_use',
|
|
158
|
-
toolName: item.name,
|
|
159
|
-
toolInput: item.input,
|
|
160
|
-
toolResult: toolResultMap.get(item.id) || undefined
|
|
161
|
-
});
|
|
162
|
-
} else if (item.type === 'text' && item.text?.trim()) {
|
|
163
|
-
activities.push({
|
|
164
|
-
type: 'text',
|
|
165
|
-
text: item.text
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return activities;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// Handle Skill tool — embed expanded skill prompt
|
|
177
|
-
function handleSkillTool(
|
|
178
|
-
item: any,
|
|
179
|
-
toolUseMap: Map<string, ToolGroup>,
|
|
180
|
-
skillPromptMap: Map<string, string>
|
|
181
|
-
): ToolUseWithResult {
|
|
182
|
-
const skillPrompt = skillPromptMap.get(item.id);
|
|
183
|
-
|
|
184
|
-
// Also embed the $result if available
|
|
185
|
-
let result: any = undefined;
|
|
186
|
-
if (item.id && toolUseMap.has(item.id)) {
|
|
187
|
-
const group = toolUseMap.get(item.id);
|
|
188
|
-
if (group?.toolResultMessage) {
|
|
189
|
-
const resultMessage = group.toolResultMessage as any;
|
|
190
|
-
const resultContent = resultMessage.message ?
|
|
191
|
-
(Array.isArray(resultMessage.message.content) ? resultMessage.message.content : [resultMessage.message.content]) : [];
|
|
192
|
-
result = findToolResult(resultContent, item.id);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
return {
|
|
197
|
-
...item,
|
|
198
|
-
...(result ? { $result: result } : {}),
|
|
199
|
-
...(skillPrompt ? { $skillPrompt: skillPrompt } : {})
|
|
200
|
-
} as ToolUseWithResult;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// Handle background bash commands
|
|
204
|
-
function handleBackgroundBash(
|
|
205
|
-
item: any,
|
|
206
|
-
toolUseMap: Map<string, ToolGroup>,
|
|
207
|
-
backgroundBashMap: Map<string, BackgroundBashData>
|
|
208
|
-
): ToolUseWithResult {
|
|
209
|
-
const group = toolUseMap.get(item.id);
|
|
210
|
-
if (!group?.toolResultMessage) return item;
|
|
211
|
-
|
|
212
|
-
const resultMessage = group.toolResultMessage as any;
|
|
213
|
-
const resultContent = resultMessage.message ?
|
|
214
|
-
(Array.isArray(resultMessage.message.content) ? resultMessage.message.content : [resultMessage.message.content]) : [];
|
|
215
|
-
|
|
216
|
-
const toolResult = findToolResult(resultContent, item.id);
|
|
217
|
-
|
|
218
|
-
if (!toolResult?.content || typeof toolResult.content !== 'string') return item;
|
|
219
|
-
|
|
220
|
-
// Extract bash ID and check for BashOutput
|
|
221
|
-
const idMatch = toolResult.content.match(/Command running in background with ID:\s*(\w+)/);
|
|
222
|
-
if (!idMatch) return item;
|
|
223
|
-
|
|
224
|
-
const bashId = idMatch[1];
|
|
225
|
-
const bashData = backgroundBashMap.get(bashId);
|
|
226
|
-
|
|
227
|
-
if (bashData && bashData.bashOutputs.length > 0) {
|
|
228
|
-
// Use the last BashOutput result
|
|
229
|
-
const lastOutput = bashData.bashOutputs[bashData.bashOutputs.length - 1];
|
|
230
|
-
return {
|
|
231
|
-
...item,
|
|
232
|
-
$result: {
|
|
233
|
-
...toolResult,
|
|
234
|
-
content: lastOutput.content || ""
|
|
235
|
-
}
|
|
236
|
-
} as ToolUseWithResult;
|
|
237
|
-
} else {
|
|
238
|
-
// No BashOutput found, clear the content
|
|
239
|
-
return {
|
|
240
|
-
...item,
|
|
241
|
-
$result: {
|
|
242
|
-
...toolResult,
|
|
243
|
-
content: ""
|
|
244
|
-
}
|
|
245
|
-
} as ToolUseWithResult;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// Handle regular tools
|
|
250
|
-
function handleRegularTool(
|
|
251
|
-
item: any,
|
|
252
|
-
toolUseMap: Map<string, ToolGroup>
|
|
253
|
-
): ToolUseWithResult {
|
|
254
|
-
const group = toolUseMap.get(item.id);
|
|
255
|
-
if (!group || !group.toolResultMessage) return item;
|
|
256
|
-
|
|
257
|
-
const resultMessage = group.toolResultMessage as any;
|
|
258
|
-
const resultContent = resultMessage.message ?
|
|
259
|
-
(Array.isArray(resultMessage.message.content) ? resultMessage.message.content : [resultMessage.message.content]) : [];
|
|
260
|
-
|
|
261
|
-
const toolResult = findToolResult(resultContent, item.id);
|
|
262
|
-
|
|
263
|
-
if (toolResult) {
|
|
264
|
-
// Embed tool_result as $result property in tool_use object
|
|
265
|
-
return {
|
|
266
|
-
...item,
|
|
267
|
-
$result: toolResult
|
|
268
|
-
} as ToolUseWithResult;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
return item;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// Helper to find tool result by id
|
|
275
|
-
function findToolResult(
|
|
276
|
-
content: any[],
|
|
277
|
-
toolUseId: string
|
|
278
|
-
): any {
|
|
279
|
-
return content.find((resultItem: any) =>
|
|
280
|
-
typeof resultItem === 'object' &&
|
|
281
|
-
resultItem !== null &&
|
|
282
|
-
'type' in resultItem &&
|
|
283
|
-
resultItem.type === 'tool_result' &&
|
|
284
|
-
'tool_use_id' in resultItem &&
|
|
285
|
-
resultItem.tool_use_id === toolUseId
|
|
286
|
-
);
|
|
287
|
-
}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Virtual Scroll for Chat Messages
|
|
3
|
-
*
|
|
4
|
-
* Manages a sliding window over the full message list,
|
|
5
|
-
* only rendering a subset to the DOM for performance.
|
|
6
|
-
* No placeholder divs — uses scroll position preservation instead.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { debug } from '$shared/utils/logger';
|
|
10
|
-
|
|
11
|
-
export const VS_CONFIG = {
|
|
12
|
-
/** Max messages rendered at once */
|
|
13
|
-
WINDOW_SIZE: 50,
|
|
14
|
-
/** Messages to load when hitting a sentinel */
|
|
15
|
-
BUFFER_SIZE: 20,
|
|
16
|
-
/** Trim when window exceeds this count */
|
|
17
|
-
TRIM_THRESHOLD: 80,
|
|
18
|
-
} as const;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Creates a virtual scroll state manager for chat messages.
|
|
22
|
-
* Only manages window bounds — the component handles DOM/observers.
|
|
23
|
-
*/
|
|
24
|
-
export function createVirtualScroll() {
|
|
25
|
-
const { WINDOW_SIZE, BUFFER_SIZE, TRIM_THRESHOLD } = VS_CONFIG;
|
|
26
|
-
|
|
27
|
-
let windowStart = $state(0);
|
|
28
|
-
let windowEnd = $state(0);
|
|
29
|
-
let totalCount = $state(0);
|
|
30
|
-
let isActive = $state(false);
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Initialize/reset window for a given count, anchored to bottom.
|
|
34
|
-
*/
|
|
35
|
-
function reset(count: number) {
|
|
36
|
-
totalCount = count;
|
|
37
|
-
if (count <= WINDOW_SIZE) {
|
|
38
|
-
windowStart = 0;
|
|
39
|
-
windowEnd = count;
|
|
40
|
-
isActive = false;
|
|
41
|
-
} else {
|
|
42
|
-
windowStart = count - WINDOW_SIZE;
|
|
43
|
-
windowEnd = count;
|
|
44
|
-
isActive = true;
|
|
45
|
-
}
|
|
46
|
-
debug.log('chat', `[VirtualScroll] Reset: ${windowStart}..${windowEnd} of ${count}, active=${isActive}`);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Sync with new total (messages added during streaming).
|
|
51
|
-
* Keeps window anchored to bottom when appropriate.
|
|
52
|
-
*/
|
|
53
|
-
function sync(newTotal: number, isAtBottom: boolean, isStreaming: boolean) {
|
|
54
|
-
totalCount = newTotal;
|
|
55
|
-
|
|
56
|
-
if (newTotal <= WINDOW_SIZE) {
|
|
57
|
-
windowStart = 0;
|
|
58
|
-
windowEnd = newTotal;
|
|
59
|
-
isActive = false;
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
isActive = true;
|
|
64
|
-
|
|
65
|
-
// Extend window end to include new messages when at bottom or streaming
|
|
66
|
-
if (isAtBottom || isStreaming) {
|
|
67
|
-
windowEnd = newTotal;
|
|
68
|
-
// Auto-trim top if window grew too large and user is at bottom
|
|
69
|
-
if (windowEnd - windowStart > TRIM_THRESHOLD && isAtBottom) {
|
|
70
|
-
windowStart = windowEnd - WINDOW_SIZE;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Expand window upward (older messages). Returns count added.
|
|
77
|
-
*/
|
|
78
|
-
function expandUp(): number {
|
|
79
|
-
if (windowStart <= 0) return 0;
|
|
80
|
-
const count = Math.min(BUFFER_SIZE, windowStart);
|
|
81
|
-
windowStart -= count;
|
|
82
|
-
debug.log('chat', `[VirtualScroll] Expand up +${count}: ${windowStart}..${windowEnd}`);
|
|
83
|
-
return count;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Expand window downward (newer messages). Returns count added.
|
|
88
|
-
*/
|
|
89
|
-
function expandDown(): number {
|
|
90
|
-
if (windowEnd >= totalCount) return 0;
|
|
91
|
-
const count = Math.min(BUFFER_SIZE, totalCount - windowEnd);
|
|
92
|
-
windowEnd += count;
|
|
93
|
-
debug.log('chat', `[VirtualScroll] Expand down +${count}: ${windowStart}..${windowEnd}`);
|
|
94
|
-
return count;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/** Trim excess messages from top of window. */
|
|
98
|
-
function trimTop() {
|
|
99
|
-
if (windowEnd - windowStart <= WINDOW_SIZE) return;
|
|
100
|
-
windowStart = windowEnd - WINDOW_SIZE;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/** Trim excess messages from bottom of window. */
|
|
104
|
-
function trimBottom() {
|
|
105
|
-
if (windowEnd - windowStart <= WINDOW_SIZE) return;
|
|
106
|
-
windowEnd = windowStart + WINDOW_SIZE;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Ensure a specific index is visible in the window.
|
|
111
|
-
* Used for edit mode / scroll-to-message.
|
|
112
|
-
*/
|
|
113
|
-
function ensureVisible(index: number) {
|
|
114
|
-
if (index >= windowStart && index < windowEnd) return;
|
|
115
|
-
|
|
116
|
-
if (index < windowStart) {
|
|
117
|
-
windowStart = Math.max(0, index - 5);
|
|
118
|
-
windowEnd = Math.min(totalCount, windowStart + WINDOW_SIZE);
|
|
119
|
-
} else {
|
|
120
|
-
windowEnd = Math.min(totalCount, index + 6);
|
|
121
|
-
windowStart = Math.max(0, windowEnd - WINDOW_SIZE);
|
|
122
|
-
}
|
|
123
|
-
isActive = totalCount > WINDOW_SIZE;
|
|
124
|
-
debug.log('chat', `[VirtualScroll] Ensure visible ${index}: ${windowStart}..${windowEnd}`);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return {
|
|
128
|
-
get windowStart() { return windowStart; },
|
|
129
|
-
get windowEnd() { return windowEnd; },
|
|
130
|
-
get totalCount() { return totalCount; },
|
|
131
|
-
get isActive() { return isActive; },
|
|
132
|
-
get hasMoreAbove() { return windowStart > 0; },
|
|
133
|
-
get hasMoreBelow() { return windowEnd < totalCount; },
|
|
134
|
-
reset,
|
|
135
|
-
sync,
|
|
136
|
-
expandUp,
|
|
137
|
-
expandDown,
|
|
138
|
-
trimTop,
|
|
139
|
-
trimBottom,
|
|
140
|
-
ensureVisible,
|
|
141
|
-
};
|
|
142
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Click Outside Action
|
|
3
|
-
* Svelte action for detecting clicks outside an element
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export function clickOutside(node: HTMLElement, callback: () => void) {
|
|
7
|
-
const handleClick = (event: MouseEvent) => {
|
|
8
|
-
if (!node.contains(event.target as Node)) {
|
|
9
|
-
callback();
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
document.addEventListener('click', handleClick, true);
|
|
14
|
-
|
|
15
|
-
return {
|
|
16
|
-
destroy() {
|
|
17
|
-
document.removeEventListener('click', handleClick, true);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Context Window Usage
|
|
3
|
-
*
|
|
4
|
-
* Calculates actual context window usage from assistant message token data.
|
|
5
|
-
* Each API call sends the full conversation, so input_tokens on the last
|
|
6
|
-
* assistant message represents total context consumed at that turn.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { SDKMessage } from '$shared/types/messaging';
|
|
10
|
-
|
|
11
|
-
const WARNING_THRESHOLD = 0.8;
|
|
12
|
-
|
|
13
|
-
export interface ContextUsage {
|
|
14
|
-
current: number;
|
|
15
|
-
max: number;
|
|
16
|
-
percentage: number;
|
|
17
|
-
nearLimit: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Get context window usage from the last assistant message.
|
|
22
|
-
*
|
|
23
|
-
* Cache tokens (creation + read) also count toward the context window.
|
|
24
|
-
*/
|
|
25
|
-
export function getContextUsage(messages: SDKMessage[], contextWindow: number): ContextUsage {
|
|
26
|
-
// Find the last assistant message with usage data (iterate backwards)
|
|
27
|
-
let lastUsage: { input_tokens: number; cache_creation_input_tokens?: number; cache_read_input_tokens?: number } | null = null;
|
|
28
|
-
for (let i = messages.length - 1; i >= 0; i--) {
|
|
29
|
-
const msg = messages[i];
|
|
30
|
-
if (msg.type === 'assistant' && 'message' in msg) {
|
|
31
|
-
const usage = (msg as any).message?.usage;
|
|
32
|
-
if (usage && typeof usage.input_tokens === 'number') {
|
|
33
|
-
lastUsage = usage;
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (!lastUsage) {
|
|
40
|
-
return { current: 0, max: contextWindow, percentage: 0, nearLimit: false };
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const current = (lastUsage.input_tokens || 0)
|
|
44
|
-
+ (lastUsage.cache_creation_input_tokens || 0)
|
|
45
|
-
+ (lastUsage.cache_read_input_tokens || 0);
|
|
46
|
-
|
|
47
|
-
const percentage = Math.min(100, Math.round((current / contextWindow) * 1000) / 10);
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
current,
|
|
51
|
-
max: contextWindow,
|
|
52
|
-
percentage,
|
|
53
|
-
nearLimit: current >= contextWindow * WARNING_THRESHOLD
|
|
54
|
-
};
|
|
55
|
-
}
|