feat: add state bag and ServerCallContextBuilder to ServerCallContext#364
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
🧪 Code Coverage
Generated by coverage-comment.yml |
There was a problem hiding this comment.
Code Review
The pull request introduces a state property to ServerCallContext and a ServerCallContextBuilder pattern, effectively mirroring the Python A2A SDK's capabilities. The implementation is robust, including a default builder that populates request headers into the state, and a withRequestedExtensions method that correctly handles context immutability. The changes are well-integrated into existing Express and gRPC handlers, and the new sample and comprehensive unit tests demonstrate and validate the new functionality. The code quality is high, and the changes align perfectly with the stated motivation and objectives.
87c04bd to
1a25ae6
Compare
1a25ae6 to
c612394
Compare
|
Friendly ping — this has been open for ~4 weeks with passing CI and positive review. Would love any feedback or a merge timeline if this fits the roadmap. |
|
Hi @ikubicki, thanks for the ping, we're currently working on 1.0 spec support (#321) and unfortunately don't have bandwidth for anything else, it's unlikely that we'll be able to incorporate this change in 0.3.x version, but we'll consider it for 1.0 as it's indeed a difference with Python you called out in the description. Could you please file an issue describing the problem? We'll link it to 1.0 milestone. For now rebasing this PR into 1.0 dev branch is a bit early as things may change there still, but we'll ping you once it's possible. Thank you! |
|
Hey @ikubicki, we've just pushed 1.0 alpha version available under Could you please rebase your PR onto |
c612394 to
ce8c2fe
Compare
- Fix context.spec.ts to use new ServerCallContext options object constructor - Fix server_call_context.ts sample: constructor, Message.parts format, AgentSkill.securityRequirements, AgentCard.supportedInterfaces - Fix rest_handler.ts: add 'as string' casts for Express 5 req.params typing - Install jose dependency for signature module
ce8c2fe to
f6e636d
Compare
…enant params Builder teraz dostaje wszystkie dane potrzebne do zbudowania kompletnego ServerCallContext - eliminuje dwuetapowy wzorzec create-base-then-overlay we wszystkich handlerach (JSONRPC, REST, gRPC).
…sitional args Introduces ServerCallContextBuilderOptions interface - rozszerzalne bez breaking change, spójne z ServerCallContextOptions.
|
@ishymko done :) |
Description
Motivation
The Python A2A SDK exposes a
statepropertyon
ServerCallContext— an arbitrary
MutableMapping[str, Any]used to pass metadata through the call pipeline.The Python app layer actively uses it (e.g.
call_context.state['method'] = method),and op-SDK implementations rely on it to carry request-scoped data such as tenant IDs,
auth tokens, or raw headers.
The TypeScript SDK was missing this capability, making it impossible to faithfully port
Python-based agent implementations to TypeScript without architectural workarounds.
Changes
ServerCallContextstateproperty — aMap<string, unknown>key/value bag, directly mirroringPython's
state: MutableMapping[str, Any].withRequestedExtensions()method that returns a new context with updated extensionswhile preserving
user,state, andactivatedExtensions.statemap.ServerCallContextBuilderServerCallContextBuilderfactory function type, mirroring Python's abstractCallContextBuilder.build(request)pattern.defaultServerCallContextBuilder— the default implementation that pre-populatesstatewith raw request headers under theheaderskey, mirroring Python'sDefaultCallContextBuilder.STATE_HEADERS_KEYconstant for the headers key.RequestHeaderstype — transport-agnostic representation of request headers.Express handlers (
jsonRpcHandler,restHandler)contextBuilder?: ServerCallContextBuildertoJsonRpcHandlerOptionsand
RestHandlerOptions, falling back todefaultServerCallContextBuilder.req.headersinto the context builder.gRPC handler
grpc_service.tsto pass request metadata as headers into the context builder.Exports
ServerCallContextBuilder,RequestHeaders,defaultServerCallContextBuilder,and
STATE_HEADERS_KEYare now exported from@a2a-js/sdk/server.Tests & samples
ServerCallContextAPI intest/server/context.spec.ts.src/samples/authentication/server_call_context.tsdemonstrating custom context usage.Impact
This change enables direct migration of Python A2A agent implementations to TypeScript —
any code relying on
context.statein the Python SDK will have a direct equivalent in theTypeScript SDK with the same semantics.
Checklist
CONTRIBUTINGGuide.