import { RemoteActorContext } from "#behavior/context/server/RemoteActorContext.js";
import { NotImplementedError } from "#general";
import {
  ServerInteraction
} from "#protocol";
class OnlineServerInteraction {
  #interaction;
  constructor(node) {
    this.#interaction = new ServerInteraction(node);
  }
  async *read(request, context) {
    const session = RemoteActorContext(context).beginReadOnly();
    try {
      for await (const report of this.#interaction.read(request, session)) {
        yield report;
      }
    } finally {
      session[Symbol.dispose]();
    }
  }
  subscribe(_request, _context) {
    throw new NotImplementedError("subscribe not implemented");
  }
  /**
   * Process write requests and return results.
   * The caller is responsible for messaging/chunking and list state tracking.
   */
  async write(request, context) {
    return RemoteActorContext(context).act((session) => this.#interaction.write(request, session));
  }
  /**
   * Process invoke requests and yield results.
   * The caller is responsible for messaging/chunking.
   */
  async *invoke(request, context) {
    const session = RemoteActorContext({ ...context, command: true }).open();
    try {
      for await (const chunk of this.#interaction.invoke(request, session)) {
        yield chunk;
      }
    } catch (error) {
      await session.reject(error);
    }
    await session.resolve(void 0);
  }
}
export {
  OnlineServerInteraction
};
//# sourceMappingURL=OnlineServerInteraction.js.map
