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
5 changes: 5 additions & 0 deletions .changeset/transcript-phase-on-attach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pymodel/pythinker-code": patch
---

Clients that open a session while a tool approval is pending now show the agent's status instead of none.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export function bindSessionTranscript(
if (loopStatus?.state === 'running' && loopStatus.activeTurnId !== undefined) {
const promptId = loopStatus.activePromptId;
projector.seedActiveTurn({ turnId: loopStatus.activeTurnId, promptId });
applyOps(handle.id, projector.seedPhase());
}
const list = agentDisposables.get(handle.id) ?? [];
list.push(busD);
Expand Down
14 changes: 12 additions & 2 deletions packages/agent-gateway/src/services/transcript/coreEventMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,25 @@ export class AgentTranscriptProjector {
return [...ops, { op: 'meta.merge', meta: { agent: { phase } } }];
}

private phaseFor(event: ProjectorBusEvent): ReturnType<typeof toLegacyPhase> {
seedPhase(): TranscriptOperation[] {
const phase = this.tracker()?.recompute();
return phase === undefined ? [] : [{ op: 'meta.merge', meta: { agent: { phase } } }];
}

private tracker(): LegacyActivityTracker | undefined {
if (this.lookups?.activitySnapshot === undefined || this.lookups.pendingApprovals === undefined) {
return undefined;
}
this.activityTracker ??= new LegacyActivityTracker(
this.lookups.activitySnapshot,
this.lookups.pendingApprovals,
);
return phaseFromDomainEvent(this.activityTracker, event);
return this.activityTracker;
}

private phaseFor(event: ProjectorBusEvent): ReturnType<typeof toLegacyPhase> {
const tracker = this.tracker();
return tracker === undefined ? undefined : phaseFromDomainEvent(tracker, event);
}

private mapEvent(event: ProjectorBusEvent): TranscriptOperation[] {
Expand Down
18 changes: 18 additions & 0 deletions packages/agent-gateway/test/services/transcript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,24 @@ describe('AgentTranscriptProjector', () => {
expect(tx.getMeta().agent).toMatchObject({ model: 'k3', thinkingEffort: 'high' });
});

it('seeds meta.agent.phase when attaching to a turn blocked on an approval', () => {
const projector = new AgentTranscriptProjector('main', TEST_SESSION_ID, {
activitySnapshot: () => ({
turn: { turnId: 1, phase: 'running', step: 1, ending: false, activeToolCalls: [], since: 1000 },
}),
pendingApprovals: () => [{ approvalId: 'ap1', toolCallId: 'c1', since: 1500 }],
});
const tx = new AgentTranscript('main');

tx.apply(projector.seedPhase());

expect(tx.getMeta().agent?.phase).toMatchObject({
kind: 'awaiting_approval',
turnId: 1,
approval: { approvalId: 'ap1', toolCallId: 'c1' },
});
});

it('maps domain events into meta.agent.phase', () => {
let snapshot: AgentActivitySnapshot = {};
let approvals: readonly LegacyActivityApproval[] = [];
Expand Down
Loading