fix(main.tsx): resolve TypeScript errors — UIMessage type, role→type, ComponentMap cast
This commit is contained in:
+12
-9
@@ -1,7 +1,10 @@
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { useStream } from "@langchain/langgraph-sdk/react";
|
||||
import { LoadExternalComponent } from "@langchain/langgraph-sdk/react-ui";
|
||||
import type { Message, UIMessage } from "@langchain/langgraph-sdk";
|
||||
import type { Message } from "@langchain/langgraph-sdk";
|
||||
|
||||
// UIMessage is not exported directly — use a local shape
|
||||
type UIMessage = { id: string; name: string; props: Record<string, unknown>; metadata?: { message_id?: string } };
|
||||
import { useState, useRef, useEffect } from "react";
|
||||
import ComponentMap from "./agent-uis/index.tsx";
|
||||
import "./index.css";
|
||||
@@ -29,7 +32,7 @@ function App() {
|
||||
const text = input.trim();
|
||||
if (!text || thread.isLoading) return;
|
||||
setInput("");
|
||||
thread.submit({ messages: [{ role: "human", content: text }] });
|
||||
thread.submit({ messages: [{ type: "human", content: text }] });
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -99,7 +102,8 @@ function App() {
|
||||
key={ui.id}
|
||||
stream={thread}
|
||||
message={ui}
|
||||
components={ComponentMap}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
components={ComponentMap as any}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
@@ -113,11 +117,8 @@ function App() {
|
||||
{thread.isLoading &&
|
||||
(thread.values?.ui ?? [])
|
||||
.filter((ui: UIMessage) => {
|
||||
const meta = (
|
||||
ui as UIMessage & { metadata?: { message_id?: string } }
|
||||
).metadata;
|
||||
const attachedToExisting = thread.messages.some(
|
||||
(m) => m.id === meta?.message_id,
|
||||
(m) => m.id === ui.metadata?.message_id,
|
||||
);
|
||||
return !attachedToExisting;
|
||||
})
|
||||
@@ -125,8 +126,10 @@ function App() {
|
||||
<LoadExternalComponent
|
||||
key={ui.id}
|
||||
stream={thread}
|
||||
message={ui}
|
||||
components={ComponentMap}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
message={ui as any}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
components={ComponentMap as any}
|
||||
/>
|
||||
))}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user