-
Notifications
You must be signed in to change notification settings - Fork 84
feat: server middleware API #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 38 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
90d93c6
make core types gob-serializable
yarolegovich a70892e
in-memory task store
yarolegovich 043ba2e
task update logic
yarolegovich 80d3853
concurrent task execution and cancelation management
yarolegovich 14da9f8
taskexec integration with default request handler
yarolegovich 0df268e
prevent possibility of failed cancelation destroying the queue which …
yarolegovich 67290a0
comments and t.Helper() calls
yarolegovich efd6922
Merge branch 'main' into yarolegovich/result-aggregation-3
yarolegovich ef1170a
lint
yarolegovich a1971d9
Merge branch 'main' into yarolegovich/result-aggregation-3
yarolegovich 601aeda
Merge branch 'yarolegovich/result-aggregation-4' into yarolegovich/re…
yarolegovich 789dfb2
artifact update logic
yarolegovich 9e28fb2
OnSendMessageStream() and tests
yarolegovich 2a84c8b
test and fix
yarolegovich 2fa71f4
PR review improvements
yarolegovich eeba7ff
Merge branch 'main' into yarolegovich/result-aggregation-4
yarolegovich c5c9812
fix blocking on nil channel and empty yield(nil, nil) in defer
yarolegovich c7251a7
lint
yarolegovich d7fdefe
Merge branch 'yarolegovich/result-aggregation-4' into yarolegovich/ar…
yarolegovich 60944c4
pass RequestContext by reference
yarolegovich e87b83b
add missing validations, move request context loading into a protecte…
yarolegovich 5910152
added request context interceptor
yarolegovich f5ec037
fix race
yarolegovich f853184
interceptor tests
yarolegovich 301d555
fix producer errors not reported
yarolegovich dc4eb45
make handler tests exercise real queues
yarolegovich d629498
comment clarification
yarolegovich c5c795a
fix error masking
yarolegovich 8dbd52b
Merge branch 'main' into yarolegovich/artifacts
yarolegovich 12bb659
refactor messages
yarolegovich bb87035
Merge branch 'yarolegovich/artifacts' into yarolegovich/req-ctx-loading
yarolegovich 6c17632
refactor test messages
yarolegovich c6bbb24
server middleware API
yarolegovich 1e83bdc
fix interceptor ordering
yarolegovich 66d0ee9
licenses
yarolegovich fed7ce6
Merge branch 'main' into yarolegovich/call-ctx-api
yarolegovich 054700f
Merge branch 'main' into yarolegovich/call-ctx-api
yarolegovich 2b71078
fix after merge
yarolegovich 7f2f031
fix grammar
yarolegovich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // Copyright 2025 The A2A Authors | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package a2asrv | ||
|
|
||
| // User can be attached to call context by authentication middleware. | ||
| type User interface { | ||
| // Name returns a username. | ||
| Name() string | ||
| // Authenticated returns true if requested was authenticated. | ||
| Authenticated() bool | ||
| } | ||
|
|
||
| // AuthenticatedUser is a simple implementation of User interface which can be configured with a username. | ||
| type AuthenticatedUser struct { | ||
| UserName string | ||
| } | ||
|
|
||
| func (u *AuthenticatedUser) Name() string { | ||
| return u.UserName | ||
| } | ||
|
|
||
| func (u *AuthenticatedUser) Authenticated() bool { | ||
| return true | ||
| } | ||
|
|
||
| type unauthenticatedUser struct{} | ||
|
|
||
| func (unauthenticatedUser) Name() string { | ||
| return "" | ||
| } | ||
|
|
||
| func (unauthenticatedUser) Authenticated() bool { | ||
| return false | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| // Copyright 2025 The A2A Authors | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package a2asrv | ||
|
|
||
| import ( | ||
| "context" | ||
| "slices" | ||
|
|
||
| "github.com/a2aproject/a2a-go/a2a" | ||
| ) | ||
|
|
||
| const ExtensionsMetaKey = "X-A2A-Extensions" | ||
|
|
||
| // Extensions provides utility methods for accessing extensions requested by the client and keeping track of extensions | ||
| // activated during request processing. | ||
| type Extensions struct { | ||
| callCtx *CallContext | ||
| } | ||
|
|
||
| // ExtensionsFrom is a helper function for quick access to Extensions in the current CallContext. | ||
| func ExtensionsFrom(ctx context.Context) (*Extensions, bool) { | ||
| serverCallCtx, ok := CallContextFrom(ctx) | ||
| if !ok { | ||
| return nil, false | ||
| } | ||
| return serverCallCtx.Extensions(), true | ||
| } | ||
|
|
||
| // Active returns true if an extension has already been activated in the current CallContext using ExtensionContext.Activate. | ||
| func (e *Extensions) Active(extension *a2a.AgentExtension) bool { | ||
| return slices.Contains(e.callCtx.activatedExtensions, extension.URI) | ||
| } | ||
|
|
||
| // Activate marks extension as activated in the current CallContext. A list of activated extensions might be attached as | ||
| // response metadata by a transport implementation. | ||
| func (e *Extensions) Activate(extension *a2a.AgentExtension) { | ||
| if e.Active(extension) { | ||
| return | ||
| } | ||
| e.callCtx.activatedExtensions = append(e.callCtx.activatedExtensions, extension.URI) | ||
| } | ||
|
|
||
| // ActivatedURIs returns all URIs activated during call execution. | ||
| func (e *Extensions) ActivatedURIs() []string { | ||
| return slices.Clone(e.callCtx.activatedExtensions) | ||
| } | ||
|
|
||
| // Requested returns true if the provided extension was requested by the client. | ||
| func (e *Extensions) Requested(extension *a2a.AgentExtension) bool { | ||
| return slices.Contains(e.RequestedURIs(), extension.URI) | ||
| } | ||
|
|
||
| // RequestedURIs returns all URIs of extensions requested by the client. | ||
| func (e *Extensions) RequestedURIs() []string { | ||
| requested, ok := e.callCtx.RequestMeta().Get(ExtensionsMetaKey) | ||
| if !ok { | ||
| return []string{} | ||
| } | ||
| return slices.Clone(requested) | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.