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
38 changes: 38 additions & 0 deletions src/workbench/extensions/agent/AgentPanelRoot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6608,6 +6608,44 @@ describe('AgentPanelRoot workflow binding', () => {
expect(bodies).toHaveLength(0)
})

it('puts the draft back when consent is cleared while the panel stays open', async () => {
makeTab('wf-42')
const bodies = mockMessagesEndpoint('wf-42')
const settleSubmission = vi.spyOn(
useAgentComposerStore(),
'settleSubmission'
)
renderWithSelectedTarget()
await sendHeldByCoach('build me a workflow')

Object.assign(useAgentConsentStore(), { accepted: false })

await waitFor(() =>
expect(settleSubmission).toHaveBeenCalledWith(expect.any(Number), false)
)
expect(bodies).toHaveLength(0)
})

it('puts the draft back when the consent identity changes during the hold', async () => {
makeTab('wf-42')
const bodies = mockMessagesEndpoint('wf-42')
const settleSubmission = vi.spyOn(
useAgentComposerStore(),
'settleSubmission'
)
renderWithSelectedTarget()
await sendHeldByCoach('build me a workflow')

Object.assign(useAgentConsentStore(), {
identity: JSON.stringify(['account-b', 'workspace-hold', 0])
})

await waitFor(() =>
expect(settleSubmission).toHaveBeenCalledWith(expect.any(Number), false)
)
expect(bodies).toHaveLength(0)
})

it('puts the draft back instead of sending when the panel closes', async () => {
makeTab('wf-42')
const bodies = mockMessagesEndpoint('wf-42')
Expand Down
16 changes: 11 additions & 5 deletions src/workbench/extensions/agent/AgentPanelRoot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ const {
} = useBillingContext()
const conversationStore = useAgentConversationStore()
const history = useAgentChatHistoryStore()
const { accepted: consentAccepted } = storeToRefs(useAgentConsentStore())
const { accepted: consentAccepted, identity: consentIdentity } = storeToRefs(
useAgentConsentStore()
)
watch(
subscription,
(currentSubscription) => {
Expand Down Expand Up @@ -641,10 +643,11 @@ function releaseCoachCompletionWaiters(proceed = true): void {
coachCompletionWaiters.clear()
}
watch(
[consentAccepted, onboardingKey, coachDeferredBy],
([accepted, key, reason]) => {
[consentAccepted, onboardingKey, coachDeferredBy, consentIdentity],
([accepted, key, reason, identity], previous) => {
if (accepted && key && !hasSeenCoach(key)) trackCoachDeferral(key, reason)
if (reason !== null) releaseCoachCompletionWaiters()
if (!accepted || reason !== null || identity !== previous[3])
releaseCoachCompletionWaiters()
},
{ immediate: true }
)
Expand Down Expand Up @@ -1693,10 +1696,12 @@ async function consentAllowsSubmission(
): Promise<boolean> {
let hasConsent = false
let coachReleased = false
let acceptedIdentity: string | null = null
consentHeldSubmissionId = submissionId
try {
await withConsent('first_message', () => {
hasConsent = true
acceptedIdentity = consentIdentity.value
})
if (hasConsent) coachReleased = await waitForCoachCompletion()
} finally {
Expand All @@ -1707,7 +1712,8 @@ async function consentAllowsSubmission(
composerStore.submission?.id === submissionId &&
hasConsent &&
coachReleased &&
consentAccepted.value
consentAccepted.value &&
consentIdentity.value === acceptedIdentity
)
}

Expand Down
Loading