|
1 | 1 | import type { |
2 | 2 | ThreadPendingApproval, |
3 | 3 | ThreadPendingUserInput, |
4 | | - ThreadUserInputQuestion, |
5 | 4 | } from "@t3tools/client-runtime/state/thread-requests"; |
6 | 5 | import { turnItemIsWorkspacePreparation } from "@t3tools/client-runtime/state/turn-item-presentation"; |
7 | 6 | import type { ThreadCheckpointSummary } from "@t3tools/client-runtime/state/thread-checkpoints"; |
@@ -81,13 +80,6 @@ import { |
81 | 80 | export type PendingApproval = ThreadPendingApproval; |
82 | 81 | export type PendingUserInput = ThreadPendingUserInput; |
83 | 82 |
|
84 | | -export interface PendingUserInputDraftAnswer { |
85 | | - readonly selectedOptionValues?: ReadonlyArray<string>; |
86 | | - readonly customAnswer?: string; |
87 | | - readonly attachmentCount?: number; |
88 | | - readonly attachmentsBlocked?: boolean; |
89 | | -} |
90 | | - |
91 | 83 | export interface ThreadFeedActivity { |
92 | 84 | readonly id: string; |
93 | 85 | readonly createdAt: string; |
@@ -406,73 +398,6 @@ function isUserInputActivityGroup(entry: ThreadFeedActivityGroup): boolean { |
406 | 398 | return entry.activities.some((activity) => activity.workEntry.questionAnswer !== undefined); |
407 | 399 | } |
408 | 400 |
|
409 | | -function normalizeDraftAnswer(value: string | undefined): string | null { |
410 | | - if (typeof value !== "string") return null; |
411 | | - const trimmed = value.trim(); |
412 | | - return trimmed.length > 0 ? trimmed : null; |
413 | | -} |
414 | | - |
415 | | -function resolvePendingUserInputOptionValue( |
416 | | - question: ThreadUserInputQuestion, |
417 | | - value: string, |
418 | | -): string | null { |
419 | | - if (question.options.some((option) => option.value === value)) { |
420 | | - return value; |
421 | | - } |
422 | | - |
423 | | - const label = value.trim(); |
424 | | - return label.length > 0 && |
425 | | - question.options.some((option) => option.value === undefined && option.label.trim() === label) |
426 | | - ? label |
427 | | - : null; |
428 | | -} |
429 | | - |
430 | | -function normalizeSelectedOptionValues( |
431 | | - question: ThreadUserInputQuestion, |
432 | | - value: ReadonlyArray<string> | undefined, |
433 | | -): ReadonlyArray<string> { |
434 | | - if (!Array.isArray(value)) { |
435 | | - return []; |
436 | | - } |
437 | | - |
438 | | - return Array.from( |
439 | | - new Set( |
440 | | - value |
441 | | - .map((entry) => resolvePendingUserInputOptionValue(question, entry)) |
442 | | - .filter((entry): entry is string => entry !== null), |
443 | | - ), |
444 | | - ); |
445 | | -} |
446 | | - |
447 | | -function resolvePendingUserInputAnswer( |
448 | | - question: ThreadUserInputQuestion, |
449 | | - draft: PendingUserInputDraftAnswer | undefined, |
450 | | -): string | ReadonlyArray<string> | null { |
451 | | - if (draft?.attachmentsBlocked) return null; |
452 | | - const customAnswer = |
453 | | - question.allowCustomAnswer === false |
454 | | - ? null |
455 | | - : question.initialAnswer !== undefined |
456 | | - ? (draft?.customAnswer ?? null) |
457 | | - : normalizeDraftAnswer(draft?.customAnswer); |
458 | | - if (customAnswer !== null && customAnswer.length > 0) { |
459 | | - return customAnswer; |
460 | | - } |
461 | | - |
462 | | - const selectedOptionValues = normalizeSelectedOptionValues(question, draft?.selectedOptionValues); |
463 | | - if (question.multiSelect) { |
464 | | - return selectedOptionValues.length > 0 |
465 | | - ? selectedOptionValues |
466 | | - : (customAnswer ?? |
467 | | - (question.allowCustomAnswer !== false && (draft?.attachmentCount ?? 0) > 0 ? "" : null)); |
468 | | - } |
469 | | - return ( |
470 | | - selectedOptionValues[0] ?? |
471 | | - customAnswer ?? |
472 | | - (question.allowCustomAnswer !== false && (draft?.attachmentCount ?? 0) > 0 ? "" : null) |
473 | | - ); |
474 | | -} |
475 | | - |
476 | 401 | function capitalizePhrase(value: string): string { |
477 | 402 | const trimmed = value.trim(); |
478 | 403 | return trimmed.length === 0 ? value : `${trimmed.charAt(0).toUpperCase()}${trimmed.slice(1)}`; |
@@ -1974,93 +1899,6 @@ function liveToolActivitySummary(activity: ThreadFeedActivity, presentTense: boo |
1974 | 1899 | return activity.detail ?? activity.summary; |
1975 | 1900 | } |
1976 | 1901 |
|
1977 | | -export function setPendingUserInputCustomAnswer( |
1978 | | - question: ThreadUserInputQuestion, |
1979 | | - draft: PendingUserInputDraftAnswer | undefined, |
1980 | | - customAnswer: string, |
1981 | | -): PendingUserInputDraftAnswer { |
1982 | | - if (question.allowCustomAnswer === false) { |
1983 | | - return draft ?? {}; |
1984 | | - } |
1985 | | - |
1986 | | - const selectedOptionValues = |
1987 | | - question.initialAnswer !== undefined || customAnswer.trim().length > 0 |
1988 | | - ? undefined |
1989 | | - : normalizeSelectedOptionValues(question, draft?.selectedOptionValues); |
1990 | | - return { |
1991 | | - customAnswer, |
1992 | | - ...(selectedOptionValues && selectedOptionValues.length > 0 ? { selectedOptionValues } : {}), |
1993 | | - }; |
1994 | | -} |
1995 | | - |
1996 | | -export function isPendingUserInputOptionSelected( |
1997 | | - question: ThreadUserInputQuestion, |
1998 | | - draft: PendingUserInputDraftAnswer | undefined, |
1999 | | - optionValue: string, |
2000 | | -): boolean { |
2001 | | - if (question.allowCustomAnswer !== false && normalizeDraftAnswer(draft?.customAnswer)) { |
2002 | | - return false; |
2003 | | - } |
2004 | | - |
2005 | | - const resolvedOptionValue = resolvePendingUserInputOptionValue(question, optionValue); |
2006 | | - return ( |
2007 | | - resolvedOptionValue !== null && |
2008 | | - normalizeSelectedOptionValues(question, draft?.selectedOptionValues).includes( |
2009 | | - resolvedOptionValue, |
2010 | | - ) |
2011 | | - ); |
2012 | | -} |
2013 | | - |
2014 | | -export function togglePendingUserInputOptionSelection( |
2015 | | - question: ThreadUserInputQuestion, |
2016 | | - draft: PendingUserInputDraftAnswer | undefined, |
2017 | | - optionValue: string, |
2018 | | -): PendingUserInputDraftAnswer { |
2019 | | - const resolvedOptionValue = resolvePendingUserInputOptionValue(question, optionValue); |
2020 | | - if (resolvedOptionValue === null) { |
2021 | | - return draft ?? {}; |
2022 | | - } |
2023 | | - |
2024 | | - if (question.multiSelect) { |
2025 | | - const selectedOptionValues = normalizeSelectedOptionValues( |
2026 | | - question, |
2027 | | - draft?.selectedOptionValues, |
2028 | | - ); |
2029 | | - const nextSelectedOptionValues = selectedOptionValues.includes(resolvedOptionValue) |
2030 | | - ? selectedOptionValues.filter((value) => value !== resolvedOptionValue) |
2031 | | - : [...selectedOptionValues, resolvedOptionValue]; |
2032 | | - |
2033 | | - return { |
2034 | | - customAnswer: "", |
2035 | | - ...(nextSelectedOptionValues.length > 0 |
2036 | | - ? { selectedOptionValues: nextSelectedOptionValues } |
2037 | | - : {}), |
2038 | | - }; |
2039 | | - } |
2040 | | - |
2041 | | - return { |
2042 | | - customAnswer: "", |
2043 | | - selectedOptionValues: [resolvedOptionValue], |
2044 | | - }; |
2045 | | -} |
2046 | | - |
2047 | | -export function buildPendingUserInputAnswers( |
2048 | | - questions: ReadonlyArray<ThreadUserInputQuestion>, |
2049 | | - draftAnswers: Record<string, PendingUserInputDraftAnswer>, |
2050 | | -): Record<string, string | ReadonlyArray<string>> | null { |
2051 | | - const answers: Record<string, string | ReadonlyArray<string>> = {}; |
2052 | | - |
2053 | | - for (const question of questions) { |
2054 | | - const answer = resolvePendingUserInputAnswer(question, draftAnswers[question.id]); |
2055 | | - if (answer === null) { |
2056 | | - return null; |
2057 | | - } |
2058 | | - answers[question.id] = answer; |
2059 | | - } |
2060 | | - |
2061 | | - return answers; |
2062 | | -} |
2063 | | - |
2064 | 1902 | interface ThreadFeedBuild { |
2065 | 1903 | readonly rows: ReadonlyArray<OrchestrationV2ProjectedTurnItem>; |
2066 | 1904 | readonly attempts: ReadonlyArray<OrchestrationV2RunAttempt> | undefined; |
|
0 commit comments