Skip to content

feat: Microsoft.Extensions.AI IChatClient integration#2

Merged
KSemenenko merged 2 commits intomanagedcode:mainfrom
luisquintanilla:feature/meai-integration
Mar 5, 2026
Merged

feat: Microsoft.Extensions.AI IChatClient integration#2
KSemenenko merged 2 commits intomanagedcode:mainfrom
luisquintanilla:feature/meai-integration

Conversation

@luisquintanilla
Copy link
Contributor

Summary

Implements the IChatClient adapter for CodexSharpSDK as a separate NuGet package ManagedCode.CodexSharpSDK.Extensions.AI, enabling standard M.E.AI consumer patterns (DI, middleware pipelines, provider-agnostic code).

What's included

  • CodexChatClient : IChatClient - full sync + streaming support
  • 5 custom AIContent types - CommandExecution, FileChange, McpToolCall, WebSearch, CollabToolCall
  • 4 internal mappers - ChatMessage, ChatOptions, ChatResponse, StreamingEvent
  • DI extensions - AddCodexChatClient / AddKeyedCodexChatClient
  • 26 unit tests - all mappers + DI registration
  • Documentation - ADR 003, feature doc, README section, architecture overview update

Design decisions

  • Separate package keeps core SDK M.E.AI-free
  • Rich Codex items preserved as typed AIContent subclasses (not flattened to text)
  • Codex-specific options via codex:* prefixed AdditionalProperties keys
  • Thread-per-call with ConversationId for multi-turn resume

Closes #1

Implement ManagedCode.CodexSharpSDK.Extensions.AI adapter package that
bridges CodexSharpSDK to the standard IChatClient interface from
Microsoft.Extensions.AI.Abstractions.

New package:
- CodexChatClient : IChatClient with sync/streaming support
- Custom AIContent types: CommandExecution, FileChange, McpToolCall,
  WebSearch, CollabToolCall
- Internal mappers: ChatMessage, ChatOptions, ChatResponse, Streaming
- DI extensions: AddCodexChatClient / AddKeyedCodexChatClient
- 26 unit tests covering all mappers and DI registration

Documentation:
- ADR 003: Microsoft.Extensions.AI Integration
- Feature doc: docs/Features/meai-integration.md
- README: M.E.AI usage section with examples
- Architecture overview updated with new module

Closes managedcode#1

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@KSemenenko
Copy link
Member

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bc11f2f2a7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +47 to +49
if (userTextParts.Count > 0)
{
prompt.Append(string.Join("\n\n", userTextParts));

Choose a reason for hiding this comment

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

P1 Badge Preserve message chronology when composing prompt

User text is collected into userTextParts and appended only after all messages are processed, while system/assistant text is appended immediately. In a normal history like User → Assistant → User, this reorders context so assistant output appears before the first user prompt, which can change model behavior and produce incorrect responses for IChatClient callers that pass full transcript history.

Useful? React with 👍 / 👎.

Copy link
Member

Choose a reason for hiding this comment

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

@codex fix this

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

@copilot fix this

Comment on lines +8 to +10
public CodexOptions? CodexOptions { get; init; }
public string? DefaultModel { get; init; }
public ThreadOptions? DefaultThreadOptions { get; init; }

Choose a reason for hiding this comment

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

P2 Badge Allow DI configuration delegate to set options

CodexChatClientOptions properties are init-only, but the DI extensions use an Action<CodexChatClientOptions> callback on an already-created instance. Consumers therefore cannot set DefaultModel/thread defaults inside AddCodexChatClient(...) configuration (assignments to init setters won't compile there), making the public configuration hook effectively non-functional.

Useful? React with 👍 / 👎.

Copy link
Member

Choose a reason for hiding this comment

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

@codex fix this

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

@copilot fix this

@KSemenenko KSemenenko merged commit d2203c0 into managedcode:main Mar 5, 2026
2 checks passed
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.

Implement Microsoft.Extensions.AI (IChatClient) integration

2 participants