-
- Reset Chat
-
-
- Send Message
-
+
+
+ >
+ )
+}
+
+type OnSubmitWithTools = (value: string | ToolMessage[]) => void
+type OnSubmit = (value: string) => void
+export function ChatTextArea({
+ placeholder,
+ clearChat,
+ onSubmit,
+ disabled = false,
+ toolRequests = [],
+ addMessages,
+}: {
+ placeholder: string
+ clearChat: () => void
+ disabled?: boolean
+ onSubmit?: OnSubmit | OnSubmitWithTools
+ addMessages?: (messages: Message[]) => void
+ toolRequests?: ToolRequest[]
+}) {
+ return (
+
0,
+ },
+ )}
+ >
+ {toolRequests.length > 0 && addMessages ? (
+
+ ) : (
+
+ )}
)
}
diff --git a/packages/web-ui/src/ds/molecules/DocumentTextEditor/Editor/RegularEditor.tsx b/packages/web-ui/src/ds/molecules/DocumentTextEditor/Editor/RegularEditor.tsx
index 8a23ae538..4298ef9e7 100644
--- a/packages/web-ui/src/ds/molecules/DocumentTextEditor/Editor/RegularEditor.tsx
+++ b/packages/web-ui/src/ds/molecules/DocumentTextEditor/Editor/RegularEditor.tsx
@@ -34,7 +34,8 @@ export function RegularMonacoEditor({
const { monacoRef, handleEditorWillMount } = useMonacoSetup({ errorFixFn })
const [defaultValue, _] = useState(value)
- const [isEditorMounted, setIsEditorMounted] = useState(false) // to avoid race conditions
+ // to avoid race conditions
+ const [isEditorMounted, setIsEditorMounted] = useState(false)
const { options } = useEditorOptions({
tabSize: 2,
readOnly: !!readOnlyMessage,
diff --git a/packages/web-ui/src/ds/molecules/DocumentTextEditor/Editor/useMonacoSetup.ts b/packages/web-ui/src/ds/molecules/DocumentTextEditor/Editor/useMonacoSetup.ts
index 063b7762d..417fcc74b 100644
--- a/packages/web-ui/src/ds/molecules/DocumentTextEditor/Editor/useMonacoSetup.ts
+++ b/packages/web-ui/src/ds/molecules/DocumentTextEditor/Editor/useMonacoSetup.ts
@@ -41,6 +41,7 @@ export function useMonacoSetup({
useEffect(() => {
if (!monacoRef.current) return
+
applyTheme(monacoRef.current)
}, [applyTheme])
diff --git a/packages/web-ui/src/index.ts b/packages/web-ui/src/index.ts
index 258ef642c..a774e8b4c 100644
--- a/packages/web-ui/src/index.ts
+++ b/packages/web-ui/src/index.ts
@@ -10,4 +10,5 @@ export * from './lib/getUserInfo'
export * from './lib/hooks/useAutoScroll'
export * from './lib/hooks/useLocalStorage'
export * from './lib/commonTypes'
+export * from './lib/versionedMessagesHelpers'
export * from './ds/atoms/ChartBlankSlate'
diff --git a/packages/web-ui/src/lib/versionedMessagesHelpers.ts b/packages/web-ui/src/lib/versionedMessagesHelpers.ts
new file mode 100644
index 000000000..6b2aa554d
--- /dev/null
+++ b/packages/web-ui/src/lib/versionedMessagesHelpers.ts
@@ -0,0 +1,85 @@
+import {
+ Message as CompilerMessage,
+ ContentType as CompilerContentType,
+ MessageRole as CompilerMessageRole,
+ ToolRequestContent as CompilerToolRequestContent,
+} from '@latitude-data/compiler'
+import { ToolCallResponse as ToolResponse } from '@latitude-data/constants'
+import {
+ Message as PromptlMessage,
+ ToolCallContent as ToolRequest,
+ ContentType as PromptlContentType,
+ MessageRole as PromptlMessageRole,
+} from 'promptl-ai'
+
+export type PromptlVersion = 0 | 1
+export type VersionedMessage
= V extends 0
+ ? CompilerMessage
+ : PromptlMessage
+type ToolResponsePart = Pick
+
+export type ToolPart = ToolRequest | ToolResponsePart
+
+function extractCompilerToolContents(messages: CompilerMessage[]): ToolPart[] {
+ return messages.flatMap((message) => {
+ if (message.role === CompilerMessageRole.tool) {
+ return message.content
+ .filter((content) => {
+ return content.type === CompilerContentType.toolResult
+ })
+ .map((content) => ({
+ id: content.toolCallId,
+ }))
+ }
+
+ if (message.role !== CompilerMessageRole.assistant) return []
+ if (typeof message.content === 'string') return []
+
+ const content = Array.isArray(message.content)
+ ? message.content
+ : [message.content]
+
+ const toolRequestContents = content.filter((content) => {
+ return content.type === CompilerContentType.toolCall
+ }) as CompilerToolRequestContent[]
+
+ return toolRequestContents.map((content) => ({
+ type: PromptlContentType.toolCall,
+ toolCallId: content.toolCallId,
+ toolName: content.toolName,
+ toolArguments: content.args,
+ }))
+ })
+}
+
+function extractPromptlToolContents(messages: PromptlMessage[]): ToolPart[] {
+ return messages.flatMap((message) => {
+ if (message.role === PromptlMessageRole.tool) {
+ return [{ id: message.toolId }]
+ }
+
+ if (message.role !== PromptlMessageRole.assistant) return []
+ if (typeof message.content === 'string') return []
+
+ const content = Array.isArray(message.content)
+ ? message.content
+ : [message.content]
+ return content.filter((content) => {
+ return content.type === PromptlContentType.toolCall
+ })
+ })
+}
+
+export function extractToolContents({
+ version,
+ messages,
+}: {
+ version: V
+ messages: VersionedMessage[]
+}) {
+ return version === 0
+ ? extractCompilerToolContents(messages as CompilerMessage[])
+ : extractPromptlToolContents(messages as PromptlMessage[])
+}
+
+export type { ToolRequest }
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 6b071821a..01801575e 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -260,8 +260,8 @@ importers:
specifier: ^4.17.21
version: 4.17.21
promptl-ai:
- specifier: ^0.3.5
- version: 0.3.5
+ specifier: ^0.4.5
+ version: 0.4.5
rate-limiter-flexible:
specifier: ^5.0.3
version: 5.0.4
@@ -427,8 +427,8 @@ importers:
specifier: ^1.161.6
version: 1.176.0
promptl-ai:
- specifier: ^0.3.5
- version: 0.3.5
+ specifier: ^0.4.5
+ version: 0.4.5
rate-limiter-flexible:
specifier: ^5.0.3
version: 5.0.4
@@ -773,8 +773,8 @@ importers:
specifier: ^1.0.5
version: 1.0.5
promptl-ai:
- specifier: ^0.3.5
- version: 0.3.5
+ specifier: ^0.4.5
+ version: 0.4.5
devDependencies:
'@ai-sdk/anthropic':
specifier: ^1.0.5
@@ -993,8 +993,8 @@ importers:
specifier: 3.3.2
version: 3.3.2
promptl-ai:
- specifier: ^0.3.5
- version: 0.3.5
+ specifier: ^0.4.5
+ version: 0.4.5
typescript:
specifier: ^5.5.4
version: 5.7.2
@@ -1186,6 +1186,9 @@ importers:
'@latitude-data/compiler':
specifier: workspace:^
version: link:../compiler
+ '@latitude-data/constants':
+ specifier: workspace:^
+ version: link:../constants
'@latitude-data/core':
specifier: workspace:^
version: link:../core
@@ -11276,6 +11279,9 @@ packages:
promptl-ai@0.3.5:
resolution: {integrity: sha512-g3RtXgCOtMky68rkdalGGApO85DBZvL65gJy7SzZ+D+eEpCB2hR+7q2G67y+s66AHDzG2DM+sU+1WTRbDCrfyg==}
+ promptl-ai@0.4.5:
+ resolution: {integrity: sha512-bJkWlLtyxJkxt28+InTtKF8e4OZ67J9QtkOnI9xKBeEv6ILRFHcU09quTbCFi0wCL+6lw6okL2tV1yix21Jf6g==}
+
prop-types@15.8.1:
resolution: {integrity: sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==}
@@ -12575,10 +12581,6 @@ packages:
resolution: {integrity: sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==}
engines: {node: '>=8'}
- type-fest@4.26.1:
- resolution: {integrity: sha512-yOGpmOAL7CkKe/91I5O3gPICmJNLJ1G4zFYVAsRHg7M64biSnPtRj0WNQt++bRkjYOqjWXrhnUw1utzmVErAdg==}
- engines: {node: '>=16'}
-
type-fest@4.30.0:
resolution: {integrity: sha512-G6zXWS1dLj6eagy6sVhOMQiLtJdxQBHIA9Z6HFUNLOlr6MFOgzV8wvmidtPONfPtEUv0uZsy77XJNzTAfwPDaA==}
engines: {node: '>=16'}
@@ -19635,7 +19637,7 @@ snapshots:
'@types/body-parser@1.19.5':
dependencies:
'@types/connect': 3.4.38
- '@types/node': 22.10.1
+ '@types/node': 20.17.10
'@types/bytes@3.1.4': {}
@@ -19654,7 +19656,7 @@ snapshots:
'@types/connect@3.4.38':
dependencies:
- '@types/node': 22.10.1
+ '@types/node': 20.17.10
'@types/cookie-parser@1.4.7':
dependencies:
@@ -19708,7 +19710,7 @@ snapshots:
'@types/express-serve-static-core@4.19.6':
dependencies:
- '@types/node': 22.10.1
+ '@types/node': 20.17.10
'@types/qs': 6.9.17
'@types/range-parser': 1.2.7
'@types/send': 0.17.4
@@ -19908,12 +19910,12 @@ snapshots:
'@types/send@0.17.4':
dependencies:
'@types/mime': 1.3.5
- '@types/node': 22.10.1
+ '@types/node': 20.17.10
'@types/serve-static@1.15.7':
dependencies:
'@types/http-errors': 2.0.4
- '@types/node': 22.10.1
+ '@types/node': 20.17.10
'@types/send': 0.17.4
'@types/shimmer@1.2.0': {}
@@ -25352,7 +25354,7 @@ snapshots:
outvariant: 1.4.3
path-to-regexp: 6.3.0
strict-event-emitter: 0.5.1
- type-fest: 4.26.1
+ type-fest: 4.30.0
yargs: 17.7.2
optionalDependencies:
typescript: 5.7.2
@@ -25377,7 +25379,7 @@ snapshots:
outvariant: 1.4.3
path-to-regexp: 6.3.0
strict-event-emitter: 0.5.1
- type-fest: 4.26.1
+ type-fest: 4.30.0
yargs: 17.7.2
optionalDependencies:
typescript: 5.7.2
@@ -25402,7 +25404,7 @@ snapshots:
outvariant: 1.4.3
path-to-regexp: 6.3.0
strict-event-emitter: 0.5.1
- type-fest: 4.26.1
+ type-fest: 4.30.0
yargs: 17.7.2
optionalDependencies:
typescript: 5.7.2
@@ -26462,6 +26464,14 @@ snapshots:
yaml: 2.6.0
zod: 3.23.8
+ promptl-ai@0.4.5:
+ dependencies:
+ acorn: 8.14.0
+ code-red: 1.0.4
+ locate-character: 3.0.0
+ yaml: 2.6.0
+ zod: 3.23.8
+
prop-types@15.8.1:
dependencies:
loose-envify: 1.4.0
@@ -28342,8 +28352,6 @@ snapshots:
type-fest@0.8.1: {}
- type-fest@4.26.1: {}
-
type-fest@4.30.0: {}
type-is@1.6.18: