diff --git a/frontend/src/lib/components/copilot/chat/AIChatInput.svelte b/frontend/src/lib/components/copilot/chat/AIChatInput.svelte index 833649e9b6..f0fc826243 100644 --- a/frontend/src/lib/components/copilot/chat/AIChatInput.svelte +++ b/frontend/src/lib/components/copilot/chat/AIChatInput.svelte @@ -90,7 +90,11 @@ let appTooltipCurrentViewNumber = $state(0) export function focusInput() { - if (aiChatManager.mode === AIMode.SCRIPT || aiChatManager.mode === AIMode.FLOW) { + if ( + aiChatManager.mode === AIMode.SCRIPT || + aiChatManager.mode === AIMode.FLOW || + aiChatManager.mode === AIMode.GLOBAL + ) { contextTextareaComponent?.focus() } else { instructionsTextareaComponent?.focus() @@ -390,7 +394,7 @@
- {#if aiChatManager.mode === AIMode.SCRIPT || aiChatManager.mode === AIMode.FLOW} + {#if aiChatManager.mode === AIMode.SCRIPT || aiChatManager.mode === AIMode.FLOW || aiChatManager.mode === AIMode.GLOBAL} {#if showContext}
diff --git a/frontend/src/lib/components/copilot/chat/AIChatManager.svelte.ts b/frontend/src/lib/components/copilot/chat/AIChatManager.svelte.ts index 0ec6d725e8..ddef347a7f 100644 --- a/frontend/src/lib/components/copilot/chat/AIChatManager.svelte.ts +++ b/frontend/src/lib/components/copilot/chat/AIChatManager.svelte.ts @@ -573,7 +573,7 @@ class AIChatManager { } else if (this.mode === AIMode.NAVIGATOR) { return prepareNavigatorUserMessage(pendingPrompt) } else if (this.mode === AIMode.GLOBAL) { - return prepareGlobalUserMessage(pendingPrompt) + return prepareGlobalUserMessage(pendingPrompt, this.contextManager.getSelectedContext()) } return undefined }, @@ -750,7 +750,7 @@ class AIChatManager { role: 'user', content: this.instructions, contextElements: - this.mode === AIMode.SCRIPT || this.mode === AIMode.FLOW + this.mode === AIMode.SCRIPT || this.mode === AIMode.FLOW || this.mode === AIMode.GLOBAL ? oldSelectedContext : undefined, snapshot, @@ -790,7 +790,7 @@ class AIChatManager { userMessage = prepareApiUserMessage(oldInstructions) break case AIMode.GLOBAL: - userMessage = prepareGlobalUserMessage(oldInstructions) + userMessage = prepareGlobalUserMessage(oldInstructions, oldSelectedContext) break case AIMode.APP: userMessage = prepareAppUserMessage( @@ -1035,6 +1035,11 @@ class AIChatManager { !copilotSessionModel?.model.endsWith('/thinking'), untrack(() => this.contextManager.getSelectedContext()) ) + } else if (this.mode === AIMode.GLOBAL) { + this.contextManager.updateAvailableContextForGlobal( + workspaceStore ?? '', + untrack(() => this.contextManager.getSelectedContext()) + ) } if (this.scriptEditorOptions) { diff --git a/frontend/src/lib/components/copilot/chat/AvailableContextList.svelte b/frontend/src/lib/components/copilot/chat/AvailableContextList.svelte index b66ab9f14f..fb914ecd0b 100644 --- a/frontend/src/lib/components/copilot/chat/AvailableContextList.svelte +++ b/frontend/src/lib/components/copilot/chat/AvailableContextList.svelte @@ -3,7 +3,7 @@ import BarsStaggered from '$lib/components/icons/BarsStaggered.svelte' import type { FlowModule } from '$lib/gen/types.gen' import { workspaceStore } from '$lib/stores' - import { workspaceRunnablesSearch, MAX_RUNNABLE_CONTENT_LENGTH } from './shared' + import { workspaceRunnablesSearch } from './shared' import { ContextIconMap, type ContextElement, @@ -167,54 +167,31 @@ }, 300) } - async function handleWorkspaceItemSelect(path: string) { - const workspace = $workspaceStore - if (!workspace || !onSelectWorkspaceItem) return + function handleWorkspaceItemSelect(item: { path: string; summary?: string }) { + if (!onSelectWorkspaceItem) return - try { - if (currentView === 'scripts') { - const script = await workspaceRunnablesSearch.getScript(path, workspace) - const content = script.content ?? '' - const truncatedContent = - content.length > MAX_RUNNABLE_CONTENT_LENGTH - ? content.slice(0, MAX_RUNNABLE_CONTENT_LENGTH) + '\n... (truncated)' - : content - const element: WorkspaceScriptElement & { deletable: boolean } = { - type: 'workspace_script', - path: script.path, - title: script.path, - summary: script.summary, - language: script.language, - content: truncatedContent, - schema: script.schema, - deletable: true - } - onSelectWorkspaceItem(element) - } else if (currentView === 'flows') { - const flow = await workspaceRunnablesSearch.getFlow(path, workspace) - const flowValue = JSON.stringify(flow.value, null, 2) - const truncatedValue = - flowValue.length > MAX_RUNNABLE_CONTENT_LENGTH - ? flowValue.slice(0, MAX_RUNNABLE_CONTENT_LENGTH) + '\n... (truncated)' - : flowValue - const element: WorkspaceFlowElement & { deletable: boolean } = { - type: 'workspace_flow', - path: flow.path, - title: flow.path, - summary: flow.summary, - description: flow.description || '', - value: truncatedValue, - schema: flow.schema, - deletable: true - } - onSelectWorkspaceItem(element) + if (currentView === 'scripts') { + const element: WorkspaceScriptElement & { deletable: boolean } = { + type: 'workspace_script', + path: item.path, + title: item.path, + summary: item.summary, + deletable: true } - currentView = 'categories' - workspaceSearchQuery = '' - workspaceSearchResults = [] - } catch (err) { - console.error('Error fetching workspace item', err) + onSelectWorkspaceItem(element) + } else if (currentView === 'flows') { + const element: WorkspaceFlowElement & { deletable: boolean } = { + type: 'workspace_flow', + path: item.path, + title: item.path, + summary: item.summary, + deletable: true + } + onSelectWorkspaceItem(element) } + currentView = 'categories' + workspaceSearchQuery = '' + workspaceSearchResults = [] } function handleKeyDown(e: KeyboardEvent) { @@ -241,7 +218,7 @@ e.stopPropagation() const selectedItem = workspaceSearchResults[itemSelectedIndex] if (selectedItem) { - handleWorkspaceItemSelect(selectedItem.path) + handleWorkspaceItemSelect(selectedItem) } } } else if (e.key === 'Escape') { @@ -358,7 +335,7 @@ > {#if stringSearch.length > 0} - {#each filteredAvailableContext as element, i} + {#each filteredAvailableContext as element, i (element.type + '-' + element.title)} {@const Icon = ContextIconMap[element.type]}