Skip to content

improvement(copilot): improve context inputs and fix some bugs#1216

Merged
Sg312 merged 12 commits intostagingfrom
improvement/copilot-context
Sep 1, 2025
Merged

improvement(copilot): improve context inputs and fix some bugs#1216
Sg312 merged 12 commits intostagingfrom
improvement/copilot-context

Conversation

@Sg312
Copy link
Contributor

@Sg312 Sg312 commented Sep 1, 2025

Summary

  • Improves context options for user input (adds docs, logs, and workflow blocks)
  • Implicitly adds current workflow
  • Optimistic new/switch chat
  • Much better error logging

Fixes #(issue)

Type of Change

  • Bug fix
  • New feature

Testing

Manual

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Sep 1, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
sim Ready Ready Preview Comment Sep 1, 2025 11:50pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Sep 1, 2025 11:50pm

@Sg312 Sg312 changed the title Improvement/copilot context improvement(copilot): improve context inputs and fix some bugs Sep 1, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Summary

This PR significantly enhances the Copilot system by introducing a comprehensive context system and improving user experience. The changes implement four new context types: current_workflow (auto-added for workflow awareness), workflow_block (specific block references), logs (execution history), and docs (documentation search). The system now automatically includes current workflow context in conversations while allowing per-chat disabling, and supports @mention syntax for referencing different context types.

Key improvements include: changing the default agent depth from 0 to 1 to enable more conversational interactions with tool calling capabilities; implementing optimistic background message saving when switching between chats to prevent data loss; adding sophisticated message sanitization for documentation searches; and enhanced error handling with user-friendly messages. The handleNewChat function was optimized to provide immediate UI feedback by removing blocking waits on data loading operations.

The implementation spans across multiple layers - from frontend type definitions and UI components to backend API processing and database queries. The system maintains backward compatibility while adding granular context awareness that allows the Copilot to provide more targeted assistance based on the user's current working context.

Confidence score: 4/5

  • This PR introduces significant new functionality with generally solid implementation patterns, though the complexity increases risk
  • Score reflects comprehensive context system additions with proper error handling, but some complex state management logic could benefit from additional testing
  • Pay close attention to the user-input component and context processing logic due to their complexity

9 files reviewed, 7 comments

Edit Code Review Bot Settings | Greptile


const results = await Promise.all(tasks)
return results.filter((r): r is AgentContext => !!r)
return results.filter((r): r is AgentContext => !!r) as AgentContext[]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Redundant type assertion - the filter already ensures the correct type

Suggested change
return results.filter((r): r is AgentContext => !!r) as AgentContext[]
return results.filter((r): r is AgentContext => !!r)

kind: c?.kind,
chatId: c?.chatId,
workflowId: c?.workflowId,
executionId: (c as any)?.executionId,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Using (c as any)?.executionId bypasses TypeScript safety. Consider updating the ChatContext type to include executionId properly.

Context Used: Context - Avoid using type assertions to 'any' in TypeScript. Instead, ensure proper type definitions are used to maintain type safety. (link)

Comment on lines +690 to +697
// Clear @mention contexts after submission, but preserve current_workflow if not disabled
setSelectedContexts((prev) => {
// Keep current_workflow context if it's not disabled
const currentWorkflowCtx = prev.find(
(ctx) => ctx.kind === 'current_workflow' && !workflowAutoAddDisabled
)
return currentWorkflowCtx ? [currentWorkflowCtx] : []
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: The context preservation logic after submission has complex conditional behavior. Consider extracting this into a separate function for better testability and clarity.

Context Used: Context - If a switch statement is large and handles multiple cases, extract each case into separate functions for better maintainability. (link)

Comment on lines +1681 to +1694
setSelectedContexts((prev) => {
// Keep contexts that are mentioned in text OR are current_workflow (unless disabled)
const filteredContexts = prev.filter((c) => {
// Always preserve current_workflow context if it's not disabled
// It should only be removable via the X button
if (c.kind === 'current_workflow' && !workflowAutoAddDisabled) {
return true
}
// For other contexts, check if they're mentioned in text
return !!c.label && presentLabels.has(c.label!)
})

return filteredContexts
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: This context filtering logic is duplicated in multiple places (lines 690-697, 1670-1675). Consider extracting into a utility function to reduce duplication.

}

addWorkflowContext()
}, [workflowId, workflowAutoAddDisabled, workflows.length, message, justSentMessage]) // Re-run when message changes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: The dependency array includes workflows.length which could cause unnecessary re-runs. Consider using workflows directly or implementing a more stable dependency.

(result as any).execution?.error || (result as any).execution?.output?.error
}
}
} catch {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Empty catch block silently swallows all errors during result inspection, which could hide important debugging information

Comment on lines +107 to +124
if (result && typeof result === 'object' && 'success' in (result as any)) {
succeeded = Boolean((result as any).success)
if (!succeeded) {
errorMessage = (result as any)?.error || (result as any)?.output?.error
}
} else if (
result &&
typeof result === 'object' &&
'execution' in (result as any) &&
(result as any).execution &&
typeof (result as any).execution === 'object'
) {
succeeded = Boolean((result as any).execution.success)
if (!succeeded) {
errorMessage =
(result as any).execution?.error || (result as any).execution?.output?.error
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Multiple type assertions to any bypass TypeScript's type safety. Consider defining proper interfaces for the expected result structures

Suggested change
if (result && typeof result === 'object' && 'success' in (result as any)) {
succeeded = Boolean((result as any).success)
if (!succeeded) {
errorMessage = (result as any)?.error || (result as any)?.output?.error
}
} else if (
result &&
typeof result === 'object' &&
'execution' in (result as any) &&
(result as any).execution &&
typeof (result as any).execution === 'object'
) {
succeeded = Boolean((result as any).execution.success)
if (!succeeded) {
errorMessage =
(result as any).execution?.error || (result as any).execution?.output?.error
}
}
interface WorkflowResult {
success: boolean;
error?: string;
output?: { error?: string };
}
interface StreamingResult {
execution: WorkflowResult;
}
if (result && typeof result === 'object' && 'success' in result) {
const workflowResult = result as WorkflowResult
succeeded = Boolean(workflowResult.success)
if (!succeeded) {
errorMessage = workflowResult.error || workflowResult.output?.error
}
} else if (
result &&
typeof result === 'object' &&
'execution' in result &&
result.execution &&
typeof result.execution === 'object'
) {
const streamingResult = result as StreamingResult
succeeded = Boolean(streamingResult.execution.success)
if (!succeeded) {
errorMessage =
streamingResult.execution.error || streamingResult.execution.output?.error
}
}

Context Used: Context - Avoid using type assertions to 'any' in TypeScript. Instead, ensure proper type definitions are used to maintain type safety. (link)

@Sg312 Sg312 merged commit 12135d2 into staging Sep 1, 2025
5 checks passed
waleedlatif1 pushed a commit that referenced this pull request Sep 2, 2025
* Add logs v1

* Update

* Updates

* Updates

* Fixes

* Fix current workflow in context

* Fix mentions

* Error handling

* Fix chat loading

* Hide current workflow from context

* Run workflow fix

* Lint
waleedlatif1 added a commit that referenced this pull request Sep 2, 2025
…ode surface area and removed redundant code (#1217)

* improvement(invitations): consolidate invite-error and invite pages, made API endpoints more restful and reduced code surface area for invitations by 50%

* refactored logs API routes

* refactor rate limit api route, consolidate usage check api endpoint

* refactored chat page and invitations page

* consolidate ollama and openrouter stores to just providers store

* removed unused route

* removed legacy envvar methods

* remove dead, legacy routes for invitations PUT and workflow SYNC

* improvement(copilot): improve context inputs and fix some bugs (#1216)

* Add logs v1

* Update

* Updates

* Updates

* Fixes

* Fix current workflow in context

* Fix mentions

* Error handling

* Fix chat loading

* Hide current workflow from context

* Run workflow fix

* Lint

* updated invitation log

* styling for invitation pages

---------

Co-authored-by: Siddharth Ganesan <33737564+Sg312@users.noreply.github.com>
@waleedlatif1 waleedlatif1 deleted the improvement/copilot-context branch September 2, 2025 04:24
waleedlatif1 pushed a commit that referenced this pull request Sep 2, 2025
* Add logs v1

* Update

* Updates

* Updates

* Fixes

* Fix current workflow in context

* Fix mentions

* Error handling

* Fix chat loading

* Hide current workflow from context

* Run workflow fix

* Lint
waleedlatif1 added a commit that referenced this pull request Sep 2, 2025
…ode surface area and removed redundant code (#1217)

* improvement(invitations): consolidate invite-error and invite pages, made API endpoints more restful and reduced code surface area for invitations by 50%

* refactored logs API routes

* refactor rate limit api route, consolidate usage check api endpoint

* refactored chat page and invitations page

* consolidate ollama and openrouter stores to just providers store

* removed unused route

* removed legacy envvar methods

* remove dead, legacy routes for invitations PUT and workflow SYNC

* improvement(copilot): improve context inputs and fix some bugs (#1216)

* Add logs v1

* Update

* Updates

* Updates

* Fixes

* Fix current workflow in context

* Fix mentions

* Error handling

* Fix chat loading

* Hide current workflow from context

* Run workflow fix

* Lint

* updated invitation log

* styling for invitation pages

---------

Co-authored-by: Siddharth Ganesan <33737564+Sg312@users.noreply.github.com>
arenadeveloper02 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Sep 19, 2025
…udioai#1216)

* Add logs v1

* Update

* Updates

* Updates

* Fixes

* Fix current workflow in context

* Fix mentions

* Error handling

* Fix chat loading

* Hide current workflow from context

* Run workflow fix

* Lint
arenadeveloper02 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Sep 19, 2025
…ode surface area and removed redundant code (simstudioai#1217)

* improvement(invitations): consolidate invite-error and invite pages, made API endpoints more restful and reduced code surface area for invitations by 50%

* refactored logs API routes

* refactor rate limit api route, consolidate usage check api endpoint

* refactored chat page and invitations page

* consolidate ollama and openrouter stores to just providers store

* removed unused route

* removed legacy envvar methods

* remove dead, legacy routes for invitations PUT and workflow SYNC

* improvement(copilot): improve context inputs and fix some bugs (simstudioai#1216)

* Add logs v1

* Update

* Updates

* Updates

* Fixes

* Fix current workflow in context

* Fix mentions

* Error handling

* Fix chat loading

* Hide current workflow from context

* Run workflow fix

* Lint

* updated invitation log

* styling for invitation pages

---------

Co-authored-by: Siddharth Ganesan <33737564+Sg312@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant