@@ -30,11 +30,20 @@ export function previewQueueSummaryPrompt(params: {
3030 noun : string ;
3131 title ?: string ;
3232} ) : string | undefined {
33- return buildQueueSummaryPrompt ( {
34- state : params . state ,
35- noun : params . noun ,
36- title : params . title ,
37- } ) ;
33+ if ( params . state . droppedCount <= 0 ) {
34+ return undefined ;
35+ }
36+ const title =
37+ params . title ??
38+ `[Queue overflow] Dropped ${ params . state . droppedCount } ${ params . noun } ${ params . state . droppedCount === 1 ? "" : "s" } due to cap.` ;
39+ const lines = [ title ] ;
40+ if ( params . state . summaryLines . length > 0 ) {
41+ lines . push ( "Summary:" ) ;
42+ for ( const line of params . state . summaryLines ) {
43+ lines . push ( `- ${ line } ` ) ;
44+ }
45+ }
46+ return lines . join ( "\n" ) ;
3847}
3948
4049/** Apply runtime queue settings while preserving previous values for omitted fields. */
@@ -64,18 +73,12 @@ export function applyQueueRuntimeSettings<TMode extends string>(params: {
6473 params . target . dropPolicy = params . settings . dropPolicy ?? params . target . dropPolicy ;
6574}
6675
67- /** Trim queue summary text to a bounded single-line preview. */
68- function elideQueueText ( text : string , limit = 140 ) : string {
69- if ( text . length <= limit ) {
70- return text ;
71- }
72- return `${ truncateUtf16Safe ( text , Math . max ( 0 , limit - 1 ) ) . trimEnd ( ) } …` ;
73- }
74-
7576/** Normalize whitespace and elide one dropped item for queue summaries. */
7677function buildQueueSummaryLine ( text : string , limit = 160 ) : string {
7778 const cleaned = text . replace ( / \s + / g, " " ) . trim ( ) ;
78- return elideQueueText ( cleaned , limit ) ;
79+ return cleaned . length <= limit
80+ ? cleaned
81+ : `${ truncateUtf16Safe ( cleaned , Math . max ( 0 , limit - 1 ) ) . trimEnd ( ) } …` ;
7982}
8083
8184/** Run optional duplicate detection before an item enters a queue. */
@@ -269,69 +272,25 @@ export async function drainNextQueueItem<T>(
269272 return true ;
270273}
271274
272- /** Drain one item when collect mode requires individual processing . */
273- async function drainCollectItemIfNeeded < T > ( params : {
274- forceIndividualCollect : boolean ;
275+ /** Drain one collect step using mutable queue collection state . */
276+ export async function drainCollectQueueStep < T > ( params : {
277+ collectState : { forceIndividualCollect : boolean } ;
275278 isCrossChannel : boolean ;
276- setForceIndividualCollect ?: ( next : boolean ) => void ;
277279 items : T [ ] ;
278280 run : ( item : T ) => Promise < void > ;
279281 reserveOptions ?: DrainQueueItemOptions < T > ;
280282} ) : Promise < "skipped" | "drained" | "empty" > {
281- if ( ! params . forceIndividualCollect && ! params . isCrossChannel ) {
283+ if ( ! params . collectState . forceIndividualCollect && ! params . isCrossChannel ) {
282284 return "skipped" ;
283285 }
284286 if ( params . isCrossChannel ) {
285287 // Once cross-channel items appear, future collection stays individual to preserve ordering.
286- params . setForceIndividualCollect ?. ( true ) ;
288+ params . collectState . forceIndividualCollect = true ;
287289 }
288290 const drained = await drainNextQueueItem ( params . items , params . run , params . reserveOptions ) ;
289291 return drained ? "drained" : "empty" ;
290292}
291293
292- /** Drain one collect step using mutable queue collection state. */
293- export async function drainCollectQueueStep < T > ( params : {
294- collectState : { forceIndividualCollect : boolean } ;
295- isCrossChannel : boolean ;
296- items : T [ ] ;
297- run : ( item : T ) => Promise < void > ;
298- reserveOptions ?: DrainQueueItemOptions < T > ;
299- } ) : Promise < "skipped" | "drained" | "empty" > {
300- return await drainCollectItemIfNeeded ( {
301- forceIndividualCollect : params . collectState . forceIndividualCollect ,
302- isCrossChannel : params . isCrossChannel ,
303- setForceIndividualCollect : ( next ) => {
304- params . collectState . forceIndividualCollect = next ;
305- } ,
306- items : params . items ,
307- run : params . run ,
308- reserveOptions : params . reserveOptions ,
309- } ) ;
310- }
311-
312- /** Build the queue overflow summary prompt. */
313- function buildQueueSummaryPrompt ( params : {
314- state : QueueSummaryState ;
315- noun : string ;
316- title ?: string ;
317- } ) : string | undefined {
318- if ( params . state . droppedCount <= 0 ) {
319- return undefined ;
320- }
321- const noun = params . noun ;
322- const title =
323- params . title ??
324- `[Queue overflow] Dropped ${ params . state . droppedCount } ${ noun } ${ params . state . droppedCount === 1 ? "" : "s" } due to cap.` ;
325- const lines = [ title ] ;
326- if ( params . state . summaryLines . length > 0 ) {
327- lines . push ( "Summary:" ) ;
328- for ( const line of params . state . summaryLines ) {
329- lines . push ( `- ${ line } ` ) ;
330- }
331- }
332- return lines . join ( "\n" ) ;
333- }
334-
335294/** Render a collect prompt from queued items and optional overflow summary. */
336295export function buildCollectPrompt < T > ( params : {
337296 title : string ;
0 commit comments