@tanstack/cta-framework-react-cra 0.17.4 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/add-ons/db/assets/src/components/demo.chat-area.tsx +1 -8
- package/add-ons/store/assets/src/lib/demo-store-devtools.tsx +64 -0
- package/add-ons/store/info.json +7 -0
- package/add-ons/store/package.json +3 -0
- package/add-ons/tanstack-query/assets/src/integrations/tanstack-query/devtools.tsx +6 -0
- package/add-ons/tanstack-query/info.json +3 -3
- package/add-ons/tanstack-query/package.json +1 -1
- package/examples/tanchat/assets/src/components/example-AIAssistant.tsx +59 -58
- package/examples/tanchat/assets/src/routes/api.demo-chat.ts +43 -0
- package/examples/tanchat/assets/src/routes/example.chat.tsx +54 -30
- package/examples/tanchat/assets/src/utils/demo.tools.ts +8 -2
- package/examples/tanchat/package.json +3 -3
- package/package.json +2 -2
- package/project/base/package.json +2 -1
- package/project/base/src/routes/__root.tsx.ejs +28 -5
- package/tests/snapshots/react-cra/cr-js-form-npm.json +2 -2
- package/tests/snapshots/react-cra/cr-js-npm.json +2 -2
- package/tests/snapshots/react-cra/cr-ts-npm.json +2 -2
- package/tests/snapshots/react-cra/cr-ts-start-npm.json +2 -2
- package/tests/snapshots/react-cra/cr-ts-start-tanstack-query-npm.json +3 -3
- package/tests/snapshots/react-cra/fr-ts-biome-npm.json +2 -2
- package/tests/snapshots/react-cra/fr-ts-npm.json +2 -2
- package/tests/snapshots/react-cra/fr-ts-tw-npm.json +2 -2
- package/add-ons/tanstack-query/assets/src/integrations/tanstack-query/layout.tsx +0 -5
- package/examples/tanchat/assets/src/utils/demo.ai.ts +0 -62
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { createServerFn } from '@tanstack/react-start'
|
|
2
|
-
import { anthropic } from '@ai-sdk/anthropic'
|
|
3
|
-
import { streamText } from 'ai'
|
|
4
|
-
|
|
5
|
-
import getTools from './demo.tools'
|
|
6
|
-
|
|
7
|
-
export interface Message {
|
|
8
|
-
id: string
|
|
9
|
-
role: 'user' | 'assistant'
|
|
10
|
-
content: string
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const SYSTEM_PROMPT = `You are a helpful assistant for a store that sells guitars.
|
|
14
|
-
|
|
15
|
-
You can use the following tools to help the user:
|
|
16
|
-
|
|
17
|
-
- getGuitars: Get all guitars from the database
|
|
18
|
-
- recommendGuitar: Recommend a guitar to the user
|
|
19
|
-
`
|
|
20
|
-
|
|
21
|
-
export const genAIResponse = createServerFn({ method: 'POST', response: 'raw' })
|
|
22
|
-
.validator(
|
|
23
|
-
(d: {
|
|
24
|
-
messages: Array<Message>
|
|
25
|
-
systemPrompt?: { value: string; enabled: boolean }
|
|
26
|
-
}) => d,
|
|
27
|
-
)
|
|
28
|
-
.handler(async ({ data }) => {
|
|
29
|
-
const messages = data.messages
|
|
30
|
-
.filter(
|
|
31
|
-
(msg) =>
|
|
32
|
-
msg.content.trim() !== '' &&
|
|
33
|
-
!msg.content.startsWith('Sorry, I encountered an error'),
|
|
34
|
-
)
|
|
35
|
-
.map((msg) => ({
|
|
36
|
-
role: msg.role,
|
|
37
|
-
content: msg.content.trim(),
|
|
38
|
-
}))
|
|
39
|
-
|
|
40
|
-
const tools = await getTools()
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
const result = streamText({
|
|
44
|
-
model: anthropic('claude-3-5-sonnet-latest'),
|
|
45
|
-
messages,
|
|
46
|
-
system: SYSTEM_PROMPT,
|
|
47
|
-
maxSteps: 10,
|
|
48
|
-
tools,
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
return result.toDataStreamResponse()
|
|
52
|
-
} catch (error) {
|
|
53
|
-
console.error('Error in genAIResponse:', error)
|
|
54
|
-
if (error instanceof Error && error.message.includes('rate limit')) {
|
|
55
|
-
return { error: 'Rate limit exceeded. Please try again in a moment.' }
|
|
56
|
-
}
|
|
57
|
-
return {
|
|
58
|
-
error:
|
|
59
|
-
error instanceof Error ? error.message : 'Failed to get AI response',
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
})
|