@sqlrooms/ai-core 0.26.0-rc.2 → 0.26.0-rc.3
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/README.md +238 -348
- package/dist/AiSlice.d.ts +37 -7
- package/dist/AiSlice.d.ts.map +1 -1
- package/dist/AiSlice.js +203 -147
- package/dist/AiSlice.js.map +1 -1
- package/dist/chatTransport.d.ts +48 -0
- package/dist/chatTransport.d.ts.map +1 -0
- package/dist/chatTransport.js +270 -0
- package/dist/chatTransport.js.map +1 -0
- package/dist/components/AiThinkingDots.d.ts +10 -0
- package/dist/components/AiThinkingDots.d.ts.map +1 -0
- package/dist/components/AiThinkingDots.js +18 -0
- package/dist/components/AiThinkingDots.js.map +1 -0
- package/dist/components/AnalysisResult.d.ts +1 -2
- package/dist/components/AnalysisResult.d.ts.map +1 -1
- package/dist/components/AnalysisResult.js +48 -18
- package/dist/components/AnalysisResult.js.map +1 -1
- package/dist/components/AnalysisResultsContainer.d.ts.map +1 -1
- package/dist/components/AnalysisResultsContainer.js +5 -10
- package/dist/components/AnalysisResultsContainer.js.map +1 -1
- package/dist/components/QueryControls.d.ts.map +1 -1
- package/dist/components/QueryControls.js +6 -3
- package/dist/components/QueryControls.js.map +1 -1
- package/dist/components/ToolCallInfo.d.ts +25 -0
- package/dist/components/ToolCallInfo.d.ts.map +1 -0
- package/dist/components/ToolCallInfo.js +32 -0
- package/dist/components/ToolCallInfo.js.map +1 -0
- package/dist/components/tools/ToolResult.d.ts +12 -7
- package/dist/components/tools/ToolResult.d.ts.map +1 -1
- package/dist/components/tools/ToolResult.js +8 -6
- package/dist/components/tools/ToolResult.js.map +1 -1
- package/dist/hooks/useAiChat.d.ts +60 -0
- package/dist/hooks/useAiChat.d.ts.map +1 -0
- package/dist/hooks/useAiChat.js +92 -0
- package/dist/hooks/useAiChat.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/utils.d.ts +23 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +24 -0
- package/dist/utils.js.map +1 -1
- package/package.json +15 -14
- package/dist/analysis.d.ts +0 -51
- package/dist/analysis.d.ts.map +0 -1
- package/dist/analysis.js +0 -43
- package/dist/analysis.js.map +0 -1
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { useEffect, useMemo } from 'react';
|
|
2
|
+
import { useChat } from '@ai-sdk/react';
|
|
3
|
+
import { lastAssistantMessageIsCompleteWithToolCalls, } from 'ai';
|
|
4
|
+
import { useStoreWithAi } from '../AiSlice';
|
|
5
|
+
/**
|
|
6
|
+
* Custom hook that provides AI chat functionality with automatic transport setup,
|
|
7
|
+
* message syncing, and tool call handling.
|
|
8
|
+
*
|
|
9
|
+
* This hook encapsulates all the logic needed to integrate the AI SDK's useChat
|
|
10
|
+
* with the AI slice state management.
|
|
11
|
+
*
|
|
12
|
+
* @returns An object containing messages and sendMessage from useChat
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* function MyComponent() {
|
|
17
|
+
* const {messages, sendMessage} = useAiChat();
|
|
18
|
+
*
|
|
19
|
+
* const handleSubmit = () => {
|
|
20
|
+
* sendMessage({text: 'Hello!'});
|
|
21
|
+
* };
|
|
22
|
+
*
|
|
23
|
+
* return (
|
|
24
|
+
* <div>
|
|
25
|
+
* {messages.map(msg => <div key={msg.id}>{msg.content}</div>)}
|
|
26
|
+
* </div>
|
|
27
|
+
* );
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export function useAiChat() {
|
|
32
|
+
// Get current session and configuration
|
|
33
|
+
const currentSession = useStoreWithAi((s) => s.ai.getCurrentSession());
|
|
34
|
+
const sessionId = currentSession?.id;
|
|
35
|
+
const model = currentSession?.model;
|
|
36
|
+
// Use messagesRevision to force reset only when messages are explicitly deleted
|
|
37
|
+
const messagesRevision = currentSession?.messagesRevision ?? 0;
|
|
38
|
+
// Get chat transport configuration
|
|
39
|
+
const getLocalChatTransport = useStoreWithAi((s) => s.ai.getLocalChatTransport);
|
|
40
|
+
const getRemoteChatTransport = useStoreWithAi((s) => s.ai.getRemoteChatTransport);
|
|
41
|
+
const endPoint = useStoreWithAi((s) => s.ai.chatEndPoint);
|
|
42
|
+
const headers = useStoreWithAi((s) => s.ai.chatHeaders);
|
|
43
|
+
// Get chat handlers
|
|
44
|
+
const onChatToolCall = useStoreWithAi((s) => s.ai.onChatToolCall);
|
|
45
|
+
const onChatFinish = useStoreWithAi((s) => s.ai.onChatFinish);
|
|
46
|
+
const onChatData = useStoreWithAi((s) => s.ai.onChatData);
|
|
47
|
+
const onChatError = useStoreWithAi((s) => s.ai.onChatError);
|
|
48
|
+
const setSessionUiMessages = useStoreWithAi((s) => s.ai.setSessionUiMessages);
|
|
49
|
+
// Create transport (recreate when model changes)
|
|
50
|
+
const transport = useMemo(() => {
|
|
51
|
+
// Recreate transport when the model changes
|
|
52
|
+
void model;
|
|
53
|
+
const trimmed = (endPoint || '').trim();
|
|
54
|
+
if (trimmed.length > 0) {
|
|
55
|
+
return getRemoteChatTransport(trimmed, headers);
|
|
56
|
+
}
|
|
57
|
+
return getLocalChatTransport();
|
|
58
|
+
}, [getLocalChatTransport, getRemoteChatTransport, headers, endPoint, model]);
|
|
59
|
+
// Setup useChat with all configuration
|
|
60
|
+
// Include messagesRevision in the id to force reset only when messages are explicitly deleted
|
|
61
|
+
// Store addToolResult in a variable that can be captured by the onToolCall closure
|
|
62
|
+
let capturedAddToolResult;
|
|
63
|
+
const { messages, sendMessage, addToolResult } = useChat({
|
|
64
|
+
id: `${sessionId}-${messagesRevision}`,
|
|
65
|
+
transport,
|
|
66
|
+
messages: currentSession?.uiMessages ?? [],
|
|
67
|
+
onToolCall: async ({ toolCall }) => {
|
|
68
|
+
// Wrap the store's onChatToolCall to provide addToolResult
|
|
69
|
+
// Use the captured addToolResult from the outer scope
|
|
70
|
+
return onChatToolCall?.({ toolCall, addToolResult: capturedAddToolResult });
|
|
71
|
+
},
|
|
72
|
+
onFinish: onChatFinish,
|
|
73
|
+
onError: onChatError,
|
|
74
|
+
onData: onChatData,
|
|
75
|
+
// Automatically submit when all tool results are available
|
|
76
|
+
// NOTE: When using sendAutomaticallyWhen, don't use await with addToolResult inside onChatToolCall as it can cause deadlocks.
|
|
77
|
+
sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithToolCalls,
|
|
78
|
+
});
|
|
79
|
+
// Capture addToolResult for use in onToolCall
|
|
80
|
+
capturedAddToolResult = addToolResult;
|
|
81
|
+
// Sync streaming updates into the store so UiMessages renders incrementally
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
if (!sessionId)
|
|
84
|
+
return;
|
|
85
|
+
setSessionUiMessages(sessionId, messages);
|
|
86
|
+
}, [messages, sessionId, setSessionUiMessages]);
|
|
87
|
+
return {
|
|
88
|
+
messages,
|
|
89
|
+
sendMessage,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=useAiChat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAiChat.js","sourceRoot":"","sources":["../../src/hooks/useAiChat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,OAAO,EAAC,MAAM,OAAO,CAAC;AACzC,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AACtC,OAAO,EAEL,2CAA2C,GAC5C,MAAM,IAAI,CAAC;AAEZ,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAC;AAa1C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,SAAS;IACvB,wCAAwC;IACxC,MAAM,cAAc,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,iBAAiB,EAAE,CAAC,CAAC;IACvE,MAAM,SAAS,GAAG,cAAc,EAAE,EAA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AEhD,OAAO;QACL,QAAQ;QACR,WAAW;KACZ,CAAC;AACJ,CAAC","sourcesContent":["import {useEffect, useMemo} from 'react';\nimport {useChat} from '@ai-sdk/react';\nimport {\n DefaultChatTransport,\n lastAssistantMessageIsCompleteWithToolCalls,\n} from 'ai';\nimport type {UIMessage} from 'ai';\nimport {useStoreWithAi} from '../AiSlice';\n\nexport type AddToolResult = (\n options:\n | {tool: string; toolCallId: string; output: unknown}\n | {\n tool: string;\n toolCallId: string;\n state: 'output-error';\n errorText: string;\n },\n) => void;\n\n/**\n * Custom hook that provides AI chat functionality with automatic transport setup,\n * message syncing, and tool call handling.\n *\n * This hook encapsulates all the logic needed to integrate the AI SDK's useChat\n * with the AI slice state management.\n *\n * @returns An object containing messages and sendMessage from useChat\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const {messages, sendMessage} = useAiChat();\n *\n * const handleSubmit = () => {\n * sendMessage({text: 'Hello!'});\n * };\n *\n * return (\n * <div>\n * {messages.map(msg => <div key={msg.id}>{msg.content}</div>)}\n * </div>\n * );\n * }\n * ```\n */\nexport function useAiChat() {\n // Get current session and configuration\n const currentSession = useStoreWithAi((s) => s.ai.getCurrentSession());\n const sessionId = currentSession?.id;\n const model = currentSession?.model;\n // Use messagesRevision to force reset only when messages are explicitly deleted\n const messagesRevision = currentSession?.messagesRevision ?? 0;\n\n // Get chat transport configuration\n const getLocalChatTransport = useStoreWithAi(\n (s) => s.ai.getLocalChatTransport,\n );\n const getRemoteChatTransport = useStoreWithAi(\n (s) => s.ai.getRemoteChatTransport,\n );\n const endPoint = useStoreWithAi((s) => s.ai.chatEndPoint);\n const headers = useStoreWithAi((s) => s.ai.chatHeaders);\n\n // Get chat handlers\n const onChatToolCall = useStoreWithAi((s) => s.ai.onChatToolCall);\n const onChatFinish = useStoreWithAi((s) => s.ai.onChatFinish);\n const onChatData = useStoreWithAi((s) => s.ai.onChatData);\n const onChatError = useStoreWithAi((s) => s.ai.onChatError);\n const setSessionUiMessages = useStoreWithAi((s) => s.ai.setSessionUiMessages);\n\n // Create transport (recreate when model changes)\n const transport: DefaultChatTransport<UIMessage> = useMemo(() => {\n // Recreate transport when the model changes\n void model;\n const trimmed = (endPoint || '').trim();\n if (trimmed.length > 0) {\n return getRemoteChatTransport(trimmed, headers);\n }\n return getLocalChatTransport();\n }, [getLocalChatTransport, getRemoteChatTransport, headers, endPoint, model]);\n\n // Setup useChat with all configuration\n // Include messagesRevision in the id to force reset only when messages are explicitly deleted\n // Store addToolResult in a variable that can be captured by the onToolCall closure\n let capturedAddToolResult: AddToolResult;\n\n const {messages, sendMessage, addToolResult} = useChat({\n id: `${sessionId}-${messagesRevision}`,\n transport,\n messages: (currentSession?.uiMessages as unknown as UIMessage[]) ?? [],\n onToolCall: async ({toolCall}: {toolCall: any}) => {\n // Wrap the store's onChatToolCall to provide addToolResult\n // Use the captured addToolResult from the outer scope\n return onChatToolCall?.({toolCall, addToolResult: capturedAddToolResult});\n },\n onFinish: onChatFinish,\n onError: onChatError,\n onData: onChatData,\n // Automatically submit when all tool results are available\n // NOTE: When using sendAutomaticallyWhen, don't use await with addToolResult inside onChatToolCall as it can cause deadlocks.\n sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithToolCalls,\n });\n\n // Capture addToolResult for use in onToolCall\n capturedAddToolResult = addToolResult;\n\n // Sync streaming updates into the store so UiMessages renders incrementally\n useEffect(() => {\n if (!sessionId) return;\n setSessionUiMessages(sessionId, messages as UIMessage[]);\n }, [messages, sessionId, setSessionUiMessages]);\n\n return {\n messages,\n sendMessage,\n };\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export type { AiSliceState } from './AiSlice';
|
|
|
7
7
|
export { AnalysisResultsContainer } from './components/AnalysisResultsContainer';
|
|
8
8
|
export { AnalysisResult } from './components/AnalysisResult';
|
|
9
9
|
export { useScrollToBottom } from './hooks/useScrollToBottom';
|
|
10
|
-
export
|
|
10
|
+
export { useAiChat } from './hooks/useAiChat';
|
|
11
11
|
export { ModelSelector } from './components/ModelSelector';
|
|
12
12
|
export { SessionControls } from './components/SessionControls';
|
|
13
13
|
export { QueryControls } from './components/QueryControls';
|
|
@@ -17,5 +17,7 @@ export { SessionDropdown } from './components/session/SessionDropdown';
|
|
|
17
17
|
export { SessionTitle } from './components/session/SessionTitle';
|
|
18
18
|
export type { SessionType } from './components/session/SessionType';
|
|
19
19
|
export { ToolErrorMessage } from './components/tools/ToolErrorMessage';
|
|
20
|
+
export { ToolCallInfo } from './components/ToolCallInfo';
|
|
20
21
|
export { AiSliceConfig, createDefaultAiConfig } from '@sqlrooms/ai-config';
|
|
22
|
+
export { AiThinkingDots } from './components/AiThinkingDots';
|
|
21
23
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,aAAa,EAAE,cAAc,EAAC,MAAM,WAAW,CAAC;AAExD,YAAY,EAAC,YAAY,EAAC,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAC,wBAAwB,EAAC,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAC,cAAc,EAAC,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAC,iBAAiB,EAAC,MAAM,2BAA2B,CAAC;AAC5D,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,aAAa,EAAE,cAAc,EAAC,MAAM,WAAW,CAAC;AAExD,YAAY,EAAC,YAAY,EAAC,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAC,wBAAwB,EAAC,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAC,cAAc,EAAC,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAC,iBAAiB,EAAC,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAC,SAAS,EAAC,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAC,aAAa,EAAC,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAC,eAAe,EAAC,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAC,aAAa,EAAC,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAC,mBAAmB,EAAC,MAAM,0CAA0C,CAAC;AAC7E,OAAO,EAAC,cAAc,EAAC,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAC,eAAe,EAAC,MAAM,sCAAsC,CAAC;AACrE,OAAO,EAAC,YAAY,EAAC,MAAM,mCAAmC,CAAC;AAC/D,YAAY,EAAC,WAAW,EAAC,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAC,gBAAgB,EAAC,MAAM,qCAAqC,CAAC;AACrE,OAAO,EAAC,YAAY,EAAC,MAAM,2BAA2B,CAAC;AAEvD,OAAO,EAAC,aAAa,EAAE,qBAAqB,EAAC,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAC,cAAc,EAAC,MAAM,6BAA6B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export { createAiSlice, useStoreWithAi } from './AiSlice';
|
|
|
6
6
|
export { AnalysisResultsContainer } from './components/AnalysisResultsContainer';
|
|
7
7
|
export { AnalysisResult } from './components/AnalysisResult';
|
|
8
8
|
export { useScrollToBottom } from './hooks/useScrollToBottom';
|
|
9
|
+
export { useAiChat } from './hooks/useAiChat';
|
|
9
10
|
export { ModelSelector } from './components/ModelSelector';
|
|
10
11
|
export { SessionControls } from './components/SessionControls';
|
|
11
12
|
export { QueryControls } from './components/QueryControls';
|
|
@@ -14,5 +15,7 @@ export { SessionActions } from './components/session/SessionActions';
|
|
|
14
15
|
export { SessionDropdown } from './components/session/SessionDropdown';
|
|
15
16
|
export { SessionTitle } from './components/session/SessionTitle';
|
|
16
17
|
export { ToolErrorMessage } from './components/tools/ToolErrorMessage';
|
|
18
|
+
export { ToolCallInfo } from './components/ToolCallInfo';
|
|
17
19
|
export { AiSliceConfig, createDefaultAiConfig } from '@sqlrooms/ai-config';
|
|
20
|
+
export { AiThinkingDots } from './components/AiThinkingDots';
|
|
18
21
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,aAAa,EAAE,cAAc,EAAC,MAAM,WAAW,CAAC;AAGxD,OAAO,EAAC,wBAAwB,EAAC,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAC,cAAc,EAAC,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAC,iBAAiB,EAAC,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,aAAa,EAAE,cAAc,EAAC,MAAM,WAAW,CAAC;AAGxD,OAAO,EAAC,wBAAwB,EAAC,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAC,cAAc,EAAC,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAC,iBAAiB,EAAC,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAC,SAAS,EAAC,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAC,aAAa,EAAC,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAC,eAAe,EAAC,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAC,aAAa,EAAC,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAC,mBAAmB,EAAC,MAAM,0CAA0C,CAAC;AAC7E,OAAO,EAAC,cAAc,EAAC,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAC,eAAe,EAAC,MAAM,sCAAsC,CAAC;AACrE,OAAO,EAAC,YAAY,EAAC,MAAM,mCAAmC,CAAC;AAE/D,OAAO,EAAC,gBAAgB,EAAC,MAAM,qCAAqC,CAAC;AACrE,OAAO,EAAC,YAAY,EAAC,MAAM,2BAA2B,CAAC;AAEvD,OAAO,EAAC,aAAa,EAAE,qBAAqB,EAAC,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAC,cAAc,EAAC,MAAM,6BAA6B,CAAC","sourcesContent":["/**\n * {@include ../README.md}\n * @packageDocumentation\n */\n\nexport {createAiSlice, useStoreWithAi} from './AiSlice';\n\nexport type {AiSliceState} from './AiSlice';\nexport {AnalysisResultsContainer} from './components/AnalysisResultsContainer';\nexport {AnalysisResult} from './components/AnalysisResult';\nexport {useScrollToBottom} from './hooks/useScrollToBottom';\nexport {useAiChat} from './hooks/useAiChat';\n\nexport {ModelSelector} from './components/ModelSelector';\nexport {SessionControls} from './components/SessionControls';\nexport {QueryControls} from './components/QueryControls';\nexport {DeleteSessionDialog} from './components/session/DeleteSessionDialog';\nexport {SessionActions} from './components/session/SessionActions';\nexport {SessionDropdown} from './components/session/SessionDropdown';\nexport {SessionTitle} from './components/session/SessionTitle';\nexport type {SessionType} from './components/session/SessionType';\nexport {ToolErrorMessage} from './components/tools/ToolErrorMessage';\nexport {ToolCallInfo} from './components/ToolCallInfo';\n\nexport {AiSliceConfig, createDefaultAiConfig} from '@sqlrooms/ai-config';\nexport {AiThinkingDots} from './components/AiThinkingDots';\n"]}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Utility functions for AI Chat UI configuration
|
|
3
3
|
*/
|
|
4
|
-
import { AiSettingsSliceConfig } from '@sqlrooms/ai-config';
|
|
4
|
+
import { AiSettingsSliceConfig, UIMessagePart } from '@sqlrooms/ai-config';
|
|
5
|
+
import { TextUIPart, ToolUIPart } from 'ai';
|
|
5
6
|
/**
|
|
6
7
|
* Extract models from aiSettings in the format expected by ModelSelector
|
|
7
8
|
* @param config - The AI model configuration
|
|
@@ -12,4 +13,25 @@ export declare function extractModelsFromSettings(config: AiSettingsSliceConfig)
|
|
|
12
13
|
label: string;
|
|
13
14
|
value: string;
|
|
14
15
|
}>;
|
|
16
|
+
/**
|
|
17
|
+
* Type guard to check if a UIMessagePart is a text part
|
|
18
|
+
* @param part - The message part to check
|
|
19
|
+
* @returns True if the part is a text part
|
|
20
|
+
*/
|
|
21
|
+
export declare function isTextPart(part: UIMessagePart): part is TextUIPart;
|
|
22
|
+
/**
|
|
23
|
+
* Type guard to check if a UIMessagePart is a reasoning part
|
|
24
|
+
* @param part - The message part to check
|
|
25
|
+
* @returns True if the part is a reasoning part
|
|
26
|
+
*/
|
|
27
|
+
export declare function isReasoningPart(part: UIMessagePart): part is Extract<UIMessagePart, {
|
|
28
|
+
type: 'reasoning';
|
|
29
|
+
text: string;
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Type guard to check if a UIMessagePart is a tool part (type starts with 'tool-')
|
|
33
|
+
* @param part - The message part to check
|
|
34
|
+
* @returns True if the part is a tool part
|
|
35
|
+
*/
|
|
36
|
+
export declare function isToolPart(part: UIMessagePart): part is ToolUIPart;
|
|
15
37
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,qBAAqB,EAErB,aAAa,EACd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAY,UAAU,EAAE,UAAU,EAAC,MAAM,IAAI,CAAC;AAErD;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,qBAAqB,GAC5B,KAAK,CAAC;IACP,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf,CAAC,CA4BD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI,IAAI,UAAU,CAElE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,aAAa,GAClB,IAAI,IAAI,OAAO,CAAC,aAAa,EAAE;IAAC,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,CAAC,CAEnE;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI,IAAI,UAAU,CAElE"}
|
package/dist/utils.js
CHANGED
|
@@ -28,4 +28,28 @@ export function extractModelsFromSettings(config) {
|
|
|
28
28
|
});
|
|
29
29
|
return models;
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Type guard to check if a UIMessagePart is a text part
|
|
33
|
+
* @param part - The message part to check
|
|
34
|
+
* @returns True if the part is a text part
|
|
35
|
+
*/
|
|
36
|
+
export function isTextPart(part) {
|
|
37
|
+
return part.type === 'text';
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Type guard to check if a UIMessagePart is a reasoning part
|
|
41
|
+
* @param part - The message part to check
|
|
42
|
+
* @returns True if the part is a reasoning part
|
|
43
|
+
*/
|
|
44
|
+
export function isReasoningPart(part) {
|
|
45
|
+
return part.type === 'reasoning';
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Type guard to check if a UIMessagePart is a tool part (type starts with 'tool-')
|
|
49
|
+
* @param part - The message part to check
|
|
50
|
+
* @returns True if the part is a tool part
|
|
51
|
+
*/
|
|
52
|
+
export function isToolPart(part) {
|
|
53
|
+
return typeof part.type === 'string' && part.type.startsWith('tool-');
|
|
54
|
+
}
|
|
31
55
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","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AAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AACxE,CAAC","sourcesContent":["/**\n * Utility functions for AI Chat UI configuration\n */\n\nimport {\n AiSettingsSliceConfig,\n AnalysisResultSchema,\n UIMessagePart,\n} from '@sqlrooms/ai-config';\nimport {UIMessage, TextUIPart, ToolUIPart} from 'ai';\n\n/**\n * Extract models from aiSettings in the format expected by ModelSelector\n * @param config - The AI model configuration\n * @returns Array of models with provider, label, and value properties\n */\nexport function extractModelsFromSettings(\n config: AiSettingsSliceConfig,\n): Array<{\n provider: string;\n label: string;\n value: string;\n}> {\n const models: Array<{\n provider: string;\n label: string;\n value: string;\n }> = [];\n\n // Extract models from providers\n Object.entries(config.providers).forEach(([providerKey, provider]) => {\n provider.models.forEach((model) => {\n models.push({\n provider: providerKey,\n label: model.modelName,\n value: model.modelName,\n });\n });\n });\n\n // Add custom models\n config.customModels.forEach((customModel) => {\n models.push({\n provider: 'custom',\n label: customModel.modelName,\n value: customModel.modelName,\n });\n });\n\n return models;\n}\n\n/**\n * Type guard to check if a UIMessagePart is a text part\n * @param part - The message part to check\n * @returns True if the part is a text part\n */\nexport function isTextPart(part: UIMessagePart): part is TextUIPart {\n return part.type === 'text';\n}\n\n/**\n * Type guard to check if a UIMessagePart is a reasoning part\n * @param part - The message part to check\n * @returns True if the part is a reasoning part\n */\nexport function isReasoningPart(\n part: UIMessagePart,\n): part is Extract<UIMessagePart, {type: 'reasoning'; text: string}> {\n return part.type === 'reasoning';\n}\n\n/**\n * Type guard to check if a UIMessagePart is a tool part (type starts with 'tool-')\n * @param part - The message part to check\n * @returns True if the part is a tool part\n */\nexport function isToolPart(part: UIMessagePart): part is ToolUIPart {\n return typeof part.type === 'string' && part.type.startsWith('tool-');\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqlrooms/ai-core",
|
|
3
|
-
"version": "0.26.0-rc.
|
|
3
|
+
"version": "0.26.0-rc.3",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -18,23 +18,24 @@
|
|
|
18
18
|
"access": "public"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@ai-sdk/
|
|
22
|
-
"@
|
|
23
|
-
"@
|
|
21
|
+
"@ai-sdk/openai": "^2.0.32",
|
|
22
|
+
"@ai-sdk/openai-compatible": "^1.0.18",
|
|
23
|
+
"@ai-sdk/react": "^2.0.44",
|
|
24
|
+
"@openassistant/utils": "1.0.0-alpha.0",
|
|
24
25
|
"@paralleldrive/cuid2": "^2.2.2",
|
|
25
|
-
"@sqlrooms/ai-config": "0.26.0-rc.
|
|
26
|
-
"@sqlrooms/monaco-editor": "0.26.0-rc.
|
|
27
|
-
"@sqlrooms/room-config": "0.26.0-rc.
|
|
28
|
-
"@sqlrooms/room-store": "0.26.0-rc.
|
|
29
|
-
"@sqlrooms/ui": "0.26.0-rc.
|
|
30
|
-
"@sqlrooms/utils": "0.26.0-rc.
|
|
31
|
-
"ai": "^
|
|
26
|
+
"@sqlrooms/ai-config": "0.26.0-rc.3",
|
|
27
|
+
"@sqlrooms/monaco-editor": "0.26.0-rc.3",
|
|
28
|
+
"@sqlrooms/room-config": "0.26.0-rc.3",
|
|
29
|
+
"@sqlrooms/room-store": "0.26.0-rc.3",
|
|
30
|
+
"@sqlrooms/ui": "0.26.0-rc.3",
|
|
31
|
+
"@sqlrooms/utils": "0.26.0-rc.3",
|
|
32
|
+
"ai": "^5.0.44",
|
|
32
33
|
"immer": "^10.1.1",
|
|
33
34
|
"lucide-react": "^0.475.0",
|
|
34
35
|
"react-markdown": "^10.1.0",
|
|
35
36
|
"rehype-raw": "^7.0.0",
|
|
36
37
|
"remark-gfm": "^4.0.0",
|
|
37
|
-
"zod": "^
|
|
38
|
+
"zod": "^4.1.8"
|
|
38
39
|
},
|
|
39
40
|
"peerDependencies": {
|
|
40
41
|
"react": ">=18",
|
|
@@ -47,5 +48,5 @@
|
|
|
47
48
|
"typecheck": "tsc --noEmit",
|
|
48
49
|
"typedoc": "typedoc"
|
|
49
50
|
},
|
|
50
|
-
"gitHead": "
|
|
51
|
-
}
|
|
51
|
+
"gitHead": "536764b2aa924e5bb6650fe0bc674113179ff444"
|
|
52
|
+
}
|
package/dist/analysis.d.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { StreamMessage } from '@openassistant/core';
|
|
2
|
-
import { AnalysisResultSchema } from '@sqlrooms/ai-config';
|
|
3
|
-
import { AiSliceTool } from './AiSlice';
|
|
4
|
-
/**
|
|
5
|
-
* Configuration options for running an AI analysis session
|
|
6
|
-
*/
|
|
7
|
-
type AnalysisParameters = {
|
|
8
|
-
/** Assistant instance identifier (default: 'sqlrooms-ai') */
|
|
9
|
-
name?: string;
|
|
10
|
-
/** AI model provider (e.g., 'openai', 'anthropic') */
|
|
11
|
-
modelProvider: string;
|
|
12
|
-
/** Model identifier (e.g., 'gpt-4', 'claude-3') */
|
|
13
|
-
model: string;
|
|
14
|
-
/** Authentication key for the model provider's API */
|
|
15
|
-
apiKey: string;
|
|
16
|
-
/** Analysis prompt or question to be processed */
|
|
17
|
-
prompt: string;
|
|
18
|
-
/** Optional controller for canceling the analysis operation */
|
|
19
|
-
abortController?: AbortController;
|
|
20
|
-
/** Maximum number of analysis steps allowed (default: 100) */
|
|
21
|
-
maxSteps?: number;
|
|
22
|
-
/** The history of analysis results (e.g. saved in localStorage) */
|
|
23
|
-
historyAnalysis?: AnalysisResultSchema[];
|
|
24
|
-
/** Tools to use in the analysis */
|
|
25
|
-
tools?: Record<string, AiSliceTool>;
|
|
26
|
-
/** Base URL for Ollama provider (required when modelProvider is 'ollama') */
|
|
27
|
-
baseUrl?: string;
|
|
28
|
-
/**
|
|
29
|
-
* Function to get custom instructions for the AI assistant
|
|
30
|
-
* @returns The instructions string to use
|
|
31
|
-
*/
|
|
32
|
-
getInstructions: () => string;
|
|
33
|
-
/**
|
|
34
|
-
* Callback for handling streaming results
|
|
35
|
-
* @param isCompleted - Indicates if this is the final message in the stream
|
|
36
|
-
* @param streamMessage - Current message content being streamed
|
|
37
|
-
*/
|
|
38
|
-
onStreamResult: (isCompleted: boolean, streamMessage?: StreamMessage) => void;
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Executes an AI analysis session on the room data
|
|
42
|
-
*
|
|
43
|
-
* @param config - Analysis configuration options. See {@link AnalysisParameters} for more details.
|
|
44
|
-
* @returns Object containing tool calls executed and the final analysis result
|
|
45
|
-
*/
|
|
46
|
-
export declare function runAnalysis({ name, modelProvider, model, apiKey, prompt, abortController, historyAnalysis, onStreamResult, maxSteps, tools, getInstructions, baseUrl, }: AnalysisParameters): Promise<{
|
|
47
|
-
streamMessage: StreamMessage;
|
|
48
|
-
messages: import("ai").CoreMessage[];
|
|
49
|
-
}>;
|
|
50
|
-
export {};
|
|
51
|
-
//# sourceMappingURL=analysis.d.ts.map
|
package/dist/analysis.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"analysis.d.ts","sourceRoot":"","sources":["../src/analysis.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,aAAa,EACd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAC,oBAAoB,EAAC,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAC,WAAW,EAAC,MAAM,WAAW,CAAC;AAEtC;;GAEG;AACH,KAAK,kBAAkB,GAAG;IACxB,6DAA6D;IAC7D,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,sDAAsD;IACtD,aAAa,EAAE,MAAM,CAAC;IAEtB,mDAAmD;IACnD,KAAK,EAAE,MAAM,CAAC;IAEd,sDAAsD;IACtD,MAAM,EAAE,MAAM,CAAC;IAEf,kDAAkD;IAClD,MAAM,EAAE,MAAM,CAAC;IAEf,+DAA+D;IAC/D,eAAe,CAAC,EAAE,eAAe,CAAC;IAElC,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,mEAAmE;IACnE,eAAe,CAAC,EAAE,oBAAoB,EAAE,CAAC;IAEzC,mCAAmC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAEpC,6EAA6E;IAC7E,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,eAAe,EAAE,MAAM,MAAM,CAAC;IAE9B;;;;OAIG;IACH,cAAc,EAAE,CAAC,WAAW,EAAE,OAAO,EAAE,aAAa,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;CAC/E,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,WAAW,CAAC,EAChC,IAAoB,EACpB,aAAa,EACb,KAAK,EACL,MAAM,EACN,MAAM,EACN,eAAe,EACf,eAAe,EACf,cAAc,EACd,QAAY,EACZ,KAAU,EACV,eAAe,EACf,OAAO,GACR,EAAE,kBAAkB;;;GA0CpB"}
|
package/dist/analysis.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { createAssistant, rebuildMessages, } from '@openassistant/core';
|
|
2
|
-
import { convertToCoreMessages } from 'ai';
|
|
3
|
-
/**
|
|
4
|
-
* Executes an AI analysis session on the room data
|
|
5
|
-
*
|
|
6
|
-
* @param config - Analysis configuration options. See {@link AnalysisParameters} for more details.
|
|
7
|
-
* @returns Object containing tool calls executed and the final analysis result
|
|
8
|
-
*/
|
|
9
|
-
export async function runAnalysis({ name = 'sqlrooms-ai', modelProvider, model, apiKey, prompt, abortController, historyAnalysis, onStreamResult, maxSteps = 5, tools = {}, getInstructions, baseUrl, }) {
|
|
10
|
-
// get the singleton assistant instance
|
|
11
|
-
const assistant = await createAssistant({
|
|
12
|
-
name,
|
|
13
|
-
modelProvider,
|
|
14
|
-
model,
|
|
15
|
-
apiKey,
|
|
16
|
-
version: 'v1',
|
|
17
|
-
instructions: getInstructions(),
|
|
18
|
-
tools: tools,
|
|
19
|
-
temperature: 0,
|
|
20
|
-
toolChoice: 'auto', // this will enable streaming
|
|
21
|
-
maxSteps,
|
|
22
|
-
...(abortController ? { abortController } : {}),
|
|
23
|
-
baseUrl, // ollama base url or LLM proxy server url
|
|
24
|
-
});
|
|
25
|
-
// restore ai messages from historyAnalysis?
|
|
26
|
-
if (historyAnalysis) {
|
|
27
|
-
const historyMessages = historyAnalysis.map((analysis) => ({
|
|
28
|
-
prompt: analysis.prompt,
|
|
29
|
-
response: analysis.streamMessage,
|
|
30
|
-
}));
|
|
31
|
-
const initialMessages = rebuildMessages(historyMessages);
|
|
32
|
-
assistant.setMessages(convertToCoreMessages(initialMessages));
|
|
33
|
-
}
|
|
34
|
-
// process the prompt
|
|
35
|
-
const newMessages = await assistant.processTextMessage({
|
|
36
|
-
textMessage: prompt,
|
|
37
|
-
streamMessageCallback: ({ isCompleted, message, }) => {
|
|
38
|
-
onStreamResult(isCompleted ?? false, message);
|
|
39
|
-
},
|
|
40
|
-
});
|
|
41
|
-
return newMessages;
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=analysis.js.map
|
package/dist/analysis.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"analysis.js","sourceRoot":"","sources":["../src/analysis.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,GAEhB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAC,qBAAqB,EAAC,MAAM,IAAI,CAAC;AAmDzC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,EAChC,IAAI,GAAG,aAAa,EACpB,aAAa,EACb,KAAK,EACL,MAAM,EACN,MAAM,EACN,eAAe,EACf,eAAe,EACf,cAAc,EACd,QAAQ,GAAG,CAAC,EACZ,KAAK,GAAG,EAAE,EACV,eAAe,EACf,OAAO,GACY;IACnB,uCAAuC;IACvC,MAAM,SAAS,GAAG,MAAM,eAAe,CAAC;QACtC,IAAI;QACJ,aAAa;QACb,KAAK;QACL,MAAM;QACN,OAAO,EAAE,IAAI;QACb,YAAY,EAAE,eAAe,EAAE;QAC/B,KAAK,EAAE,KAAK;QACZ,WAAW,EAAE,CAAC;QACd,UAAU,EAAE,MAAM,EAAE,6BAA6B;QACjD,QAAQ;QACR,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC,EAAC,eAAe,EAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7C,OAAO,EAAE,0CAA0C;KACpD,CAAC,CAAC;IAEH,4CAA4C;IAC5C,IAAI,eAAe,EAAE,CAAC;QACpB,MAAM,eAAe,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;YACzD,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,QAAQ,EAAE,QAAQ,CAAC,aAA8B;SAClD,CAAC,CAAC,CAAC;QACJ,MAAM,eAAe,GAAG,eAAe,CAAC,eAAe,CAAC,CAAC;QACzD,SAAS,CAAC,WAAW,CAAC,qBAAqB,CAAC,eAAe,CAAC,CAAC,CAAC;IAChE,CAAC;IAED,qBAAqB;IACrB,MAAM,WAAW,GAAG,MAAM,SAAS,CAAC,kBAAkB,CAAC;QACrD,WAAW,EAAE,MAAM;QACnB,qBAAqB,EAAE,CAAC,EACtB,WAAW,EACX,OAAO,GAIR,EAAE,EAAE;YACH,cAAc,CAAC,WAAW,IAAI,KAAK,EAAE,OAAO,CAAC,CAAC;QAChD,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["import {\n createAssistant,\n rebuildMessages,\n StreamMessage,\n} from '@openassistant/core';\nimport {AnalysisResultSchema} from '@sqlrooms/ai-config';\nimport {convertToCoreMessages} from 'ai';\nimport {AiSliceTool} from './AiSlice';\n\n/**\n * Configuration options for running an AI analysis session\n */\ntype AnalysisParameters = {\n /** Assistant instance identifier (default: 'sqlrooms-ai') */\n name?: string;\n\n /** AI model provider (e.g., 'openai', 'anthropic') */\n modelProvider: string;\n\n /** Model identifier (e.g., 'gpt-4', 'claude-3') */\n model: string;\n\n /** Authentication key for the model provider's API */\n apiKey: string;\n\n /** Analysis prompt or question to be processed */\n prompt: string;\n\n /** Optional controller for canceling the analysis operation */\n abortController?: AbortController;\n\n /** Maximum number of analysis steps allowed (default: 100) */\n maxSteps?: number;\n\n /** The history of analysis results (e.g. saved in localStorage) */\n historyAnalysis?: AnalysisResultSchema[];\n\n /** Tools to use in the analysis */\n tools?: Record<string, AiSliceTool>;\n\n /** Base URL for Ollama provider (required when modelProvider is 'ollama') */\n baseUrl?: string;\n\n /**\n * Function to get custom instructions for the AI assistant\n * @returns The instructions string to use\n */\n getInstructions: () => string;\n\n /**\n * Callback for handling streaming results\n * @param isCompleted - Indicates if this is the final message in the stream\n * @param streamMessage - Current message content being streamed\n */\n onStreamResult: (isCompleted: boolean, streamMessage?: StreamMessage) => void;\n};\n\n/**\n * Executes an AI analysis session on the room data\n *\n * @param config - Analysis configuration options. See {@link AnalysisParameters} for more details.\n * @returns Object containing tool calls executed and the final analysis result\n */\nexport async function runAnalysis({\n name = 'sqlrooms-ai',\n modelProvider,\n model,\n apiKey,\n prompt,\n abortController,\n historyAnalysis,\n onStreamResult,\n maxSteps = 5,\n tools = {},\n getInstructions,\n baseUrl,\n}: AnalysisParameters) {\n // get the singleton assistant instance\n const assistant = await createAssistant({\n name,\n modelProvider,\n model,\n apiKey,\n version: 'v1',\n instructions: getInstructions(),\n tools: tools,\n temperature: 0,\n toolChoice: 'auto', // this will enable streaming\n maxSteps,\n ...(abortController ? {abortController} : {}),\n baseUrl, // ollama base url or LLM proxy server url\n });\n\n // restore ai messages from historyAnalysis?\n if (historyAnalysis) {\n const historyMessages = historyAnalysis.map((analysis) => ({\n prompt: analysis.prompt,\n response: analysis.streamMessage as StreamMessage,\n }));\n const initialMessages = rebuildMessages(historyMessages);\n assistant.setMessages(convertToCoreMessages(initialMessages));\n }\n\n // process the prompt\n const newMessages = await assistant.processTextMessage({\n textMessage: prompt,\n streamMessageCallback: ({\n isCompleted,\n message,\n }: {\n isCompleted?: boolean;\n message?: StreamMessage;\n }) => {\n onStreamResult(isCompleted ?? false, message);\n },\n });\n\n return newMessages;\n}\n"]}
|