Skip to content

Commit 3a4a86a

Browse files
fix(streaming): match encoded output selectors
1 parent f64457f commit 3a4a86a

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

apps/sim/executor/utils.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
2+
import { formatInternalOutputSelector } from '@/lib/workflows/streaming/output-selector'
23
import {
34
StreamingResponseFormatProcessor,
45
streamingResponseFormatProcessor,
@@ -221,6 +222,33 @@ describe('StreamingResponseFormatProcessor', () => {
221222
])
222223
})
223224

225+
it('matches encoded selectors for block IDs containing underscores', async () => {
226+
let sourceSink: AgentStreamSink | undefined
227+
const projectedText: string[] = []
228+
const subscribe = processor.processEventSubscription(
229+
(sink) => {
230+
sourceSink = sink
231+
return () => {}
232+
},
233+
'answer_agent',
234+
[formatInternalOutputSelector('answer_agent', 'answer')],
235+
{ schema: { properties: { answer: { type: 'string' } } } }
236+
)
237+
238+
subscribe?.({
239+
onEvent: (event) => {
240+
if (event.type === 'text_delta') projectedText.push(event.text)
241+
},
242+
})
243+
await sourceSink?.onEvent({
244+
type: 'text_delta',
245+
text: '{"answer":"Streamed"}',
246+
turn: 'final',
247+
})
248+
249+
expect(projectedText).toEqual(['Streamed'])
250+
})
251+
224252
it('holds incomplete JSON escapes until they can be decoded', async () => {
225253
let sourceSink: AgentStreamSink | undefined
226254
const projectedText: string[] = []

apps/sim/executor/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createLogger } from '@sim/logger'
22
import { isRecordLike } from '@sim/utils/object'
3+
import { formatInternalOutputSelector } from '@/lib/workflows/streaming/output-selector'
34
import type { ResponseFormatStreamProcessor } from '@/executor/types'
45
import type { AgentStreamSink, UnsubscribeAgentStreamSink } from '@/providers/stream-events'
56

@@ -13,7 +14,7 @@ interface JsonStringToken {
1314
}
1415

1516
function selectedFieldsForBlock(blockId: string, selectedOutputs: string[]): string[] {
16-
const prefix = `${blockId}_`
17+
const prefix = `${formatInternalOutputSelector(blockId)}_`
1718
return selectedOutputs
1819
.filter((outputId) => outputId.startsWith(prefix))
1920
.map((outputId) => outputId.slice(prefix.length))

0 commit comments

Comments
 (0)