refactor: extract shared protocol kernel into @agentic-kit/protocol#12
Merged
Conversation
Extract the shared protocol kernel — types, EventStream, and the usage/message/JSON/base-url helpers — into a standalone leaf package with no runtime dependencies, so every provider adapter can depend on it without pulling in the framework. Establishes a single source of truth for the contract that was previously copy-pasted across packages.
Drop the local kernel copies (types, event-stream, messages) and import them from @agentic-kit/protocol, re-exporting the package so the public surface is unchanged. agentic-kit still depends on all three providers, auto-registers them on module load, and owns the createXKit helpers — import 'agentic-kit' behaves exactly as before.
Point the openai, anthropic, and ollama adapters at @agentic-kit/protocol instead of re-declaring the kernel locally, removing ~900 lines of byte-identical and drifting copies. Each adapter now depends only on the zero-dep kernel, so it stays independently installable, and all three share the canonical Context.tools, ToolCallContent.rawArguments/decision, and full StreamOptions.
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
Extracts the duplicated protocol kernel — types,
EventStream, and the usage/message/JSON/base-url helpers — into a new zero-dependency@agentic-kit/protocolleaf package, and points all four packages (the three provider adapters plusagentic-kit) at it. This replaces ~900 lines of byte-identical (and already drifting) copies with a single source of truth.Why
The kernel was copy-pasted across
agentic-kitand the three providers because of a dependency cycle:agentic-kitdepends on the providers and registers them at module load, so the providers couldn't import back fromagentic-kit. The copies had started to drift (e.g. ollama'sContexthad notoolsfield; no provider copy carriedToolCallContent.decision) — a latent correctness risk. A zero-dep leaf package that everything depends on breaks the cycle without inverting it.Key properties
agentic-kitstill depends on all three providers, auto-registers them on module load, re-exports them, and ownscreateOpenAIKit/createAnthropicKit/createOllamaKit/createMultiProviderKit.import 'agentic-kit'behaves exactly as before — no consumer changes (apps/is untouched).Context.tools,ToolCallContent.rawArguments,ToolCallContent.decision, and the full 12-fieldStreamOptions.Net effect
~-819 source lines. anthropic 891→557, openai 966→621, ollama 738→501; kernel single-sourced at 600 lines in
@agentic-kit/protocol.Verification
@agentic-kit/protocol→ {openai, anthropic, ollama} → agentic-kit → agent → reacttsc --noEmitclean; lint clean on all changed sourcesCommits
feat(protocol)— add the zero-dep packagerefactor(agentic-kit)— source the kernel from the package, drop local copiesrefactor(providers)— point openai/anthropic/ollama at the package