LearnNewsExamplesServices
Frontmatter
id8207
titleai.Client: Enhance handleRequest to support sync and async execution
stateClosed
labels
enhancementai
assigneestobiu
createdAtDec 30, 2025, 12:59 AM
updatedAtDec 30, 2025, 1:12 AM
githubUrlhttps://github.com/neomjs/neo/issues/8207
authortobiu
commentsCount1
parentIssue8169
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtDec 30, 2025, 1:12 AM

ai.Client: Enhance handleRequest to support sync and async execution

Closed v11.18.0 enhancementai
tobiu
tobiu commented on Dec 30, 2025, 12:59 AM

Refactor src/ai/Client.mjs => handleRequest() to match the execution pattern in src/worker/mixin/RemoteMethodAccess.mjs.

Currently, handleRequest implicitly assumes async execution. We should explicitly check if the result is a Promise.

Requirements:

  • Update handleRequest to execute the service method.
  • Check if the result is a Promise using Neo.isPromise().
  • If Promise: attach .then() and .catch() handlers.
  • If Sync: return the result directly (or resolve it immediately if the caller expects a promise).
  • Ensure error handling covers both synchronous throws and asynchronous rejections.
tobiu added the enhancement label on Dec 30, 2025, 12:59 AM
tobiu added the ai label on Dec 30, 2025, 12:59 AM
tobiu added parent issue #8169 on Dec 30, 2025, 12:59 AM
tobiu assigned to @tobiu on Dec 30, 2025, 1:00 AM
tobiu
tobiu Dec 30, 2025, 1:11 AM

Input from Gemini:

✦ I have implemented the enhancements to handleRequest with a slight variation from the original proposal to better align with the existing onSocketMessage error handling architecture.

Implementation Details:

  • Context Preservation: Explicitly used .call(service, params) when invoking methods to ensure the service instance context is maintained.
  • Sync/Async Support: Added checks for both Neo.isFunction and Neo.isPromise to handle synchronous and asynchronous returns correctly.
  • Error Handling: Retained the existing try...catch block in onSocketMessage as the central error handling mechanism, rather than moving it inside handleRequest. handleRequest simply returns the result or promise, allowing onSocketMessage to await it and catch any rejections/errors to send the appropriate JSON-RPC error response.
tobiu closed this issue on Dec 30, 2025, 1:12 AM