Open History to see the last commit
1import { errorDisplayMessage } from "@t3tools/client-runtime/errors";
2import { useAtomValue } from "@effect/atom-react";
3import { msg } from "gt-react";
4import {
5 type CheckpointDiffTarget,
6 type ComposerPathSearchTarget,
7} from "@t3tools/client-runtime/state/threads";
8import {
9 createThreadSearchResultsAtomFamily,
10 makeThreadSearchKey,
11 visibleThreadSearch,
12 type EnvironmentThreadSearchMatch,
13 type SettledThreadSearch,
14 type ThreadSearchResultsState,
15 type ThreadSearchScope,
16} from "@t3tools/client-runtime/state/thread-search";
17import {
18 ProjectSearchContentsError,
19 PROJECT_SEARCH_CONTENTS_QUERY_MAX_LENGTH,
20 THREAD_SEARCH_QUERY_MAX_LENGTH,
21 trimAsciiWhitespace,
22} from "@t3tools/contracts";
23import { messageSearchTokens } from "@t3tools/shared/paletteSearch";
24import { mergeBranchRefPages, type VcsRefTarget } from "@t3tools/client-runtime/state/vcs";
25import type {
26 EnvironmentId,
27 OrchestrationV2GetTurnItemResult,
28 ProjectContentMatch,
29 ProjectEntry,
30 ProjectEntryKind,
31 ThreadId,
32 TurnItemId,
33 VcsListRefsResult,
34 VcsRef,
35} from "@t3tools/contracts";
36import * as Cause from "effect/Cause";
37import * as Schema from "effect/Schema";
38import { AsyncResult, Atom } from "effect/reactivity";
39import { useEffect, useState } from "react";
40
41import { m, type MessageResolver } from "../i18n/messages";
42import { appAtomRegistry } from "../rpc/atomRegistry";
43import { useFilesystemReadAccess } from "./filesystem";
44import { orchestrationEnvironment } from "./orchestration";
45import { olderSettledThreads, threadFamilies } from "./threads";
46import { isPaginatedBranchesNextPagePending } from "./paginatedBranches";
47import { projectContentSearch, projectEnvironment } from "./projects";
48import { useEnvironmentQuery } from "./query";
49import { vcsEnvironment } from "./vcs";
50
51const PROJECT_PATH_SEARCH_DEBOUNCE_MS = 120;
52const COMPOSER_PATH_SEARCH_LIMIT = 80;
53const PROJECT_CONTENT_SEARCH_DEBOUNCE_MS = 120;
54const PROJECT_CONTENT_SEARCH_LIMIT = 500;
55const PROJECT_CONTENT_SEARCH_SCAN_RETRY_MS = 30_000;
56const isProjectSearchContentsError = Schema.is(ProjectSearchContentsError);
57const THREAD_SEARCH_DEBOUNCE_MS = 120;
58const VCS_REF_LIST_LIMIT = 100;
59const EMPTY_REFS: ReadonlyArray<VcsRef> = [];
60const EMPTY_PROJECT_ENTRIES: ReadonlyArray<ProjectEntry> = [];
61const EMPTY_CONTENT_MATCHES: ReadonlyArray<ProjectContentMatch> = [];
62const INITIAL_BRANCH_CURSORS = [undefined] as const;
63const EMPTY_THREAD_SEARCH_MATCHES: ReadonlyArray<EnvironmentThreadSearchMatch> = Object.freeze([]);
64const EMPTY_THREAD_SEARCH_ATOM = Atom.make<ThreadSearchResultsState>({
65 matches: EMPTY_THREAD_SEARCH_MATCHES,
66 isLoading: false,
67 failed: false,
68 rows: [],
69}).pipe(Atom.withLabel("web:thread-search:empty"));
70
71const olderSettledBeforeAtom = Atom.family((environmentId: EnvironmentId) =>
72 Atom.make((get) => get(olderSettledThreads.olderSettledAtom(environmentId))?.before ?? null).pipe(
73 Atom.withLabel(`web:older-settled-before:${environmentId}`),
74 ),
75);
76// Whether any of these environments leaves older settled threads out, so short queries matter.
77const anyOlderSettledAtom = Atom.family((environmentIdsKey: string) =>
78 Atom.make((get) =>
79 (JSON.parse(environmentIdsKey) as ReadonlyArray<EnvironmentId>).some(
80 (environmentId) => get(olderSettledBeforeAtom(environmentId)) !== null,
81 ),
82 ).pipe(Atom.withLabel(`web:any-older-settled:${environmentIdsKey}`)),
83);
84const threadSearch = createThreadSearchResultsAtomFamily({
85 getSearchAtom: (environmentId, input) =>
86 input.olderSettledBefore === undefined
87 ? orchestrationEnvironment.threadSearch({ environmentId, input })
88 : olderSettledThreads.searchAtom(environmentId, input),
89 olderSettledBefore: olderSettledBeforeAtom,
90 labelPrefix: "web:thread-search",
91});
92
93export function useDebouncedValue<A>(value: A, delayMs: number): A {
94 const [debounced, setDebounced] = useState(value);
95
96 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- debounce timer that publishes the value after delayMs
97 useEffect(() => {
98 const timer = window.setTimeout(() => {
99 setDebounced(value);
100 }, delayMs);
101 return () => {
102 window.clearTimeout(timer);
103 };
104 }, [delayMs, value]);
105
106 return debounced;
107}
108
109/**
110 * Server matches for a thread search: message hits, and on environments that leave older settled
111 * threads out of the shell, the rows of the best older matches, mounted into the thread list while
112 * they show so the caller's own ranking finds them.
113 */
114export function useThreadSearch(
115 environmentIds: ReadonlyArray<EnvironmentId>,
116 query: string,
117 scope: ThreadSearchScope = {},
118): {
119 readonly matches: ReadonlyArray<EnvironmentThreadSearchMatch>;
120 readonly query: string;
121 readonly isPending: boolean;
122 /** No environment could run the search for the current query, so an empty result is not "no matches". */
123 readonly failed: boolean;
124} {
125 // A pasted wall of text searches by its start rather than failing the request.
126 const normalizedQuery = query.trim().slice(0, THREAD_SEARCH_QUERY_MAX_LENGTH).trim();
127 const debouncedQuery = useDebouncedValue(normalizedQuery, THREAD_SEARCH_DEBOUNCE_MS);
128 const anyOlderSettled = useAtomValue(anyOlderSettledAtom(JSON.stringify(environmentIds)));
129 // Messages need a word of three or more letters; older settled titles match from two.
130 const canSearch =
131 environmentIds.length > 0 &&
132 ((scope.titlesOnly !== true && messageSearchTokens(normalizedQuery).long.length > 0) ||
133 (anyOlderSettled && normalizedQuery.length >= 2));
134 const settledQuery = canSearch && normalizedQuery === debouncedQuery ? debouncedQuery : null;
135 const searchKeyOf = (searchQuery: string) =>
136 makeThreadSearchKey(environmentIds, searchQuery, scope);
137 const searchKey = settledQuery === null ? null : searchKeyOf(settledQuery);
138 const result = useAtomValue(
139 searchKey === null ? EMPTY_THREAD_SEARCH_ATOM : threadSearch.results(searchKey),
140 );
141 const failed = settledQuery !== null && !result.isLoading && result.failed;
142 // What fast environments returned shows without waiting for a slow one;
143 // callers keep shown rows in place with `nextShownOrder`.
144 const ready =
145 settledQuery !== null &&
146 (!result.isLoading || result.matches.length > 0 || result.rows.length > 0)
147 ? { query: settledQuery, matches: result.matches }
148 : null;
149 // Kept from earlier renders: React's pattern for information from previous renders.
150 const [previous, setPrevious] = useState<SettledThreadSearch | null>(null);
151 if (ready !== null && previous?.matches !== ready.matches) setPrevious(ready);
152 const visible = canSearch
153 ? visibleThreadSearch(normalizedQuery, ready, previous)
154 : { query: "", matches: EMPTY_THREAD_SEARCH_MATCHES };
155 // The shown results' rows stay mounted until newer results replace them.
156 const shownKey = visible.query === "" ? null : searchKeyOf(visible.query);
157 const [mountedKey, setMountedKey] = useState<string | null>(null);
158 // Rows reach callers' shells only once mounted, so the search stays pending until then.
159 const isPending =
160 canSearch &&
161 (normalizedQuery !== debouncedQuery ||
162 result.isLoading ||
163 (result.rows.length > 0 && mountedKey !== searchKey));
164 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- mounts the shown search results' rows into the thread family registry until newer results replace them
165 useEffect(() => {
166 if (shownKey === null) return;
167 const environments = (JSON.parse(shownKey) as [ReadonlyArray<EnvironmentId>])[0];
168 const releases = environments.map((environmentId) =>
169 threadFamilies.mountRows(
170 appAtomRegistry,
171 environmentId,
172 `search:${shownKey}`,
173 threadSearch.rows(shownKey, environmentId),
174 ),
175 );
176 // oxlint-disable-next-line react/set-state-in-effect -- Records that the rows reached the registry, which the effect just did.
177 setMountedKey(shownKey);
178 return () => {
179 for (const release of releases) release();
180 };
181 }, [shownKey]);
182 return {
183 matches: visible.matches,
184 query: visible.query,
185 isPending,
186 failed,
187 };
188}
189
190function vcsRefPageAtom(targetKey: string, cursor: number | undefined) {
191 const [environmentId, cwd, query] = JSON.parse(targetKey) as [EnvironmentId, string, string];
192 return vcsEnvironment.listRefs({
193 environmentId,
194 input: {
195 cwd,
196 ...(query.length > 0 ? { query } : {}),
197 ...(cursor === undefined ? {} : { cursor }),
198 limit: VCS_REF_LIST_LIMIT,
199 },
200 });
201}
202
203const EMPTY_VCS_REF_PAGES_ATOM = Atom.make<
204 ReadonlyArray<Atom.Type<ReturnType<typeof vcsRefPageAtom>>>
205>([]).pipe(Atom.withLabel("web:vcs-ref-pages:empty"));
206
207const vcsRefPagesAtom = Atom.family((pagesKey: string) => {
208 const [targetKey, cursors] = JSON.parse(pagesKey) as [string, Array<number | null>];
209 const pageAtoms = cursors.map((cursor) => vcsRefPageAtom(targetKey, cursor ?? undefined));
210 return Atom.make((get) => pageAtoms.map((atom) => get(atom))).pipe(
211 Atom.withLabel(`web:vcs-ref-pages:${pagesKey}`),
212 );
213});
214
215export function usePaginatedBranches(target: VcsRefTarget, resolve: MessageResolver = m) {
216 // Leave unkeyed; mismatches already reset cursors, and a seeded key would break caching across the hook.
217 const [pagination, setPagination] = useState<{
218 readonly targetKey: string | null;
219 readonly cursors: ReadonlyArray<number | undefined>;
220 }>({
221 targetKey: null,
222 cursors: INITIAL_BRANCH_CURSORS,
223 });
224 const { environmentId, cwd } = target;
225 const query = trimAsciiWhitespace(target.query ?? "");
226 const targetKey =
227 environmentId !== null && cwd !== null ? JSON.stringify([environmentId, cwd, query]) : null;
228 const cursors = pagination.targetKey === targetKey ? pagination.cursors : INITIAL_BRANCH_CURSORS;
229 const pagesKey = targetKey === null ? null : JSON.stringify([targetKey, cursors]);
230 const results = useAtomValue(
231 pagesKey === null ? EMPTY_VCS_REF_PAGES_ATOM : vcsRefPagesAtom(pagesKey),
232 );
233 const values = results.flatMap((result) => {
234 const value = AsyncResult.getOrElse(result, () => null);
235 return value === null ? [] : [value];
236 });
237 const first = values[0] ?? null;
238 const last = values.at(-1) ?? null;
239 const data: VcsListRefsResult | null =
240 first === null || last === null
241 ? null
242 : {
243 refs: mergeBranchRefPages(values),
244 isRepo: first.isRepo,
245 hasPrimaryRemote: first.hasPrimaryRemote,
246 nextCursor: last.nextCursor,
247 totalCount: Math.max(...values.map((value) => value.totalCount)),
248 };
249 const failed = results.find((result) => result._tag === "Failure");
250 const isPending = results.some((result) => result.waiting);
251 const isLoadingFirstPage = data === null && isPending && failed === undefined;
252 // A new search keeps showing the last refs from the same checkout until its first page arrives.
253 const sourceKey = targetKey === null ? null : JSON.stringify([environmentId, cwd]);
254 const [settled, setSettled] = useState<{
255 readonly sourceKey: string;
256 readonly results: typeof results;
257 readonly data: VcsListRefsResult;
258 } | null>(null);
259 if (data !== null && sourceKey !== null && settled?.results !== results) {
260 setSettled({ sourceKey, results, data });
261 }
262 const shownData = isLoadingFirstPage && settled?.sourceKey === sourceKey ? settled.data : data;
263 const isFetchingNextPage = isPaginatedBranchesNextPagePending(results);
264 const error =
265 failed?._tag === "Failure"
266 ? (() => {
267 const cause = Cause.squash(failed.cause);
268 return (
269 (cause instanceof Error ? errorDisplayMessage(cause, resolve) : null) ??
270 resolve(msg("Failed to load refs."))
271 );
272 })()
273 : null;
274 const refresh = () => {
275 setPagination({ targetKey, cursors: INITIAL_BRANCH_CURSORS });
276 if (targetKey !== null) {
277 appAtomRegistry.refresh(vcsRefPageAtom(targetKey, undefined));
278 }
279 };
280 const nextCursor = data?.nextCursor;
281 const loadNext = () => {
282 if (targetKey === null || nextCursor === null || nextCursor === undefined) {
283 return;
284 }
285 setPagination((current) => {
286 const currentCursors =
287 current.targetKey === targetKey ? current.cursors : INITIAL_BRANCH_CURSORS;
288 return currentCursors.includes(nextCursor)
289 ? { targetKey, cursors: currentCursors }
290 : { targetKey, cursors: [...currentCursors, nextCursor] };
291 });
292 };
293
294 return {
295 data: shownData,
296 refs: shownData?.refs ?? EMPTY_REFS,
297 error,
298 isPending,
299 isLoadingFirstPage,
300 isFetchingNextPage,
301 refresh,
302 loadNext,
303 };
304}
305
306type ProjectPathSearchTarget = ComposerPathSearchTarget & {
307 readonly kind?: ProjectEntryKind | undefined;
308 readonly imageOnly?: boolean | undefined;
309};
310
311function areProjectPathSearchTargetsEqual(
312 left: ProjectPathSearchTarget,
313 right: ProjectPathSearchTarget,
314): boolean {
315 return (
316 left.environmentId === right.environmentId &&
317 left.cwd === right.cwd &&
318 left.query === right.query &&
319 left.kind === right.kind &&
320 left.imageOnly === right.imageOnly
321 );
322}
323
324export function useProjectPathSearch(
325 target: ProjectPathSearchTarget,
326 limit: number,
327 options?: { readonly allowEmptyQuery?: boolean },
328 resolve: MessageResolver = m,
329) {
330 const allowEmptyQuery = options?.allowEmptyQuery === true;
331 const normalizedTarget = {
332 environmentId: target.environmentId,
333 cwd: target.cwd,
334 query: target.query == null ? null : target.query.trim(),
335 kind: target.kind,
336 imageOnly: target.imageOnly,
337 };
338 const debouncedTarget = useDebouncedValue(normalizedTarget, PROJECT_PATH_SEARCH_DEBOUNCE_MS);
339 const fileAccess = useFilesystemReadAccess(debouncedTarget.environmentId, resolve);
340 const { canReadFiles } = fileAccess;
341 const searchTarget =
342 debouncedTarget.environmentId !== null &&
343 debouncedTarget.cwd !== null &&
344 debouncedTarget.query !== null &&
345 (allowEmptyQuery || debouncedTarget.query.length > 0)
346 ? {
347 environmentId: debouncedTarget.environmentId,
348 input: {
349 cwd: debouncedTarget.cwd,
350 query: debouncedTarget.query.slice(0, 256).replace(/[\uD800-\uDBFF]$/, ""),
351 limit,
352 ...(debouncedTarget.kind ? { kind: debouncedTarget.kind } : {}),
353 ...(debouncedTarget.imageOnly ? { imageOnly: true } : {}),
354 },
355 }
356 : null;
357 const result = useEnvironmentQuery(
358 canReadFiles && searchTarget !== null ? projectEnvironment.searchEntries(searchTarget) : null,
359 resolve,
360 );
361 const hasTarget = searchTarget !== null;
362 // A new query keeps showing the last entries from the same folder until its answer arrives.
363 const sourceKey =
364 searchTarget === null
365 ? null
366 : JSON.stringify([
367 searchTarget.environmentId,
368 searchTarget.input.cwd,
369 debouncedTarget.kind ?? null,
370 debouncedTarget.imageOnly === true,
371 ]);
372 const [settled, setSettled] = useState<{
373 readonly sourceKey: string;
374 readonly data: NonNullable<typeof result.data>;
375 readonly target: typeof debouncedTarget;
376 } | null>(null);
377 if (result.data !== null && sourceKey !== null && settled?.data !== result.data) {
378 setSettled({ sourceKey, data: result.data, target: debouncedTarget });
379 }
380 const kept =
381 result.data === null && result.isPending && !result.error && settled?.sourceKey === sourceKey
382 ? settled
383 : null;
384 const shownData = kept?.data ?? result.data;
385 // Kept entries answer the earlier query, so stale picks stay rejectable by their target.
386 const shownTarget = kept?.target ?? debouncedTarget;
387
388 return {
389 entries: shownData?.entries ?? EMPTY_PROJECT_ENTRIES,
390 error:
391 !hasTarget || fileAccess.isPending
392 ? null
393 : canReadFiles
394 ? result.error
395 : (fileAccess.error ?? resolve(msg("This connection cannot search host files."))),
396 isPending:
397 !areProjectPathSearchTargetsEqual(normalizedTarget, debouncedTarget) ||
398 (hasTarget && (fileAccess.isPending || result.isPending)),
399 searchedTarget: shownTarget,
400 searchedQuery: shownTarget.query ?? "",
401 truncated: shownData?.truncated ?? false,
402 refresh: result.refresh,
403 };
404}
405
406export function useComposerPathSearch(
407 target: ComposerPathSearchTarget,
408 resolve: MessageResolver = m,
409) {
410 return useProjectPathSearch(
411 target,
412 COMPOSER_PATH_SEARCH_LIMIT,
413 { allowEmptyQuery: true },
414 resolve,
415 );
416}
417
418interface ProjectContentSearchTarget {
419 readonly environmentId: EnvironmentId | null;
420 readonly cwd: string | null;
421 readonly query: string;
422 readonly caseSensitive: boolean;
423 readonly wholeWord: boolean;
424 readonly useRegex: boolean;
425}
426
427export function useProjectContentSearch(
428 target: ProjectContentSearchTarget,
429 resolve: MessageResolver = m,
430) {
431 const hasTarget = target.environmentId !== null && target.cwd !== null;
432 const fileAccess = useFilesystemReadAccess(target.environmentId, resolve);
433 const canReadFiles = hasTarget && fileAccess.canReadFiles;
434 const isCheckingAccess = hasTarget && fileAccess.isPending;
435 // Preserve query whitespace; trim only to detect blank input.
436 const query = target.query;
437 const hasQuery = query.trim().length > 0;
438 const queryTooLong = query.length > PROJECT_SEARCH_CONTENTS_QUERY_MAX_LENGTH;
439 const debouncedQuery = useDebouncedValue(query, PROJECT_CONTENT_SEARCH_DEBOUNCE_MS);
440 const result = useEnvironmentQuery(
441 canReadFiles &&
442 target.environmentId !== null &&
443 target.cwd !== null &&
444 hasQuery &&
445 !queryTooLong &&
446 debouncedQuery.trim().length > 0 &&
447 debouncedQuery.length <= PROJECT_SEARCH_CONTENTS_QUERY_MAX_LENGTH
448 ? projectContentSearch({
449 environmentId: target.environmentId,
450 input: {
451 cwd: target.cwd,
452 query: debouncedQuery,
453 limit: PROJECT_CONTENT_SEARCH_LIMIT,
454 caseSensitive: target.caseSensitive,
455 wholeWord: target.wholeWord,
456 useRegex: target.useRegex,
457 },
458 })
459 : null,
460 resolve,
461 );
462 // A longer query keeps showing the last matches for the same folder and options until it answers.
463 const sourceKey = JSON.stringify([
464 target.environmentId,
465 target.cwd,
466 target.caseSensitive,
467 target.wholeWord,
468 target.useRegex,
469 ]);
470 const [settled, setSettled] = useState<{
471 readonly sourceKey: string;
472 readonly data: NonNullable<typeof result.data>;
473 } | null>(null);
474 if (result.data !== null && settled?.data !== result.data) {
475 setSettled({ sourceKey, data: result.data });
476 }
477 const shownData =
478 result.data ??
479 (result.isPending && !result.error && settled?.sourceKey === sourceKey ? settled.data : null);
480 // Only once the timeout has come back: a refresh restarts a search still in flight.
481 const settledScanTimeout =
482 !result.isPending &&
483 isProjectSearchContentsError(result.failure) &&
484 result.failure.failure === "search_index_scan_timed_out"
485 ? result.failure
486 : null;
487 const { refresh } = result;
488 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- retry timer: nothing tells the client when the server's first scan ends
489 useEffect(() => {
490 if (settledScanTimeout === null) return;
491 const timer = window.setTimeout(refresh, PROJECT_CONTENT_SEARCH_SCAN_RETRY_MS);
492 return () => {
493 window.clearTimeout(timer);
494 };
495 }, [refresh, settledScanTimeout]);
496
497 return {
498 canReadFiles,
499 isCheckingAccess,
500 matches: shownData?.matches ?? EMPTY_CONTENT_MATCHES,
501 error:
502 !hasTarget || isCheckingAccess
503 ? null
504 : !canReadFiles
505 ? (fileAccess.error ?? resolve(msg("This connection cannot search host files.")))
506 : queryTooLong
507 ? resolve(
508 msg`Search is limited to ${{ count: PROJECT_SEARCH_CONTENTS_QUERY_MAX_LENGTH }} characters.`,
509 )
510 : result.error,
511 isPending:
512 isCheckingAccess ||
513 (canReadFiles && hasQuery && !queryTooLong && (query !== debouncedQuery || result.isPending)),
514 hasQuery,
515 truncated: shownData?.truncated ?? false,
516 invalidRegex: target.useRegex && shownData?.regexFallbackError !== undefined,
517 };
518}
519
520export function useCheckpointDiff(
521 target: CheckpointDiffTarget,
522 options?: { readonly enabled?: boolean },
523) {
524 const enabled =
525 options?.enabled !== false &&
526 target.environmentId !== null &&
527 target.threadId !== null &&
528 target.fromTurnCount !== null &&
529 target.toTurnCount !== null;
530 const fullThreadTarget =
531 enabled && target.fromTurnCount === 0
532 ? {
533 environmentId: target.environmentId!,
534 input: {
535 threadId: target.threadId!,
536 toTurnCount: target.toTurnCount!,
537 ignoreWhitespace: target.ignoreWhitespace,
538 },
539 }
540 : null;
541 const turnTarget =
542 enabled && target.fromTurnCount !== 0
543 ? {
544 environmentId: target.environmentId!,
545 input: {
546 threadId: target.threadId!,
547 fromTurnCount: target.fromTurnCount!,
548 toTurnCount: target.toTurnCount!,
549 ignoreWhitespace: target.ignoreWhitespace,
550 },
551 }
552 : null;
553 const fullThread = useEnvironmentQuery(
554 fullThreadTarget === null ? null : orchestrationEnvironment.fullThreadDiff(fullThreadTarget),
555 );
556 const turn = useEnvironmentQuery(
557 turnTarget === null ? null : orchestrationEnvironment.turnDiff(turnTarget),
558 );
559 return fullThreadTarget === null ? turn : fullThread;
560}
561
562/** Reads one item's detail from somewhere other than the environment, as the guest page does. */
563export type TurnItemDetailSource = (input: {
564 readonly threadId: ThreadId;
565 readonly itemId: TurnItemId;
566 readonly revision: string;
567}) => Atom.Atom<AsyncResult.AsyncResult<OrchestrationV2GetTurnItemResult, unknown>>;
568
569export function useTurnItemDetail(
570 target: {
571 readonly environmentId: EnvironmentId;
572 readonly threadId: ThreadId;
573 readonly itemId: TurnItemId;
574 readonly revision: string;
575 } | null,
576 source?: TurnItemDetailSource,
577) {
578 const input =
579 target === null
580 ? null
581 : { threadId: target.threadId, itemId: target.itemId, revision: target.revision };
582 return useEnvironmentQuery<OrchestrationV2GetTurnItemResult, unknown>(
583 target === null || input === null
584 ? null
585 : source
586 ? source(input)
587 : orchestrationEnvironment.turnItem({ environmentId: target.environmentId, input }),
588 );
589}