Merge branch 'main' into paste-images
This commit is contained in:
commit
733faa4f86
11 changed files with 518 additions and 29 deletions
215
.github/workflows/respond-to-cubic.yaml
vendored
Normal file
215
.github/workflows/respond-to-cubic.yaml
vendored
Normal file
|
|
@ -0,0 +1,215 @@
|
|||
name: Respond to @continuedev Comments
|
||||
|
||||
on:
|
||||
issue_comment:
|
||||
types: [created]
|
||||
pull_request_review_comment:
|
||||
types: [created]
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
issues: write
|
||||
|
||||
jobs:
|
||||
respond-to-comment:
|
||||
# Only run on pull request comments
|
||||
if: github.event_name == 'issue_comment' && github.event.issue.pull_request
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Check if comment contains @continuedev
|
||||
id: check-mention
|
||||
run: |
|
||||
if echo "${{ github.event.comment.body }}" | grep -q "@continuedev"; then
|
||||
echo "contains_mention=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "contains_mention=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Checkout PR branch
|
||||
if: steps.check-mention.outputs.contains_mention == 'true'
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Get PR information
|
||||
if: steps.check-mention.outputs.contains_mention == 'true'
|
||||
id: pr-info
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const { data: pr } = await github.rest.pulls.get({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
pull_number: context.issue.number
|
||||
});
|
||||
|
||||
core.setOutput('head_ref', pr.head.ref);
|
||||
core.setOutput('head_sha', pr.head.sha);
|
||||
return pr;
|
||||
|
||||
- name: Checkout PR branch
|
||||
if: steps.check-mention.outputs.contains_mention == 'true'
|
||||
run: |
|
||||
git checkout ${{ steps.pr-info.outputs.head_ref }}
|
||||
|
||||
- name: Setup Node.js
|
||||
if: steps.check-mention.outputs.contains_mention == 'true'
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "20"
|
||||
|
||||
- name: Install Continue CLI globally
|
||||
if: steps.check-mention.outputs.contains_mention == 'true'
|
||||
run: npm i -g @continuedev/cli
|
||||
|
||||
- name: Start remote session
|
||||
if: steps.check-mention.outputs.contains_mention == 'true'
|
||||
id: remote-session
|
||||
env:
|
||||
CONTINUE_API_KEY: ${{ secrets.CONTINUE_API_KEY }}
|
||||
run: |
|
||||
# Create the prompt for remote session
|
||||
PROMPT="Please help with the following request from @${{ github.event.comment.user.login }} on PR #${{ github.event.issue.number }}:
|
||||
|
||||
${{ github.event.comment.body }}
|
||||
|
||||
Please analyze the current PR, understand the request, implement the necessary changes, and commit them to this branch."
|
||||
|
||||
# Start remote session and capture JSON output
|
||||
SESSION_OUTPUT=$(echo "$PROMPT" | cn remote -s --branch ${{ steps.pr-info.outputs.head_ref }})
|
||||
echo "Raw session output: $SESSION_OUTPUT"
|
||||
|
||||
# Extract URL from JSON output
|
||||
SESSION_URL=$(echo "$SESSION_OUTPUT" | jq -r '.url // empty')
|
||||
|
||||
if [ -z "$SESSION_URL" ] || [ "$SESSION_URL" = "null" ]; then
|
||||
echo "Failed to extract session URL from output: $SESSION_OUTPUT"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "session_url=$SESSION_URL" >> $GITHUB_OUTPUT
|
||||
echo "✅ Started remote session: $SESSION_URL"
|
||||
|
||||
- name: Comment with session URL
|
||||
if: steps.check-mention.outputs.contains_mention == 'true' && steps.remote-session.outputs.session_url
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const commentBody = `I've started [a remote session](${{ steps.remote-session.outputs.session_url }}) to help with your request:
|
||||
> ${{ github.event.comment.body }}`;
|
||||
|
||||
await github.rest.issues.createComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: context.issue.number,
|
||||
body: commentBody
|
||||
});
|
||||
|
||||
- name: Log session details
|
||||
if: steps.check-mention.outputs.contains_mention == 'true'
|
||||
run: |
|
||||
echo "✅ Successfully started remote session for comment from ${{ github.event.comment.user.login }} on PR #${{ github.event.issue.number }}"
|
||||
echo "Session URL: ${{ steps.remote-session.outputs.session_url }}"
|
||||
echo "Original comment: ${{ github.event.comment.body }}"
|
||||
|
||||
respond-to-review-comment:
|
||||
# Only run on pull request review comments
|
||||
if: github.event_name == 'pull_request_review_comment'
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Check if comment contains @continuedev
|
||||
id: check-mention
|
||||
run: |
|
||||
if echo "${{ github.event.comment.body }}" | grep -q "@continuedev"; then
|
||||
echo "contains_mention=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "contains_mention=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Checkout PR branch
|
||||
if: steps.check-mention.outputs.contains_mention == 'true'
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
fetch-depth: 0
|
||||
ref: ${{ github.event.pull_request.head.ref }}
|
||||
|
||||
- name: Setup Node.js
|
||||
if: steps.check-mention.outputs.contains_mention == 'true'
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "20"
|
||||
|
||||
- name: Install Continue CLI globally
|
||||
if: steps.check-mention.outputs.contains_mention == 'true'
|
||||
run: npm i -g @continuedev/cli
|
||||
|
||||
- name: Start remote session
|
||||
if: steps.check-mention.outputs.contains_mention == 'true'
|
||||
id: remote-session
|
||||
env:
|
||||
CONTINUE_API_KEY: ${{ secrets.CONTINUE_API_KEY }}
|
||||
run: |
|
||||
# Create a temporary file for the prompt to handle special characters and newlines properly
|
||||
cat > /tmp/prompt.txt << 'PROMPT_EOF'
|
||||
Please help with the following code review comment from @${{ github.event.comment.user.login }} on PR #${{ github.event.pull_request.number }}:
|
||||
|
||||
**File:** ${{ github.event.comment.path }}
|
||||
**Line:** ${{ github.event.comment.line || github.event.comment.original_line || 'N/A' }}
|
||||
**Comment:** ${{ github.event.comment.body }}
|
||||
|
||||
Please analyze the specific file and line mentioned, understand the review feedback, implement the necessary changes, and commit them to this branch.
|
||||
PROMPT_EOF
|
||||
|
||||
# Debug output
|
||||
echo "PROMPT content:"
|
||||
cat /tmp/prompt.txt
|
||||
|
||||
# Start remote session and capture JSON output
|
||||
echo "Starting cn with prompt..."
|
||||
SESSION_OUTPUT=$(cat /tmp/prompt.txt | cn remote -s --branch ${{ github.event.pull_request.head.ref }})
|
||||
echo "Raw session output: $SESSION_OUTPUT"
|
||||
|
||||
# Extract URL from JSON output
|
||||
SESSION_URL=$(echo "$SESSION_OUTPUT" | jq -r '.url // empty')
|
||||
|
||||
if [ -z "$SESSION_URL" ] || [ "$SESSION_URL" = "null" ]; then
|
||||
echo "Failed to extract session URL from output: $SESSION_OUTPUT"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "session_url=$SESSION_URL" >> $GITHUB_OUTPUT
|
||||
echo "✅ Started remote session: $SESSION_URL"
|
||||
|
||||
- name: Comment with session URL
|
||||
if: steps.check-mention.outputs.contains_mention == 'true' && steps.remote-session.outputs.session_url
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const commentBody = `I've started [a remote session](${{ steps.remote-session.outputs.session_url }}) to help with your request:
|
||||
> ${{ github.event.comment.body }}`;
|
||||
|
||||
const commentParams = {
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
pull_number: ${{ github.event.pull_request.number }},
|
||||
body: commentBody,
|
||||
commit_id: '${{ github.event.pull_request.head.sha }}',
|
||||
path: '${{ github.event.comment.path }}',
|
||||
in_reply_to: ${{ github.event.comment.id }}
|
||||
};
|
||||
|
||||
await github.rest.pulls.createReviewComment(commentParams);
|
||||
|
||||
- name: Log session details
|
||||
if: steps.check-mention.outputs.contains_mention == 'true'
|
||||
run: |
|
||||
echo "✅ Successfully started remote session for review comment from ${{ github.event.comment.user.login }} on PR #${{ github.event.pull_request.number }}"
|
||||
echo "Session URL: ${{ steps.remote-session.outputs.session_url }}"
|
||||
echo "File: ${{ github.event.comment.path }}"
|
||||
echo "Line: ${{ github.event.comment.line }}"
|
||||
echo "Original comment: ${{ github.event.comment.body }}"
|
||||
|
|
@ -103,7 +103,6 @@ export class ChatDescriber {
|
|||
|
||||
return undefined;
|
||||
} catch (error) {
|
||||
console.debug("Error generating chat title:", error);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,6 +83,9 @@ vi.mock("./session.js", () => ({
|
|||
() => "/home/test/.continue/cli-sessions/continue-cli-pid-12345.json",
|
||||
),
|
||||
hasSession: vi.fn(() => false),
|
||||
getCurrentSession: vi.fn(() => {
|
||||
throw new Error("Session not available");
|
||||
}),
|
||||
}));
|
||||
|
||||
describe("slashCommands", () => {
|
||||
|
|
@ -141,8 +144,8 @@ describe("slashCommands", () => {
|
|||
expect(result?.output).toContain("Not logged in");
|
||||
expect(result?.output).toContain("Configuration:");
|
||||
expect(result?.output).toContain("/test/config.yaml");
|
||||
expect(result?.output).toContain("Session History:");
|
||||
expect(result?.output).toContain(".json");
|
||||
expect(result?.output).toContain("Session:");
|
||||
expect(result?.output).toContain("Session not available");
|
||||
expect(result?.exit).toBe(false);
|
||||
});
|
||||
|
||||
|
|
@ -244,12 +247,18 @@ describe("slashCommands", () => {
|
|||
it("should use test session directory when in test mode", async () => {
|
||||
const { isAuthenticated } = await import("./auth/workos.js");
|
||||
const { services } = await import("./services/index.js");
|
||||
const { getSessionFilePath } = await import("./session.js");
|
||||
const { getSessionFilePath, getCurrentSession } = await import(
|
||||
"./session.js"
|
||||
);
|
||||
|
||||
// Mock the session path for this specific test
|
||||
// Mock the session functions for this specific test
|
||||
(getSessionFilePath as any).mockReturnValue(
|
||||
"/test-home/.continue/cli-sessions/continue-cli-test-123.json",
|
||||
);
|
||||
(getCurrentSession as any).mockReturnValue({
|
||||
sessionId: "test-123",
|
||||
title: "Test Session",
|
||||
});
|
||||
|
||||
(
|
||||
isAuthenticated as MockedFunction<typeof isAuthenticated>
|
||||
|
|
@ -265,6 +274,8 @@ describe("slashCommands", () => {
|
|||
|
||||
const result = await handleSlashCommands("/info", mockAssistant);
|
||||
|
||||
expect(result?.output).toContain("Session:");
|
||||
expect(result?.output).toContain("Test Session");
|
||||
expect(result?.output).toContain("/test-home/.continue/cli-sessions/");
|
||||
expect(result?.output).toContain(".json");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import {
|
|||
} from "./auth/workos.js";
|
||||
import { getAllSlashCommands } from "./commands/commands.js";
|
||||
import { reloadService, SERVICE_NAMES, services } from "./services/index.js";
|
||||
import { getSessionFilePath } from "./session.js";
|
||||
import { getCurrentSession, getSessionFilePath } from "./session.js";
|
||||
import { posthogService } from "./telemetry/posthogService.js";
|
||||
import { SlashCommandResult } from "./ui/hooks/useChat.types.js";
|
||||
import { getVersion } from "./version.js";
|
||||
|
|
@ -179,12 +179,19 @@ async function handleInfo() {
|
|||
infoLines.push(` ${chalk.red("Configuration service not available")}`);
|
||||
}
|
||||
|
||||
// Session history path
|
||||
// Session info
|
||||
infoLines.push("");
|
||||
infoLines.push(chalk.white("Session History:"));
|
||||
const sessionFilePath = getSessionFilePath();
|
||||
infoLines.push(chalk.white("Session:"));
|
||||
try {
|
||||
const currentSession = getCurrentSession();
|
||||
infoLines.push(` Title: ${chalk.green(currentSession.title)}`);
|
||||
infoLines.push(` ID: ${chalk.gray(currentSession.sessionId)}`);
|
||||
|
||||
infoLines.push(` File: ${chalk.blue(sessionFilePath)}`);
|
||||
const sessionFilePath = getSessionFilePath();
|
||||
infoLines.push(` File: ${chalk.blue(sessionFilePath)}`);
|
||||
} catch {
|
||||
infoLines.push(` ${chalk.red("Session not available")}`);
|
||||
}
|
||||
|
||||
return {
|
||||
exit: false,
|
||||
|
|
|
|||
|
|
@ -342,6 +342,10 @@ export async function streamChatResponse(
|
|||
tools,
|
||||
});
|
||||
|
||||
if (abortController?.signal.aborted) {
|
||||
return finalResponse || content || fullResponse;
|
||||
}
|
||||
|
||||
fullResponse += content;
|
||||
|
||||
// Update final response based on mode
|
||||
|
|
|
|||
|
|
@ -188,6 +188,7 @@ const TUIChat: React.FC<TUIChatProps> = ({
|
|||
responseStartTime,
|
||||
inputMode,
|
||||
activePermissionRequest,
|
||||
wasInterrupted,
|
||||
handleUserMessage,
|
||||
handleInterrupt,
|
||||
handleFileAttached,
|
||||
|
|
@ -318,6 +319,7 @@ const TUIChat: React.FC<TUIChatProps> = ({
|
|||
handleInterrupt={handleInterrupt}
|
||||
handleFileAttached={handleFileAttached}
|
||||
isInputDisabled={isInputDisabled}
|
||||
wasInterrupted={wasInterrupted}
|
||||
isRemoteMode={isRemoteMode}
|
||||
/>
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ interface UserInputProps {
|
|||
inputMode: boolean;
|
||||
onInterrupt?: () => void;
|
||||
assistant?: AssistantConfig;
|
||||
wasInterrupted?: boolean;
|
||||
onFileAttached?: (filePath: string, content: string) => void;
|
||||
disabled?: boolean;
|
||||
placeholder?: string;
|
||||
|
|
@ -38,6 +39,7 @@ const UserInput: React.FC<UserInputProps> = ({
|
|||
inputMode,
|
||||
onInterrupt,
|
||||
assistant,
|
||||
wasInterrupted = false,
|
||||
onFileAttached,
|
||||
disabled = false,
|
||||
placeholder,
|
||||
|
|
@ -407,14 +409,18 @@ const UserInput: React.FC<UserInputProps> = ({
|
|||
}
|
||||
|
||||
// Normal Enter behavior - submit if there's content
|
||||
if (textBuffer.text.trim() && !isWaitingForResponse) {
|
||||
if ((textBuffer.text.trim() || wasInterrupted) && !isWaitingForResponse) {
|
||||
// Get images before expanding paste blocks
|
||||
const imageMap = textBuffer.getAllImages();
|
||||
|
||||
// Expand all paste blocks before submitting
|
||||
textBuffer.expandAllPasteBlocks();
|
||||
const submittedText = textBuffer.text.trim();
|
||||
inputHistory.addEntry(submittedText);
|
||||
|
||||
// Only add to history if there's actual text (not when resuming)
|
||||
if (submittedText) {
|
||||
inputHistory.addEntry(submittedText);
|
||||
}
|
||||
|
||||
// Submit with images
|
||||
onSubmit(submittedText, imageMap);
|
||||
|
|
@ -657,6 +663,15 @@ const UserInput: React.FC<UserInputProps> = ({
|
|||
|
||||
return (
|
||||
<Box flexDirection="column">
|
||||
{/* Interruption message - shown just above the input box */}
|
||||
{wasInterrupted && (
|
||||
<Box paddingX={1} marginBottom={0}>
|
||||
<Text color="yellow">
|
||||
⚠ Interrupted by user - Press enter to resume
|
||||
</Text>
|
||||
</Box>
|
||||
)}
|
||||
|
||||
{/* Input box */}
|
||||
<Box
|
||||
borderStyle="round"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,195 @@
|
|||
import { render } from "ink-testing-library";
|
||||
import React from "react";
|
||||
import { vi, expect, describe, it, beforeEach, afterEach } from "vitest";
|
||||
|
||||
import { UserInput } from "../UserInput.js";
|
||||
|
||||
describe("TUIChat - Interruption UI (Minimal Test)", () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.clearAllTimers();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it("shows interruption message when wasInterrupted is true", () => {
|
||||
const mockOnSubmit = vi.fn();
|
||||
const mockOnInterrupt = vi.fn();
|
||||
|
||||
const { lastFrame, rerender, unmount } = render(
|
||||
React.createElement(UserInput, {
|
||||
onSubmit: mockOnSubmit,
|
||||
isWaitingForResponse: false,
|
||||
inputMode: true,
|
||||
onInterrupt: mockOnInterrupt,
|
||||
wasInterrupted: false, // Initially false
|
||||
}),
|
||||
);
|
||||
|
||||
try {
|
||||
// Initial render - no interruption message
|
||||
let frame = lastFrame();
|
||||
expect(frame).toBeDefined();
|
||||
expect(frame).not.toContain("⚠ Interrupted by user");
|
||||
expect(frame).not.toContain("Press enter to resume");
|
||||
|
||||
// Re-render with wasInterrupted: true
|
||||
rerender(
|
||||
React.createElement(UserInput, {
|
||||
onSubmit: mockOnSubmit,
|
||||
isWaitingForResponse: false,
|
||||
inputMode: true,
|
||||
onInterrupt: mockOnInterrupt,
|
||||
wasInterrupted: true, // Now true
|
||||
}),
|
||||
);
|
||||
|
||||
// Should show interruption message
|
||||
frame = lastFrame();
|
||||
expect(frame).toBeDefined();
|
||||
expect(frame).toContain("⚠ Interrupted by user");
|
||||
expect(frame).toContain("Press enter to resume");
|
||||
} finally {
|
||||
unmount();
|
||||
}
|
||||
});
|
||||
|
||||
it("hides interruption message when wasInterrupted is false", () => {
|
||||
const mockOnSubmit = vi.fn();
|
||||
const mockOnInterrupt = vi.fn();
|
||||
|
||||
const { lastFrame, rerender, unmount } = render(
|
||||
React.createElement(UserInput, {
|
||||
onSubmit: mockOnSubmit,
|
||||
isWaitingForResponse: false,
|
||||
inputMode: true,
|
||||
onInterrupt: mockOnInterrupt,
|
||||
wasInterrupted: true, // Initially true
|
||||
}),
|
||||
);
|
||||
|
||||
try {
|
||||
// Initial render - should show interruption message
|
||||
let frame = lastFrame();
|
||||
expect(frame).toBeDefined();
|
||||
expect(frame).toContain("⚠ Interrupted by user");
|
||||
expect(frame).toContain("Press enter to resume");
|
||||
|
||||
// Re-render with wasInterrupted: false
|
||||
rerender(
|
||||
React.createElement(UserInput, {
|
||||
onSubmit: mockOnSubmit,
|
||||
isWaitingForResponse: false,
|
||||
inputMode: true,
|
||||
onInterrupt: mockOnInterrupt,
|
||||
wasInterrupted: false, // Now false
|
||||
}),
|
||||
);
|
||||
|
||||
// Should not show interruption message
|
||||
frame = lastFrame();
|
||||
expect(frame).toBeDefined();
|
||||
expect(frame).not.toContain("⚠ Interrupted by user");
|
||||
expect(frame).not.toContain("Press enter to resume");
|
||||
} finally {
|
||||
unmount();
|
||||
}
|
||||
});
|
||||
|
||||
it("calls onSubmit with empty string when Enter is pressed while interrupted", () => {
|
||||
const mockOnSubmit = vi.fn();
|
||||
const mockOnInterrupt = vi.fn();
|
||||
|
||||
const { stdin, unmount } = render(
|
||||
React.createElement(UserInput, {
|
||||
onSubmit: mockOnSubmit,
|
||||
isWaitingForResponse: false,
|
||||
inputMode: true,
|
||||
onInterrupt: mockOnInterrupt,
|
||||
wasInterrupted: true, // Interrupted state
|
||||
}),
|
||||
);
|
||||
|
||||
try {
|
||||
// Press Enter while in interrupted state
|
||||
stdin.write("\r");
|
||||
|
||||
// Should call onSubmit with empty string (for resume)
|
||||
expect(mockOnSubmit).toHaveBeenCalledWith("");
|
||||
} finally {
|
||||
unmount();
|
||||
}
|
||||
});
|
||||
|
||||
it("calls onSubmit with typed content when typing new message after interruption", () => {
|
||||
const mockOnSubmit = vi.fn();
|
||||
const mockOnInterrupt = vi.fn();
|
||||
|
||||
const { stdin, unmount } = render(
|
||||
React.createElement(UserInput, {
|
||||
onSubmit: mockOnSubmit,
|
||||
isWaitingForResponse: false,
|
||||
inputMode: true,
|
||||
onInterrupt: mockOnInterrupt,
|
||||
wasInterrupted: true, // Interrupted state
|
||||
}),
|
||||
);
|
||||
|
||||
try {
|
||||
// Type a new message
|
||||
stdin.write("New message after interruption");
|
||||
stdin.write("\r");
|
||||
|
||||
// Should call onSubmit with the typed content
|
||||
expect(mockOnSubmit).toHaveBeenCalledWith(
|
||||
"New message after interruption",
|
||||
);
|
||||
} finally {
|
||||
unmount();
|
||||
}
|
||||
});
|
||||
|
||||
it("shows interruption message above input box in correct position", () => {
|
||||
const mockOnSubmit = vi.fn();
|
||||
const mockOnInterrupt = vi.fn();
|
||||
|
||||
const { lastFrame, unmount } = render(
|
||||
React.createElement(UserInput, {
|
||||
onSubmit: mockOnSubmit,
|
||||
isWaitingForResponse: false,
|
||||
inputMode: true,
|
||||
onInterrupt: mockOnInterrupt,
|
||||
wasInterrupted: true,
|
||||
}),
|
||||
);
|
||||
|
||||
try {
|
||||
const frame = lastFrame();
|
||||
expect(frame).toBeDefined();
|
||||
|
||||
// The interruption message should appear before the input box
|
||||
const frameLines = frame?.split("\n") || [];
|
||||
|
||||
let foundInterruptionLine = -1;
|
||||
let foundInputBoxLine = -1;
|
||||
|
||||
frameLines.forEach((line, index) => {
|
||||
if (line.includes("⚠ Interrupted by user")) {
|
||||
foundInterruptionLine = index;
|
||||
}
|
||||
if (line.includes("●") && line.includes("▋")) {
|
||||
foundInputBoxLine = index;
|
||||
}
|
||||
});
|
||||
|
||||
// Interruption message should come before the input box
|
||||
expect(foundInterruptionLine).toBeGreaterThan(-1);
|
||||
expect(foundInputBoxLine).toBeGreaterThan(-1);
|
||||
expect(foundInterruptionLine).toBeLessThan(foundInputBoxLine);
|
||||
} finally {
|
||||
unmount();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -36,6 +36,7 @@ interface ScreenContentProps {
|
|||
handleInterrupt: () => void;
|
||||
handleFileAttached: (filePath: string, content: string) => void;
|
||||
isInputDisabled: boolean;
|
||||
wasInterrupted?: boolean;
|
||||
isRemoteMode: boolean;
|
||||
}
|
||||
|
||||
|
|
@ -57,6 +58,7 @@ export const ScreenContent: React.FC<ScreenContentProps> = ({
|
|||
handleInterrupt,
|
||||
handleFileAttached,
|
||||
isInputDisabled,
|
||||
wasInterrupted = false,
|
||||
isRemoteMode,
|
||||
}) => {
|
||||
// Login prompt
|
||||
|
|
@ -147,6 +149,7 @@ export const ScreenContent: React.FC<ScreenContentProps> = ({
|
|||
inputMode={inputMode}
|
||||
onInterrupt={handleInterrupt}
|
||||
assistant={services.config?.config || undefined}
|
||||
wasInterrupted={wasInterrupted}
|
||||
onFileAttached={handleFileAttached}
|
||||
disabled={isInputDisabled}
|
||||
isRemoteMode={isRemoteMode}
|
||||
|
|
|
|||
|
|
@ -232,7 +232,6 @@ export async function executeStreaming({
|
|||
chatHistory,
|
||||
currentCompactionIndex,
|
||||
);
|
||||
const _originalLength = historyForLLM.length;
|
||||
|
||||
await streamChatResponse(
|
||||
historyForLLM,
|
||||
|
|
|
|||
|
|
@ -108,6 +108,9 @@ export function useChat({
|
|||
return null;
|
||||
});
|
||||
|
||||
// Track interrupted state for resume functionality
|
||||
const [wasInterrupted, setWasInterrupted] = useState(false);
|
||||
|
||||
// Clean up abort controller on unmount
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
|
|
@ -183,7 +186,6 @@ export function useChat({
|
|||
const executeStreamingResponse = async (
|
||||
newHistory: ChatHistoryItem[],
|
||||
currentCompactionIndex: number | null,
|
||||
message: string,
|
||||
) => {
|
||||
// Clean up previous abort controller if it exists
|
||||
if (abortController && !abortController.signal.aborted) {
|
||||
|
|
@ -197,7 +199,6 @@ export function useChat({
|
|||
setResponseStartTime(Date.now());
|
||||
setInputMode(false);
|
||||
logger.debug("Starting chat response stream", {
|
||||
messageLength: message.length,
|
||||
historyLength: newHistory.length,
|
||||
});
|
||||
|
||||
|
|
@ -222,9 +223,6 @@ export function useChat({
|
|||
// Save the updated session with the latest chat history that includes the assistant's reply
|
||||
// The streamCallbacks update setChatHistory during streaming, so we need to get the current state
|
||||
setChatHistory((currentHistory) => {
|
||||
logger.debug("Saving session", {
|
||||
historyLength: currentHistory.length,
|
||||
});
|
||||
const updatedSession: Session = {
|
||||
...currentSession,
|
||||
history: currentHistory,
|
||||
|
|
@ -261,6 +259,39 @@ export function useChat({
|
|||
message: string,
|
||||
imageMap?: Map<string, Buffer>,
|
||||
) => {
|
||||
// Check if this is a resume request (empty message after interruption)
|
||||
if (message === "" && wasInterrupted) {
|
||||
// Find the index of the last user or tool message to resume from
|
||||
let lastUserOrToolIndex = -1;
|
||||
for (let i = chatHistory.length - 1; i >= 0; i--) {
|
||||
if (
|
||||
chatHistory[i].message.role === "user" ||
|
||||
!!chatHistory[i].toolCallStates?.length
|
||||
) {
|
||||
lastUserOrToolIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (lastUserOrToolIndex >= 0) {
|
||||
// Truncate history to include up to and including the user/tool message
|
||||
const truncatedHistory = chatHistory.slice(0, lastUserOrToolIndex + 1);
|
||||
setChatHistory(truncatedHistory);
|
||||
|
||||
// Clear the interrupted state and resume
|
||||
setWasInterrupted(false);
|
||||
|
||||
// Re-execute streaming with the truncated history
|
||||
await executeStreamingResponse(truncatedHistory, compactionIndex);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Clear interrupted state if user types a new message
|
||||
if (wasInterrupted && message !== "") {
|
||||
setWasInterrupted(false);
|
||||
}
|
||||
|
||||
// Handle special commands
|
||||
const handled = await handleSpecialCommands({
|
||||
message,
|
||||
|
|
@ -373,7 +404,7 @@ export function useChat({
|
|||
setChatHistory(newHistory);
|
||||
|
||||
// Execute the streaming response
|
||||
await executeStreamingResponse(newHistory, currentCompactionIndex, message);
|
||||
await executeStreamingResponse(newHistory, currentCompactionIndex);
|
||||
};
|
||||
|
||||
const handleInterrupt = () => {
|
||||
|
|
@ -395,16 +426,23 @@ export function useChat({
|
|||
// Local mode: abort the controller
|
||||
if (abortController && isWaitingForResponse) {
|
||||
abortController.abort();
|
||||
setChatHistory((prev) => [
|
||||
...prev,
|
||||
{
|
||||
message: {
|
||||
role: "system",
|
||||
content: "[Interrupted by user]",
|
||||
},
|
||||
contextItems: [],
|
||||
},
|
||||
]);
|
||||
|
||||
// Remove the last message if it's from assistant (partial response)
|
||||
setChatHistory((current) => {
|
||||
const lastMessage = current[current.length - 1];
|
||||
if (
|
||||
lastMessage?.message.role === "assistant" &&
|
||||
!lastMessage.toolCallStates?.length
|
||||
) {
|
||||
return current.slice(0, -1);
|
||||
}
|
||||
return current;
|
||||
});
|
||||
|
||||
setWasInterrupted(true);
|
||||
setIsWaitingForResponse(false);
|
||||
setResponseStartTime(null);
|
||||
setInputMode(true);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -494,6 +532,7 @@ export function useChat({
|
|||
inputMode,
|
||||
attachedFiles,
|
||||
activePermissionRequest,
|
||||
wasInterrupted,
|
||||
handleUserMessage,
|
||||
handleInterrupt,
|
||||
handleFileAttached,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue