repoburg 1.3.188 → 1.3.196
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/agent-pane/.prettierignore +5 -0
- package/agent-pane/.prettierrc +8 -0
- package/agent-pane/backend/coverage/base.css +224 -0
- package/agent-pane/backend/coverage/block-navigation.js +87 -0
- package/agent-pane/backend/coverage/clover.xml +887 -0
- package/agent-pane/backend/coverage/coverage-final.json +10 -0
- package/agent-pane/backend/coverage/favicon.png +0 -0
- package/agent-pane/backend/coverage/index.html +176 -0
- package/agent-pane/backend/coverage/prettify.css +1 -0
- package/agent-pane/backend/coverage/prettify.js +2 -0
- package/agent-pane/backend/coverage/sort-arrow-sprite.png +0 -0
- package/agent-pane/backend/coverage/sorter.js +210 -0
- package/agent-pane/backend/coverage/src/codex/codex-provider.ts.html +1402 -0
- package/agent-pane/backend/coverage/src/codex/index.html +131 -0
- package/agent-pane/backend/coverage/src/codex/item-mapper.ts.html +331 -0
- package/agent-pane/backend/coverage/src/db/index.html +131 -0
- package/agent-pane/backend/coverage/src/db/index.ts.html +436 -0
- package/agent-pane/backend/coverage/src/db/schema.ts.html +175 -0
- package/agent-pane/backend/coverage/src/index.html +116 -0
- package/agent-pane/backend/coverage/src/index.ts.html +262 -0
- package/agent-pane/backend/coverage/src/routes/index.html +146 -0
- package/agent-pane/backend/coverage/src/routes/sessions.ts.html +991 -0
- package/agent-pane/backend/coverage/src/routes/turns.ts.html +256 -0
- package/agent-pane/backend/coverage/src/routes/workspaces.ts.html +406 -0
- package/agent-pane/backend/coverage/src/ws/index.html +116 -0
- package/agent-pane/backend/coverage/src/ws/index.ts.html +238 -0
- package/agent-pane/backend/data.db +0 -0
- package/agent-pane/backend/data.db-shm +0 -0
- package/agent-pane/backend/data.db-wal +0 -0
- package/agent-pane/backend/dist/index.js +70869 -0
- package/agent-pane/backend/package-lock.json +4529 -1013
- package/agent-pane/backend/package.json +10 -6
- package/agent-pane/backend/src/claude/claude-message-mapper.test.ts +163 -0
- package/agent-pane/backend/src/claude/claude-message-mapper.ts +154 -0
- package/agent-pane/backend/src/claude/claude-provider.test.ts +65 -0
- package/agent-pane/backend/src/claude/claude-provider.ts +482 -0
- package/agent-pane/backend/src/claude/claude-types.ts +33 -0
- package/agent-pane/backend/src/codex/app-server-client.test.ts +183 -0
- package/agent-pane/backend/src/codex/app-server-client.ts +225 -0
- package/agent-pane/backend/src/codex/app-server-types.ts +259 -0
- package/agent-pane/backend/src/codex/codex-provider-runtime-config.test.ts +56 -0
- package/agent-pane/backend/src/codex/codex-provider.test.ts +60 -0
- package/agent-pane/backend/src/codex/codex-provider.ts +521 -265
- package/agent-pane/backend/src/codex/item-mapper.test.ts +221 -0
- package/agent-pane/backend/src/codex/item-mapper.ts +35 -8
- package/agent-pane/backend/src/codex/shared-app-server.ts +25 -0
- package/agent-pane/backend/src/db/index.test.ts +125 -0
- package/agent-pane/backend/src/db/index.ts +39 -8
- package/agent-pane/backend/src/db/schema.ts +28 -74
- package/agent-pane/backend/src/index.ts +29 -2
- package/agent-pane/backend/src/integration/__fixtures__/cancel-turn.json +29 -0
- package/agent-pane/backend/src/integration/__fixtures__/delta-streaming.json +40 -0
- package/agent-pane/backend/src/integration/__fixtures__/failed-turn.json +16 -0
- package/agent-pane/backend/src/integration/__fixtures__/mcp-tool-call.json +60 -0
- package/agent-pane/backend/src/integration/__fixtures__/missing-item-started.json +34 -0
- package/agent-pane/backend/src/integration/__fixtures__/multi-item-turn.json +85 -0
- package/agent-pane/backend/src/integration/__fixtures__/multi-turn.json +48 -0
- package/agent-pane/backend/src/integration/__fixtures__/simple-turn.json +35 -0
- package/agent-pane/backend/src/integration/delta-streaming.test.ts +130 -0
- package/agent-pane/backend/src/integration/helpers/app-server-mock.ts +272 -0
- package/agent-pane/backend/src/integration/helpers/test-app.ts +108 -0
- package/agent-pane/backend/src/integration/helpers/ws-capture.ts +64 -0
- package/agent-pane/backend/src/integration/item-lifecycle.test.ts +133 -0
- package/agent-pane/backend/src/integration/mcp-tool-call.test.ts +102 -0
- package/agent-pane/backend/src/integration/missing-item-started.test.ts +91 -0
- package/agent-pane/backend/src/integration/multi-turn.test.ts +121 -0
- package/agent-pane/backend/src/integration/session-operations.test.ts +168 -0
- package/agent-pane/backend/src/integration/title-generation.test.ts +109 -0
- package/agent-pane/backend/src/integration/turn-cancel.test.ts +111 -0
- package/agent-pane/backend/src/integration/turn-failure.test.ts +97 -0
- package/agent-pane/backend/src/integration/turn-lifecycle.test.ts +141 -0
- package/agent-pane/backend/src/providers/index.ts +14 -0
- package/agent-pane/backend/src/providers/registry.test.ts +92 -0
- package/agent-pane/backend/src/providers/registry.ts +43 -0
- package/agent-pane/backend/src/providers/runtime-provider.ts +25 -0
- package/agent-pane/backend/src/routes/files.ts +31 -0
- package/agent-pane/backend/src/routes/mcp.ts +33 -0
- package/agent-pane/backend/src/routes/models.test.ts +92 -0
- package/agent-pane/backend/src/routes/models.ts +16 -0
- package/agent-pane/backend/src/routes/plugins.ts +40 -0
- package/agent-pane/backend/src/routes/providers.test.ts +69 -0
- package/agent-pane/backend/src/routes/providers.ts +57 -0
- package/agent-pane/backend/src/routes/sessions.test.ts +424 -0
- package/agent-pane/backend/src/routes/sessions.ts +295 -42
- package/agent-pane/backend/src/routes/skills.test.ts +114 -0
- package/agent-pane/backend/src/routes/skills.ts +70 -0
- package/agent-pane/backend/src/routes/turns.test.ts +152 -0
- package/agent-pane/backend/src/routes/turns.ts +36 -16
- package/agent-pane/backend/src/routes/workspaces.test.ts +197 -0
- package/agent-pane/backend/src/routes/workspaces.ts +73 -55
- package/agent-pane/backend/src/ws/index.test.ts +107 -0
- package/agent-pane/backend/src/ws/index.ts +19 -11
- package/agent-pane/backend/tsconfig.json +4 -2
- package/agent-pane/backend/vitest.config.ts +20 -0
- package/agent-pane/eslint.config.js +33 -0
- package/agent-pane/frontend/coverage/base.css +224 -0
- package/agent-pane/frontend/coverage/block-navigation.js +87 -0
- package/agent-pane/frontend/coverage/clover.xml +2962 -0
- package/agent-pane/frontend/coverage/coverage-final.json +37 -0
- package/agent-pane/frontend/coverage/favicon.png +0 -0
- package/agent-pane/frontend/coverage/index.html +251 -0
- package/agent-pane/frontend/coverage/prettify.css +1 -0
- package/agent-pane/frontend/coverage/prettify.js +2 -0
- package/agent-pane/frontend/coverage/sort-arrow-sprite.png +0 -0
- package/agent-pane/frontend/coverage/sorter.js +210 -0
- package/agent-pane/frontend/coverage/src/App.tsx.html +217 -0
- package/agent-pane/frontend/coverage/src/AppInitializer.tsx.html +223 -0
- package/agent-pane/frontend/coverage/src/api/client.ts.html +187 -0
- package/agent-pane/frontend/coverage/src/api/index.html +161 -0
- package/agent-pane/frontend/coverage/src/api/sessions.ts.html +316 -0
- package/agent-pane/frontend/coverage/src/api/websocket.ts.html +544 -0
- package/agent-pane/frontend/coverage/src/api/workspaces.ts.html +199 -0
- package/agent-pane/frontend/coverage/src/components/CollapsibleToolCalls.tsx.html +226 -0
- package/agent-pane/frontend/coverage/src/components/CommandInputBar.tsx.html +382 -0
- package/agent-pane/frontend/coverage/src/components/CommandPalette.tsx.html +715 -0
- package/agent-pane/frontend/coverage/src/components/IdeWorkspace.tsx.html +160 -0
- package/agent-pane/frontend/coverage/src/components/ModelSelector.tsx.html +478 -0
- package/agent-pane/frontend/coverage/src/components/NewSessionDialog.tsx.html +472 -0
- package/agent-pane/frontend/coverage/src/components/RenderArea.tsx.html +574 -0
- package/agent-pane/frontend/coverage/src/components/RightPanel.tsx.html +205 -0
- package/agent-pane/frontend/coverage/src/components/RuntimeIcon.tsx.html +133 -0
- package/agent-pane/frontend/coverage/src/components/SessionTabs.tsx.html +217 -0
- package/agent-pane/frontend/coverage/src/components/StatusBar.tsx.html +271 -0
- package/agent-pane/frontend/coverage/src/components/StatusDot.tsx.html +109 -0
- package/agent-pane/frontend/coverage/src/components/Toast.tsx.html +313 -0
- package/agent-pane/frontend/coverage/src/components/TurnContent.tsx.html +1216 -0
- package/agent-pane/frontend/coverage/src/components/WorkspaceSidebar.tsx.html +1138 -0
- package/agent-pane/frontend/coverage/src/components/index.html +326 -0
- package/agent-pane/frontend/coverage/src/components/panels/ChangesPanel.tsx.html +247 -0
- package/agent-pane/frontend/coverage/src/components/panels/LogsPanel.tsx.html +160 -0
- package/agent-pane/frontend/coverage/src/components/panels/MetricsPanel.tsx.html +427 -0
- package/agent-pane/frontend/coverage/src/components/panels/TurnsPanel.tsx.html +397 -0
- package/agent-pane/frontend/coverage/src/components/panels/index.html +161 -0
- package/agent-pane/frontend/coverage/src/constants/index.html +116 -0
- package/agent-pane/frontend/coverage/src/constants/models.ts.html +406 -0
- package/agent-pane/frontend/coverage/src/hooks/index.html +146 -0
- package/agent-pane/frontend/coverage/src/hooks/useEscapeKey.ts.html +124 -0
- package/agent-pane/frontend/coverage/src/hooks/useOutsideClick.ts.html +142 -0
- package/agent-pane/frontend/coverage/src/hooks/useSessionStatus.ts.html +187 -0
- package/agent-pane/frontend/coverage/src/index.html +146 -0
- package/agent-pane/frontend/coverage/src/main.tsx.html +115 -0
- package/agent-pane/frontend/coverage/src/store/index.html +116 -0
- package/agent-pane/frontend/coverage/src/store/store.ts.html +2404 -0
- package/agent-pane/frontend/coverage/src/test/component-helpers.ts.html +190 -0
- package/agent-pane/frontend/coverage/src/test/fixtures.ts.html +367 -0
- package/agent-pane/frontend/coverage/src/test/index.html +131 -0
- package/agent-pane/frontend/coverage/src/types/index.html +116 -0
- package/agent-pane/frontend/coverage/src/types/index.ts.html +466 -0
- package/agent-pane/frontend/coverage/src/utils/changes.ts.html +202 -0
- package/agent-pane/frontend/coverage/src/utils/duration.ts.html +127 -0
- package/agent-pane/frontend/coverage/src/utils/index.html +131 -0
- package/agent-pane/frontend/dist/assets/index-Bg0PF2aV.css +1 -0
- package/agent-pane/frontend/dist/assets/index-BlybeX5e.js +281 -0
- package/agent-pane/frontend/dist/index.html +19 -0
- package/agent-pane/frontend/package-lock.json +2434 -213
- package/agent-pane/frontend/package.json +10 -3
- package/agent-pane/frontend/src/App.test.tsx +74 -0
- package/agent-pane/frontend/src/App.tsx +1 -1
- package/agent-pane/frontend/src/AppInitializer.test.tsx +142 -0
- package/agent-pane/frontend/src/AppInitializer.tsx +1 -1
- package/agent-pane/frontend/src/api/client.test.ts +126 -0
- package/agent-pane/frontend/src/api/client.ts +22 -29
- package/agent-pane/frontend/src/api/models.ts +7 -0
- package/agent-pane/frontend/src/api/providers.ts +12 -0
- package/agent-pane/frontend/src/api/sessions.test.ts +241 -0
- package/agent-pane/frontend/src/api/sessions.ts +43 -1
- package/agent-pane/frontend/src/api/skills.ts +12 -0
- package/agent-pane/frontend/src/api/websocket.test.ts +288 -0
- package/agent-pane/frontend/src/api/websocket.ts +27 -2
- package/agent-pane/frontend/src/api/workspaces.test.ts +112 -0
- package/agent-pane/frontend/src/api/workspaces.ts +17 -3
- package/agent-pane/frontend/src/components/CollapsibleToolCalls.test.tsx +49 -0
- package/agent-pane/frontend/src/components/CollapsibleToolCalls.tsx +2 -5
- package/agent-pane/frontend/src/components/CommandInputBar.test.tsx +133 -0
- package/agent-pane/frontend/src/components/CommandInputBar.tsx +296 -17
- package/agent-pane/frontend/src/components/CommandPalette.test.tsx +230 -0
- package/agent-pane/frontend/src/components/CommandPalette.tsx +26 -23
- package/agent-pane/frontend/src/components/IdeWorkspace.tsx +1 -1
- package/agent-pane/frontend/src/components/ModelSelector.test.tsx +129 -0
- package/agent-pane/frontend/src/components/ModelSelector.tsx +191 -0
- package/agent-pane/frontend/src/components/NewSessionDialog.test.tsx +95 -0
- package/agent-pane/frontend/src/components/NewSessionDialog.tsx +58 -13
- package/agent-pane/frontend/src/components/RenderArea.test.tsx +160 -0
- package/agent-pane/frontend/src/components/RenderArea.tsx +18 -25
- package/agent-pane/frontend/src/components/RightPanel.test.tsx +43 -0
- package/agent-pane/frontend/src/components/RightPanel.tsx +1 -1
- package/agent-pane/frontend/src/components/RuntimeIcon.test.tsx +32 -0
- package/agent-pane/frontend/src/components/RuntimeIcon.tsx +1 -1
- package/agent-pane/frontend/src/components/SessionTabs.test.tsx +72 -0
- package/agent-pane/frontend/src/components/SessionTabs.tsx +12 -12
- package/agent-pane/frontend/src/components/StatusBar.test.tsx +56 -0
- package/agent-pane/frontend/src/components/StatusBar.tsx +25 -31
- package/agent-pane/frontend/src/components/StatusDot.test.tsx +25 -0
- package/agent-pane/frontend/src/components/StatusDot.tsx +2 -7
- package/agent-pane/frontend/src/components/Toast.test.tsx +79 -0
- package/agent-pane/frontend/src/components/Toast.tsx +2 -6
- package/agent-pane/frontend/src/components/TurnContent.test.tsx +287 -0
- package/agent-pane/frontend/src/components/TurnContent.tsx +107 -24
- package/agent-pane/frontend/src/components/WorkspaceSidebar.test.tsx +297 -0
- package/agent-pane/frontend/src/components/WorkspaceSidebar.tsx +33 -32
- package/agent-pane/frontend/src/components/input/OptionSubPopup.tsx +32 -0
- package/agent-pane/frontend/src/components/input/SkillMentionPopup.test.tsx +63 -0
- package/agent-pane/frontend/src/components/input/SkillMentionPopup.tsx +78 -0
- package/agent-pane/frontend/src/components/input/SlashPopup.test.tsx +96 -0
- package/agent-pane/frontend/src/components/input/SlashPopup.tsx +63 -0
- package/agent-pane/frontend/src/components/panels/ChangesPanel.test.tsx +61 -0
- package/agent-pane/frontend/src/components/panels/ChangesPanel.tsx +12 -39
- package/agent-pane/frontend/src/components/panels/LogsPanel.test.tsx +58 -0
- package/agent-pane/frontend/src/components/panels/LogsPanel.tsx +1 -1
- package/agent-pane/frontend/src/components/panels/MetricsPanel.test.tsx +71 -0
- package/agent-pane/frontend/src/components/panels/MetricsPanel.tsx +63 -31
- package/agent-pane/frontend/src/components/panels/TurnsPanel.test.tsx +83 -0
- package/agent-pane/frontend/src/components/panels/TurnsPanel.tsx +66 -7
- package/agent-pane/frontend/src/constants/models.test.ts +97 -0
- package/agent-pane/frontend/src/constants/models.ts +129 -0
- package/agent-pane/frontend/src/hooks/useEscapeKey.test.ts +42 -0
- package/agent-pane/frontend/src/hooks/useEscapeKey.ts +13 -0
- package/agent-pane/frontend/src/hooks/useOutsideClick.test.ts +92 -0
- package/agent-pane/frontend/src/hooks/useOutsideClick.ts +19 -0
- package/agent-pane/frontend/src/hooks/useProvider.ts +44 -0
- package/agent-pane/frontend/src/hooks/useSessionStatus.test.ts +114 -0
- package/agent-pane/frontend/src/hooks/useSessionStatus.ts +34 -0
- package/agent-pane/frontend/src/main.test.tsx +37 -0
- package/agent-pane/frontend/src/main.tsx +1 -1
- package/agent-pane/frontend/src/store/sessionSlice.ts +417 -0
- package/agent-pane/frontend/src/store/store.test.ts +1284 -0
- package/agent-pane/frontend/src/store/store.ts +16 -617
- package/agent-pane/frontend/src/store/uiSlice.ts +83 -0
- package/agent-pane/frontend/src/store/workspaceSlice.ts +77 -0
- package/agent-pane/frontend/src/store/wsSlice.ts +292 -0
- package/agent-pane/frontend/src/styles/app.css +113 -7
- package/agent-pane/frontend/src/test/component-helpers.ts +36 -0
- package/agent-pane/frontend/src/test/fixtures.ts +96 -0
- package/agent-pane/frontend/src/test-setup.ts +5 -0
- package/agent-pane/frontend/src/types/index.test.ts +128 -0
- package/agent-pane/frontend/src/types/index.ts +80 -104
- package/agent-pane/frontend/src/utils/changes.test.ts +81 -0
- package/agent-pane/frontend/src/utils/changes.ts +39 -0
- package/agent-pane/frontend/src/utils/duration.test.ts +71 -0
- package/agent-pane/frontend/src/utils/duration.ts +14 -0
- package/agent-pane/frontend/tsconfig.json +4 -1
- package/agent-pane/frontend/vite.config.ts +6 -0
- package/agent-pane/frontend/vitest.config.ts +29 -0
- package/agent-pane/package-lock.json +1527 -0
- package/agent-pane/package.json +19 -0
- package/agent-pane/shared/provider-types.ts +53 -0
- package/agent-pane/shared/types.ts +107 -0
- package/agentpane-branch-session.png +0 -0
- package/agentpane-expanded-all.png +0 -0
- package/agentpane-fixed-rendering.png +0 -0
- package/agentpane-focus-check.png +0 -0
- package/agentpane-initial.png +0 -0
- package/agentpane-mcp-detail.png +0 -0
- package/agentpane-no-focus-ring.png +0 -0
- package/agentpane-soft-focus.png +0 -0
- package/backend/dist/src/llm-provider/ollama-llm.provider.js +1 -0
- package/backend/dist/src/llm-provider/ollama-llm.provider.js.map +1 -1
- package/backend/dist/tsconfig.build.tsbuildinfo +1 -1
- package/data.db +0 -0
- package/empty-state.png +0 -0
- package/frontend-home.png +0 -0
- package/model-selector-open.png +0 -0
- package/package.json +1 -1
- package/slash-popup-working.png +0 -0
- package/agent-pane/frontend/src/components/DiffViewer.tsx +0 -27
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useStore } from '../store/store.ts';
|
|
2
|
+
import { statusToDot, statusToLabel, runtimeIcon } from '../types/index.ts';
|
|
3
|
+
import type { Session } from '../types/index.ts';
|
|
4
|
+
|
|
5
|
+
interface SessionStatus {
|
|
6
|
+
dot: string;
|
|
7
|
+
label: string;
|
|
8
|
+
iconClass: string;
|
|
9
|
+
iconText: string;
|
|
10
|
+
isRunning: boolean;
|
|
11
|
+
isFinished: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Hook: derive UI status (dot, label, icon) from a session by ID. */
|
|
15
|
+
export function useSessionStatus(sessionId: string | null): SessionStatus | null {
|
|
16
|
+
const session = useStore((s) => (sessionId ? (s.sessions.find((x) => x.id === sessionId) ?? null) : null));
|
|
17
|
+
if (!session) return null;
|
|
18
|
+
return deriveSessionStatus(session);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Derive UI status from a Session object (no hook, for use in render props). */
|
|
22
|
+
export function deriveSessionStatus(s: Session): SessionStatus {
|
|
23
|
+
const isRunning = s.is_running === 1;
|
|
24
|
+
const isFinished = s.lifecycle === 'finished';
|
|
25
|
+
const ri = runtimeIcon(s.runtime_type);
|
|
26
|
+
return {
|
|
27
|
+
dot: statusToDot(s.status, isRunning, s.has_unreviewed === 1, s.lifecycle),
|
|
28
|
+
label: statusToLabel(s.status, isRunning, s.has_unreviewed === 1, s.lifecycle),
|
|
29
|
+
iconClass: ri.iconClass,
|
|
30
|
+
iconText: ri.iconText,
|
|
31
|
+
isRunning,
|
|
32
|
+
isFinished,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
// Mock react-dom/client before importing main.tsx
|
|
4
|
+
const mockRender = vi.fn();
|
|
5
|
+
const mockCreateRoot = vi.fn(() => ({ render: mockRender }));
|
|
6
|
+
vi.mock('react-dom/client', () => ({
|
|
7
|
+
default: { createRoot: mockCreateRoot },
|
|
8
|
+
createRoot: mockCreateRoot,
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
// Create #root element BEFORE importing main.tsx (jsdom has no #root by default)
|
|
12
|
+
const rootEl = document.createElement('div');
|
|
13
|
+
rootEl.id = 'root';
|
|
14
|
+
document.body.appendChild(rootEl);
|
|
15
|
+
|
|
16
|
+
// Import AFTER mock + root element are set up
|
|
17
|
+
await import('./main.tsx');
|
|
18
|
+
|
|
19
|
+
/** Type helper: extract first call arg from a mock with no typed params */
|
|
20
|
+
function firstCallArg(mock: ReturnType<typeof vi.fn>): unknown {
|
|
21
|
+
const calls = mock.mock.calls as unknown as unknown[][];
|
|
22
|
+
return calls[0]?.[0];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe('main.tsx', () => {
|
|
26
|
+
it('calls createRoot with the #root element', () => {
|
|
27
|
+
expect(mockCreateRoot).toHaveBeenCalledTimes(1);
|
|
28
|
+
expect(firstCallArg(mockCreateRoot)).toBe(rootEl);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('calls render with a React element', () => {
|
|
32
|
+
expect(mockRender).toHaveBeenCalledTimes(1);
|
|
33
|
+
const vnode = firstCallArg(mockRender);
|
|
34
|
+
expect(vnode).toBeDefined();
|
|
35
|
+
expect(typeof vnode).toBe('object');
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
import type { StateCreator } from 'zustand';
|
|
2
|
+
import type { Session, SessionDetail, Turn } from '../types/index.ts';
|
|
3
|
+
import type { StoreState, CreateSessionBody } from './store.ts';
|
|
4
|
+
import {
|
|
5
|
+
fetchSessions,
|
|
6
|
+
fetchSessionDetail,
|
|
7
|
+
createSession as apiCreateSession,
|
|
8
|
+
deleteSession as apiDeleteSession,
|
|
9
|
+
submitPrompt as apiSubmitPrompt,
|
|
10
|
+
cancelTurn as apiCancelTurn,
|
|
11
|
+
renameSession as apiRenameSession,
|
|
12
|
+
markFinished as apiMarkFinished,
|
|
13
|
+
reopenSession as apiReopenSession,
|
|
14
|
+
clearUnreviewed as apiClearUnreviewed,
|
|
15
|
+
rewindSession as apiRewindSession,
|
|
16
|
+
branchSession as apiBranchSession,
|
|
17
|
+
updateModelConfig as apiUpdateModelConfig,
|
|
18
|
+
updateRuntimeConfig as apiUpdateRuntimeConfig,
|
|
19
|
+
} from '../api/sessions.ts';
|
|
20
|
+
import { fetchWorkspaces as apiFetchWorkspaces } from '../api/workspaces.ts';
|
|
21
|
+
|
|
22
|
+
export type SessionSlice = {
|
|
23
|
+
sessions: Session[];
|
|
24
|
+
sessionDetails: Record<string, SessionDetail>;
|
|
25
|
+
activeSessionId: string | null;
|
|
26
|
+
openTabs: string[];
|
|
27
|
+
activeTurnIndex: number;
|
|
28
|
+
submittingPrompt: string | null;
|
|
29
|
+
restoredPrompt: string | null;
|
|
30
|
+
|
|
31
|
+
init: () => Promise<void>;
|
|
32
|
+
selectSession: (id: string) => Promise<void>;
|
|
33
|
+
closeTab: (id: string) => void;
|
|
34
|
+
createSession: (body: CreateSessionBody) => Promise<void>;
|
|
35
|
+
deleteSession: (id: string) => Promise<void>;
|
|
36
|
+
renameSession: (id: string, title: string) => Promise<void>;
|
|
37
|
+
markFinished: (id: string) => Promise<void>;
|
|
38
|
+
reopenSession: (id: string) => Promise<void>;
|
|
39
|
+
submitPrompt: (prompt: string) => Promise<void>;
|
|
40
|
+
cancelTurn: () => Promise<void>;
|
|
41
|
+
refreshActiveSession: () => Promise<void>;
|
|
42
|
+
rewindToTurn: (sessionId: string, turnId: string) => Promise<void>;
|
|
43
|
+
branchFromTurn: (sessionId: string, turnId: string, title?: string) => Promise<void>;
|
|
44
|
+
updateModelConfig: (model: string, reasoningEffort: string, runtimeType?: string) => Promise<void>;
|
|
45
|
+
updateRuntimeConfig: (config: Record<string, unknown>) => Promise<void>;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const createSessionSlice: StateCreator<StoreState, [], [], SessionSlice> = (set, get) => ({
|
|
49
|
+
sessions: [],
|
|
50
|
+
sessionDetails: {},
|
|
51
|
+
activeSessionId: null,
|
|
52
|
+
openTabs: [],
|
|
53
|
+
activeTurnIndex: 0,
|
|
54
|
+
submittingPrompt: null,
|
|
55
|
+
restoredPrompt: null,
|
|
56
|
+
|
|
57
|
+
init: async () => {
|
|
58
|
+
try {
|
|
59
|
+
const saved = localStorage.getItem('agentpane:last-model-config');
|
|
60
|
+
if (saved) set({ lastModelConfig: JSON.parse(saved) });
|
|
61
|
+
} catch {
|
|
62
|
+
/* ignore parse errors */
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
set({ loading: true, error: null });
|
|
66
|
+
try {
|
|
67
|
+
const [sessions, workspaces] = await Promise.all([fetchSessions(), apiFetchWorkspaces()]);
|
|
68
|
+
set({ sessions, workspaces, loading: false });
|
|
69
|
+
if (sessions.length > 0 && !get().activeSessionId) {
|
|
70
|
+
await get().selectSession(sessions[0].id);
|
|
71
|
+
}
|
|
72
|
+
} catch (err) {
|
|
73
|
+
set({ loading: false, error: (err as Error).message });
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
selectSession: async (id) => {
|
|
78
|
+
if (get().sessionDetails[id]) {
|
|
79
|
+
const detail = get().sessionDetails[id];
|
|
80
|
+
set({
|
|
81
|
+
activeSessionId: id,
|
|
82
|
+
activeTurnIndex: detail.turns.length > 0 ? detail.turns.length - 1 : 0,
|
|
83
|
+
activeRightTab: 'turns',
|
|
84
|
+
openTabs: get().openTabs.includes(id) ? get().openTabs : [...get().openTabs, id],
|
|
85
|
+
});
|
|
86
|
+
if (detail.has_unreviewed === 1) {
|
|
87
|
+
apiClearUnreviewed(id).catch(() => {});
|
|
88
|
+
set((state) => ({
|
|
89
|
+
sessions: state.sessions.map((s) => (s.id === id ? { ...s, has_unreviewed: 0 } : s)),
|
|
90
|
+
sessionDetails: { ...state.sessionDetails, [id]: { ...detail, has_unreviewed: 0 } },
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
set({ loading: true, error: null });
|
|
97
|
+
try {
|
|
98
|
+
const detail = await fetchSessionDetail(id);
|
|
99
|
+
set((state) => ({
|
|
100
|
+
sessionDetails: { ...state.sessionDetails, [id]: detail },
|
|
101
|
+
activeSessionId: id,
|
|
102
|
+
activeTurnIndex: detail.turns.length > 0 ? detail.turns.length - 1 : 0,
|
|
103
|
+
activeRightTab: 'turns',
|
|
104
|
+
loading: false,
|
|
105
|
+
}));
|
|
106
|
+
if (detail.has_unreviewed === 1) {
|
|
107
|
+
apiClearUnreviewed(id).catch(() => {});
|
|
108
|
+
set((state) => ({
|
|
109
|
+
sessions: state.sessions.map((s) => (s.id === id ? { ...s, has_unreviewed: 0 } : s)),
|
|
110
|
+
sessionDetails: { ...state.sessionDetails, [id]: { ...detail, has_unreviewed: 0 } },
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
} catch (err) {
|
|
114
|
+
set({ loading: false, error: (err as Error).message });
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
closeTab: (id) => {
|
|
119
|
+
set((state) => {
|
|
120
|
+
const newTabs = state.openTabs.filter((t) => t !== id);
|
|
121
|
+
if (state.activeSessionId === id && newTabs.length > 0) {
|
|
122
|
+
const newActive = newTabs[newTabs.length - 1];
|
|
123
|
+
const detail = state.sessionDetails[newActive];
|
|
124
|
+
return {
|
|
125
|
+
openTabs: newTabs,
|
|
126
|
+
activeSessionId: newActive,
|
|
127
|
+
activeTurnIndex: detail && detail.turns.length > 0 ? detail.turns.length - 1 : 0,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
openTabs: newTabs,
|
|
132
|
+
activeSessionId: state.activeSessionId === id ? null : state.activeSessionId,
|
|
133
|
+
};
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
updateModelConfig: async (model, reasoningEffort, runtimeType) => {
|
|
138
|
+
const sessionId = get().activeSessionId;
|
|
139
|
+
if (!sessionId) return;
|
|
140
|
+
|
|
141
|
+
set({ error: null });
|
|
142
|
+
try {
|
|
143
|
+
const updated = await apiUpdateModelConfig(sessionId, model, reasoningEffort, runtimeType);
|
|
144
|
+
|
|
145
|
+
const config = {
|
|
146
|
+
provider: updated.runtime_type,
|
|
147
|
+
model: updated.model ?? '',
|
|
148
|
+
reasoning: updated.model_reasoning_effort ?? '',
|
|
149
|
+
};
|
|
150
|
+
set({ lastModelConfig: config });
|
|
151
|
+
localStorage.setItem('agentpane:last-model-config', JSON.stringify(config));
|
|
152
|
+
|
|
153
|
+
set((state) => ({
|
|
154
|
+
sessions: state.sessions.map((s) => (s.id === sessionId ? updated : s)),
|
|
155
|
+
sessionDetails: state.sessionDetails[sessionId]
|
|
156
|
+
? {
|
|
157
|
+
...state.sessionDetails,
|
|
158
|
+
[sessionId]: {
|
|
159
|
+
...state.sessionDetails[sessionId],
|
|
160
|
+
model: updated.model,
|
|
161
|
+
model_reasoning_effort: updated.model_reasoning_effort,
|
|
162
|
+
external_thread_id: updated.external_thread_id,
|
|
163
|
+
},
|
|
164
|
+
}
|
|
165
|
+
: state.sessionDetails,
|
|
166
|
+
}));
|
|
167
|
+
|
|
168
|
+
await get().refreshActiveSession();
|
|
169
|
+
} catch (err) {
|
|
170
|
+
set({ error: (err as Error).message });
|
|
171
|
+
get().addToast('error', `Failed to update model — ${(err as Error).message}`);
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
createSession: async (body) => {
|
|
176
|
+
set({ error: null });
|
|
177
|
+
try {
|
|
178
|
+
const session = await apiCreateSession(body);
|
|
179
|
+
set((state) => ({
|
|
180
|
+
sessions: [session, ...state.sessions],
|
|
181
|
+
showNewSessionDialog: false,
|
|
182
|
+
}));
|
|
183
|
+
|
|
184
|
+
const config = {
|
|
185
|
+
provider: session.runtime_type,
|
|
186
|
+
model: session.model ?? '',
|
|
187
|
+
reasoning: session.model_reasoning_effort ?? '',
|
|
188
|
+
};
|
|
189
|
+
set({ lastModelConfig: config });
|
|
190
|
+
localStorage.setItem('agentpane:last-model-config', JSON.stringify(config));
|
|
191
|
+
|
|
192
|
+
await get().selectSession(session.id);
|
|
193
|
+
get().addLogEntry('INFO', `Session created — ${session.id.slice(0, 8)}`);
|
|
194
|
+
get().addToast('success', `Session created — ${session.title || session.id.slice(0, 8)}`);
|
|
195
|
+
} catch (err) {
|
|
196
|
+
set({ error: (err as Error).message });
|
|
197
|
+
get().addToast('error', `Failed to create session — ${(err as Error).message}`);
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
|
|
201
|
+
deleteSession: async (id) => {
|
|
202
|
+
set({ error: null });
|
|
203
|
+
const sessionTitle = get().sessions.find((s) => s.id === id)?.title;
|
|
204
|
+
try {
|
|
205
|
+
await apiDeleteSession(id);
|
|
206
|
+
set((state) => {
|
|
207
|
+
const newDetails = { ...state.sessionDetails };
|
|
208
|
+
delete newDetails[id];
|
|
209
|
+
const newTabs = state.openTabs.filter((t) => t !== id);
|
|
210
|
+
let newActive = state.activeSessionId;
|
|
211
|
+
let newTurnIndex = state.activeTurnIndex;
|
|
212
|
+
if (state.activeSessionId === id) {
|
|
213
|
+
newActive = newTabs.length > 0 ? newTabs[newTabs.length - 1] : null;
|
|
214
|
+
const detail = newActive ? newDetails[newActive] : null;
|
|
215
|
+
newTurnIndex = detail && detail.turns.length > 0 ? detail.turns.length - 1 : 0;
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
sessions: state.sessions.filter((s) => s.id !== id),
|
|
219
|
+
sessionDetails: newDetails,
|
|
220
|
+
openTabs: newTabs,
|
|
221
|
+
activeSessionId: newActive,
|
|
222
|
+
activeTurnIndex: newTurnIndex,
|
|
223
|
+
};
|
|
224
|
+
});
|
|
225
|
+
get().addLogEntry('INFO', `Session deleted — ${id.slice(0, 8)}`);
|
|
226
|
+
get().addToast('info', `Session "${sessionTitle || id.slice(0, 8)}" deleted`);
|
|
227
|
+
} catch (err) {
|
|
228
|
+
set({ error: (err as Error).message });
|
|
229
|
+
get().addToast('error', `Failed to delete session — ${(err as Error).message}`);
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
|
|
233
|
+
renameSession: async (id, title) => {
|
|
234
|
+
set({ error: null });
|
|
235
|
+
try {
|
|
236
|
+
const updated = await apiRenameSession(id, title.trim());
|
|
237
|
+
set((state) => ({
|
|
238
|
+
sessions: state.sessions.map((s) => (s.id === id ? updated : s)),
|
|
239
|
+
sessionDetails: state.sessionDetails[id]
|
|
240
|
+
? { ...state.sessionDetails, [id]: { ...state.sessionDetails[id], title: updated.title } }
|
|
241
|
+
: state.sessionDetails,
|
|
242
|
+
}));
|
|
243
|
+
} catch (err) {
|
|
244
|
+
set({ error: (err as Error).message });
|
|
245
|
+
get().addToast('error', `Failed to rename session — ${(err as Error).message}`);
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
|
|
249
|
+
markFinished: async (id) => {
|
|
250
|
+
set({ error: null });
|
|
251
|
+
try {
|
|
252
|
+
const updated = await apiMarkFinished(id);
|
|
253
|
+
set((state) => ({
|
|
254
|
+
sessions: state.sessions.map((s) => (s.id === id ? updated : s)),
|
|
255
|
+
}));
|
|
256
|
+
get().addToast('info', 'Session marked as finished');
|
|
257
|
+
} catch (err) {
|
|
258
|
+
set({ error: (err as Error).message });
|
|
259
|
+
get().addToast('error', `Failed to mark as finished — ${(err as Error).message}`);
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
|
|
263
|
+
reopenSession: async (id) => {
|
|
264
|
+
set({ error: null });
|
|
265
|
+
try {
|
|
266
|
+
const updated = await apiReopenSession(id);
|
|
267
|
+
set((state) => ({
|
|
268
|
+
sessions: state.sessions.map((s) => (s.id === id ? updated : s)),
|
|
269
|
+
}));
|
|
270
|
+
get().addToast('info', 'Session reopened');
|
|
271
|
+
} catch (err) {
|
|
272
|
+
set({ error: (err as Error).message });
|
|
273
|
+
get().addToast('error', `Failed to reopen session — ${(err as Error).message}`);
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
|
|
277
|
+
submitPrompt: async (prompt) => {
|
|
278
|
+
const sessionId = get().activeSessionId;
|
|
279
|
+
if (!sessionId) return;
|
|
280
|
+
|
|
281
|
+
set({ error: null, submittingPrompt: prompt });
|
|
282
|
+
|
|
283
|
+
set((state) => {
|
|
284
|
+
const detail = state.sessionDetails[sessionId];
|
|
285
|
+
if (!detail) return {};
|
|
286
|
+
return {
|
|
287
|
+
sessionDetails: {
|
|
288
|
+
...state.sessionDetails,
|
|
289
|
+
[sessionId]: { ...detail, is_running: 1, status: 'running' },
|
|
290
|
+
},
|
|
291
|
+
sessions: state.sessions.map((s) => (s.id === sessionId ? { ...s, is_running: 1, status: 'running' } : s)),
|
|
292
|
+
};
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
try {
|
|
296
|
+
const turn = await apiSubmitPrompt(sessionId, prompt);
|
|
297
|
+
get().addLogEntry('INFO', `Turn submitted — "${prompt.slice(0, 40)}"`);
|
|
298
|
+
|
|
299
|
+
set((state) => {
|
|
300
|
+
const detail = state.sessionDetails[sessionId];
|
|
301
|
+
if (!detail) return { submittingPrompt: null };
|
|
302
|
+
const newTurn: Turn = { ...turn, items: [] };
|
|
303
|
+
return {
|
|
304
|
+
submittingPrompt: null,
|
|
305
|
+
sessionDetails: {
|
|
306
|
+
...state.sessionDetails,
|
|
307
|
+
[sessionId]: {
|
|
308
|
+
...detail,
|
|
309
|
+
turns: [...detail.turns, newTurn],
|
|
310
|
+
},
|
|
311
|
+
},
|
|
312
|
+
activeTurnIndex: detail.turns.length,
|
|
313
|
+
};
|
|
314
|
+
});
|
|
315
|
+
} catch (err) {
|
|
316
|
+
set({ submittingPrompt: null, error: (err as Error).message });
|
|
317
|
+
get().addLogEntry('ERROR', `Turn failed — ${(err as Error).message}`);
|
|
318
|
+
get().addToast('error', `Failed to send prompt — ${(err as Error).message}`);
|
|
319
|
+
|
|
320
|
+
set((state) => ({
|
|
321
|
+
sessionDetails: state.sessionDetails[sessionId]
|
|
322
|
+
? {
|
|
323
|
+
...state.sessionDetails,
|
|
324
|
+
[sessionId]: { ...state.sessionDetails[sessionId], is_running: 0, status: 'active' },
|
|
325
|
+
}
|
|
326
|
+
: state.sessionDetails,
|
|
327
|
+
sessions: state.sessions.map((s) => (s.id === sessionId ? { ...s, is_running: 0, status: 'active' } : s)),
|
|
328
|
+
}));
|
|
329
|
+
}
|
|
330
|
+
},
|
|
331
|
+
|
|
332
|
+
cancelTurn: async () => {
|
|
333
|
+
const sessionId = get().activeSessionId;
|
|
334
|
+
if (!sessionId) return;
|
|
335
|
+
|
|
336
|
+
try {
|
|
337
|
+
await apiCancelTurn(sessionId);
|
|
338
|
+
} catch (err) {
|
|
339
|
+
set({ error: (err as Error).message });
|
|
340
|
+
}
|
|
341
|
+
},
|
|
342
|
+
|
|
343
|
+
rewindToTurn: async (sessionId, turnId) => {
|
|
344
|
+
set({ error: null });
|
|
345
|
+
try {
|
|
346
|
+
await apiRewindSession(sessionId, turnId);
|
|
347
|
+
const detail = await fetchSessionDetail(sessionId);
|
|
348
|
+
set((state) => ({
|
|
349
|
+
sessionDetails: { ...state.sessionDetails, [sessionId]: detail },
|
|
350
|
+
sessions: state.sessions.map((s) =>
|
|
351
|
+
s.id === sessionId ? { ...s, external_thread_id: null, is_running: 0, status: 'active' } : s,
|
|
352
|
+
),
|
|
353
|
+
activeTurnIndex: detail.turns.length > 0 ? detail.turns.length - 1 : 0,
|
|
354
|
+
}));
|
|
355
|
+
get().addToast('info', 'Rewound to selected turn');
|
|
356
|
+
} catch (err) {
|
|
357
|
+
set({ error: (err as Error).message });
|
|
358
|
+
get().addToast('error', `Failed to rewind — ${(err as Error).message}`);
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
|
|
362
|
+
branchFromTurn: async (sessionId, turnId, title) => {
|
|
363
|
+
set({ error: null });
|
|
364
|
+
try {
|
|
365
|
+
const newSession = await apiBranchSession(sessionId, turnId, title);
|
|
366
|
+
set((state) => ({
|
|
367
|
+
sessions: [newSession, ...state.sessions],
|
|
368
|
+
}));
|
|
369
|
+
await get().selectSession(newSession.id);
|
|
370
|
+
get().addToast('success', 'Branched from selected turn');
|
|
371
|
+
} catch (err) {
|
|
372
|
+
set({ error: (err as Error).message });
|
|
373
|
+
get().addToast('error', `Failed to branch — ${(err as Error).message}`);
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
|
|
377
|
+
updateRuntimeConfig: async (config) => {
|
|
378
|
+
const sessionId = get().activeSessionId;
|
|
379
|
+
if (!sessionId) return;
|
|
380
|
+
|
|
381
|
+
set({ error: null });
|
|
382
|
+
try {
|
|
383
|
+
const updated = await apiUpdateRuntimeConfig(sessionId, JSON.stringify(config));
|
|
384
|
+
|
|
385
|
+
set((state) => ({
|
|
386
|
+
sessions: state.sessions.map((s) => (s.id === sessionId ? updated : s)),
|
|
387
|
+
sessionDetails: state.sessionDetails[sessionId]
|
|
388
|
+
? {
|
|
389
|
+
...state.sessionDetails,
|
|
390
|
+
[sessionId]: { ...state.sessionDetails[sessionId], runtime_config: updated.runtime_config },
|
|
391
|
+
}
|
|
392
|
+
: state.sessionDetails,
|
|
393
|
+
}));
|
|
394
|
+
} catch (err) {
|
|
395
|
+
set({ error: (err as Error).message });
|
|
396
|
+
get().addToast('error', `Failed to update config — ${(err as Error).message}`);
|
|
397
|
+
}
|
|
398
|
+
},
|
|
399
|
+
|
|
400
|
+
refreshActiveSession: async () => {
|
|
401
|
+
const sessionId = get().activeSessionId;
|
|
402
|
+
if (!sessionId) return;
|
|
403
|
+
|
|
404
|
+
try {
|
|
405
|
+
const detail = await fetchSessionDetail(sessionId);
|
|
406
|
+
set((state) => ({
|
|
407
|
+
sessionDetails: { ...state.sessionDetails, [sessionId]: detail },
|
|
408
|
+
activeTurnIndex: detail.turns.length > 0 ? Math.min(state.activeTurnIndex, detail.turns.length - 1) : 0,
|
|
409
|
+
sessions: state.sessions.map((s) =>
|
|
410
|
+
s.id === sessionId ? { ...s, is_running: detail.is_running, status: detail.status } : s,
|
|
411
|
+
),
|
|
412
|
+
}));
|
|
413
|
+
} catch (err) {
|
|
414
|
+
set({ error: (err as Error).message });
|
|
415
|
+
}
|
|
416
|
+
},
|
|
417
|
+
});
|