Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@
"@shopify/hydrogen-react": "^2026.4.0",
"@tailwindcss/typography": "^0.5.19",
"@tailwindcss/vite": "^4.2.2",
"@tanstack/ai": "^0.54.0",
"@tanstack/ai": "^0.57.0",
"@tanstack/ai-anthropic": "^0.18.6",
"@tanstack/ai-client": "^0.31.1",
"@tanstack/ai-openai": "^0.22.6",
"@tanstack/ai-openrouter": "^0.19.9",
"@tanstack/ai-typesafe": "0.1.0",
"@tanstack/charts": "0.16.1",
"@tanstack/create": "^0.70.0",
"@tanstack/highlight": "^0.0.9",
Expand Down
69 changes: 55 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

104 changes: 94 additions & 10 deletions src/components/application-starter/useApplicationStarter.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import {
applicationStarterPartnerIntentSchema,
selectIntentPartners,
type ApplicationStarterPartnerIntent,
} from '~/utils/application-starter-intent'
import * as React from 'react'
import { useDebouncedValue } from '@tanstack/react-pacer'
import { useToast } from '~/components/ToastProvider'
Expand Down Expand Up @@ -112,6 +117,7 @@ export function useApplicationStarter({
StarterToolchain | undefined
>(undefined)
const latestRequestIdRef = React.useRef(0)
const resolvedInputRef = React.useRef<string | null>(null)
const hasUserEditedStarterRef = React.useRef(false)
const migrationRepositoryInputRef = React.useRef<HTMLInputElement | null>(
null,
Expand All @@ -123,13 +129,74 @@ export function useApplicationStarter({
),
[explicitPartnerSelections, partnerSuggestions],
)
const [partnerAnalysis, setPartnerAnalysis] = React.useState<{
input: string
intent: ApplicationStarterPartnerIntent | null
} | null>(null)
React.useEffect(() => {
if (
context !== 'home' ||
!debouncedInput.trim() ||
debouncedInput !== input
)
return
const controller = new AbortController()
async function analyze() {
let intent: ApplicationStarterPartnerIntent | null = null
try {
const response = await fetch('/api/application-starter/resolve', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
mode: 'analyze',
context,
input: debouncedInput,
}),
signal: controller.signal,
})
if (response.ok) {
const body: unknown = await response.json()
if (body && typeof body === 'object' && 'partnerIntent' in body) {
const parsed = applicationStarterPartnerIntentSchema.safeParse(
body.partnerIntent,
)
if (parsed.success) intent = parsed.data
}
}
} catch {
// Keep the existing selections when recommendations are unavailable.
}
if (!controller.signal.aborted)
setPartnerAnalysis({ input: debouncedInput, intent })
}
void analyze()
return () => controller.abort()
}, [context, debouncedInput, input])
const inferredPartners = React.useMemo(
() =>
selectIntentPartners({
intent:
context === 'home' && partnerAnalysis?.input === input
? partnerAnalysis.intent
: null,
partners: partnerSuggestions,
selections: explicitPartnerSelections,
}),
[
context,
explicitPartnerSelections,
input,
partnerAnalysis,
partnerSuggestions,
],
)
const selectedPartners = React.useMemo(
() =>
getApplicationStarterCompatiblePartnerIds(
explicitlySelectedPartners,
[...explicitlySelectedPartners, ...inferredPartners],
partnerSuggestions,
),
[explicitlySelectedPartners, partnerSuggestions],
[explicitlySelectedPartners, inferredPartners, partnerSuggestions],
)
const visiblePartnerSuggestions = React.useMemo(
() =>
Expand Down Expand Up @@ -188,8 +255,8 @@ export function useApplicationStarter({

const markInputDirty = React.useCallback(() => {
markUserEditedStarter()
invalidateResult({ clearResult: false })
}, [invalidateResult, markUserEditedStarter])
invalidateResult({ clearResult: context === 'home' })
}, [context, invalidateResult, markUserEditedStarter])

React.useEffect(() => {
if (revealOptionsImmediately) {
Expand Down Expand Up @@ -229,7 +296,7 @@ export function useApplicationStarter({
const buildSubmittedInput = React.useCallback(
(
nextSelectedPartners: Array<string> = explicitlySelectedPartners,
nextInferredPartners: Array<string> = [],
nextInferredPartners: Array<string> = inferredPartners,
nextSelectedLibraries: Array<LibraryId> = selectedLibraries,
) =>
composeStarterInput({
Expand All @@ -244,6 +311,7 @@ export function useApplicationStarter({
}),
[
explicitlySelectedPartners,
inferredPartners,
forceRouterOnly,
input,
migrationRepositoryUrl,
Expand All @@ -256,7 +324,7 @@ export function useApplicationStarter({
const buildDebouncedSubmittedInput = React.useCallback(
(
nextSelectedPartners: Array<string> = explicitlySelectedPartners,
nextInferredPartners: Array<string> = [],
nextInferredPartners: Array<string> = inferredPartners,
nextSelectedLibraries: Array<LibraryId> = selectedLibraries,
) =>
composeStarterInput({
Expand All @@ -273,6 +341,7 @@ export function useApplicationStarter({
debouncedInput,
debouncedMigrationRepositoryUrl,
explicitlySelectedPartners,
inferredPartners,
forceRouterOnly,
selectedPackageManager,
selectedLibraries,
Expand Down Expand Up @@ -459,6 +528,7 @@ export function useApplicationStarter({
return null
}

resolvedInputRef.current = trimmed
applyResolvedResultState(nextResult)

if (options?.applyApplicationStarter && applicationStarterIntegration) {
Expand Down Expand Up @@ -538,7 +608,7 @@ export function useApplicationStarter({
)

React.useEffect(() => {
if (!hasRevealedOptions) {
if (!hasRevealedOptions || debouncedInput !== input) {
return
}

Expand All @@ -552,7 +622,13 @@ export function useApplicationStarter({
applyApplicationStarter: hasUserEditedStarterRef.current,
silentApplicationStarter: true,
})
}, [buildDebouncedSubmittedInput, hasRevealedOptions, resolveSubmittedInput])
}, [
buildDebouncedSubmittedInput,
debouncedInput,
hasRevealedOptions,
input,
resolveSubmittedInput,
])

const selectSuggestion = React.useCallback(
async ({
Expand Down Expand Up @@ -581,7 +657,11 @@ export function useApplicationStarter({
return null
}

if (result && !isDirtySinceLastResult) {
if (
result &&
!isDirtySinceLastResult &&
resolvedInputRef.current === submittedInput.trim()
) {
return result
}

Expand Down Expand Up @@ -709,7 +789,9 @@ export function useApplicationStarter({
const generatePrompt = React.useCallback(async () => {
const submittedInput = buildSubmittedInput()
const nextResult =
result && !isDirtySinceLastResult
result &&
!isDirtySinceLastResult &&
resolvedInputRef.current === submittedInput.trim()
? result
: await resolveSubmittedInput(submittedInput)

Expand Down Expand Up @@ -800,6 +882,8 @@ export function useApplicationStarter({
hasUserEditedStarterRef.current = false
sessionContextRef.current = defaultApplicationStarterSessionContext
setInput('')
setPartnerAnalysis(null)
resolvedInputRef.current = null
setHasRevealedOptions(revealOptionsImmediately)
setResult(null)
setCopiedKind(null)
Expand Down
Loading
Loading