Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/agent/__tests__/state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,19 @@ describe('AgentState', () => {
const state = new AgentState()
expect(state.getAll()).toEqual({})
})

it('supports typed usage with generic state interface', () => {
interface MyState extends Record<string, number | string> {
count: number
name: string
}

const state = new AgentState({ count: 10, name: 'test' })
const result = state.getAll<MyState>()

expect(result.count).toBe(10)
expect(result.name).toBe('test')
})
})

describe('keys', () => {
Expand Down
12 changes: 12 additions & 0 deletions src/agent/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,20 @@ export class AgentState implements StateSerializable {
/**
* Get a copy of all state as an object.
*
* @typeParam TState - Optional state interface type for typed returns
* @returns Deep copy of all state
*
* @example
* ```typescript
* // Typed usage
* const all = state.getAll<AppState>() // AppState
*
* // Untyped usage
* const raw = state.getAll() // Record<string, JSONValue>
* ```
*/
getAll<TState extends Record<string, JSONValue>>(): TState
getAll(): Record<string, JSONValue>
getAll(): Record<string, JSONValue> {
return deepCopy(this._state) as Record<string, JSONValue>
}
Expand Down