spectrum-ts 2.0.0 → 3.1.0
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/{attachment-B4nSrKVd.d.ts → attachment-CEpGtZLm.d.ts} +1 -1
- package/dist/{authoring-BjE5BvlO.d.ts → authoring-CP3vRza8.d.ts} +61 -26
- package/dist/authoring.d.ts +3 -3
- package/dist/authoring.js +5 -5
- package/dist/{chunk-NNY6LMSC.js → chunk-77U6SH5A.js} +1 -1
- package/dist/{chunk-WXY5QP3M.js → chunk-7ON5XHC2.js} +27 -21
- package/dist/{chunk-6BI4PFTP.js → chunk-CHY5YLLV.js} +1 -1
- package/dist/{chunk-Q537JPTG.js → chunk-FA7VA4XN.js} +10 -10
- package/dist/{chunk-NGC4DJIX.js → chunk-L3NUESOW.js} +425 -137
- package/dist/{chunk-2ILTJC35.js → chunk-LQMDV75O.js} +205 -11
- package/dist/{chunk-3B4QH4JG.js → chunk-MHGCPC2V.js} +1 -1
- package/dist/{chunk-U7AWXDH6.js → chunk-NZ5WCMTY.js} +1 -1
- package/dist/{chunk-5LT5J3NR.js → chunk-PSSWQBOH.js} +262 -30
- package/dist/{chunk-U3LXXT3W.js → chunk-Q44CIGG6.js} +20 -8
- package/dist/{chunk-ATNAE7OR.js → chunk-WMG36LHW.js} +676 -159
- package/dist/index.d.ts +107 -56
- package/dist/index.js +29 -182
- package/dist/providers/imessage/index.d.ts +7 -14
- package/dist/providers/imessage/index.js +6 -6
- package/dist/providers/index.d.ts +3 -3
- package/dist/providers/index.js +11 -11
- package/dist/providers/slack/index.d.ts +1 -2
- package/dist/providers/slack/index.js +3 -3
- package/dist/providers/telegram/index.d.ts +3 -5
- package/dist/providers/telegram/index.js +5 -5
- package/dist/providers/terminal/index.d.ts +2 -4
- package/dist/providers/terminal/index.js +5 -5
- package/dist/providers/whatsapp-business/index.d.ts +1 -1
- package/dist/providers/whatsapp-business/index.js +4 -4
- package/dist/{types-Bje8aq1k.d.ts → types-Be0T6E0e.d.ts} +172 -23
- package/dist/{types-BD0-kKyv.d.ts → types-CDYXH2R7.d.ts} +1 -1
- package/package.json +2 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import './attachment-
|
|
1
|
+
import './attachment-CEpGtZLm.js';
|
|
2
2
|
import vCard from 'vcf';
|
|
3
3
|
import z__default from 'zod';
|
|
4
|
-
import { U as User, C as ContentBuilder, M as Message, e as Space, h as ContentInput } from './types-
|
|
4
|
+
import { U as User, C as ContentBuilder, M as Message, e as Space, h as ContentInput } from './types-Be0T6E0e.js';
|
|
5
5
|
|
|
6
6
|
declare const nameSchema: z__default.ZodObject<{
|
|
7
7
|
formatted: z__default.ZodOptional<z__default.ZodString>;
|
|
@@ -140,6 +140,43 @@ declare const asGroup: (input: {
|
|
|
140
140
|
}) => Group;
|
|
141
141
|
declare function group(...items: [ContentInput, ContentInput, ...ContentInput[]]): ContentBuilder;
|
|
142
142
|
|
|
143
|
+
/**
|
|
144
|
+
* Maps one chunk emitted by a stream to the incremental text it carries.
|
|
145
|
+
* Return a string to emit, or `null`/`undefined` to skip the chunk (e.g. for
|
|
146
|
+
* control events that carry no text).
|
|
147
|
+
*/
|
|
148
|
+
type DeltaExtractor<T> = (chunk: T) => string | null | undefined;
|
|
149
|
+
/**
|
|
150
|
+
* Anything the stream overloads of `text()` and `markdown()` accept as a
|
|
151
|
+
* source. The builder normalizes all of these to an internal
|
|
152
|
+
* `AsyncIterable<string>` of text deltas:
|
|
153
|
+
*
|
|
154
|
+
* - the Vercel AI SDK `streamText()` result (its `.textStream` is picked up
|
|
155
|
+
* automatically — pass either the whole result or `.textStream` directly),
|
|
156
|
+
* - a raw `AsyncIterable<T>` (e.g. an OpenAI / Anthropic streaming response),
|
|
157
|
+
* - a raw `ReadableStream<T>` of chunks.
|
|
158
|
+
*/
|
|
159
|
+
type StreamTextSource<T = unknown> = {
|
|
160
|
+
textStream: AsyncIterable<string> | ReadableStream<string>;
|
|
161
|
+
} | AsyncIterable<T> | ReadableStream<T>;
|
|
162
|
+
interface TextStreamOptions<T = unknown> {
|
|
163
|
+
/**
|
|
164
|
+
* Map each chunk to its incremental text. Omit to rely on built-in
|
|
165
|
+
* auto-detection of the common SDK shapes (OpenAI chat/responses, Anthropic
|
|
166
|
+
* messages, AI SDK text streams, and plain strings).
|
|
167
|
+
*/
|
|
168
|
+
extract?: DeltaExtractor<T>;
|
|
169
|
+
}
|
|
170
|
+
declare const streamTextSchema: z__default.ZodObject<{
|
|
171
|
+
type: z__default.ZodLiteral<"streamText">;
|
|
172
|
+
stream: z__default.ZodCustom<() => AsyncIterable<string>, () => AsyncIterable<string>>;
|
|
173
|
+
format: z__default.ZodOptional<z__default.ZodEnum<{
|
|
174
|
+
markdown: "markdown";
|
|
175
|
+
plain: "plain";
|
|
176
|
+
}>>;
|
|
177
|
+
}, z__default.core.$strip>;
|
|
178
|
+
type StreamText = z__default.infer<typeof streamTextSchema>;
|
|
179
|
+
|
|
143
180
|
declare const pollChoiceSchema: z__default.ZodObject<{
|
|
144
181
|
title: z__default.ZodString;
|
|
145
182
|
}, z__default.core.$strip>;
|
|
@@ -185,28 +222,6 @@ declare const option: (title: string) => PollChoice;
|
|
|
185
222
|
declare function poll(title: string, options: PollChoiceInput[]): ContentBuilder;
|
|
186
223
|
declare function poll(title: string, ...options: PollChoiceInput[]): ContentBuilder;
|
|
187
224
|
|
|
188
|
-
declare const reactionSchema: z__default.ZodObject<{
|
|
189
|
-
type: z__default.ZodLiteral<"reaction">;
|
|
190
|
-
emoji: z__default.ZodString;
|
|
191
|
-
target: z__default.ZodCustom<Message<string, User, Space<unknown>>, Message<string, User, Space<unknown>>>;
|
|
192
|
-
}, z__default.core.$strip>;
|
|
193
|
-
type Reaction = z__default.infer<typeof reactionSchema>;
|
|
194
|
-
declare const asReaction: (input: {
|
|
195
|
-
emoji: string;
|
|
196
|
-
target: Message;
|
|
197
|
-
}) => Reaction;
|
|
198
|
-
/**
|
|
199
|
-
* Construct a `reaction` content value targeting the given message.
|
|
200
|
-
*
|
|
201
|
-
* `space.send(reaction(emoji, message))` is sugar for `message.react(emoji)`.
|
|
202
|
-
* Reactions are fire-and-forget — the returned `Message` will be `undefined`
|
|
203
|
-
* because platforms do not surface a message id for reactions.
|
|
204
|
-
*
|
|
205
|
-
* To react to a message known only by id, resolve it first via
|
|
206
|
-
* `space.getMessage(id)`.
|
|
207
|
-
*/
|
|
208
|
-
declare function reaction(emoji: string, target: Message): ContentBuilder;
|
|
209
|
-
|
|
210
225
|
declare const richlinkSchema: z__default.ZodObject<{
|
|
211
226
|
type: z__default.ZodLiteral<"richlink">;
|
|
212
227
|
url: z__default.ZodURL;
|
|
@@ -239,7 +254,27 @@ declare const textSchema: z__default.ZodObject<{
|
|
|
239
254
|
text: z__default.ZodString;
|
|
240
255
|
}, z__default.core.$strip>;
|
|
241
256
|
declare const asText: (text: string) => z__default.infer<typeof textSchema>;
|
|
242
|
-
|
|
257
|
+
/**
|
|
258
|
+
* Send plain text — a static string or a streaming LLM response.
|
|
259
|
+
*
|
|
260
|
+
* `text("hi")` sends one message. `text(source)` wraps a text stream so it
|
|
261
|
+
* can be sent like any other content; delivery is platform-specific —
|
|
262
|
+
* iMessage (remote) sends the first chunk as a real message and then edits it
|
|
263
|
+
* in place as more text arrives; Telegram (private chats) animates a native
|
|
264
|
+
* draft preview and persists the final text as one message. Platforms that
|
|
265
|
+
* can't stream wait for the stream to finish and deliver the accumulated text
|
|
266
|
+
* as one plain message.
|
|
267
|
+
*
|
|
268
|
+
* A stream source accepts whatever the popular SDKs return (the AI SDK
|
|
269
|
+
* `streamText()` result, OpenAI / Anthropic streaming responses, or any
|
|
270
|
+
* `AsyncIterable` / `ReadableStream`); pass `options.extract` for any chunk
|
|
271
|
+
* shape the built-in detection doesn't recognize. A stream can only be sent
|
|
272
|
+
* once. Options apply to stream sources only — they are ignored for strings.
|
|
273
|
+
*
|
|
274
|
+
* For text written in markdown, use `markdown()` instead.
|
|
275
|
+
*/
|
|
276
|
+
declare function text(source: string): ContentBuilder;
|
|
277
|
+
declare function text<T = unknown>(source: StreamTextSource<T>, options?: TextStreamOptions<T>): ContentBuilder;
|
|
243
278
|
|
|
244
279
|
declare const voiceSchema: z__default.ZodObject<{
|
|
245
280
|
type: z__default.ZodLiteral<"voice">;
|
|
@@ -266,4 +301,4 @@ declare function voice(input: VoiceInput, options?: {
|
|
|
266
301
|
duration?: number;
|
|
267
302
|
}): ContentBuilder;
|
|
268
303
|
|
|
269
|
-
export {
|
|
304
|
+
export { asVoice as A, type ContactInput as C, type DeltaExtractor as D, type Group as G, type Poll as P, type Richlink as R, type StreamTextSource as S, type TextStreamOptions as T, type Voice as V, type Contact as a, type ContactAddress as b, type ContactDetails as c, type ContactEmail as d, type ContactName as e, type ContactOrg as f, type ContactPhone as g, type PollChoice as h, type PollChoiceInput as i, type PollOption as j, type StreamText as k, contact as l, custom as m, group as n, option as o, poll as p, asContact as q, richlink as r, asCustom as s, text as t, asGroup as u, voice as v, asPoll as w, asPollOption as x, asRichlink as y, asText as z };
|
package/dist/authoring.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { c as asAttachment } from './attachment-
|
|
2
|
-
export {
|
|
3
|
-
export { d as ProviderMessageRecord } from './types-
|
|
1
|
+
export { c as asAttachment } from './attachment-CEpGtZLm.js';
|
|
2
|
+
export { q as asContact, s as asCustom, u as asGroup, w as asPoll, x as asPollOption, y as asRichlink, z as asText, A as asVoice } from './authoring-CP3vRza8.js';
|
|
3
|
+
export { d as ProviderMessageRecord, $ as asReaction } from './types-Be0T6E0e.js';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import 'vcf';
|
|
6
6
|
import 'hotscript';
|
package/dist/authoring.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import { createRequire as __spectrumCreateRequire } from "node:module"; const require = __spectrumCreateRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
asRichlink
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-CHY5YLLV.js";
|
|
5
5
|
import {
|
|
6
6
|
asGroup
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-MHGCPC2V.js";
|
|
8
8
|
import {
|
|
9
9
|
asVoice
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-77U6SH5A.js";
|
|
11
11
|
import {
|
|
12
12
|
asPoll,
|
|
13
13
|
asPollOption
|
|
14
14
|
} from "./chunk-2D27WW5B.js";
|
|
15
15
|
import {
|
|
16
16
|
asContact
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-NZ5WCMTY.js";
|
|
18
18
|
import "./chunk-6UZFVXQF.js";
|
|
19
19
|
import {
|
|
20
20
|
asAttachment,
|
|
21
21
|
asCustom,
|
|
22
22
|
asReaction,
|
|
23
23
|
asText
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-LQMDV75O.js";
|
|
25
25
|
export {
|
|
26
26
|
asAttachment,
|
|
27
27
|
asContact,
|
|
@@ -9,13 +9,13 @@ import {
|
|
|
9
9
|
import {
|
|
10
10
|
UnsupportedError,
|
|
11
11
|
definePlatform
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-L3NUESOW.js";
|
|
13
13
|
import {
|
|
14
14
|
asAttachment,
|
|
15
15
|
asCustom,
|
|
16
16
|
asReaction,
|
|
17
17
|
asText
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-LQMDV75O.js";
|
|
19
19
|
|
|
20
20
|
// src/providers/slack/index.ts
|
|
21
21
|
import { createClient as createClient2, staticTokens } from "@photon-ai/slack";
|
|
@@ -340,13 +340,12 @@ var send = async (client, space, content) => {
|
|
|
340
340
|
);
|
|
341
341
|
}
|
|
342
342
|
if (content.type === "reaction") {
|
|
343
|
-
await reactToMessage(
|
|
343
|
+
return await reactToMessage(
|
|
344
344
|
client,
|
|
345
345
|
space,
|
|
346
346
|
content.target.ts ?? content.target.id,
|
|
347
|
-
content
|
|
347
|
+
content
|
|
348
348
|
);
|
|
349
|
-
return;
|
|
350
349
|
}
|
|
351
350
|
if (content.type === "typing") {
|
|
352
351
|
return;
|
|
@@ -388,15 +387,23 @@ var sendContent = async (client, space, content, threadTs) => {
|
|
|
388
387
|
throw UnsupportedError.content(content.type);
|
|
389
388
|
}
|
|
390
389
|
};
|
|
391
|
-
var reactToMessage = async (client, space, targetTs,
|
|
390
|
+
var reactToMessage = async (client, space, targetTs, content) => {
|
|
392
391
|
await client.team(space.teamId).messages.send({
|
|
393
392
|
channel: space.id,
|
|
394
393
|
reaction: {
|
|
395
|
-
emoji,
|
|
394
|
+
emoji: content.emoji,
|
|
396
395
|
itemChannel: space.id,
|
|
397
396
|
itemTs: targetTs
|
|
398
397
|
}
|
|
399
398
|
});
|
|
399
|
+
return {
|
|
400
|
+
id: `${targetTs}:reaction:self:${content.emoji}`,
|
|
401
|
+
content,
|
|
402
|
+
space: { id: space.id, teamId: space.teamId },
|
|
403
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
404
|
+
ts: targetTs,
|
|
405
|
+
isFromMe: true
|
|
406
|
+
};
|
|
400
407
|
};
|
|
401
408
|
var replyToMessage = async (client, space, targetTs, content) => await sendContent(client, space, content, targetTs);
|
|
402
409
|
|
|
@@ -424,7 +431,6 @@ var spaceSchema = z.object({
|
|
|
424
431
|
teamId: z.string()
|
|
425
432
|
});
|
|
426
433
|
var spaceParamsSchema = z.object({
|
|
427
|
-
channel: z.string().optional(),
|
|
428
434
|
teamId: z.string()
|
|
429
435
|
});
|
|
430
436
|
var messageSchema = z.object({
|
|
@@ -475,27 +481,18 @@ var slack = definePlatform("Slack", {
|
|
|
475
481
|
space: {
|
|
476
482
|
schema: spaceSchema,
|
|
477
483
|
params: spaceParamsSchema,
|
|
478
|
-
|
|
484
|
+
create: async ({ input }) => {
|
|
479
485
|
const teamId = input.params?.teamId;
|
|
480
486
|
if (!teamId) {
|
|
481
487
|
throw new Error(
|
|
482
|
-
"Slack space creation requires a teamId param. Pass it via
|
|
483
|
-
);
|
|
484
|
-
}
|
|
485
|
-
const channel = input.params?.channel;
|
|
486
|
-
if (channel) {
|
|
487
|
-
return { id: channel, teamId };
|
|
488
|
-
}
|
|
489
|
-
if (input.users.length === 0) {
|
|
490
|
-
throw new Error(
|
|
491
|
-
"Slack space creation requires either a channel param or at least one user"
|
|
488
|
+
"Slack space creation requires a teamId param. Pass it via space.create(user, { teamId })."
|
|
492
489
|
);
|
|
493
490
|
}
|
|
494
491
|
if (input.users.length > 1) {
|
|
495
492
|
throw UnsupportedError.action(
|
|
496
|
-
"
|
|
493
|
+
"space.create",
|
|
497
494
|
"Slack",
|
|
498
|
-
"group DMs require an explicit channel id (Slack's conversations.open is not exposed);
|
|
495
|
+
"group DMs require an explicit channel id (Slack's conversations.open is not exposed); use space.get(channelId, { teamId })"
|
|
499
496
|
);
|
|
500
497
|
}
|
|
501
498
|
const user = input.users[0];
|
|
@@ -503,6 +500,15 @@ var slack = definePlatform("Slack", {
|
|
|
503
500
|
throw new Error("Slack space creation requires a user");
|
|
504
501
|
}
|
|
505
502
|
return { id: user.id, teamId };
|
|
503
|
+
},
|
|
504
|
+
get: async ({ input }) => {
|
|
505
|
+
const teamId = input.params?.teamId;
|
|
506
|
+
if (!teamId) {
|
|
507
|
+
throw new Error(
|
|
508
|
+
"Slack spaces require a teamId param. Pass it via space.get(channelId, { teamId })."
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
return { id: input.id, teamId };
|
|
506
512
|
}
|
|
507
513
|
},
|
|
508
514
|
message: {
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "./chunk-3GEJYGZK.js";
|
|
8
8
|
import {
|
|
9
9
|
asContact
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-NZ5WCMTY.js";
|
|
11
11
|
import {
|
|
12
12
|
mergeStreams,
|
|
13
13
|
stream
|
|
@@ -15,13 +15,13 @@ import {
|
|
|
15
15
|
import {
|
|
16
16
|
UnsupportedError,
|
|
17
17
|
definePlatform
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-L3NUESOW.js";
|
|
19
19
|
import {
|
|
20
20
|
asAttachment,
|
|
21
21
|
asCustom,
|
|
22
22
|
asReaction,
|
|
23
23
|
asText
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-LQMDV75O.js";
|
|
25
25
|
|
|
26
26
|
// src/providers/whatsapp-business/index.ts
|
|
27
27
|
import { createClient as createClient2 } from "@photon-ai/whatsapp-business";
|
|
@@ -639,8 +639,7 @@ var send = async (clients, spaceId, content) => {
|
|
|
639
639
|
);
|
|
640
640
|
}
|
|
641
641
|
if (content.type === "reaction") {
|
|
642
|
-
await reactToMessage(clients, spaceId, content
|
|
643
|
-
return;
|
|
642
|
+
return await reactToMessage(clients, spaceId, content);
|
|
644
643
|
}
|
|
645
644
|
if (content.type === "typing") {
|
|
646
645
|
return;
|
|
@@ -706,11 +705,12 @@ var send = async (clients, spaceId, content) => {
|
|
|
706
705
|
throw UnsupportedError.content(content.type);
|
|
707
706
|
}
|
|
708
707
|
};
|
|
709
|
-
var reactToMessage = async (clients, spaceId,
|
|
710
|
-
await primary(clients).messages.send({
|
|
708
|
+
var reactToMessage = async (clients, spaceId, content) => {
|
|
709
|
+
const result = await primary(clients).messages.send({
|
|
711
710
|
to: spaceId,
|
|
712
|
-
reaction: { messageId, emoji:
|
|
711
|
+
reaction: { messageId: content.target.id, emoji: content.emoji }
|
|
713
712
|
});
|
|
713
|
+
return toRecord(result, spaceId, content);
|
|
714
714
|
};
|
|
715
715
|
var replyToMessage = async (clients, spaceId, messageId, content) => {
|
|
716
716
|
const client = primary(clients);
|
|
@@ -833,13 +833,13 @@ var whatsappBusiness = definePlatform("WhatsApp Business", {
|
|
|
833
833
|
},
|
|
834
834
|
space: {
|
|
835
835
|
schema: spaceSchema,
|
|
836
|
-
|
|
836
|
+
create: async ({ input }) => {
|
|
837
837
|
if (input.users.length === 0) {
|
|
838
838
|
throw new Error("WhatsApp space creation requires at least one user");
|
|
839
839
|
}
|
|
840
840
|
if (input.users.length > 1) {
|
|
841
841
|
throw UnsupportedError.action(
|
|
842
|
-
"
|
|
842
|
+
"space.create",
|
|
843
843
|
"WhatsApp Business",
|
|
844
844
|
"only 1:1 conversations are supported"
|
|
845
845
|
);
|