@@ -12,7 +12,10 @@ import { |
12 | 12 | type ThreadSearchResultsState, |
13 | 13 | type ThreadSearchScope, |
14 | 14 | } from "@t3tools/client-runtime/state/thread-search"; |
15 | | -import { THREAD_SEARCH_QUERY_MAX_LENGTH } from "@t3tools/contracts"; |
| 15 | +import { |
| 16 | + PROJECT_SEARCH_CONTENTS_QUERY_MAX_LENGTH, |
| 17 | + THREAD_SEARCH_QUERY_MAX_LENGTH, |
| 18 | +} from "@t3tools/contracts"; |
16 | 19 | import { messageSearchTokens } from "@t3tools/shared/paletteSearch"; |
17 | 20 | import { type VcsRefTarget } from "@t3tools/client-runtime/state/vcs"; |
18 | 21 | import type { |
@@ -364,13 +367,16 @@ export function useProjectContentSearch(target: ProjectContentSearchTarget) { |
364 | 367 | // Preserve query whitespace; trim only to detect blank input. |
365 | 368 | const query = target.query; |
366 | 369 | const hasQuery = query.trim().length > 0; |
| 370 | + const queryTooLong = query.length > PROJECT_SEARCH_CONTENTS_QUERY_MAX_LENGTH; |
367 | 371 | const debouncedQuery = useDebouncedValue(query, PROJECT_CONTENT_SEARCH_DEBOUNCE_MS); |
368 | 372 | const result = useEnvironmentQuery( |
369 | 373 | canReadFiles && |
370 | 374 | target.environmentId !== null && |
371 | 375 | target.cwd !== null && |
372 | 376 | hasQuery && |
373 | | - debouncedQuery.trim().length > 0 |
| 377 | + !queryTooLong && |
| 378 | + debouncedQuery.trim().length > 0 && |
| 379 | + debouncedQuery.length <= PROJECT_SEARCH_CONTENTS_QUERY_MAX_LENGTH |
374 | 380 | ? projectContentSearch({ |
375 | 381 | environmentId: target.environmentId, |
376 | 382 | input: { |
@@ -392,12 +398,14 @@ export function useProjectContentSearch(target: ProjectContentSearchTarget) { |
392 | 398 | error: |
393 | 399 | !hasTarget || isCheckingAccess |
394 | 400 | ? null |
395 | | - : canReadFiles |
396 | | - ? result.error |
397 | | - : (fileAccess.error ?? "This connection cannot search host files."), |
| 401 | + : !canReadFiles |
| 402 | + ? (fileAccess.error ?? "This connection cannot search host files.") |
| 403 | + : queryTooLong |
| 404 | + ? `Search is limited to ${PROJECT_SEARCH_CONTENTS_QUERY_MAX_LENGTH} characters.` |
| 405 | + : result.error, |
398 | 406 | isPending: |
399 | 407 | isCheckingAccess || |
400 | | - (canReadFiles && hasQuery && (query !== debouncedQuery || result.isPending)), |
| 408 | + (canReadFiles && hasQuery && !queryTooLong && (query !== debouncedQuery || result.isPending)), |
401 | 409 | hasQuery, |
402 | 410 | truncated: result.data?.truncated ?? false, |
403 | 411 | invalidRegex: target.useRegex && result.data?.regexFallbackError !== undefined, |
|