@@ -4,18 +4,9 @@ import { Subject, type Observable } from 'rxjs';
44import type { BaseMessage } from '@langchain/core/messages' ;
55import type { ToolCallWithResult , Interrupt } from '@langchain/langgraph-sdk' ;
66import type {
7- AgentWithHistory ,
8- AgentCheckpoint ,
9- AgentCustomEvent ,
10- Message ,
11- Role ,
12- AgentStatus ,
13- ToolCall ,
14- ToolCallStatus ,
15- AgentInterrupt ,
16- Subagent ,
17- AgentSubmitInput ,
18- AgentSubmitOptions ,
7+ AgentWithHistory , AgentCheckpoint , AgentEvent ,
8+ Message , Role , ToolCall , ToolCallStatus , AgentStatus ,
9+ AgentInterrupt , Subagent , AgentSubmitInput , AgentSubmitOptions ,
1910} from '@cacheplane/chat' ;
2011import type { AgentRef , CustomStreamEvent , SubagentStreamRef , ThreadState } from './agent.types' ;
2112import { ResourceStatus } from './agent.types' ;
@@ -56,7 +47,7 @@ export function toAgent<T>(ref: AgentRef<T, any>): AgentWithHistory {
5647 return out ;
5748 } ) ;
5849
59- const customEvents $ = buildCustomEvents $( ref ) ;
50+ const events $ = buildEvents $( ref ) ;
6051
6152 const history = computed < AgentCheckpoint [ ] > ( ( ) =>
6253 ref . history ( ) . map ( toCheckpoint ) ,
@@ -71,7 +62,7 @@ export function toAgent<T>(ref: AgentRef<T, any>): AgentWithHistory {
7162 state,
7263 interrupt,
7364 subagents,
74- customEvents $,
65+ events $,
7566 history,
7667 submit : ( input : AgentSubmitInput , opts ?: AgentSubmitOptions ) =>
7768 ref . submit ( buildSubmitPayload ( input ) , opts ? { signal : opts . signal } as never : undefined ) ,
@@ -80,15 +71,15 @@ export function toAgent<T>(ref: AgentRef<T, any>): AgentWithHistory {
8071}
8172
8273/**
83- * Build an Observable<AgentCustomEvent > that bridges LangGraph's
74+ * Build an Observable<AgentEvent > that bridges LangGraph's
8475 * `Signal<CustomStreamEvent[]>` (append-only array) into a stream of newly
8576 * emitted events. Each effect firing compares against a cursor tracking the
8677 * previously-seen length and emits only the tail slice.
8778 */
88- function buildCustomEvents $(
79+ function buildEvents $(
8980 ref : AgentRef < unknown , any > ,
90- ) : Observable < AgentCustomEvent > {
91- const subject = new Subject < AgentCustomEvent > ( ) ;
81+ ) : Observable < AgentEvent > {
82+ const subject = new Subject < AgentEvent > ( ) ;
9283 let seen = 0 ;
9384 effect ( ( ) => {
9485 const all = ref . customEvents ( ) ;
@@ -97,15 +88,18 @@ function buildCustomEvents$(
9788 seen = 0 ;
9889 }
9990 for ( let i = seen ; i < all . length ; i ++ ) {
100- subject . next ( toCustomEvent ( all [ i ] ) ) ;
91+ subject . next ( toAgentEvent ( all [ i ] ) ) ;
10192 }
10293 seen = all . length ;
10394 } ) ;
10495 return subject . asObservable ( ) ;
10596}
10697
107- function toCustomEvent ( e : CustomStreamEvent ) : AgentCustomEvent {
108- return { type : e . name , data : e . data } ;
98+ function toAgentEvent ( e : CustomStreamEvent ) : AgentEvent {
99+ if ( e . name === 'state_update' && isRecord ( e . data ) ) {
100+ return { type : 'state_update' , data : e . data } ;
101+ }
102+ return { type : 'custom' , name : e . name , data : e . data } ;
109103}
110104
111105function mapStatus ( s : ResourceStatus ) : AgentStatus {
0 commit comments