@agimon-ai/po-team 0.0.0-alpha.5 → 0.0.0-alpha.7

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.
@@ -3596,16 +3596,18 @@ function createHeadlessIntercomTool(channel, sessions) {
3596
3596
  const params = parseTeamToolParams(parameters);
3597
3597
  const peers = channel.current() === void 0 ? [] : sessions?.peers() ?? [];
3598
3598
  const to = params.to?.trim();
3599
- const teamMember = to !== void 0 && channel.snapshot().members.some((member) => member.name === to) && !peers.some((peer) => peer.sessionId === to);
3600
- const peer = sessions === void 0 || to === void 0 || teamMember ? void 0 : resolvePeer(peers, to);
3601
- if (sessions !== void 0 && peer !== void 0) {
3599
+ const knownId = channel.current() !== void 0 && to !== void 0 && sessions?.canCommunicate(to) === true;
3600
+ const teamMember = to !== void 0 && channel.snapshot().members.some((member) => member.name === to) && !knownId && !peers.some((peer) => peer.sessionId === to);
3601
+ const peer = sessions === void 0 || to === void 0 || teamMember || knownId ? void 0 : resolvePeer(peers, to);
3602
+ const recipientId = knownId ? to : peer?.sessionId;
3603
+ if (sessions !== void 0 && recipientId !== void 0) {
3602
3604
  if (params.action !== "send") throw invalidRequest("Session peers support send only.", "Use send with the session name or ID.");
3603
3605
  const message = validateMessage(params.message);
3604
3606
  const delivery = sessions.delivery();
3605
3607
  if (delivery === void 0) throw new Error("Session delivery is unavailable.");
3606
3608
  const receipt = await delivery.deliver({
3607
3609
  deliveryId: `intercom:${sessions.sessionId}:${toolCallId}`,
3608
- recipientKey: peer.sessionId,
3610
+ recipientKey: recipientId,
3609
3611
  kind: "intercom_message",
3610
3612
  prompt: `Message from session ${sessions.sessionId} via intercom.\n\n${message}\n\nReply using intercom({ action: "send", to: "${sessions.sessionId}", message: "..." }).`,
3611
3613
  delivery: "steer"
@@ -3613,11 +3615,11 @@ function createHeadlessIntercomTool(channel, sessions) {
3613
3615
  return {
3614
3616
  content: [{
3615
3617
  type: "text",
3616
- text: `Message queued for session ${peer.name || peer.sessionId}.`
3618
+ text: `Message queued for session ${peer?.name || recipientId}.`
3617
3619
  }],
3618
3620
  details: {
3619
3621
  ...receipt,
3620
- to: peer.sessionId
3622
+ to: recipientId
3621
3623
  }
3622
3624
  };
3623
3625
  }
@@ -6464,11 +6466,11 @@ const root = (0, _agimon_ai_po_core_extensionFile.defineRoot)(({ context, host:
6464
6466
  } });
6465
6467
  const intercom = createHeadlessIntercomTool(channel, {
6466
6468
  sessionId: execution.sessionId,
6467
- peers: () => [...sessionPeers].filter((id) => serverHost.context.sessionService?.canCommunicate?.(execution.sessionId, id) === true).map((id) => serverHost.context.sessionCommunication?.describePeer?.(id) ?? {
6468
- sessionId: id,
6469
- name: "",
6470
- sharedGroups: []
6469
+ peers: () => [...sessionPeers].filter((id) => serverHost.context.sessionService?.canCommunicate?.(execution.sessionId, id) === true).flatMap((id) => {
6470
+ const peer = serverHost.context.sessionCommunication?.describePeer?.(id);
6471
+ return peer === void 0 ? [] : [peer];
6471
6472
  }),
6473
+ canCommunicate: (id) => serverHost.context.sessionService?.canCommunicate?.(execution.sessionId, id) === true,
6472
6474
  delivery: () => (0, _agimon_ai_po_session.readPoSessionDelivery)(context)
6473
6475
  });
6474
6476
  const serverService = (ctx) => {