Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement initial agentsync hook and frontend integration #733

Closed
AtlantisPleb opened this issue Feb 19, 2025 · 3 comments · Fixed by #736 · May be fixed by #753
Closed

Implement initial agentsync hook and frontend integration #733

AtlantisPleb opened this issue Feb 19, 2025 · 3 comments · Fixed by #736 · May be fixed by #753

Comments

@AtlantisPleb
Copy link
Contributor

This is a sub-issue of #730 focused on the initial frontend implementation of the agentsync hook and its integration with the chat interface.

Tasks

  1. Create agentsync folder structure:
frontend/app/lib/agentsync/
├── index.ts       # Main exports
├── types.ts       # TypeScript types/interfaces
└── hooks/
    └── useAgentSync.ts  # Initial hook implementation
  1. Add path alias to tsconfig.json:
{
  "compilerOptions": {
    "paths": {
      "agentsync": ["./app/lib/agentsync"]
    }
  }
}
  1. Implement initial hook with types:
  • Define core types for sync state and operations
  • Implement basic hook structure
  • Add initial sync operations
  • Include proper TypeScript coverage
  1. Integrate with chat interface:
  • Update chat form submission to use the hook
  • Handle repo sync state
  • Prepare for backend integration

Implementation Details

Types (types.ts)

export interface SyncState {
  isOnline: boolean;
  lastSyncId: number;
  pendingChanges: number;
}

export interface SyncOptions {
  scope: string;
  models?: string[];
  subscribe?: string[];
}

export interface AgentSyncHook {
  state: SyncState;
  sendMessage: (content: string) => Promise<void>;
  // Additional methods will be added as needed
}

Hook Implementation (useAgentSync.ts)

Initial version will focus on:

  • Connection state management
  • Basic message sending
  • Preparation for full sync capabilities

Chat Integration

The hook will be used in the chat index component for:

  • Message submission
  • Repo state sync
  • Real-time updates

Next Steps

  1. Review and approve implementation plan
  2. Implement core functionality
  3. Add tests
  4. Integrate with backend sync engine

Related: #730

@AtlantisPleb
Copy link
Contributor Author

Status update on implementation:

Completed all initial tasks with the following changes:

  1. Created agentsync folder structure with initial files:
frontend/app/lib/agentsync/
├── index.ts       # Main exports
├── types.ts       # TypeScript types/interfaces
└── hooks/
    └── useAgentSync.ts  # Initial hook implementation
  1. Added path alias in tsconfig.json:
{
  "compilerOptions": {
    "paths": {
      "agentsync": ["./app/lib/agentsync"]
    }
  }
}
  1. Implemented core types (types.ts):
export interface SyncState {
  isOnline: boolean;
  lastSyncId: number;
  pendingChanges: number;
}

export interface SyncOptions {
  scope: string;
  models?: string[];
  subscribe?: string[];
}

export interface StartChatResponse {
  id: string;
  initialMessage: string;
}

export interface AgentSyncHook {
  state: SyncState;
  sendMessage: (content: string, repos?: string[]) => Promise<StartChatResponse>;
}
  1. Implemented useAgentSync hook with:
  • Online/offline detection
  • Client-side UUID generation for chat sessions
  • Proper error handling
  • Type-safe API responses
  1. Updated chat components:
  • Modified ChatInput to handle async submissions
  • Added submission state handling
  • Fixed Enter key submission
  • Added proper loading states
  • Improved error handling
  1. Added dependencies:
  • uuid
  • @types/uuid

All changes are on the startsync branch. The implementation now provides:

  • Client-generated UUIDs for chat sessions
  • Immediate navigation to chat sessions
  • Proper handling of async operations
  • Full TypeScript coverage
  • Improved error states and loading indicators

Next steps:

  1. Implement backend endpoint
  2. Add WebSocket connection
  3. Implement full sync protocol
  4. Add offline queue functionality

(Comment from OpenAgents)

@AtlantisPleb
Copy link
Contributor Author

Instructions for implementing initial backend endpoint:

  1. Create a new endpoint at /api/start-repo-chat that accepts POST requests with this structure:
// Request body type
interface StartRepoChatRequest {
  id: string;        // Client-generated UUID
  message: string;   // User's message
  repos: string[];   // Array of repo strings like "owner/name#branch"
  scope: string;     // Currently always "chat"
}

// Response type (must match frontend StartChatResponse)
interface StartChatResponse {
  id: string;           // Echo back the same UUID
  initialMessage: string; // Echo back the same message for now
}
  1. Minimum successful response example:
{
  "id": "123e4567-e89b-12d3-a456-426614174000",
  "initialMessage": "Hello, I'll help you with repo xyz"
}
  1. Implementation requirements:
  • Accept POST requests only
  • Validate request body matches expected type
  • Return 400 for invalid requests
  • Return 200 with StartChatResponse for valid requests
  • Set Content-Type: application/json
  • Handle CORS if needed
  1. Error response format:
{
  "error": "Invalid request format",
  "details": "Missing required field: message"
}

Start with the absolute minimum implementation that validates and echoes back the input. We'll add actual chat processing logic later.

Test with this curl command:

curl -X POST http://localhost:3000/api/start-repo-chat \
  -H "Content-Type: application/json" \
  -d '{
    "id": "123e4567-e89b-12d3-a456-426614174000",
    "message": "Help me with repo xyz",
    "repos": ["owner/repo#main"],
    "scope": "chat"
  }'

Expected 200 response:

{
  "id": "123e4567-e89b-12d3-a456-426614174000",
  "initialMessage": "Help me with repo xyz"
}

(Comment from OpenAgents)

@AtlantisPleb
Copy link
Contributor Author

I've implemented the backend endpoint for starting repo chats as requested. The changes include:

  1. Created a new chat handler module at backend/src/server/handlers/chat.rs with:

    • StartRepoChatRequest struct matching the frontend types
    • StartChatResponse struct for the response
    • start_repo_chat handler function that:
      • Creates a new conversation in the database
      • Creates the initial message
      • Returns the conversation ID and initial message
  2. Added the new module to backend/src/server/handlers/mod.rs

  3. Added the route to the main router in backend/src/server/config.rs:

    .route("/api/start-repo-chat", post(server::handlers::start_repo_chat))

The endpoint accepts POST requests to /api/start-repo-chat with this structure:

// Request
{
  id: string,        // Client-generated UUID
  message: string,   // User's message
  repos: string[],   // Array of repo strings like "owner/name#branch"
  scope: string      // Currently always "chat"
}

// Response
{
  id: string,           // Conversation UUID
  initial_message: string // Echo back the same message for now
}

Next steps:

  1. Add user session handling to get the actual user ID
  2. Add repo validation
  3. Implement the AI chat logic
  4. Add WebSocket integration for real-time updates

All changes are on the startsync branch.

(Comment from OpenAgents)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant