@@ -34,6 +34,23 @@ type DirectConversationDraft = {
3434 agentAId : string ;
3535 agentBId : string ;
3636} ;
37+
38+ const emptyState : AgentCommsState = {
39+ humans : [ ] ,
40+ agents : [ ] ,
41+ forums : [ ] ,
42+ subscriptions : [ ] ,
43+ threads : [ ] ,
44+ replies : [ ] ,
45+ directConversations : [ ] ,
46+ directMessages : [ ] ,
47+ suggestions : [ ] ,
48+ gates : [ ] ,
49+ todos : [ ] ,
50+ } ;
51+
52+ const useDemoData = import . meta. env . DEV && new URLSearchParams ( window . location . search ) . get ( "demo" ) === "1" ;
53+
3754type LiveConversationSession = {
3855 id : string ;
3956 conversationId : string ;
@@ -1341,7 +1358,7 @@ function AgentProfilePage({
13411358
13421359export function App ( ) {
13431360 const [ view , setView ] = useState < View > ( "overview" ) ;
1344- const [ state , setState ] = useState < AgentCommsState > ( demoState ) ;
1361+ const [ state , setState ] = useState < AgentCommsState > ( ( ) => ( useDemoData ? demoState : emptyState ) ) ;
13451362 const [ branding , setBranding ] = useState ( defaultBranding ) ;
13461363 const [ selectedForumId , setSelectedForumId ] = useState < string | null > ( null ) ;
13471364 const [ isCreateForumOpen , setCreateForumOpen ] = useState ( false ) ;
@@ -1369,7 +1386,7 @@ export function App() {
13691386 const [ mintedTokens , setMintedTokens ] = useState < Record < string , { token : string ; copied ?: boolean ; fileCopied ?: boolean } | undefined > > ( { } ) ;
13701387 const [ liveSessions , setLiveSessions ] = useState < LiveConversationSession [ ] > ( [ ] ) ;
13711388 const [ operatorToken ] = useState ( ( ) => localStorage . getItem ( "agent-comms-operator-token" ) ?? "" ) ;
1372- const [ apiStatus , setApiStatus ] = useState ( "demo data" ) ;
1389+ const [ apiStatus , setApiStatus ] = useState ( useDemoData ? "demo data" : "loading durable storage ") ;
13731390 const [ actionStatus , setActionStatus ] = useState ( "" ) ;
13741391 const refreshSequenceRef = useRef ( 0 ) ;
13751392 const mutationEpochRef = useRef ( 0 ) ;
@@ -1401,7 +1418,13 @@ export function App() {
14011418 const payload = contentType . includes ( "application/json" )
14021419 ? await response . json ( )
14031420 : { error : await response . text ( ) } ;
1421+ if ( ! contentType . includes ( "application/json" ) ) {
1422+ throw new Error ( readableRequestError ( payload . error ?? "Operator API returned a non-JSON response." ) ) ;
1423+ }
14041424 if ( ! response . ok ) throw new Error ( readableRequestError ( payload . error ?? "Operator request failed." ) ) ;
1425+ if ( payload && typeof payload === "object" && "error" in payload && Object . keys ( payload ) . length === 1 ) {
1426+ throw new Error ( readableRequestError ( ( payload as { error ?: unknown } ) . error ) ) ;
1427+ }
14051428 return payload ;
14061429 } ,
14071430 [ operatorToken ] ,
0 commit comments