Skip to content
Merged
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
7 changes: 7 additions & 0 deletions .changeset/add-model-to-start-run-event.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@perstack/core": patch
"@perstack/runtime": patch
"perstack": patch
---

feat: add model field to startRun and resumeFromStop event payloads
8 changes: 7 additions & 1 deletion packages/core/src/adapters/event-creators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ describe("@perstack/core: event-creators", () => {
output: "",
})
const initCheckpoint = { ...checkpoint, status: "init" as const, stepNumber: 0 }
const event = createStartRunEvent("job-1", "run-1", "expert-key", initCheckpoint)
const event = createStartRunEvent(
"job-1",
"run-1",
"expert-key",
initCheckpoint,
"claude-sonnet-4-20250514",
)
expect(event.type).toBe("startRun")
expect(event.jobId).toBe("job-1")
expect(event.runId).toBe("run-1")
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/adapters/event-creators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export function createStartRunEvent(
runId: string,
expertKey: string,
checkpoint: Checkpoint,
model: string,
): RunEvent {
return {
type: "startRun",
Expand All @@ -60,6 +61,7 @@ export function createStartRunEvent(
stepNumber: checkpoint.stepNumber,
initialCheckpoint: checkpoint,
inputMessages: [],
model,
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/schemas/runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ describe("@perstack/core: createEvent", () => {
const event = startRun(mockSetting, mockCheckpoint, {
initialCheckpoint: mockCheckpoint,
inputMessages: [],
model: "test-model",
})
expect(event.type).toBe("startRun")
expect(event.jobId).toBe("job-123")
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/schemas/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,14 @@ type ExpertStatePayloads = {
startRun: {
initialCheckpoint: Checkpoint
inputMessages: (InstructionMessage | UserMessage | ToolMessage)[]
/** Resolved model name used for this run */
model: string
}
/** Resume from stoppedByDelegate or stoppedByInteractiveTool */
resumeFromStop: {
checkpoint: Checkpoint
/** Resolved model name used for this run */
model: string
}
/** Proceed to CallingInteractiveTools from ResumingFromStop */
proceedToInteractiveTools: {
Expand Down
3 changes: 3 additions & 0 deletions packages/runtime/src/state-machine/states/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ describe("@perstack/runtime: StateMachineLogic['Init']", () => {
contents: [{ type: "textPart", id: expect.any(String), text: "How are you?" }],
},
],
model: setting.model,
})
})

Expand Down Expand Up @@ -208,6 +209,7 @@ describe("@perstack/runtime: StateMachineLogic['Init']", () => {
contents: [{ type: "textPart", id: expect.any(String), text: "test-text" }],
},
],
model: setting.model,
})
})

Expand Down Expand Up @@ -264,6 +266,7 @@ describe("@perstack/runtime: StateMachineLogic['Init']", () => {
contents: [{ type: "textPart", id: expect.any(String), text: "resume-text" }],
},
],
model: setting.model,
})
})
})
12 changes: 12 additions & 0 deletions packages/runtime/src/state-machine/states/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,26 @@ export async function initLogic({
if (!setting.input.text) {
throw new Error("Input message is undefined")
}
if (!setting.model) {
throw new Error("Model is not resolved")
}
return startRun(setting, checkpoint, {
initialCheckpoint: checkpoint,
inputMessages: [
createInstructionMessage(expert, setting.startedAt),
createUserMessage([{ type: "textPart", text: setting.input.text }]),
],
model: setting.model,
})
}
case "stoppedByDelegate":
case "stoppedByInteractiveTool": {
if (!setting.input.interactiveToolCallResult) {
throw new Error("Interactive tool call result is undefined")
}
if (!setting.model) {
throw new Error("Model is not resolved")
}
const { toolCallId, toolName, skillName, text } = setting.input.interactiveToolCallResult
const pendingToolCalls = checkpoint.pendingToolCalls ?? []
const newToolResult: ToolResult = {
Expand All @@ -58,15 +65,20 @@ export async function initLogic({
}
return resumeFromStop(setting, checkpoint, {
checkpoint: updatedCheckpoint,
model: setting.model,
})
}
default:
if (!setting.input.text) {
throw new Error("Input message is undefined")
}
if (!setting.model) {
throw new Error("Model is not resolved")
}
return startRun(setting, checkpoint, {
initialCheckpoint: checkpoint,
inputMessages: [createUserMessage([{ type: "textPart", text: setting.input.text }])],
model: setting.model,
})
}
}