feat(claude): add sendChatHistoryAsync for Claude Agent SDK#258
Open
gwharris7 wants to merge 9 commits into
Open
feat(claude): add sendChatHistoryAsync for Claude Agent SDK#258gwharris7 wants to merge 9 commits into
gwharris7 wants to merge 9 commits into
Conversation
0df9c99 to
ee5a71e
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Adds Claude parity with the OpenAI tooling extension by introducing a Claude-specific chat history sender that pulls session messages via the upgraded Claude Agent SDK and forwards them to the MCP platform for threat protection.
Changes:
- Implement
sendChatHistoryAsync/sendChatHistoryMessagesAsyncin the Claude tooling extension, including conversion fromSessionMessage[]toChatHistoryMessage[]. - Upgrade
@anthropic-ai/claude-agent-sdkto a version that exposesgetSessionMessages, and re-export relevant Claude SDK helpers/types. - Add comprehensive unit tests and update design documentation to reflect the new Claude chat history support.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/tooling-extensions-claude/sendChatHistoryAsync.test.ts | Adds unit tests for session retrieval, delegation, and error handling for sendChatHistoryAsync. |
| tests/tooling-extensions-claude/messageConversion.test.ts | Adds unit tests for role normalization, content extraction, and ID handling during message conversion. |
| tests/tooling-extensions-claude/fixtures/mockClaudeTypes.ts | Introduces test fixtures for creating representative Claude SessionMessage shapes (string + block content). |
| pnpm-workspace.yaml | Bumps workspace catalog Claude SDK version to enable getSessionMessages. |
| pnpm-lock.yaml | Updates the lockfile to the new Claude SDK graph and adds uuid / related transitive deps. |
| packages/agents-a365-tooling-extensions-claude/src/McpToolRegistrationService.ts | Implements new Claude chat history APIs and message conversion helpers. |
| packages/agents-a365-tooling-extensions-claude/src/index.ts | Re-exports Claude SDK getSessionMessages and types for convenience. |
| packages/agents-a365-tooling-extensions-claude/package.json | Adds uuid and @types/uuid dependencies for fallback ID generation. |
| packages/agents-a365-tooling-extensions-claude/docs/design.md | Updates design doc to mark issue #164 resolved and documents new APIs and conversion behavior. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
ee5a71e to
6573766
Compare
6573766 to
1e30e55
Compare
1e30e55 to
a5b6f83
Compare
a5b6f83 to
537fef1
Compare
Implement Claude-specific sendChatHistoryAsync and sendChatHistoryMessagesAsync methods that mirror the OpenAI implementation from PR #157. This resolves the gap tracked in issue #164. Changes: - Upgrade @anthropic-ai/claude-agent-sdk from ^0.1.30 to ^0.3.162 which includes the new getSessionMessages() API - Add sendChatHistoryAsync(turnContext, sessionId, limit?, toolOptions?) that retrieves session messages and sends them to the MCP platform for real-time threat protection - Add sendChatHistoryMessagesAsync for pre-fetched message arrays - Handle structured content blocks (text, tool_use, tool_result) - Normalize message types to standard roles (user, assistant, system, tool) - Add uuid dependency for fallback ID generation - Re-export getSessionMessages and SessionMessage from the package - Add comprehensive tests (28 passing) covering validation, conversion, error handling, and integration - Update design docs to reflect resolved state Resolves #164 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
537fef1 to
4c3ba5a
Compare
The @anthropic-ai/claude-agent-sdk is ESM-only (type: module), which causes Jest/ts-jest to hang when resolving imports. Added: - moduleNameMapper for the Claude SDK in jest.config.cjs - Manual mock at tests/__mocks__/@anthropic-ai/claude-agent-sdk.ts - Local MockSessionMessage type in fixtures (avoids ESM type import) - jest.requireMock pattern instead of direct import in test file - @ts-nocheck for sendChatHistoryAsync.test.ts (requireMock types) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Pin to exact 0.2.59 to avoid platform-specific native binaries introduced in 0.2.110. This removes: - 8 platform-specific optional deps (@anthropic-ai/claude-agent-sdk-*) - @anthropic-ai/sdk peer dependency - @babel/runtime and json-schema-to-ts transitive deps - @modelcontextprotocol/sdk (unused in Claude extension source) Net result: +12 -51 packages in lockfile. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…m/microsoft/Agent365-nodejs into gwharris7/claude-sdk-chat-history
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements a Claude-specific
sendChatHistoryAsyncmethod that mirrors the OpenAI implementation from PR #157, resolving the gap tracked in issue #164.The Claude Agent SDK (
@anthropic-ai/claude-agent-sdk) now exportsgetSessionMessages(sessionId, options?)which returnsSessionMessage[]. This PR leverages that API to provide first-class chat history support for Claude agents.Changes
Source (
packages/agents-a365-tooling-extensions-claude)McpToolRegistrationService— Added two new methods:sendChatHistoryAsync(turnContext, sessionId, limit?, toolOptions?)— Retrieves messages from a Claude session and sends them to the MCP platform for real-time threat protectionsendChatHistoryMessagesAsync(turnContext, messages, toolOptions?)— Sends pre-fetchedSessionMessage[]to the MCP platformtypefield (user,assistant,system) to standard chat rolesindex.ts— Re-exportsgetSessionMessages,SessionMessage, andGetSessionMessagesOptionsfor convenienceDependencies
@anthropic-ai/claude-agent-sdkfrom^0.1.30to^0.2.59(addsgetSessionMessagesAPI)uuiddependency for fallback ID generationTests (
tests/tooling-extensions-claude/)sendChatHistoryAsync.test.ts— 16 tests covering input validation, successful scenarios, error handling, OperationResult behavior, and integrationmessageConversion.test.ts— 12 tests covering role normalization, content extraction (string, blocks, tool calls), ID handling, and mixed contentDocumentation
docs/design.mdto reflect the resolved state with usage examples and API referenceResolves #164