Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 8, 2026

Implementation Plan for Chat History API ✅ COMPLETE

Based on the .NET PR #148, I need to implement the following in the Node.js/TypeScript SDK:

Phase 1: Runtime Package Updates

  • Create OperationResult class in runtime package
  • Create OperationError class in runtime package
  • Export new classes from runtime index

Phase 2: Tooling Package - Models

  • Create ChatHistoryMessage interface/class in tooling package
  • Create ChatMessageRequest interface/class in tooling package
  • Export new models from contracts or create models file
  • REFACTORED: Move models to models/ directory with one file per type

Phase 3: Tooling Package - Service Methods

  • Add GetChatHistoryEndpoint utility method to Utility class
  • Add SendChatHistory method overload (without ToolOptions) to McpToolServerConfigurationService
  • Add SendChatHistory method overload (with ToolOptions) to McpToolServerConfigurationService
  • Update interface exports

Phase 4: Testing

  • Create tests for OperationResult and OperationError (15 tests)
  • Create tests for ChatHistoryMessage model (3 tests)
  • Create tests for ChatMessageRequest model (3 tests)
  • Create tests for GetChatHistoryEndpoint utility (5 tests)
  • NEW: Create comprehensive tests for sendChatHistory method (20 tests)
  • Run all tests to ensure no regressions - All 284 tests passing

Phase 5: Build and Validation

  • Build all packages - Success
  • Run linting - No errors
  • Code review - No issues found
  • CodeQL security scan - No vulnerabilities found
  • Final validation - COMPLETE

Phase 6: Code Review Feedback

  • Refactor models into separate files in models/ directory
  • Add comprehensive tests for sendChatHistory method
  • FIX CI: Add --experimental-vm-modules flag for Node.js 18+ compatibility

Summary

Successfully implemented the chat history API for the MCP platform following the .NET SDK pattern:

Files Added (11):

  • packages/agents-a365-runtime/src/operation-error.ts
  • packages/agents-a365-runtime/src/operation-result.ts
  • packages/agents-a365-tooling/src/models/ChatHistoryMessage.ts
  • packages/agents-a365-tooling/src/models/ChatMessageRequest.ts
  • packages/agents-a365-tooling/src/models/index.ts
  • tests/runtime/operation-error.test.ts
  • tests/runtime/operation-result.test.ts
  • tests/tooling/models.test.ts
  • tests/tooling/utility.test.ts
  • tests/tooling/mcp-tool-server-configuration-service.test.ts

Files Modified (6):

  • packages/agents-a365-runtime/src/index.ts
  • packages/agents-a365-tooling/src/McpToolServerConfigurationService.ts
  • packages/agents-a365-tooling/src/Utility.ts
  • packages/agents-a365-tooling/src/index.ts
  • package.json (updated test scripts for Node.js 18+ compatibility)
  • tests/package.json (updated test scripts for Node.js 18+ compatibility)

Quality Metrics:

✅ 284/284 tests passing (46 new tests added)
✅ 100% build success
✅ 0 linting errors
✅ 0 code review issues
✅ 0 security vulnerabilities
✅ All copyright headers present
✅ Models organized in separate files per feedback
✅ Comprehensive test coverage for sendChatHistory method
✅ CI test failures fixed with --experimental-vm-modules flag

Original prompt

This section details on the original issue you should resolve

<issue_title>Implementation of API to send chat history to MCP platform.</issue_title>
<issue_description>Implement the generic API to send chat history to MCP platform. Follow the changes that were made for the .NET version of the SDK: microsoft/Agent365-dotnet#148</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- Add OperationResult and OperationError classes to runtime package
- Add ChatHistoryMessage and ChatMessageRequest models to tooling package
- Add GetChatHistoryEndpoint utility method
- Add sendChatHistory methods to McpToolServerConfigurationService
- Add comprehensive tests for all new functionality
- All builds and tests pass successfully

Co-authored-by: pontemonti <[email protected]>
Copilot AI changed the title [WIP] Implement API to send chat history to MCP platform Add chat history API for MCP platform real-time threat protection Jan 8, 2026
Copilot AI requested a review from pontemonti January 8, 2026 00:46
- Create models directory under src
- Split ChatHistoryMessage and ChatMessageRequest into separate files
- Add models/index.ts to export all models
- Update imports in McpToolServerConfigurationService and tests
- Delete old models.ts file
- All 264 tests passing, no regressions

Co-authored-by: pontemonti <[email protected]>
- Add 20 new tests for sendChatHistory method
- Test successful scenarios (with and without options, empty history)
- Test validation errors (null/undefined parameters, missing required fields)
- Test error handling (HTTP errors, timeouts, connection aborted)
- Test OperationResult behavior
- Test endpoint configuration (production and custom endpoints)
- All 284 tests passing, no regressions

Co-authored-by: pontemonti <[email protected]>
@pontemonti
Copy link
Contributor

@copilot - follow these instructions to address errors in PR workflow:
The failing job is due to test failures in tests/tooling/mcp-tool-server-configuration-service.test.ts. The logs show repeated failures to send chat history using axios, with errors including network errors, timeouts (ETIMEDOUT, ECONNABORTED), and HTTP 500 errors when posting to https://agent365.svc.cloud.microsoft/agents/real-time-threat-protection/chat-message. All occur inside McpToolServerConfigurationService.sendChatHistory.

Root causes and recommended solutions:

  1. ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG (Node v18+)

    • This error occurs when running Jest without the --experimental-vm-modules flag in Node.js v18+ (needed for ESM/vm module dynamic imports).
      Solution:
      In your test script in package.json, add:
    "test": "node --experimental-vm-modules ./node_modules/.bin/jest --config jest.config.cjs --passWithNoTests --testPathIgnorePatterns=/integration/"

    Or set the JEST_WORKER_ID workaround or update Jest to >=29.5 which handles this better.

  2. External POST request failures (axios errors in tests)

    • The failures in tests result from simulated network, timeout, and HTTP errors, which seems to be correctly handled in your code and tests.
    • If you're running unit tests, axios should be fully mocked (which your test does via jest.mock('axios')). If you see real network calls, ensure that no test disables the mock or that individual tests do not create unmocked axios instances.
  3. Node version

    • Ensure your CI runs with proper Node.js flags by updating the test script or the ci.yml workflow. In .github/workflows/ci.yml, under the “Run tests” step, change:
    - name: Run tests
      run: node --experimental-vm-modules ./node_modules/.bin/jest --config jest.config.cjs --passWithNoTests --testPathIgnorePatterns=/integration/

    This guarantees compatibility with your test suite and Node v18+.

Summary of changes:

  • Update your test command(s) in package.json and CI to include --experimental-vm-modules with Node 18+ (and possibly Node 20+).
  • Make sure axios is always mocked in tests.
  • Optional: Upgrade Jest to a version that fully supports ESM and dynamic vm modules on Node 18+.

These fixes will address the test failures and unblock your workflow.

References:

- Update test scripts in tests/package.json to use --experimental-vm-modules flag
- Update test:coverage and test:integration scripts in root package.json
- Use $(npm root)/../node_modules/.bin/jest to locate jest from monorepo root
- Fixes ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG error in Node.js 18+
- All 284 tests passing with Node.js 20

Co-authored-by: pontemonti <[email protected]>
Copy link
Contributor Author

Copilot AI commented Jan 8, 2026

@copilot - follow these instructions to address errors in PR workflow:
The failing job is due to test failures in tests/tooling/mcp-tool-server-configuration-service.test.ts. The logs show repeated f...

Fixed CI test failures by adding --experimental-vm-modules flag for Node.js 18+ compatibility:

  • Updated test scripts in tests/package.json to include the flag
  • Updated test:coverage and test:integration scripts in root package.json
  • Used $(npm root)/../node_modules/.bin/jest to correctly locate jest in monorepo
  • All 284 tests passing locally with Node.js 20

The axios errors in tests are intentional - they test error handling paths. The mock ensures no real network calls are made.

Commit: 9c9ff3a

@pontemonti pontemonti marked this pull request as ready for review January 8, 2026 05:08
Copilot AI review requested due to automatic review settings January 8, 2026 05:08
@pontemonti pontemonti requested a review from a team as a code owner January 8, 2026 05:08
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request successfully implements a chat history API for the MCP platform's real-time threat protection feature, following the patterns established in the .NET SDK (PR #148). The implementation adds new operation result handling classes to the runtime package, new data models for chat messages, and a service method to send chat history to the MCP platform.

Key Changes:

  • Added OperationResult and OperationError classes to the runtime package for standardized operation result handling
  • Created ChatHistoryMessage and ChatMessageRequest models in the tooling package with proper TypeScript interfaces
  • Implemented sendChatHistory method in McpToolServerConfigurationService with comprehensive error handling and logging
  • Added GetChatHistoryEndpoint utility method to construct the appropriate endpoint URL
  • Fixed Node.js 18+ compatibility by adding --experimental-vm-modules flag to test scripts

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/agents-a365-runtime/src/operation-error.ts New class that encapsulates operation errors with exception wrapping and message extraction
packages/agents-a365-runtime/src/operation-result.ts New class providing standardized success/failure result handling with error collection
packages/agents-a365-runtime/src/index.ts Exports new OperationError and OperationResult classes
packages/agents-a365-tooling/src/models/ChatHistoryMessage.ts Interface defining the structure of a chat message in history
packages/agents-a365-tooling/src/models/ChatMessageRequest.ts Interface for the request payload sent to the MCP platform
packages/agents-a365-tooling/src/models/index.ts Exports for the new model interfaces
packages/agents-a365-tooling/src/Utility.ts Added GetChatHistoryEndpoint method to construct the threat protection endpoint URL
packages/agents-a365-tooling/src/McpToolServerConfigurationService.ts Implemented sendChatHistory method with two overloads for sending chat history to MCP platform
packages/agents-a365-tooling/src/index.ts Added export for new models directory
tests/runtime/operation-error.test.ts Comprehensive tests for OperationError class (5 tests)
tests/runtime/operation-result.test.ts Tests for OperationResult success and failure scenarios (9 tests)
tests/tooling/models.test.ts Tests for ChatHistoryMessage and ChatMessageRequest models (6 tests)
tests/tooling/utility.test.ts Tests for GetChatHistoryEndpoint with various configurations (5 tests)
tests/tooling/mcp-tool-server-configuration-service.test.ts Comprehensive tests for sendChatHistory method including validation, error handling, and endpoint configuration (20 tests)
package.json Updated test scripts to include --experimental-vm-modules flag for Node.js 18+ compatibility
tests/package.json Updated test scripts with --experimental-vm-modules flag for Jest compatibility

@pontemonti pontemonti enabled auto-merge (squash) January 8, 2026 05:13
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.

Implementation of API to send chat history to MCP platform.

3 participants