@@ -8,7 +8,10 @@ import {
8
8
} from '../src/runState' ;
9
9
import { RunContext } from '../src/runContext' ;
10
10
import { Agent } from '../src/agent' ;
11
- import { RunToolApprovalItem as ToolApprovalItem } from '../src/items' ;
11
+ import {
12
+ RunToolApprovalItem as ToolApprovalItem ,
13
+ RunMessageOutputItem ,
14
+ } from '../src/items' ;
12
15
import { computerTool } from '../src/tool' ;
13
16
import * as protocol from '../src/types/protocol' ;
14
17
import { TEST_MODEL_MESSAGE , FakeComputer } from './stubs' ;
@@ -31,6 +34,32 @@ describe('RunState', () => {
31
34
expect ( state . _context . context ) . toEqual ( { foo : 'bar' } ) ;
32
35
} ) ;
33
36
37
+ it ( 'returns history including original input and generated items' , ( ) => {
38
+ const context = new RunContext ( ) ;
39
+ const agent = new Agent ( { name : 'HistAgent' } ) ;
40
+ const state = new RunState ( context , 'input' , agent , 1 ) ;
41
+ state . _generatedItems . push (
42
+ new RunMessageOutputItem ( TEST_MODEL_MESSAGE , agent ) ,
43
+ ) ;
44
+
45
+ expect ( state . history ) . toEqual ( [
46
+ { type : 'message' , role : 'user' , content : 'input' } ,
47
+ TEST_MODEL_MESSAGE ,
48
+ ] ) ;
49
+ } ) ;
50
+
51
+ it ( 'preserves history after serialization' , async ( ) => {
52
+ const context = new RunContext ( ) ;
53
+ const agent = new Agent ( { name : 'HistAgent2' } ) ;
54
+ const state = new RunState ( context , 'input' , agent , 1 ) ;
55
+ state . _generatedItems . push (
56
+ new RunMessageOutputItem ( TEST_MODEL_MESSAGE , agent ) ,
57
+ ) ;
58
+
59
+ const restored = await RunState . fromString ( agent , state . toString ( ) ) ;
60
+ expect ( restored . history ) . toEqual ( state . history ) ;
61
+ } ) ;
62
+
34
63
it ( 'toJSON and toString produce valid JSON' , ( ) => {
35
64
const context = new RunContext ( ) ;
36
65
const agent = new Agent ( { name : 'Agent1' } ) ;
0 commit comments