spectrum-ts 1.5.0 → 1.7.2
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/dist/{chunk-NIIJ6U34.js → chunk-2SB6VN7J.js} +48 -50
- package/dist/{chunk-NNRUJOPT.js → chunk-ET42EGIA.js} +27 -26
- package/dist/{chunk-L6LUFBLF.js → chunk-HWADNTQF.js} +4 -4
- package/dist/{chunk-LH4YEBG3.js → chunk-JWWIFSI7.js} +173 -185
- package/dist/{chunk-66GJ45ZZ.js → chunk-VO43HJ5B.js} +1 -1
- package/dist/{chunk-B4MHPWPZ.js → chunk-VVXMZYDH.js} +2 -2
- package/dist/{chunk-4U4RINOV.js → chunk-ZDNX3S3H.js} +224 -103
- package/dist/index.d.ts +549 -8
- package/dist/index.js +87 -92
- package/dist/providers/imessage/index.d.ts +31 -35
- package/dist/providers/imessage/index.js +6 -4
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.js +7 -7
- package/dist/providers/terminal/index.d.ts +256 -28
- package/dist/providers/terminal/index.js +3 -3
- package/dist/providers/whatsapp-business/index.d.ts +2 -16
- package/dist/providers/whatsapp-business/index.js +3 -3
- package/dist/types-lUyzRurY.d.ts +1029 -0
- package/package.json +1 -1
- package/dist/types-D0QSU6kb.d.ts +0 -490
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
asVoice
|
|
3
|
-
} from "./chunk-
|
|
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-
|
|
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
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
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:
|
|
806
|
-
content:
|
|
807
|
-
sender: { id:
|
|
808
|
-
space: { id:
|
|
809
|
-
timestamp: parseTimestamp(
|
|
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
|
-
|
|
815
|
-
|
|
816
|
-
const
|
|
817
|
-
const
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
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
|
-
|
|
834
|
-
|
|
835
|
-
const
|
|
836
|
-
|
|
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-
|
|
6
|
+
} from "./chunk-HWADNTQF.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-
|
|
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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
832
|
-
|
|
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 {
|
|
@@ -78,7 +78,7 @@ function stream(setup) {
|
|
|
78
78
|
});
|
|
79
79
|
return Object.assign(repeater, {
|
|
80
80
|
close: async () => {
|
|
81
|
-
|
|
81
|
+
await repeater.return(void 0).catch(ignoreCleanupError);
|
|
82
82
|
}
|
|
83
83
|
});
|
|
84
84
|
}
|
|
@@ -105,7 +105,7 @@ function mergeStreams(streams) {
|
|
|
105
105
|
});
|
|
106
106
|
return async () => {
|
|
107
107
|
await Promise.allSettled(streams.map((source) => source.close()));
|
|
108
|
-
|
|
108
|
+
await Promise.allSettled(workers).catch(ignoreCleanupError);
|
|
109
109
|
};
|
|
110
110
|
});
|
|
111
111
|
}
|
|
@@ -176,7 +176,7 @@ function broadcast(source) {
|
|
|
176
176
|
try {
|
|
177
177
|
await source.close();
|
|
178
178
|
if (pumpPromise) {
|
|
179
|
-
|
|
179
|
+
await pumpPromise.catch(ignoreCleanupError);
|
|
180
180
|
}
|
|
181
181
|
} finally {
|
|
182
182
|
if (!terminated) {
|
|
@@ -192,7 +192,7 @@ function broadcast(source) {
|
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
// src/utils/cloud.ts
|
|
195
|
-
var SPECTRUM_CLOUD_URL =
|
|
195
|
+
var SPECTRUM_CLOUD_URL = process.env.SPECTRUM_CLOUD_URL ?? "https://spectrum.photon.codes";
|
|
196
196
|
var SpectrumCloudError = class extends Error {
|
|
197
197
|
status;
|
|
198
198
|
code;
|