Skip to content

feat(copilot): context#1157

Merged
Sg312 merged 34 commits intostagingfrom
feat/copilot-read-other-workflows
Aug 28, 2025
Merged

feat(copilot): context#1157
Sg312 merged 34 commits intostagingfrom
feat/copilot-read-other-workflows

Conversation

@Sg312
Copy link
Contributor

@Sg312 Sg312 commented Aug 28, 2025

Summary

Adds @ context to copilot
Also adds tools to view/set vars

Type of Change

  • 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 Aug 28, 2025

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

Project Deployment Preview Comments Updated (UTC)
sim Ready Ready Preview Comment Aug 28, 2025 4:09am
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Aug 28, 2025 4:09am

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 implements a comprehensive @ context feature for the copilot system, allowing users to reference and interact with various types of contextual information during conversations. The changes introduce a new ChatContext union type supporting 6 different context kinds: past_chat, workflow, blocks, logs, knowledge, and templates. Users can now type @ followed by context names to include relevant information in their copilot interactions.

The implementation spans multiple layers of the application:

Frontend UI Changes: The user input component (user-input.tsx) receives a major enhancement with over 1400 lines of new code implementing a sophisticated mention menu system with keyboard navigation, real-time filtering, and visual highlighting. The copilot message component now displays context chips above messages and highlights @ mentions in text.

Tool System Expansion: Five new client-side tools are added to support workflow operations (list_user_workflows, get_workflow_from_name, get_global_workflow_variables, set_global_workflow_variables) and OAuth integration (oauth_request_access). These tools follow the established BaseClientTool pattern with proper state management and error handling.

API and Backend Integration: New API endpoints are created (copilot chats route), existing endpoints are enhanced with context support, and a comprehensive context processing system (process-contents.ts) handles fetching and formatting contextual data from various sources including databases and registries.

State Management: The copilot store is updated to handle context data throughout the message lifecycle, including context validation, persistence in contentBlocks, and restoration from saved messages.

Infrastructure Updates: Chat title generation is enhanced to support both OpenAI and Azure OpenAI providers with model upgrades, and UI components are updated to properly display the new workflow variable operations with structured table layouts.

The feature integrates seamlessly with the existing copilot architecture while significantly expanding its capabilities to work with broader workspace context beyond just the immediate conversation.

Confidence score: 3/5

  • This PR introduces significant complexity with potential stability risks due to extensive new code and multiple type safety issues
  • Score reflects concerns about type assertions to 'any', complex state management, and insufficient error handling in critical paths
  • Pay close attention to user-input.tsx (1400+ lines), process-contents.ts (type safety issues), and tool registry files (type assertions)

Context used:

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

23 files reviewed, 28 comments

Edit Code Review Bot Settings | Greptile

gdrive_request_access: toolCallSSEFor(
'gdrive_request_access',
ToolArgSchemas.gdrive_request_access
ToolArgSchemas.gdrive_request_access as any
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Type assertion to 'any' bypasses TypeScript safety. Should define proper schema instead.

Suggested change
ToolArgSchemas.gdrive_request_access as any
ToolArgSchemas.gdrive_request_access

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 +95 to +96
{String((toolCall.parameters as any).method || '').toUpperCase() ||
'GET'}
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 throughout this section violate TypeScript safety. Consider defining proper interfaces for tool parameters.

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 +433 to +439
...(contexts && contexts.length > 0 && { contexts }),
...(contexts &&
contexts.length > 0 && {
contentBlocks: [
{ type: 'contexts', contexts: contexts as any, timestamp: Date.now() },
] as any,
}),
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: The contexts are stored twice in the message object - once as a top-level property and once in contentBlocks. This duplication could lead to synchronization issues if they get out of sync.

Comment on lines +183 to +184
key={idx}
className='grid grid-cols-3 items-center gap-0 px-2 py-1.5'
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Using array index as React key can cause rendering issues if operations order changes. Consider using a unique identifier if available.

onClosed as EventListener,
{
once: true,
} as any
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Type assertion to any bypasses TypeScript's event listener options checking

Suggested change
} as any
} satisfies AddEventListenerOptions

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 +53 to +58
const varsRecord = (json?.data as Record<string, any>) || {}
// Convert to name/value pairs for clarity
const variables = Object.values(varsRecord).map((v: any) => ({
name: String(v?.name || ''),
value: (v as any)?.value,
}))
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Using multiple type assertions to any could cause runtime errors if the API response structure changes. Consider defining proper types for the expected response format.

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 +376 to +378
{(Array.isArray((message as any).contexts) && (message as any).contexts.length > 0) ||
(Array.isArray(message.contentBlocks) &&
(message.contentBlocks as any[]).some((b: any) => b?.type === 'contexts')) ? (
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Complex conditional logic spread across multiple lines makes this hard to read and maintain. Consider extracting this into a helper function or using early returns.

Comment on lines +382 to +441
{(() => {
const direct = Array.isArray((message as any).contexts)
? ((message as any).contexts as any[])
: []
const block = Array.isArray(message.contentBlocks)
? (message.contentBlocks as any[]).find((b: any) => b?.type === 'contexts')
: null
const fromBlock = Array.isArray((block as any)?.contexts)
? ((block as any).contexts as any[])
: []
const allContexts = direct.length > 0 ? direct : fromBlock
const MAX_VISIBLE = 4
const visible = showAllContexts
? allContexts
: allContexts.slice(0, MAX_VISIBLE)
return (
<>
{visible.map((ctx: any, idx: number) => (
<span
key={`ctx-${idx}-${ctx?.label || ctx?.kind}`}
className='inline-flex items-center gap-1 rounded-full bg-[color-mix(in_srgb,var(--brand-primary-hover-hex)_14%,transparent)] px-1.5 py-0.5 text-[11px] text-foreground'
title={ctx?.label || ctx?.kind}
>
{ctx?.kind === 'past_chat' ? (
<Bot className='h-3 w-3 text-muted-foreground' />
) : ctx?.kind === 'workflow' ? (
<Workflow className='h-3 w-3 text-muted-foreground' />
) : ctx?.kind === 'blocks' ? (
<Blocks className='h-3 w-3 text-muted-foreground' />
) : ctx?.kind === 'knowledge' ? (
<LibraryBig className='h-3 w-3 text-muted-foreground' />
) : ctx?.kind === 'templates' ? (
<Shapes className='h-3 w-3 text-muted-foreground' />
) : (
<Info className='h-3 w-3 text-muted-foreground' />
)}
<span className='max-w-[140px] truncate'>
{ctx?.label || ctx?.kind}
</span>
</span>
))}
{allContexts.length > MAX_VISIBLE && (
<button
type='button'
onClick={() => setShowAllContexts((v) => !v)}
className='inline-flex items-center gap-1 rounded-full bg-[color-mix(in_srgb,var(--brand-primary-hover-hex)_10%,transparent)] px-1.5 py-0.5 text-[11px] text-foreground hover:bg-[color-mix(in_srgb,var(--brand-primary-hover-hex)_14%,transparent)]'
title={
showAllContexts
? 'Show less'
: `Show ${allContexts.length - MAX_VISIBLE} more`
}
>
{showAllContexts
? 'Show less'
: `+${allContexts.length - MAX_VISIBLE} more`}
</button>
)}
</>
)
})()}
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 IIFE contains complex state logic that's difficult to follow. The context merging logic should be extracted into a custom hook or utility function for better testability and reusability.

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 +498 to +530
{(() => {
const text = message.content || ''
const contexts: any[] = Array.isArray((message as any).contexts)
? ((message as any).contexts as any[])
: []
const labels = contexts.map((c) => c?.label).filter(Boolean) as string[]
if (!labels.length) return <WordWrap text={text} />

const escapeRegex = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
const pattern = new RegExp(`@(${labels.map(escapeRegex).join('|')})`, 'g')

const nodes: React.ReactNode[] = []
let lastIndex = 0
let match: RegExpExecArray | null
while ((match = pattern.exec(text)) !== null) {
const i = match.index
const before = text.slice(lastIndex, i)
if (before) nodes.push(before)
const mention = match[0]
nodes.push(
<span
key={`mention-${i}-${lastIndex}`}
className='rounded-[6px] bg-[color-mix(in_srgb,var(--brand-primary-hover-hex)_14%,transparent)] px-1'
>
{mention}
</span>
)
lastIndex = i + mention.length
}
const tail = text.slice(lastIndex)
if (tail) nodes.push(tail)
return nodes
})()}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Another IIFE with complex regex logic and React node manipulation. This mention highlighting logic should be extracted into a separate function or custom hook.

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 +500 to +502
const contexts: any[] = Array.isArray((message as any).contexts)
? ((message as any).contexts as any[])
: []
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 any[] type assertions throughout the contexts handling. Consider defining proper TypeScript interfaces for better type safety.

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 force-pushed the feat/copilot-read-other-workflows branch from 9ce1a1b to 939c93a Compare August 28, 2025 04:04
@vercel vercel bot temporarily deployed to Preview – docs August 28, 2025 04:04 Inactive
@Sg312 Sg312 merged commit 06e9a6b into staging Aug 28, 2025
4 of 5 checks passed
aadamgough pushed a commit that referenced this pull request Aug 28, 2025
* Copilot updates

* Set/get vars

* Credentials opener v1

* Progress

* Checkpoint?

* Context v1

* Workflow references

* Add knowledge base context

* Blocks

* Templates

* Much better pills

* workflow updates

* Major ui

* Workflow box colors

* Much i mproved ui

* Improvements

* Much better

* Add @ icon

* Welcome page

* Update tool names

* Matches

* UPdate ordering

* Good sort

* Good @ handling

* Update placeholder

* Updates

* Lint

* Almost there

* Wrapped up?

* Lint

* Builid error fix

* Build fix?

* Lint

* Fix load vars
@waleedlatif1 waleedlatif1 deleted the feat/copilot-read-other-workflows branch August 29, 2025 05:01
arenadeveloper02 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Sep 19, 2025
* Copilot updates

* Set/get vars

* Credentials opener v1

* Progress

* Checkpoint?

* Context v1

* Workflow references

* Add knowledge base context

* Blocks

* Templates

* Much better pills

* workflow updates

* Major ui

* Workflow box colors

* Much i mproved ui

* Improvements

* Much better

* Add @ icon

* Welcome page

* Update tool names

* Matches

* UPdate ordering

* Good sort

* Good @ handling

* Update placeholder

* Updates

* Lint

* Almost there

* Wrapped up?

* Lint

* Builid error fix

* Build fix?

* Lint

* Fix load vars
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