From 8eaabf374c1268ed93fe2035c1a626d53fdd1a04 Mon Sep 17 00:00:00 2001 From: Simon Farshid Date: Mon, 14 Oct 2024 17:36:28 -0700 Subject: [PATCH] fix: runtime errors (#1016) --- packages/react/src/api/MessageRuntime.ts | 36 +++++++++++++----------- packages/react/src/api/ThreadRuntime.ts | 26 +++++++++-------- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/packages/react/src/api/MessageRuntime.ts b/packages/react/src/api/MessageRuntime.ts index 8f0b5d9ab..8edf93a2f 100644 --- a/packages/react/src/api/MessageRuntime.ts +++ b/packages/react/src/api/MessageRuntime.ts @@ -162,23 +162,25 @@ export class MessageRuntimeImpl implements MessageRuntime { constructor( private _core: MessageStateBinding, private _threadBinding: ThreadRuntimeCoreBinding, - ) {} - - public composer = new EditComposerRuntimeImpl( - new NestedSubscriptionSubject({ - path: { - ...this.path, - ref: this.path.ref + `${this.path.ref}.composer`, - composerSource: "edit", - }, - getState: () => - this._threadBinding - .getState() - .getEditComposer(this._core.getState().id), - subscribe: (callback) => this._threadBinding.subscribe(callback), - }), - () => this._threadBinding.getState().beginEdit(this._core.getState().id), - ); + ) { + this.composer = new EditComposerRuntimeImpl( + new NestedSubscriptionSubject({ + path: { + ...this.path, + ref: this.path.ref + `${this.path.ref}.composer`, + composerSource: "edit", + }, + getState: () => + this._threadBinding + .getState() + .getEditComposer(this._core.getState().id), + subscribe: (callback) => this._threadBinding.subscribe(callback), + }), + () => this._threadBinding.getState().beginEdit(this._core.getState().id), + ); + } + + public composer; public getState() { return this._core.getState(); diff --git a/packages/react/src/api/ThreadRuntime.ts b/packages/react/src/api/ThreadRuntime.ts index 3eccc3e84..a458a6bea 100644 --- a/packages/react/src/api/ThreadRuntime.ts +++ b/packages/react/src/api/ThreadRuntime.ts @@ -306,19 +306,21 @@ export class ThreadRuntimeImpl outerSubscribe: (callback) => threadBinding.outerSubscribe(callback), subscribe: (callback) => threadBinding.subscribe(callback), }; + + this.composer = new ThreadComposerRuntimeImpl( + new NestedSubscriptionSubject({ + path: { + ...this.path, + ref: this.path.ref + `${this.path.ref}.composer`, + composerSource: "thread", + }, + getState: () => this._threadBinding.getState().composer, + subscribe: (callback) => this._threadBinding.subscribe(callback), + }), + ); } - public readonly composer = new ThreadComposerRuntimeImpl( - new NestedSubscriptionSubject({ - path: { - ...this.path, - ref: this.path.ref + `${this.path.ref}.composer`, - composerSource: "thread", - }, - getState: () => this._threadBinding.getState().composer, - subscribe: (callback) => this._threadBinding.subscribe(callback), - }), - ); + public readonly composer; public getState() { return this._threadBinding.getStateState(); @@ -463,7 +465,7 @@ export class ThreadRuntimeImpl const { messages, speech: speechState } = this._threadBinding.getState(); - if (!message || !parentId) return SKIP_UPDATE; + if (!message || parentId === undefined) return SKIP_UPDATE; const thread = this._threadBinding.getState();