Skip to content

feat(agent): add generic type parameter to AgentState.getAll()#575

Open
NickEckardt wants to merge 1 commit intostrands-agents:mainfrom
NickEckardt:feat/getall-generic
Open

feat(agent): add generic type parameter to AgentState.getAll()#575
NickEckardt wants to merge 1 commit intostrands-agents:mainfrom
NickEckardt:feat/getall-generic

Conversation

@NickEckardt
Copy link

@NickEckardt NickEckardt commented Feb 26, 2026

The get, set, and delete methods all accept a generic for type-safe state access, but getAll() forced callers to use as casts. This adds a generic overload so callers can opt into a narrower return type (e.g. state.getAll()) without a cast, while the unparameterized overload continues to return Record<string, JSONValue>.

No runtime behavior changes.

Description

Adds a generic overload to AgentState.getAll() matching the existing pattern on get, set, and delete. Callers can now write state.getAll<MyState>() instead of state.getAll() as MyState. The extends Record<string, JSONValue> constraint ensures only compatible types can be asserted. The unparameterized getAll() overload continues to return Record<string, JSONValue> — no breaking changes.

Related Issues

None

Documentation PR

None — no new public API surface, just an additional overload on an existing method.

Type of Change

New feature

Testing

How have you tested the change?

  • I ran npm run check

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

The get, set, and delete methods all accept a <TState> generic for
type-safe state access, but getAll() forced callers to use `as` casts.
This adds a generic overload so callers can opt into a narrower return
type (e.g. state.getAll<AppState>()) without a cast, while the
unparameterized overload continues to return Record<string, JSONValue>.

No runtime behavior changes.
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.

2 participants