MCPcopy Index your code
hub / github.com/sourcebot-dev/sourcebot / getTurnProgressState

Function getTurnProgressState

packages/web/src/features/chat/utils.ts:338–377  ·  view source on GitHub ↗
({
    messages,
    status,
}: {
    messages: SBChatMessage[];
    status: ChatStatus;
})

Source from the content-addressed store, hash-verified

336}
337
338export const getTurnProgressState = ({
339 messages,
340 status,
341}: {
342 messages: SBChatMessage[];
343 status: ChatStatus;
344}) => {
345 const isNetworkActive = status === 'submitted' || status === 'streaming';
346 const latestMessage = messages.at(-1);
347 const latestAssistantMessage = latestMessage?.role === 'assistant' ? latestMessage : undefined;
348 const latestStepToolParts = getLastStepParts(latestAssistantMessage?.parts ?? [])
349 .filter(isSBChatToolPart);
350
351 const hasPendingToolApproval = latestStepToolParts.some(
352 (part) => part.state === 'approval-requested'
353 );
354 const hasApprovalContinuationReady =
355 latestStepToolParts.some((part) => part.state === 'approval-responded') &&
356 latestStepToolParts.every((part) =>
357 part.state === 'output-available' ||
358 part.state === 'output-error' ||
359 part.state === 'approval-responded'
360 );
361
362 const isReady = status === 'ready';
363 const isTurnInProgress =
364 isNetworkActive ||
365 (isReady && (hasPendingToolApproval || hasApprovalContinuationReady));
366 const isAwaitingToolApproval = isReady && hasPendingToolApproval;
367 const shouldGuardNavigation = isNetworkActive || (isReady && hasApprovalContinuationReady);
368
369 return {
370 isNetworkActive,
371 hasPendingToolApproval,
372 hasApprovalContinuationReady,
373 isAwaitingToolApproval,
374 isTurnInProgress,
375 shouldGuardNavigation,
376 };
377}
378
379// LLMs like to not follow instructions... this takes care of some common mistakes they tend to make.
380export const repairReferences = (text: string): string => {

Callers 5

utils.test.tsFile · 0.90
createMessageStreamFunction · 0.90
ChatThreadFunction · 0.90

Calls 1

getLastStepPartsFunction · 0.85

Tested by

no test coverage detected