diff --git a/apps/mcp/src/shared/types.ts b/apps/mcp/src/shared/types.ts index c46eb2d8..34affbf2 100644 --- a/apps/mcp/src/shared/types.ts +++ b/apps/mcp/src/shared/types.ts @@ -124,5 +124,5 @@ export type Props = { containerTag?: string } -// MCP resource URI for the widget bundle. -export const SUPERMEMORY_RESOURCE_URI = "ui://supermemory/app.html" +// Hosts cache MCP UI resources by URI, so bump this when shipping a new widget bundle. +export const SUPERMEMORY_RESOURCE_URI = "ui://supermemory/app-v2.html" diff --git a/apps/mcp/src/widget/hooks/useApp.ts b/apps/mcp/src/widget/hooks/useApp.ts index 816b0987..e011dd91 100644 --- a/apps/mcp/src/widget/hooks/useApp.ts +++ b/apps/mcp/src/widget/hooks/useApp.ts @@ -47,16 +47,12 @@ export function useApp() { } }, - /** Inject a user message into the conversation. Triggers a new agent turn. */ - async sendMessage(content: string): Promise { + /** Make widget state available to the model on a future turn. */ + async updateModelContext(content: string): Promise { try { - const result = await app.sendMessage({ - role: "user", + await app.updateModelContext({ content: [{ type: "text", text: content }], }) - if (result.isError) { - return { ok: false, error: "Host rejected the message" } - } return { ok: true } } catch (err) { return { ok: false, error: String(err) } diff --git a/apps/mcp/src/widget/views/Picker.tsx b/apps/mcp/src/widget/views/Picker.tsx index f86b2941..a6a137d0 100644 --- a/apps/mcp/src/widget/views/Picker.tsx +++ b/apps/mcp/src/widget/views/Picker.tsx @@ -28,7 +28,7 @@ export function Picker({ onAdvance, onError, }: Props) { - const { callTool, sendMessage } = useApp() + const { callTool, updateModelContext } = useApp() const log = useLog() const [pending, setPending] = useState(null) const [query, setQuery] = useState("") @@ -56,13 +56,13 @@ export function Picker({ return } onAdvance(result.data) - const notification = await sendMessage( - `I selected "${containerTag}" as my active Supermemory workspace. Use this workspace for future Supermemory actions until I select another one.`, + const contextUpdate = await updateModelContext( + `Supermemory workspace selection changed. Active workspace: "${containerTag}". Use it for future Supermemory actions until another workspace is selected.`, ) - if (!notification.ok) { + if (!contextUpdate.ok) { log( "warning", - `[picker] agent notification failed: ${notification.error}`, + `[picker] model context update failed: ${contextUpdate.error}`, ) } } diff --git a/apps/mcp/src/widget/views/Save.tsx b/apps/mcp/src/widget/views/Save.tsx index 50e15813..83dd7211 100644 --- a/apps/mcp/src/widget/views/Save.tsx +++ b/apps/mcp/src/widget/views/Save.tsx @@ -27,7 +27,7 @@ export function Save({ onAdvance, onError, }: Props) { - const { callTool, sendMessage } = useApp() + const { callTool, updateModelContext } = useApp() const log = useLog() const [content, setContent] = useState(prefill ?? "") const [selectedTag, setSelectedTag] = useState( @@ -66,11 +66,14 @@ export function Save({ const memoryId = result.data.view === "save-success" ? result.data.id : undefined onAdvance(result.data) - const notification = await sendMessage( - `I used the Supermemory widget to save a memory to workspace "${selectedTag}"${memoryId ? ` (memory ID: ${memoryId})` : ""}. The memory is already saved; do not save it again.`, + const contextUpdate = await updateModelContext( + `Supermemory widget action completed. A memory was saved to workspace "${selectedTag}"${memoryId ? ` with memory ID "${memoryId}"` : ""}. It is already saved; do not save it again.`, ) - if (!notification.ok) { - log("warning", `[save] agent notification failed: ${notification.error}`) + if (!contextUpdate.ok) { + log( + "warning", + `[save] model context update failed: ${contextUpdate.error}`, + ) } } diff --git a/apps/mcp/src/widget/views/Upload.tsx b/apps/mcp/src/widget/views/Upload.tsx index d05921fb..f20add32 100644 --- a/apps/mcp/src/widget/views/Upload.tsx +++ b/apps/mcp/src/widget/views/Upload.tsx @@ -30,7 +30,7 @@ function formatFileSize(bytes: number): string { const ACCEPT = ".txt,.pdf,.png,.jpg,.jpeg,.mp4" export function Upload({ activeTag, writableTags, onAdvance, onError }: Props) { - const { callTool, sendMessage } = useApp() + const { callTool, updateModelContext } = useApp() const log = useLog() const [file, setFile] = useState(null) const [selectedTag, setSelectedTag] = useState( @@ -65,13 +65,13 @@ export function Upload({ activeTag, writableTags, onAdvance, onError }: Props) { const documentId = result.data.view === "upload-success" ? result.data.id : undefined onAdvance(result.data) - const notification = await sendMessage( - `I used the Supermemory widget to upload "${file.name}" to workspace "${selectedTag}"${documentId ? ` (document ID: ${documentId})` : ""}. The file is already uploaded; do not upload it again.`, + const contextUpdate = await updateModelContext( + `Supermemory widget action completed. "${file.name}" was uploaded to workspace "${selectedTag}"${documentId ? ` with document ID "${documentId}"` : ""}. It is already uploaded; do not upload it again.`, ) - if (!notification.ok) { + if (!contextUpdate.ok) { log( "warning", - `[upload] agent notification failed: ${notification.error}`, + `[upload] model context update failed: ${contextUpdate.error}`, ) } } catch (err) {