hypha-rpc 0.1.0-post5 → 0.1.0-post6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypha-rpc",
3
- "version": "0.1.0-post5",
3
+ "version": "0.1.0-post6",
4
4
  "description": "Hypha RPC client for connecting to Hypha server for data management and AI model serving.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
package/src/rpc.js CHANGED
@@ -409,7 +409,7 @@ export class RPC extends MessageEmitter {
409
409
  }
410
410
 
411
411
  throw new Error(
412
- `Permission denied for protected service: ${service_id}, workspace mismatch: ${ws} != ${context["ws"]}`,
412
+ `Permission denied for getting protected service: ${service_id}, workspace mismatch: ${ws} != ${context["ws"]}`,
413
413
  );
414
414
  }
415
415
  async get_remote_service(service_uri, timeout) {
@@ -591,13 +591,13 @@ export class RPC extends MessageEmitter {
591
591
  const serviceInfo = this._extract_service_info(service);
592
592
  if (notify) {
593
593
  if (this.manager_id) {
594
- this.emit({
594
+ await this.emit({
595
595
  type: "service-added",
596
596
  to: "*/" + this.manager_id,
597
597
  service: serviceInfo,
598
598
  });
599
599
  } else {
600
- this.emit({ type: "service-added", to: "*", service: serviceInfo });
600
+ await this.emit({ type: "service-added", to: "*", service: serviceInfo });
601
601
  }
602
602
  }
603
603
  return serviceInfo;
@@ -941,9 +941,10 @@ export class RPC extends MessageEmitter {
941
941
  let reject = null;
942
942
  let heartbeat_task = null;
943
943
  try {
944
- assert(data.method && data.ctx && data.from && data.ws);
944
+ assert(data.method && data.ctx && data.from);
945
945
  const method_name = data.from + ":" + data.method;
946
946
  const remote_workspace = data.from.split("/")[0];
947
+ const remote_client_id = data.from.split("/")[1];
947
948
  // Make sure the target id is an absolute id
948
949
  data["to"] = data["to"].includes("/")
949
950
  ? data["to"]
@@ -1010,9 +1011,9 @@ export class RPC extends MessageEmitter {
1010
1011
  if (this._method_annotations.has(method)) {
1011
1012
  // For services, it should not be protected
1012
1013
  if (this._method_annotations.get(method).visibility === "protected") {
1013
- if (local_workspace !== remote_workspace) {
1014
+ if (local_workspace !== remote_workspace && (remote_workspace !== "*" || remote_client_id !== this.manager_id)) {
1014
1015
  throw new Error(
1015
- "Permission denied for protected method " +
1016
+ "Permission denied for invoking protected method " +
1016
1017
  method_name +
1017
1018
  ", workspace mismatch: " +
1018
1019
  local_workspace +
@@ -154,7 +154,7 @@ async function getRTCService(server, service_id, config) {
154
154
  const rpc = await _setupRPC(config);
155
155
  pc.rpc = rpc;
156
156
  async function getService(name) {
157
- return await rpc.get_remote_service(config.peer_id + ":" + name);
157
+ return await rpc.get_remote_service(config.workspace + "/" + config.peer_id + ":" + name);
158
158
  }
159
159
  async function disconnect() {
160
160
  await rpc.disconnect();