Skip to content

Commit d7fd8dc

Browse files
authored
fix: schema version serialization (#25)
* fix(core): reference schema version constant * chore(core): add changeset for schema version fix
1 parent 0474de9 commit d7fd8dc

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@openai/agents-core': patch
3+
---
4+
5+
Export CURRENT_SCHEMA_VERSION constant and use it when serializing run state.

packages/agents-core/src/runState.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { safeExecute } from './utils/safeExecute';
3737
* run state is compatible with the current version of the SDK.
3838
* If anything in this schema changes, the version will have to be incremented.
3939
*/
40-
const CURRENT_SCHEMA_VERSION = '1.0' as const;
40+
export const CURRENT_SCHEMA_VERSION = '1.0' as const;
4141
const $schemaVersion = z.literal(CURRENT_SCHEMA_VERSION);
4242

4343
const serializedAgentSchema = z.object({
@@ -349,7 +349,7 @@ export class RunState<TContext, TAgent extends Agent<any, any>> {
349349
*/
350350
toJSON(): z.infer<typeof SerializedRunState> {
351351
const output = {
352-
$schemaVersion: '1.0',
352+
$schemaVersion: CURRENT_SCHEMA_VERSION,
353353
currentTurn: this._currentTurn,
354354
currentAgent: {
355355
name: this._currentAgent.name,

packages/agents-core/test/runState.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
buildAgentMap,
55
deserializeModelResponse,
66
deserializeItem,
7+
CURRENT_SCHEMA_VERSION,
78
} from '../src/runState';
89
import { RunContext } from '../src/runContext';
910
import { Agent } from '../src/agent';
@@ -35,7 +36,7 @@ describe('RunState', () => {
3536
const agent = new Agent({ name: 'Agent1' });
3637
const state = new RunState(context, 'input1', agent, 2);
3738
const json = state.toJSON();
38-
expect(json.$schemaVersion).toBe('1.0');
39+
expect(json.$schemaVersion).toBe(CURRENT_SCHEMA_VERSION);
3940
expect(json.currentTurn).toBe(0);
4041
expect(json.currentAgent).toEqual({ name: 'Agent1' });
4142
expect(json.originalInput).toEqual('input1');
@@ -65,7 +66,7 @@ describe('RunState', () => {
6566
expect(
6667
async () => await RunState.fromString(agent, JSON.stringify(jsonVersion)),
6768
).rejects.toThrow(
68-
'Run state schema version 0.1 is not supported. Please use version 1.0',
69+
`Run state schema version 0.1 is not supported. Please use version ${CURRENT_SCHEMA_VERSION}`,
6970
);
7071
});
7172

0 commit comments

Comments
 (0)