spectrum-ts 1.18.0 → 3.0.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.
Files changed (38) hide show
  1. package/README.md +11 -1
  2. package/dist/{attachment-DfWSZS5L.d.ts → attachment-WePAHfcH.d.ts} +1 -1
  3. package/dist/{authoring-C9uDdZ2F.d.ts → authoring-DDh3muGT.d.ts} +61 -26
  4. package/dist/authoring.d.ts +3 -3
  5. package/dist/authoring.js +8 -5
  6. package/dist/chunk-34FQGGD7.js +34 -0
  7. package/dist/chunk-3GEJYGZK.js +84 -0
  8. package/dist/{chunk-MC6ZKFSG.js → chunk-5XEFJBN2.js} +25 -103
  9. package/dist/{chunk-QGJFZMD5.js → chunk-6UZFVXQF.js} +17 -101
  10. package/dist/{chunk-NNY6LMSC.js → chunk-77U6SH5A.js} +1 -1
  11. package/dist/{chunk-YN6WOTBF.js → chunk-AYCMTRVC.js} +622 -79
  12. package/dist/{chunk-JQN6CRSC.js → chunk-CHY5YLLV.js} +11 -40
  13. package/dist/{chunk-5BKZJMZV.js → chunk-EZ5SNNFS.js} +79 -38
  14. package/dist/{chunk-3OTECDNH.js → chunk-FULEQIRQ.js} +31 -23
  15. package/dist/{chunk-2ILTJC35.js → chunk-LQMDV75O.js} +205 -11
  16. package/dist/{chunk-IPOFBAIM.js → chunk-LX437ZTY.js} +439 -154
  17. package/dist/chunk-MHGCPC2V.js +35 -0
  18. package/dist/chunk-NZ5WCMTY.js +91 -0
  19. package/dist/chunk-TXRWKSNH.js +927 -0
  20. package/dist/{chunk-5TIF3FIE.js → chunk-UXJ5OO6P.js} +16 -14
  21. package/dist/index.d.ts +125 -129
  22. package/dist/index.js +180 -73
  23. package/dist/manifest.json +6 -0
  24. package/dist/providers/imessage/index.d.ts +6 -14
  25. package/dist/providers/imessage/index.js +9 -6
  26. package/dist/providers/index.d.ts +5 -2
  27. package/dist/providers/index.js +18 -10
  28. package/dist/providers/slack/index.d.ts +1 -2
  29. package/dist/providers/slack/index.js +5 -4
  30. package/dist/providers/telegram/index.d.ts +45 -0
  31. package/dist/providers/telegram/index.js +13 -0
  32. package/dist/providers/terminal/index.d.ts +18 -422
  33. package/dist/providers/terminal/index.js +7 -5
  34. package/dist/providers/whatsapp-business/index.d.ts +1 -1
  35. package/dist/providers/whatsapp-business/index.js +7 -5
  36. package/dist/types-BujGKBin.d.ts +82 -0
  37. package/dist/{types-DcQ5a7PK.d.ts → types-YqCNUDIt.d.ts} +204 -26
  38. package/package.json +3 -1
@@ -4,6 +4,16 @@ import z__default from 'zod';
4
4
  declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObject<{
5
5
  type: z__default.ZodLiteral<"text">;
6
6
  text: z__default.ZodString;
7
+ }, z__default.core.$strip>, z__default.ZodObject<{
8
+ type: z__default.ZodLiteral<"markdown">;
9
+ markdown: z__default.ZodString;
10
+ }, z__default.core.$strip>, z__default.ZodObject<{
11
+ type: z__default.ZodLiteral<"streamText">;
12
+ stream: z__default.ZodCustom<() => AsyncIterable<string>, () => AsyncIterable<string>>;
13
+ format: z__default.ZodOptional<z__default.ZodEnum<{
14
+ markdown: "markdown";
15
+ plain: "plain";
16
+ }>>;
7
17
  }, z__default.core.$strip>, z__default.ZodObject<{
8
18
  type: z__default.ZodLiteral<"custom">;
9
19
  raw: z__default.ZodUnknown;
@@ -121,6 +131,9 @@ declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObj
121
131
  content: z__default.ZodDiscriminatedUnion<[z__default.ZodObject<{
122
132
  type: z__default.ZodLiteral<"text">;
123
133
  text: z__default.ZodString;
134
+ }, z__default.core.$strip>, z__default.ZodObject<{
135
+ type: z__default.ZodLiteral<"markdown">;
136
+ markdown: z__default.ZodString;
124
137
  }, z__default.core.$strip>, z__default.ZodObject<{
125
138
  type: z__default.ZodLiteral<"attachment">;
126
139
  id: z__default.ZodString;
@@ -163,6 +176,9 @@ declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObj
163
176
  } | {
164
177
  type: "text";
165
178
  text: string;
179
+ } | {
180
+ type: "markdown";
181
+ markdown: string;
166
182
  } | {
167
183
  type: "attachment";
168
184
  id: string;
@@ -171,6 +187,10 @@ declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObj
171
187
  read: z__default.core.$InferOuterFunctionType<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>>>;
172
188
  stream: z__default.core.$InferOuterFunctionType<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>>>;
173
189
  size?: number | undefined;
190
+ } | {
191
+ type: "streamText";
192
+ stream: () => AsyncIterable<string>;
193
+ format?: "markdown" | "plain" | undefined;
174
194
  } | {
175
195
  type: "custom";
176
196
  raw: unknown;
@@ -267,6 +287,9 @@ declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObj
267
287
  content: {
268
288
  type: "text";
269
289
  text: string;
290
+ } | {
291
+ type: "markdown";
292
+ markdown: string;
270
293
  } | {
271
294
  type: "attachment";
272
295
  id: string;
@@ -295,6 +318,9 @@ declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObj
295
318
  } | {
296
319
  type: "text";
297
320
  text: string;
321
+ } | {
322
+ type: "markdown";
323
+ markdown: string;
298
324
  } | {
299
325
  type: "attachment";
300
326
  id: string;
@@ -303,6 +329,10 @@ declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObj
303
329
  read: z__default.core.$InferOuterFunctionType<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>>>;
304
330
  stream: z__default.core.$InferOuterFunctionType<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>>>;
305
331
  size?: number | undefined;
332
+ } | {
333
+ type: "streamText";
334
+ stream: () => AsyncIterable<string>;
335
+ format?: "markdown" | "plain" | undefined;
306
336
  } | {
307
337
  type: "custom";
308
338
  raw: unknown;
@@ -399,6 +429,9 @@ declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObj
399
429
  content: {
400
430
  type: "text";
401
431
  text: string;
432
+ } | {
433
+ type: "markdown";
434
+ markdown: string;
402
435
  } | {
403
436
  type: "attachment";
404
437
  id: string;
@@ -431,6 +464,9 @@ declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObj
431
464
  } | {
432
465
  type: "text";
433
466
  text: string;
467
+ } | {
468
+ type: "markdown";
469
+ markdown: string;
434
470
  } | {
435
471
  type: "attachment";
436
472
  id: string;
@@ -439,6 +475,10 @@ declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObj
439
475
  read: z__default.core.$InferOuterFunctionType<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>>>;
440
476
  stream: z__default.core.$InferOuterFunctionType<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>>>;
441
477
  size?: number | undefined;
478
+ } | {
479
+ type: "streamText";
480
+ stream: () => AsyncIterable<string>;
481
+ format?: "markdown" | "plain" | undefined;
442
482
  } | {
443
483
  type: "custom";
444
484
  raw: unknown;
@@ -535,6 +575,9 @@ declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObj
535
575
  content: {
536
576
  type: "text";
537
577
  text: string;
578
+ } | {
579
+ type: "markdown";
580
+ markdown: string;
538
581
  } | {
539
582
  type: "attachment";
540
583
  id: string;
@@ -563,6 +606,9 @@ declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObj
563
606
  } | {
564
607
  type: "text";
565
608
  text: string;
609
+ } | {
610
+ type: "markdown";
611
+ markdown: string;
566
612
  } | {
567
613
  type: "attachment";
568
614
  id: string;
@@ -571,6 +617,10 @@ declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObj
571
617
  read: z__default.core.$InferOuterFunctionType<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>>>;
572
618
  stream: z__default.core.$InferOuterFunctionType<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>>>;
573
619
  size?: number | undefined;
620
+ } | {
621
+ type: "streamText";
622
+ stream: () => AsyncIterable<string>;
623
+ format?: "markdown" | "plain" | undefined;
574
624
  } | {
575
625
  type: "custom";
576
626
  raw: unknown;
@@ -667,6 +717,9 @@ declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObj
667
717
  content: {
668
718
  type: "text";
669
719
  text: string;
720
+ } | {
721
+ type: "markdown";
722
+ markdown: string;
670
723
  } | {
671
724
  type: "attachment";
672
725
  id: string;
@@ -685,6 +738,9 @@ declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObj
685
738
  displayName: string;
686
739
  }>;
687
740
  target: z__default.ZodCustom<Message<string, User, Space<unknown>>, Message<string, User, Space<unknown>>>;
741
+ }, z__default.core.$strip>, z__default.ZodObject<{
742
+ type: z__default.ZodLiteral<"unsend">;
743
+ target: z__default.ZodCustom<Message<string, User, Space<unknown>>, Message<string, User, Space<unknown>>>;
688
744
  }, z__default.core.$strip>], "type">;
689
745
  type Content = z__default.infer<typeof contentSchema>;
690
746
  interface ContentBuilder {
@@ -701,6 +757,43 @@ interface AgentSender extends User {
701
757
  readonly kind: "agent";
702
758
  }
703
759
 
760
+ /**
761
+ * A `ContentBuilder` whose build is statically known to produce `Reaction`
762
+ * content. `space.send` overloads on this so `space.send(reaction(...))`
763
+ * returns a Message with `content` narrowed to `Reaction`, matching
764
+ * `message.react()`.
765
+ */
766
+ interface ReactionBuilder extends ContentBuilder {
767
+ build(): Promise<Reaction>;
768
+ }
769
+ declare const reactionSchema: z__default.ZodObject<{
770
+ type: z__default.ZodLiteral<"reaction">;
771
+ emoji: z__default.ZodString;
772
+ target: z__default.ZodCustom<Message<string, User, Space<unknown>>, Message<string, User, Space<unknown>>>;
773
+ }, z__default.core.$strip>;
774
+ type Reaction = z__default.infer<typeof reactionSchema>;
775
+ declare const asReaction: (input: {
776
+ emoji: string;
777
+ target: Message;
778
+ }) => Reaction;
779
+ /**
780
+ * Construct a `reaction` content value targeting the given message.
781
+ *
782
+ * `space.send(reaction(emoji, message))` is the canonical form of
783
+ * `message.react(emoji)`. It resolves to the reaction `Message`
784
+ * (`content.type === "reaction"`) — keep it as the handle to `unsend()`
785
+ * later. Resolves `undefined` only when the platform does not support
786
+ * reactions (warned and skipped).
787
+ *
788
+ * Accepts `Message | undefined` so `space.send` results chain without
789
+ * narrowing (`send` resolves `undefined` when a platform skips unsupported
790
+ * content); an undefined target throws at build time.
791
+ *
792
+ * To react to a message known only by id, resolve it first via
793
+ * `space.getMessage(id)`.
794
+ */
795
+ declare function reaction(emoji: string, target: Message | undefined): ReactionBuilder;
796
+
704
797
  interface Space<_Def = unknown> {
705
798
  readonly __platform: string;
706
799
  /**
@@ -725,7 +818,12 @@ interface Space<_Def = unknown> {
725
818
  avatar(input: Buffer, options: {
726
819
  mimeType: string;
727
820
  }): Promise<void>;
728
- edit(message: Message, newContent: ContentInput): Promise<void>;
821
+ /**
822
+ * Rewrite a previously-sent outbound message. Sugar for
823
+ * `send(edit(newContent, message))`. Accepts `Message | undefined` so
824
+ * `send` results chain without narrowing; an undefined target throws.
825
+ */
826
+ edit(message: Message | undefined, newContent: ContentInput): Promise<void>;
729
827
  /**
730
828
  * Look up a message in this space by its id. Returns `undefined` if the
731
829
  * platform has no way to resolve the id (e.g. cache miss with no by-id
@@ -742,10 +840,25 @@ interface Space<_Def = unknown> {
742
840
  */
743
841
  rename(displayName: string): Promise<void>;
744
842
  responding<T>(fn: () => T | Promise<T>): Promise<T>;
843
+ /**
844
+ * A reaction send resolves to the reaction Message (`content` narrowed to
845
+ * `Reaction`) — the handle to `unsend()` later. Listed before the general
846
+ * overload so `send(reaction(...))` picks it; every other `ContentBuilder`
847
+ * fails the `ReactionBuilder` shape and falls through.
848
+ */
849
+ send(content: ReactionBuilder): Promise<(Message<string, AgentSender> & {
850
+ content: Reaction;
851
+ }) | undefined>;
745
852
  send(content: ContentInput): Promise<Message<string, AgentSender> | undefined>;
746
853
  send(...content: [ContentInput, ContentInput, ...ContentInput[]]): Promise<Message<string, AgentSender>[]>;
747
854
  startTyping(): Promise<void>;
748
855
  stopTyping(): Promise<void>;
856
+ /**
857
+ * Retract a previously-sent outbound message. Sugar for
858
+ * `send(unsend(message))`. Accepts `Message | undefined` so `send`
859
+ * results chain without narrowing; an undefined target throws.
860
+ */
861
+ unsend(message: Message | undefined): Promise<void>;
749
862
  }
750
863
 
751
864
  interface Message<TPlatform extends string = string, TSender extends User = User, TSpace extends Space = Space> {
@@ -754,12 +867,34 @@ interface Message<TPlatform extends string = string, TSender extends User = User
754
867
  edit(newContent: ContentInput): Promise<void>;
755
868
  readonly id: string;
756
869
  platform: TPlatform;
757
- react(reaction: string): Promise<void>;
870
+ /**
871
+ * React to this message. Resolves to the reaction `Message` (content
872
+ * narrowed to `Reaction`) — keep it as the handle to `unsend()` later.
873
+ * Resolves `undefined` when the platform does not support reactions
874
+ * (warned and skipped).
875
+ *
876
+ * The return type is an inline intersection rather than a `TContent`
877
+ * generic on `Message`: a content type parameter would need `Content` as
878
+ * its default, and `Content`'s schemas (`reaction`, `reply`, `edit`,
879
+ * `group`) reference `Message` — TS rejects the resulting circular
880
+ * default (TS2716).
881
+ */
882
+ react(reaction: string): Promise<(Message<TPlatform, AgentSender, TSpace> & {
883
+ content: Reaction;
884
+ }) | undefined>;
758
885
  reply(content: ContentInput): Promise<Message<TPlatform, AgentSender, TSpace> | undefined>;
759
886
  reply(...content: [ContentInput, ContentInput, ...ContentInput[]]): Promise<Message<TPlatform, AgentSender, TSpace>[]>;
760
887
  sender: TSender | undefined;
761
888
  space: TSpace;
762
889
  timestamp: Date;
890
+ /**
891
+ * Retract this message. Sugar for `space.send(unsend(this))`. Unsends are
892
+ * fire-and-forget; per-platform support and constraints (e.g. iMessage's
893
+ * ~2-minute unsend window for regular messages) surface from the
894
+ * provider's send action. Only outbound messages can be unsent; calling
895
+ * this on an inbound message throws.
896
+ */
897
+ unsend(): Promise<void>;
763
898
  }
764
899
 
765
900
  type SubscriptionStatus = "active" | "canceled" | "past_due";
@@ -823,6 +958,12 @@ interface ProjectData {
823
958
  id: string;
824
959
  name: string;
825
960
  profile: ProjectProfile;
961
+ /**
962
+ * URL-safe project identifier (e.g. `what-c62a6`). Used as the subdomain of
963
+ * the Fusor "super webhook" edge a platform registers its provider webhook
964
+ * against — see Telegram's `webhookUrl`.
965
+ */
966
+ slug: string;
826
967
  }
827
968
  declare class SpectrumCloudError extends Error {
828
969
  readonly status: number;
@@ -883,7 +1024,7 @@ declare function broadcast<T>(source: ManagedStream<T>): Broadcaster<T>;
883
1024
  * through `space.send(...)`, call the underlying SDK, or perform any other
884
1025
  * side effect.
885
1026
  *
886
- * Names that collide with reserved `Space` keys (`send`, `edit`,
1027
+ * Names that collide with reserved `Space` keys (`send`, `edit`, `unsend`,
887
1028
  * `getMessage`, `startTyping`, `stopTyping`, `responding`, `id`,
888
1029
  * `__platform`) are skipped at runtime with a warning and excluded at the
889
1030
  * type level via `Exclude<…, keyof Space>`.
@@ -897,9 +1038,9 @@ type SpaceActionFn = (space: Space, ...args: never[]) => Promise<void>;
897
1038
  * SDK, or perform any other side effect.
898
1039
  *
899
1040
  * Names that collide with reserved `Message` keys (`react`, `reply`, `edit`,
900
- * `id`, `space`, `sender`, `content`, `platform`, `direction`, `timestamp`)
901
- * are skipped at runtime with a warning and excluded at the type level via
902
- * `Exclude<…, keyof Message>`.
1041
+ * `unsend`, `id`, `space`, `sender`, `content`, `platform`, `direction`,
1042
+ * `timestamp`) are skipped at runtime with a warning and excluded at the
1043
+ * type level via `Exclude<…, keyof Message>`.
903
1044
  */
904
1045
  type MessageActionFn = (message: Message, ...args: never[]) => Promise<void>;
905
1046
  /**
@@ -1010,10 +1151,17 @@ type ProviderMessageRecord = {
1010
1151
  } & Record<string, unknown>;
1011
1152
  type MergeSchema<TSchema extends z__default.ZodType | undefined, TBase extends object> = TSchema extends z__default.ZodType ? string extends keyof z__default.infer<TSchema> ? TBase : Omit<z__default.infer<TSchema>, keyof TBase> & TBase : TBase;
1012
1153
  type SchemaMessage<TUserSchema extends z__default.ZodType | undefined = undefined, TSpaceSchema extends z__default.ZodType | undefined = undefined> = ProviderMessage<MergeSchema<TUserSchema, ResolvedUser>, MergeSchema<TSpaceSchema, ResolvedSpace>>;
1013
- type InferEventPayload<T> = T extends (ctx: never) => AsyncIterable<infer P> ? P : never;
1154
+ type InferEventPayload<T> = T extends z__default.ZodType ? z__default.infer<T> : T extends (ctx: never) => AsyncIterable<infer P> ? P : never;
1014
1155
  type ReservedNames = "stop" | "send" | "config" | "__internal" | "__providers";
1015
1156
  interface CreateClientContext<_ConfigSchema extends z__default.ZodType<object>> {
1016
1157
  config: z__default.infer<_ConfigSchema>;
1158
+ /**
1159
+ * The resolved cloud project record (slug, profile, …) when `Spectrum()` runs
1160
+ * with `projectId` + `projectSecret`; `undefined` in local/direct mode. Lets
1161
+ * `createClient` self-register provider webhooks against the Fusor edge keyed
1162
+ * by `projectConfig.slug` — see Telegram.
1163
+ */
1164
+ projectConfig: ProjectData | undefined;
1017
1165
  projectId: string | undefined;
1018
1166
  projectSecret: string | undefined;
1019
1167
  store: Store;
@@ -1034,7 +1182,7 @@ interface CreateClientContext<_ConfigSchema extends z__default.ZodType<object>>
1034
1182
  * Minimum viable platform integration:
1035
1183
  * `name`, `config`, `lifecycle`, `user`, `space`, `messages`, `send`.
1036
1184
  */
1037
- interface PlatformDef<_Name extends string = string, _ConfigSchema extends z__default.ZodType<object> = z__default.ZodType<object>, _UserSchema extends z__default.ZodType<object> | undefined = undefined, _SpaceSchema extends z__default.ZodType<object> | undefined = undefined, _SpaceParamsSchema extends z__default.ZodType<object> | undefined = undefined, _Client = unknown, _ResolvedUser extends ResolvedUser = ResolvedUser, _ResolvedSpace extends ResolvedSpace = ResolvedSpace, _MessageSchema extends z__default.ZodType<object> | undefined = undefined, _MessageType extends ProviderMessage<_ResolvedUser, _ResolvedSpace, InferSchema<_MessageSchema>> = ProviderMessage<_ResolvedUser, _ResolvedSpace, InferSchema<_MessageSchema>>, _Events extends (Record<string, EventProducer<unknown, _Client, z__default.infer<_ConfigSchema>>> & {
1185
+ interface PlatformDef<_Name extends string = string, _ConfigSchema extends z__default.ZodType<object> = z__default.ZodType<object>, _UserSchema extends z__default.ZodType<object> | undefined = undefined, _SpaceSchema extends z__default.ZodType<object> | undefined = undefined, _SpaceParamsSchema extends z__default.ZodType<object> | undefined = undefined, _Client = unknown, _ResolvedUser extends ResolvedUser = ResolvedUser, _ResolvedSpace extends ResolvedSpace = ResolvedSpace, _MessageSchema extends z__default.ZodType<object> | undefined = undefined, _MessageType extends ProviderMessage<_ResolvedUser, _ResolvedSpace, InferSchema<_MessageSchema>> = ProviderMessage<_ResolvedUser, _ResolvedSpace, InferSchema<_MessageSchema>>, _Events extends (Record<string, EventProducer<unknown, _Client, z__default.infer<_ConfigSchema>> | z__default.ZodType<object>> & {
1038
1186
  messages?: never;
1039
1187
  }) | undefined = undefined, _SpaceActions extends Record<string, SpaceActionFn> = Record<never, never>, _MessageActions extends Record<string, MessageActionFn> = Record<never, never>, _Actions extends Record<string, InstanceActionFn> = Record<never, never>> {
1040
1188
  /**
@@ -1128,8 +1276,10 @@ interface PlatformDef<_Name extends string = string, _ConfigSchema extends z__de
1128
1276
  * through this single action.
1129
1277
  *
1130
1278
  * Returns a `ProviderMessageRecord` (id + timestamp) for content that
1131
- * produces a message; returns `undefined` for fire-and-forget control
1132
- * signals (reactions, typing, edits) on platforms that don't return ids.
1279
+ * produces a message including reactions, whose record is the unsend
1280
+ * handle (synthesize a deterministic id when the platform assigns none);
1281
+ * returns `undefined` only for fire-and-forget control signals (typing,
1282
+ * edits, renames, avatars, unsends) on platforms that don't return ids.
1133
1283
  *
1134
1284
  * One of the two universal platform contracts (along with `messages`).
1135
1285
  */
@@ -1143,7 +1293,7 @@ interface PlatformDef<_Name extends string = string, _ConfigSchema extends z__de
1143
1293
  space: {
1144
1294
  schema?: _SpaceSchema;
1145
1295
  params?: _SpaceParamsSchema;
1146
- resolve: (_: {
1296
+ create: (_: {
1147
1297
  input: {
1148
1298
  users: (_ResolvedUser & {
1149
1299
  __platform: _Name;
@@ -1154,6 +1304,21 @@ interface PlatformDef<_Name extends string = string, _ConfigSchema extends z__de
1154
1304
  config: z__default.infer<_ConfigSchema>;
1155
1305
  store: Store;
1156
1306
  }) => Promise<_ResolvedSpace>;
1307
+ /**
1308
+ * Optional: hydrate a space from a known platform space id. When absent,
1309
+ * the framework builds the candidate `{ id }` and validates it against
1310
+ * `space.schema` — providers whose schema requires more fields must
1311
+ * implement this.
1312
+ */
1313
+ get?: (_: {
1314
+ input: {
1315
+ id: string;
1316
+ params?: _SpaceParamsSchema extends z__default.ZodType<object> ? z__default.infer<_SpaceParamsSchema> : undefined;
1317
+ };
1318
+ client: NoInferClient<_Client>;
1319
+ config: z__default.infer<_ConfigSchema>;
1320
+ store: Store;
1321
+ }) => Promise<_ResolvedSpace>;
1157
1322
  /**
1158
1323
  * Optional platform-specific methods bound to `PlatformSpace<Def>`.
1159
1324
  *
@@ -1169,9 +1334,9 @@ interface PlatformDef<_Name extends string = string, _ConfigSchema extends z__de
1169
1334
  * lives here for platform-specific surface area.
1170
1335
  *
1171
1336
  * Names that collide with reserved `Space` keys (`send`, `edit`,
1172
- * `getMessage`, `startTyping`, `stopTyping`, `responding`, `id`,
1173
- * `__platform`) are skipped at runtime with a warning and excluded at
1174
- * the type level.
1337
+ * `unsend`, `getMessage`, `startTyping`, `stopTyping`, `responding`,
1338
+ * `id`, `__platform`) are skipped at runtime with a warning and excluded
1339
+ * at the type level.
1175
1340
  */
1176
1341
  actions?: _SpaceActions;
1177
1342
  };
@@ -1191,7 +1356,7 @@ interface AnyPlatformDef {
1191
1356
  actions?: Record<string, InstanceActionFn>;
1192
1357
  config: z__default.ZodType<object>;
1193
1358
  events?: {
1194
- [key: string]: (ctx: any) => AsyncIterable<any>;
1359
+ [key: string]: ((ctx: any) => AsyncIterable<any>) | z__default.ZodType<object>;
1195
1360
  };
1196
1361
  lifecycle: {
1197
1362
  createClient: (ctx: any) => Promise<any>;
@@ -1207,7 +1372,8 @@ interface AnyPlatformDef {
1207
1372
  space: {
1208
1373
  schema?: z__default.ZodType<object>;
1209
1374
  params?: z__default.ZodType<object>;
1210
- resolve: (_: any) => Promise<any>;
1375
+ create: (_: any) => Promise<any>;
1376
+ get?: (_: any) => Promise<any>;
1211
1377
  actions?: Record<string, SpaceActionFn>;
1212
1378
  };
1213
1379
  user: {
@@ -1249,21 +1415,31 @@ type UnifiedCustomEvent<Providers extends PlatformProviderConfig[], EventName ex
1249
1415
  type CustomEventStreams<Providers extends PlatformProviderConfig[]> = {
1250
1416
  [K in Exclude<AllCustomEventNames<Providers>, ReservedNames> & string]: AsyncIterable<UnifiedCustomEvent<Providers, K>>;
1251
1417
  };
1252
- type ResolvedSpaceOf<Def extends AnyPlatformDef> = AwaitedReturn<Def["space"]["resolve"]>;
1418
+ type ResolvedSpaceOf<Def extends AnyPlatformDef> = AwaitedReturn<Def["space"]["create"]>;
1253
1419
  type SchemaSpaceOf<Def extends AnyPlatformDef> = InferOptionalSchema<Def["space"]["schema"]>;
1254
1420
  type ResolvedUserOf<Def extends AnyPlatformDef> = AwaitedReturn<Def["user"]["resolve"]>;
1255
1421
  type SpaceShapeOf<Def extends AnyPlatformDef> = [SchemaSpaceOf<Def>] extends [
1256
1422
  never
1257
1423
  ] ? ResolvedSpaceOf<Def> : SchemaSpaceOf<Def>;
1258
- type SpaceParamsInputOf<Def extends AnyPlatformDef> = InputSchema<Def["space"]["params"]>;
1424
+ type SpaceParamsInputOf<Def extends AnyPlatformDef> = z__default.ZodType<object> extends Def["space"]["params"] ? never : InputSchema<Def["space"]["params"]>;
1259
1425
  type SpaceUserLike<Def extends AnyPlatformDef> = PlatformUser<Def> | string;
1260
- type SpaceArrayArgs<Def extends AnyPlatformDef> = [
1261
- SpaceParamsInputOf<Def>
1262
- ] extends [never] ? [users: SpaceUserLike<Def>[]] : [users: SpaceUserLike<Def>[]] | [users: SpaceUserLike<Def>[], params: SpaceParamsInputOf<Def>] | [params: SpaceParamsInputOf<Def>];
1263
- type SpaceVarargArgs<Def extends AnyPlatformDef> = [
1426
+ type SpaceParamsArgs<Def extends AnyPlatformDef> = [
1264
1427
  SpaceParamsInputOf<Def>
1265
- ] extends [never] ? SpaceUserLike<Def>[] : SpaceUserLike<Def>[] | [...SpaceUserLike<Def>[], SpaceParamsInputOf<Def>];
1266
- type SpaceArgs<Def extends AnyPlatformDef> = SpaceArrayArgs<Def> | SpaceVarargArgs<Def>;
1428
+ ] extends [never] ? [] : Record<string, never> extends SpaceParamsInputOf<Def> ? [params?: SpaceParamsInputOf<Def>] : [params: SpaceParamsInputOf<Def>];
1429
+ interface SpaceNamespace<Def extends AnyPlatformDef> {
1430
+ /**
1431
+ * Resolve or create a space from its participants — a single user (1:1
1432
+ * conversation) or several (group, where the platform supports it). Users
1433
+ * may be raw id strings or previously resolved `PlatformUser`s.
1434
+ */
1435
+ create(users: SpaceUserLike<Def> | SpaceUserLike<Def>[], ...params: SpaceParamsArgs<Def>): Promise<PlatformSpace<Def>>;
1436
+ /**
1437
+ * Construct a space from a known platform space id — e.g. one persisted
1438
+ * from an earlier event. Providers may hydrate platform-specific fields
1439
+ * (or verify existence) via their `space.get` hook.
1440
+ */
1441
+ get(id: string, ...params: SpaceParamsArgs<Def>): Promise<PlatformSpace<Def>>;
1442
+ }
1267
1443
  type SpaceActionFns<Def extends AnyPlatformDef> = Def["space"] extends {
1268
1444
  actions?: infer A;
1269
1445
  } ? A extends Record<string, SpaceActionFn> ? A : Record<string, never> : Record<string, never>;
@@ -1294,7 +1470,7 @@ type PlatformMessage<Def extends AnyPlatformDef> = Omit<SchemaInfer<Def["message
1294
1470
  type PlatformUser<Def extends AnyPlatformDef> = Omit<ResolvedUserOf<Def>, keyof User> & User;
1295
1471
  type PlatformInstance<Def extends AnyPlatformDef> = {
1296
1472
  readonly messages: AsyncIterable<[PlatformSpace<Def>, PlatformMessage<Def>]>;
1297
- space(...args: SpaceArgs<Def>): Promise<PlatformSpace<Def>>;
1473
+ readonly space: SpaceNamespace<Def>;
1298
1474
  user(userID: string): Promise<PlatformUser<Def>>;
1299
1475
  } & CustomEventInstanceProperties<Def> & PlatformWiseInstanceMethods<Def> & InstanceActionMethods<Def>;
1300
1476
  type CustomEventInstanceProperties<Def extends AnyPlatformDef> = Def["events"] extends Record<string, unknown> ? {
@@ -1304,7 +1480,9 @@ interface PlatformRuntime {
1304
1480
  client: unknown;
1305
1481
  config: unknown;
1306
1482
  definition: AnyPlatformDef;
1483
+ projectConfig: ProjectData | undefined;
1307
1484
  store: Store;
1485
+ subscribeEvent?: (channel: string) => AsyncIterable<unknown> | undefined;
1308
1486
  subscribeMessages: () => ManagedStream<[Space, Message]>;
1309
1487
  }
1310
1488
  interface SpectrumLike<Providers extends PlatformProviderConfig[] = PlatformProviderConfig[]> {
@@ -1323,4 +1501,4 @@ interface Platform<Def extends AnyPlatformDef> {
1323
1501
  (message: Message): PlatformMessage<Def>;
1324
1502
  }
1325
1503
 
1326
- export { type AgentSender as A, type Broadcaster as B, type ContentBuilder as C, type DedicatedTokenData as D, type EventProducer as E, type FusorTokenData as F, type SharedTokenData as G, type SlackTeamMeta as H, type InstanceActionFn as I, type SlackTokenData as J, SpectrumCloudError as K, type SubscriptionData as L, type Message as M, type SubscriptionStatus as N, broadcast as O, type Platform as P, cloud as Q, mergeStreams as R, type SchemaMessage as S, type TokenData as T, type User as U, stream as V, type PlatformDef as a, type Space as b, type ContentInput as c, type Store as d, type Content as e, type ProviderMessageRecord as f, type SpaceActionFn as g, type MessageActionFn as h, type CreateClientContext as i, type ProviderMessage as j, type PlatformProviderConfig as k, type SpectrumLike as l, type CustomEventStreams as m, type ProjectData as n, type AnyPlatformDef as o, type CloudPlatform as p, type ImessageInfoData as q, type ManagedStream as r, type PlatformInstance as s, type PlatformMessage as t, type PlatformRuntime as u, type PlatformSpace as v, type PlatformStatus as w, type PlatformUser as x, type PlatformsData as y, type ProjectProfile as z };
1504
+ export { asReaction as $, type AgentSender as A, type Broadcaster as B, type ContentBuilder as C, type DedicatedTokenData as D, type EventProducer as E, type FusorTokenData as F, type ProjectProfile as G, type ReactionBuilder as H, type InstanceActionFn as I, type SharedTokenData as J, type SlackTeamMeta as K, type SlackTokenData as L, type Message as M, type SpaceNamespace as N, SpectrumCloudError as O, type Platform as P, type SubscriptionData as Q, type Reaction as R, type SchemaMessage as S, type SubscriptionStatus as T, type User as U, type TokenData as V, broadcast as W, cloud as X, mergeStreams as Y, reaction as Z, stream as _, type PlatformDef as a, type ProjectData as b, type Store as c, type ProviderMessageRecord as d, type Space as e, contentSchema as f, type ProviderMessage as g, type ContentInput as h, type Content as i, type SpaceActionFn as j, type MessageActionFn as k, type CreateClientContext as l, type PlatformProviderConfig as m, type SpectrumLike as n, type CustomEventStreams as o, type AnyPlatformDef as p, type CloudPlatform as q, type ImessageInfoData as r, type ManagedStream as s, type PlatformInstance as t, type PlatformMessage as u, type PlatformRuntime as v, type PlatformSpace as w, type PlatformStatus as x, type PlatformUser as y, type PlatformsData as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spectrum-ts",
3
- "version": "1.18.0",
3
+ "version": "3.0.0",
4
4
  "description": "Bring agents to any interface — unified messaging SDK for TypeScript.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -42,11 +42,13 @@
42
42
  "@photon-ai/imessage-kit": "^3.0.0",
43
43
  "@photon-ai/otel": "^0.1.1",
44
44
  "@photon-ai/slack": "^0.2.0",
45
+ "@photon-ai/telegram-ts": "10.0.0",
45
46
  "@photon-ai/whatsapp-business": "^0.1.1",
46
47
  "@photon-ai/proto": "^0.2.4",
47
48
  "@repeaterjs/repeater": "^3.0.6",
48
49
  "better-grpc": "^0.3.2",
49
50
  "lru-cache": "^11.0.0",
51
+ "marked": "^18.0.5",
50
52
  "mime-types": "^3.0.1",
51
53
  "nice-grpc": "^2.1.16",
52
54
  "nice-grpc-common": "^2.0.2",