spectrum-ts 1.5.0 → 1.7.1

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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  asVoice
3
- } from "./chunk-B4MHPWPZ.js";
3
+ } from "./chunk-VVXMZYDH.js";
4
4
  import {
5
5
  UnsupportedError,
6
6
  asAttachment,
@@ -10,7 +10,7 @@ import {
10
10
  fromVCard,
11
11
  reactionSchema,
12
12
  toVCard
13
- } from "./chunk-LH4YEBG3.js";
13
+ } from "./chunk-JWWIFSI7.js";
14
14
 
15
15
  // src/providers/terminal/index.ts
16
16
  import { spawn } from "child_process";
@@ -747,9 +747,7 @@ var terminal = definePlatform("terminal", {
747
747
  })
748
748
  },
749
749
  lifecycle: {
750
- createClient: async ({ config }) => {
751
- return await spawnClient({ commands: config.commands });
752
- },
750
+ createClient: async ({ config }) => await spawnClient({ commands: config.commands }),
753
751
  destroyClient: async ({ client }) => {
754
752
  client.hijack.restore();
755
753
  try {
@@ -781,60 +779,60 @@ var terminal = definePlatform("terminal", {
781
779
  return { id };
782
780
  }
783
781
  },
784
- events: {
785
- async *messages({ client }) {
786
- for await (const evt of client.events) {
787
- if (evt.kind === "message") {
788
- const msg = evt.value;
789
- client.knownChats.add(msg.spaceId);
790
- yield {
791
- id: msg.id,
792
- content: protocolToSpectrum(msg.content),
793
- sender: { id: msg.senderId },
794
- space: { id: msg.spaceId },
795
- timestamp: parseTimestamp(msg.timestamp),
796
- // replyTo is a terminal-specific extra — agents inspect via a
797
- // cast until Spectrum's message model grows first-class support.
798
- ...msg.replyTo ? { replyTo: msg.replyTo } : {}
799
- };
800
- continue;
801
- }
802
- const r = evt.value;
803
- client.knownChats.add(r.spaceId);
782
+ async *messages({ client }) {
783
+ for await (const evt of client.events) {
784
+ if (evt.kind === "message") {
785
+ const msg = evt.value;
786
+ client.knownChats.add(msg.spaceId);
804
787
  yield {
805
- id: `reaction:${r.messageId}:${r.reaction}:${r.timestamp}`,
806
- content: reactionContentFromProtocol(r),
807
- sender: { id: r.senderId },
808
- space: { id: r.spaceId },
809
- timestamp: parseTimestamp(r.timestamp)
788
+ id: msg.id,
789
+ content: protocolToSpectrum(msg.content),
790
+ sender: { id: msg.senderId },
791
+ space: { id: msg.spaceId },
792
+ timestamp: parseTimestamp(msg.timestamp),
793
+ // replyTo is a terminal-specific extra — agents inspect via a
794
+ // cast until Spectrum's message model grows first-class support.
795
+ ...msg.replyTo ? { replyTo: msg.replyTo } : {}
810
796
  };
797
+ continue;
811
798
  }
799
+ const r = evt.value;
800
+ client.knownChats.add(r.spaceId);
801
+ yield {
802
+ id: `reaction:${r.messageId}:${r.reaction}:${r.timestamp}`,
803
+ content: reactionContentFromProtocol(r),
804
+ sender: { id: r.senderId },
805
+ space: { id: r.spaceId },
806
+ timestamp: parseTimestamp(r.timestamp)
807
+ };
812
808
  }
813
809
  },
814
- actions: {
815
- send: async ({ client, content, space }) => {
816
- const proto = await spectrumToProtocol(content);
817
- const result = await client.session.request("send", { spaceId: space.id, content: proto });
818
- return buildOutboundRecord(result, content, space.id);
819
- },
820
- startTyping: async ({ client, space }) => {
821
- await client.session.request("startTyping", { spaceId: space.id });
822
- },
823
- stopTyping: async ({ client, space }) => {
824
- await client.session.request("stopTyping", { spaceId: space.id });
825
- },
826
- reactToMessage: async ({ client, space, target, reaction }) => {
810
+ send: async ({ client, content, space }) => {
811
+ if (content.type === "reply") {
812
+ const inner = await spectrumToProtocol(content.content);
813
+ const result2 = await client.session.request("replyToMessage", {
814
+ spaceId: space.id,
815
+ messageId: content.target.id,
816
+ content: inner
817
+ });
818
+ return buildOutboundRecord(result2, content.content, space.id);
819
+ }
820
+ if (content.type === "reaction") {
827
821
  await client.session.request("reactToMessage", {
828
822
  spaceId: space.id,
829
- messageId: target.id,
830
- reaction
823
+ messageId: content.target.id,
824
+ reaction: content.emoji
831
825
  });
832
- },
833
- replyToMessage: async ({ client, space, messageId, content }) => {
834
- const proto = await spectrumToProtocol(content);
835
- const result = await client.session.request("replyToMessage", { spaceId: space.id, messageId, content: proto });
836
- return buildOutboundRecord(result, content, space.id);
826
+ return;
827
+ }
828
+ if (content.type === "typing") {
829
+ const method = content.state === "start" ? "startTyping" : "stopTyping";
830
+ await client.session.request(method, { spaceId: space.id });
831
+ return;
837
832
  }
833
+ const proto = await spectrumToProtocol(content);
834
+ const result = await client.session.request("send", { spaceId: space.id, content: proto });
835
+ return buildOutboundRecord(result, content, space.id);
838
836
  }
839
837
  });
840
838
 
@@ -3,7 +3,7 @@ import {
3
3
  cloud,
4
4
  mergeStreams,
5
5
  stream
6
- } from "./chunk-L6LUFBLF.js";
6
+ } from "./chunk-WFIUWFE4.js";
7
7
  import {
8
8
  UnsupportedError,
9
9
  asAttachment,
@@ -12,7 +12,7 @@ import {
12
12
  asReaction,
13
13
  asText,
14
14
  definePlatform
15
- } from "./chunk-LH4YEBG3.js";
15
+ } from "./chunk-JWWIFSI7.js";
16
16
 
17
17
  // src/providers/whatsapp-business/index.ts
18
18
  import { createClient as createClient2 } from "@photon-ai/whatsapp-business";
@@ -137,13 +137,11 @@ async function disposeCloudAuth(clients) {
137
137
  }
138
138
  var buildClientProxy = (state, refresh) => {
139
139
  const forwarder = (pick) => new Proxy({}, {
140
- get: (_, prop) => {
141
- return async (...args) => {
142
- await refresh();
143
- const target = pick(state.current);
144
- const fn = target[prop];
145
- return Reflect.apply(fn, pick(state.current), args);
146
- };
140
+ get: (_, prop) => async (...args) => {
141
+ await refresh();
142
+ const target = pick(state.current);
143
+ const fn = target[prop];
144
+ return Reflect.apply(fn, pick(state.current), args);
147
145
  }
148
146
  });
149
147
  const events = {
@@ -308,7 +306,7 @@ var optionIndexFromId = (id) => {
308
306
  };
309
307
  var mapWaPhoneType = (type) => {
310
308
  if (!type) {
311
- return void 0;
309
+ return;
312
310
  }
313
311
  const upper = type.toUpperCase();
314
312
  if (upper === "CELL" || upper === "MOBILE" || upper === "IPHONE") {
@@ -324,7 +322,7 @@ var mapWaPhoneType = (type) => {
324
322
  };
325
323
  var mapWaSimpleType = (type) => {
326
324
  if (!type) {
327
- return void 0;
325
+ return;
328
326
  }
329
327
  const upper = type.toUpperCase();
330
328
  if (upper === "HOME") {
@@ -543,7 +541,7 @@ var spectrumPhoneTypeToWa = (type) => {
543
541
  if (type === "home" || type === "work" || type === "other") {
544
542
  return type.toUpperCase();
545
543
  }
546
- return void 0;
544
+ return;
547
545
  };
548
546
  var spectrumSimpleTypeToWa = (type) => type ? type.toUpperCase() : void 0;
549
547
  var spectrumNameToWa = (name) => ({
@@ -622,6 +620,21 @@ var clientStream = (client) => {
622
620
  };
623
621
  var messages = (clients) => mergeStreams(clients.map(clientStream));
624
622
  var send = async (clients, spaceId, content) => {
623
+ if (content.type === "reply") {
624
+ return await replyToMessage(
625
+ clients,
626
+ spaceId,
627
+ content.target.id,
628
+ content.content
629
+ );
630
+ }
631
+ if (content.type === "reaction") {
632
+ await reactToMessage(clients, spaceId, content.target.id, content.emoji);
633
+ return;
634
+ }
635
+ if (content.type === "typing") {
636
+ return;
637
+ }
625
638
  const client = primary(clients);
626
639
  switch (content.type) {
627
640
  case "text":
@@ -828,20 +841,8 @@ var whatsappBusiness = definePlatform("WhatsApp Business", {
828
841
  return { id: user.id };
829
842
  }
830
843
  },
831
- events: {
832
- messages: ({ client }) => messages(client)
833
- },
834
- actions: {
835
- send: async ({ space, content, client }) => {
836
- return await send(client, space.id, content);
837
- },
838
- reactToMessage: async ({ space, target, reaction, client }) => {
839
- await reactToMessage(client, space.id, target.id, reaction);
840
- },
841
- replyToMessage: async ({ space, messageId, content, client }) => {
842
- return await replyToMessage(client, space.id, messageId, content);
843
- }
844
- }
844
+ messages: ({ client }) => messages(client),
845
+ send: async ({ space, content, client }) => await send(client, space.id, content)
845
846
  });
846
847
 
847
848
  export {