Skip to content

Commit cc78bd1

Browse files
authored
fix: chat context picker not getting the full svelte context (#9158)
1 parent 8bcf63f commit cc78bd1

3 files changed

Lines changed: 10 additions & 23 deletions

File tree

web-common/src/features/chat/core/context/editor-plugins.svelte.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,21 @@ import Document from "@tiptap/extension-document";
88
import Paragraph from "@tiptap/extension-paragraph";
99
import Text from "@tiptap/extension-text";
1010
import { Placeholder, UndoRedo } from "@tiptap/extensions";
11-
import { mount, unmount } from "svelte";
11+
import { mount, unmount, getAllContexts } from "svelte";
1212
import {
1313
convertContextToInlinePrompt,
1414
INLINE_CHAT_CONTEXT_TAG,
1515
type InlineContext,
1616
normalizeInlineContext,
1717
parseInlineAttr,
1818
} from "@rilldata/web-common/features/chat/core/context/inline-context.ts";
19-
import {
20-
RUNTIME_CONTEXT_KEY,
21-
RuntimeClient,
22-
} from "@rilldata/web-common/runtime-client/v2";
2319

2420
export function getEditorPlugins({
2521
placeholder,
2622
onSubmit,
27-
runtimeClient,
2823
}: {
2924
placeholder: string;
3025
onSubmit: () => void;
31-
runtimeClient: RuntimeClient;
3226
}) {
3327
const sharedEditorStore = new SharedEditorStore();
3428

@@ -40,7 +34,7 @@ export function getEditorPlugins({
4034
placeholder,
4135
}),
4236
EditorSubmitExtension.configure({ onSubmit, sharedEditorStore }),
43-
configureInlineContextTipTapExtension(sharedEditorStore, runtimeClient),
37+
configureInlineContextTipTapExtension(sharedEditorStore),
4438
UndoRedo,
4539
];
4640

@@ -103,7 +97,7 @@ const EditorSubmitExtension = Extension.create(() => {
10397

10498
type InlineContextOptions = MentionOptions<never, InlineContext> & {
10599
sharedEditorStore: SharedEditorStore;
106-
runtimeClient: RuntimeClient;
100+
allParentContexts: Map<any, any>;
107101
};
108102

109103
// Add the startMention command to the Commands type.
@@ -127,7 +121,7 @@ const InlineContextExtension = Mention.extend<InlineContextOptions>({
127121
// These have to be configured for the extension to work
128122
manager: {} as ConversationManager,
129123
sharedEditorStore: {} as SharedEditorStore,
130-
runtimeClient: {} as RuntimeClient,
124+
allParentContexts: new Map(),
131125
};
132126
},
133127

@@ -188,7 +182,7 @@ const InlineContextExtension = Mention.extend<InlineContextOptions>({
188182
// We need this here to make sure the component is rendered inline.
189183
target.className = "inline-block";
190184

191-
const { sharedEditorStore, runtimeClient } = this.options;
185+
const { sharedEditorStore, allParentContexts } = this.options;
192186

193187
// Create the inline chat context component. Pass the wrapper as the target.
194188
const comp = mount(InlineContextComponent, {
@@ -216,7 +210,7 @@ const InlineContextExtension = Mention.extend<InlineContextOptions>({
216210
}
217211
: { mode: "readonly" },
218212
},
219-
context: new Map([[RUNTIME_CONTEXT_KEY, runtimeClient]]),
213+
context: allParentContexts,
220214
}) as InlineContextExports;
221215
sharedEditorStore.componentAdded(comp);
222216

@@ -237,15 +231,16 @@ const InlineContextExtension = Mention.extend<InlineContextOptions>({
237231
*/
238232
export function configureInlineContextTipTapExtension(
239233
sharedEditorStore: SharedEditorStore,
240-
runtimeClient: RuntimeClient,
241234
) {
242235
let comp: Record<string, unknown> | null = null;
243236
const pickerProps: Record<string, unknown> = $state({});
244237
let selected = false;
245238

239+
const allParentContexts = getAllContexts();
240+
246241
return InlineContextExtension.configure({
247242
sharedEditorStore,
248-
runtimeClient,
243+
allParentContexts,
249244
suggestion: {
250245
char: "@",
251246
allowSpaces: true,
@@ -264,7 +259,7 @@ export function configureInlineContextTipTapExtension(
264259
comp = mount(InlineContextPicker, {
265260
target: document.body,
266261
props: pickerProps,
267-
context: new Map([[RUNTIME_CONTEXT_KEY, runtimeClient]]),
262+
context: allParentContexts,
268263
});
269264
sharedEditorStore.contextOpen = true;
270265
},

web-common/src/features/chat/core/input/ChatInput.svelte

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import type { ChatConfig } from "@rilldata/web-common/features/chat/core/types.ts";
1111
import Button from "@rilldata/web-common/components/button/Button.svelte";
1212
import { ArrowUp } from "lucide-svelte";
13-
import { useRuntimeClient } from "@rilldata/web-common/runtime-client/v2";
1413
1514
export let conversationManager: ConversationManager;
1615
export let onSend: (() => void) | undefined = undefined;
@@ -21,8 +20,6 @@
2120
2221
let value = "";
2322
24-
const runtimeClient = useRuntimeClient();
25-
2623
$: ({ placeholder, additionalContextStoreGetter } = config);
2724
$: additionalContextStore = additionalContextStoreGetter();
2825
// Since additionalContextStore is only used within sendMessage it will not be fetched unless used.
@@ -90,7 +87,6 @@
9087
extensions: getEditorPlugins({
9188
placeholder,
9289
onSubmit: () => void sendMessage(),
93-
runtimeClient,
9490
}),
9591
content: "",
9692
editorProps: {

web-common/src/features/chat/core/messages/text/UserMessage.svelte

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55
import { onMount } from "svelte";
66
import type { V1Message } from "../../../../../runtime-client";
77
import { extractMessageText } from "../../utils";
8-
import { useRuntimeClient } from "@rilldata/web-common/runtime-client/v2";
98
109
export let message: V1Message;
1110
12-
const runtimeClient = useRuntimeClient();
13-
1411
let element: HTMLDivElement;
1512
let editor: Editor;
1613
@@ -26,7 +23,6 @@
2623
extensions: getEditorPlugins({
2724
placeholder: "",
2825
onSubmit: () => {},
29-
runtimeClient,
3026
}),
3127
content,
3228
});

0 commit comments

Comments
 (0)