MCPcopy Create free account
hub / github.com/IgorWarzocha/howcode / dequeueComposerPrompt

Function dequeueComposerPrompt

desktop/runtime/composer-service.ts:488–547  ·  view source on GitHub ↗
(
  request: ComposerStateRequest & {
    queueId: string
    queueSnapshotKey: string
    queueMode: Exclude<ComposerStreamingBehavior, 'stop'>
  },
)

Source from the content-addressed store, hash-verified

486}
487
488export async function dequeueComposerPrompt(
489 request: ComposerStateRequest & {
490 queueId: string
491 queueSnapshotKey: string
492 queueMode: Exclude<ComposerStreamingBehavior, 'stop'>
493 },
494): Promise<string | null> {
495 const persistedSessionPath = getPersistedSessionPath(request.sessionPath)
496 if (!persistedSessionPath) {
497 return null
498 }
499
500 return await withRuntimeMutationLock(persistedSessionPath, async () => {
501 const runtime = await getOrCreateRuntimeForSessionPath(persistedSessionPath, {
502 suspendDisposal: true,
503 settingsCwd: request.composerSessionDir ?? null,
504 chatGroupId: request.chatGroupId ?? null,
505 })
506
507 try {
508 const currentQueueSnapshot = {
509 steering: [...runtime.session.getSteeringMessages()],
510 followUp: [...runtime.session.getFollowUpMessages()],
511 }
512
513 if (buildComposerQueueSnapshotKey(currentQueueSnapshot) !== request.queueSnapshotKey) {
514 await emitComposerUpdate({ ...request, sessionPath: persistedSessionPath })
515 return null
516 }
517
518 const currentQueue =
519 request.queueMode === 'steer'
520 ? currentQueueSnapshot.steering
521 : currentQueueSnapshot.followUp
522 if (findQueuedPromptIndexById(request.queueMode, currentQueue, request.queueId) === null) {
523 await emitComposerUpdate({ ...request, sessionPath: persistedSessionPath })
524 return null
525 }
526
527 const clearedQueue = runtime.session.clearQueue()
528 const dequeueResult = removeQueuedPromptById(clearedQueue, request.queueMode, request.queueId)
529
530 if (!dequeueResult) {
531 await replayComposerQueue(runtime.session, clearedQueue)
532 await emitComposerUpdate({ ...request, sessionPath: persistedSessionPath })
533 return null
534 }
535
536 return await replayDequeuedComposerQueue({
537 clearedQueue,
538 dequeueResult,
539 request,
540 runtime,
541 sessionPath: persistedSessionPath,
542 })
543 } finally {
544 scheduleRuntimeDisposalForRuntime(runtime)
545 }

Callers 1

Calls 10

getPersistedSessionPathFunction · 0.90
withRuntimeMutationLockFunction · 0.90
removeQueuedPromptByIdFunction · 0.90
replayComposerQueueFunction · 0.90
emitComposerUpdateFunction · 0.70

Tested by

no test coverage detected