diff --git a/apps/mcp/src/widget/hooks/useApp.ts b/apps/mcp/src/widget/hooks/useApp.ts index 2c5ff25a..816b0987 100644 --- a/apps/mcp/src/widget/hooks/useApp.ts +++ b/apps/mcp/src/widget/hooks/useApp.ts @@ -48,19 +48,19 @@ export function useApp() { }, /** Inject a user message into the conversation. Triggers a new agent turn. */ - sendMessage(content: string) { - return app.sendMessage({ - role: "user", - content: [{ type: "text", text: content }], - }) - }, - - /** Update ambient model context. Model sees on next user message. */ - updateContext(text: string, structuredContent?: Record) { - return app.updateModelContext({ - content: [{ type: "text", text }], - structuredContent, - }) + async sendMessage(content: string): Promise { + try { + const result = await app.sendMessage({ + role: "user", + 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) } + } }, /** Send a structured log line to the host. */ diff --git a/apps/mcp/src/widget/views/Picker.tsx b/apps/mcp/src/widget/views/Picker.tsx index 48eae948..16cfb964 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, updateContext } = useApp() + const { callTool, sendMessage } = useApp() const log = useLog() const [pending, setPending] = useState(null) const [query, setQuery] = useState("") @@ -55,20 +55,13 @@ export function Picker({ onError(result.error ?? "Failed to set active workspace") return } - try { - await updateContext( - `The user selected the Supermemory workspace "${containerTag}". Use this as the active workspace for future Supermemory actions unless the user selects another workspace.`, - { - supermemory: { - activeWorkspace: containerTag, - lastAction: "workspace-selected", - }, - }, - ) - } catch (error) { - log("warning", `[picker] model context update failed: ${error}`) - } 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.`, + ) + if (!notification.ok) { + log("warning", `[picker] agent notification failed: ${notification.error}`) + } } const count = containerTags.length diff --git a/apps/mcp/src/widget/views/Save.tsx b/apps/mcp/src/widget/views/Save.tsx index 2ba5c7e6..50e15813 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, updateContext } = useApp() + const { callTool, sendMessage } = useApp() const log = useLog() const [content, setContent] = useState(prefill ?? "") const [selectedTag, setSelectedTag] = useState( @@ -63,20 +63,15 @@ export function Save({ onError(result.error ?? "Failed to save memory") return } - try { - await updateContext( - `The user saved a memory to the Supermemory workspace "${selectedTag}" from the interactive widget.`, - { - supermemory: { - activeWorkspace: selectedTag, - lastAction: "memory-saved", - }, - }, - ) - } catch (error) { - log("warning", `[save] model context update failed: ${error}`) - } + 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.`, + ) + if (!notification.ok) { + log("warning", `[save] agent notification failed: ${notification.error}`) + } } return ( diff --git a/apps/mcp/src/widget/views/Upload.tsx b/apps/mcp/src/widget/views/Upload.tsx index 6b0af03c..d05921fb 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, updateContext } = useApp() + const { callTool, sendMessage } = useApp() const log = useLog() const [file, setFile] = useState(null) const [selectedTag, setSelectedTag] = useState( @@ -62,21 +62,18 @@ export function Upload({ activeTag, writableTags, onAdvance, onError }: Props) { onError(result.error ?? "Upload failed") return } - try { - await updateContext( - `The user uploaded "${file.name}" to the Supermemory workspace "${selectedTag}" from the interactive widget.`, - { - supermemory: { - activeWorkspace: selectedTag, - lastAction: "file-uploaded", - fileName: file.name, - }, - }, - ) - } catch (error) { - log("warning", `[upload] model context update failed: ${error}`) - } + 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.`, + ) + if (!notification.ok) { + log( + "warning", + `[upload] agent notification failed: ${notification.error}`, + ) + } } catch (err) { log("error", `[upload] threw: ${err}`) onError(String(err))