-
Notifications
You must be signed in to change notification settings - Fork 0
feat(runtime): expose typed request context to operation handlers and the test harness (#223) #273
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 all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
979738e
feat(runtime): expose typed request context to operation handlers and…
ScriptedAlchemy 8c8f5ed
test(runtime): pin the notices/inbox-route subpath in the packaging e…
ScriptedAlchemy afde7a2
test: register tool:harness/context in the contract matrix fixtures
ScriptedAlchemy 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| --- | ||
| "@agent-bundle/runtime": minor | ||
| "agent-bundle": minor | ||
| --- | ||
|
|
||
| Expose the transport-installed `AgentRequestContext` as optional | ||
| `context.request` to `defineOperation` handlers while preserving the same | ||
| request handle returned by `agent()`. Identity axes remain honest `Observed` | ||
| values with typed unavailable reasons when a transport cannot know them. | ||
|
|
||
| Document `await agent()` as the route-component context contract and the | ||
| `renderRoute(..., { context })` identity-injection seam for tests. Business | ||
| input cannot override host, session, actor, workspace, or capability context. |
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
46 changes: 46 additions & 0 deletions
46
packages/agent-bundle/fixtures/route-harness/src/mcp/harness/tools/context.tsx
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 @@ | ||
| import { Agent, agent, type JsonValue } from '@agent-bundle/runtime'; | ||
| import { z } from 'zod'; | ||
|
|
||
| export const config = { | ||
| description: 'Returns the request identity axes observed by this route.', | ||
| title: 'Context', | ||
| }; | ||
|
|
||
| export const inputSchema = z.object({ | ||
| host: z.string().optional(), | ||
| session: z.string().optional(), | ||
| }).strict(); | ||
|
|
||
| export const resultSchema = z.object({ | ||
| actor: z.unknown(), | ||
| host: z.unknown(), | ||
| session: z.unknown(), | ||
| workspace: z.unknown(), | ||
| }).strict(); | ||
|
|
||
| export default async function Context() { | ||
| const context = await agent(); | ||
| const actor: JsonValue = context.actor.state === 'available' | ||
| ? { source: context.actor.source, state: context.actor.state, value: { id: context.actor.value.id } } | ||
| : { reason: context.actor.reason, state: context.actor.state }; | ||
| const host: JsonValue = context.host.state === 'available' | ||
| ? { source: context.host.source, state: context.host.state, value: { name: context.host.value.name } } | ||
| : { reason: context.host.reason, state: context.host.state }; | ||
| const session: JsonValue = context.session.state === 'available' | ||
| ? { source: context.session.source, state: context.session.state, value: { sessionId: context.session.value.sessionId } } | ||
| : { reason: context.session.reason, state: context.session.state }; | ||
| const workspace: JsonValue = context.workspace.state === 'available' | ||
| ? { source: context.workspace.source, state: context.workspace.state, value: { root: context.workspace.value.root } } | ||
| : { reason: context.workspace.reason, state: context.workspace.state }; | ||
| const result = { | ||
| actor, | ||
| host, | ||
| session, | ||
| workspace, | ||
| }; | ||
| return ( | ||
| <Agent.Result value={result}> | ||
| <Agent.Text>Request context observed.</Agent.Text> | ||
| </Agent.Result> | ||
| ); | ||
| } |
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
defineOperation.executeruns outside an invocation, this probe now callsgetStore(), which both creates the realm-wideSymbol.for('@agent-bundle/runtime/request-store')store and throws if another installed runtime version already owns it. Consequently, an otherwise context-free direct operation can either fail withstore-version-conflictin a mixed-version process or claim the symbol and cause the other runtime to fail later, even though direct execution previously did not touch request storage. Make the non-throwing probe inspect an existing compatible store without creating or rejecting on an unrelated version.Useful? React with 👍 / 👎.