spectrum-ts 1.9.2 → 1.11.3

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.
@@ -91,10 +91,10 @@ declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObj
91
91
  }, z__default.core.$strip>, z__default.ZodObject<{
92
92
  type: z__default.ZodLiteral<"reaction">;
93
93
  emoji: z__default.ZodString;
94
- target: z__default.ZodCustom<Message, Message>;
94
+ target: z__default.ZodCustom<Message<string, User, Space<unknown>>, Message<string, User, Space<unknown>>>;
95
95
  }, z__default.core.$strip>, z__default.ZodObject<{
96
96
  type: z__default.ZodLiteral<"group">;
97
- items: z__default.ZodArray<z__default.ZodCustom<Message, Message>>;
97
+ items: z__default.ZodArray<z__default.ZodCustom<Message<string, User, Space<unknown>>, Message<string, User, Space<unknown>>>>;
98
98
  }, z__default.core.$strip>, z__default.ZodObject<{
99
99
  type: z__default.ZodLiteral<"poll">;
100
100
  title: z__default.ZodString;
@@ -214,10 +214,10 @@ declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObj
214
214
  } | {
215
215
  type: "reaction";
216
216
  emoji: string;
217
- target: Message;
217
+ target: Message<string, User, Space<unknown>>;
218
218
  } | {
219
219
  type: "group";
220
- items: Message[];
220
+ items: Message<string, User, Space<unknown>>[];
221
221
  } | {
222
222
  type: "poll";
223
223
  title: string;
@@ -332,10 +332,10 @@ declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObj
332
332
  } | {
333
333
  type: "reaction";
334
334
  emoji: string;
335
- target: Message;
335
+ target: Message<string, User, Space<unknown>>;
336
336
  } | {
337
337
  type: "group";
338
- items: Message[];
338
+ items: Message<string, User, Space<unknown>>[];
339
339
  } | {
340
340
  type: "poll";
341
341
  title: string;
@@ -374,7 +374,7 @@ declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObj
374
374
  type: "typing";
375
375
  state: "start" | "stop";
376
376
  }>;
377
- target: z__default.ZodCustom<Message, Message>;
377
+ target: z__default.ZodCustom<Message<string, User, Space<unknown>>, Message<string, User, Space<unknown>>>;
378
378
  }, z__default.core.$strip>, z__default.ZodObject<{
379
379
  type: z__default.ZodLiteral<"edit">;
380
380
  content: z__default.ZodCustom<{
@@ -454,10 +454,10 @@ declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObj
454
454
  } | {
455
455
  type: "reaction";
456
456
  emoji: string;
457
- target: Message;
457
+ target: Message<string, User, Space<unknown>>;
458
458
  } | {
459
459
  type: "group";
460
- items: Message[];
460
+ items: Message<string, User, Space<unknown>>[];
461
461
  } | {
462
462
  type: "poll";
463
463
  title: string;
@@ -572,10 +572,10 @@ declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObj
572
572
  } | {
573
573
  type: "reaction";
574
574
  emoji: string;
575
- target: Message;
575
+ target: Message<string, User, Space<unknown>>;
576
576
  } | {
577
577
  type: "group";
578
- items: Message[];
578
+ items: Message<string, User, Space<unknown>>[];
579
579
  } | {
580
580
  type: "poll";
581
581
  title: string;
@@ -614,7 +614,7 @@ declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObj
614
614
  type: "typing";
615
615
  state: "start" | "stop";
616
616
  }>;
617
- target: z__default.ZodCustom<Message, Message>;
617
+ target: z__default.ZodCustom<Message<string, User, Space<unknown>>, Message<string, User, Space<unknown>>>;
618
618
  }, z__default.core.$strip>], "type">;
619
619
  type Content = z__default.infer<typeof contentSchema>;
620
620
  interface ContentBuilder {
@@ -625,11 +625,15 @@ type ContentInput = string | ContentBuilder;
625
625
  interface User {
626
626
  readonly __platform: string;
627
627
  readonly id: string;
628
+ readonly kind?: "agent";
629
+ }
630
+ interface AgentSender extends User {
631
+ readonly kind: "agent";
628
632
  }
629
633
 
630
634
  interface Space<_Def = unknown> {
631
635
  readonly __platform: string;
632
- edit(message: OutboundMessage, newContent: ContentInput): Promise<void>;
636
+ edit(message: Message, newContent: ContentInput): Promise<void>;
633
637
  /**
634
638
  * Look up a message in this space by its id. Returns `undefined` if the
635
639
  * platform has no way to resolve the id (e.g. cache miss with no by-id
@@ -639,32 +643,25 @@ interface Space<_Def = unknown> {
639
643
  getMessage(id: string): Promise<Message | undefined>;
640
644
  readonly id: string;
641
645
  responding<T>(fn: () => T | Promise<T>): Promise<T>;
642
- send(content: ContentInput): Promise<OutboundMessage | undefined>;
643
- send(...content: [ContentInput, ContentInput, ...ContentInput[]]): Promise<OutboundMessage[]>;
646
+ send(content: ContentInput): Promise<Message<string, AgentSender> | undefined>;
647
+ send(...content: [ContentInput, ContentInput, ...ContentInput[]]): Promise<Message<string, AgentSender>[]>;
644
648
  startTyping(): Promise<void>;
645
649
  stopTyping(): Promise<void>;
646
650
  }
647
651
 
648
- interface BaseMessage<TPlatform extends string = string, TSender extends User = User, TSpace extends Space = Space> {
652
+ interface Message<TPlatform extends string = string, TSender extends User = User, TSpace extends Space = Space> {
649
653
  content: Content;
654
+ direction: "inbound" | "outbound";
655
+ edit(newContent: ContentInput): Promise<void>;
650
656
  readonly id: string;
651
657
  platform: TPlatform;
652
658
  react(reaction: string): Promise<void>;
653
- reply(content: ContentInput): Promise<OutboundMessage<TPlatform, TSender, TSpace> | undefined>;
654
- reply(...content: [ContentInput, ContentInput, ...ContentInput[]]): Promise<OutboundMessage<TPlatform, TSender, TSpace>[]>;
659
+ reply(content: ContentInput): Promise<Message<TPlatform, AgentSender, TSpace> | undefined>;
660
+ reply(...content: [ContentInput, ContentInput, ...ContentInput[]]): Promise<Message<TPlatform, AgentSender, TSpace>[]>;
661
+ sender: TSender | undefined;
655
662
  space: TSpace;
656
663
  timestamp: Date;
657
664
  }
658
- interface InboundMessage<TPlatform extends string = string, TSender extends User = User, TSpace extends Space = Space> extends BaseMessage<TPlatform, TSender, TSpace> {
659
- direction: "inbound";
660
- sender: TSender;
661
- }
662
- interface OutboundMessage<TPlatform extends string = string, TSender extends User = User, TSpace extends Space = Space> extends BaseMessage<TPlatform, TSender, TSpace> {
663
- direction: "outbound";
664
- edit(newContent: ContentInput): Promise<void>;
665
- sender: TSender | undefined;
666
- }
667
- type Message<TPlatform extends string = string, TSender extends User = User, TSpace extends Space = Space> = InboundMessage<TPlatform, TSender, TSpace> | OutboundMessage<TPlatform, TSender, TSpace>;
668
665
 
669
666
  /**
670
667
  * A small per-platform key-value bag, modeled after Swift's `UserDefaults`.
@@ -702,16 +699,31 @@ interface Broadcaster<T> {
702
699
  declare function broadcast<T>(source: ManagedStream<T>): Broadcaster<T>;
703
700
 
704
701
  /**
705
- * A platform-defined sugar method on `Space`. Each entry is a content-builder
706
- * factory; the runtime injects a thin wrapper that calls
707
- * `space.send(factory(...args))` and returns the result.
702
+ * A platform-defined method on `Space`. The first parameter is bound to the
703
+ * built `Space` at construction time, so callers only pass the trailing args.
704
+ * Actions are plain functions returning `Promise<void>` they can delegate
705
+ * through `space.send(...)`, call the underlying SDK, or perform any other
706
+ * side effect.
708
707
  *
709
708
  * Names that collide with reserved `Space` keys (`send`, `edit`,
710
709
  * `getMessage`, `startTyping`, `stopTyping`, `responding`, `id`,
711
710
  * `__platform`) are skipped at runtime with a warning and excluded at the
712
711
  * type level via `Exclude<…, keyof Space>`.
713
712
  */
714
- type SpaceActionFactory = (...args: never[]) => ContentBuilder;
713
+ type SpaceActionFn = (space: Space, ...args: never[]) => Promise<void>;
714
+ /**
715
+ * A platform-defined method on `Message`. The first parameter is bound to
716
+ * the message itself (`self`) at build time, so callers only pass the
717
+ * trailing args. Actions are plain functions returning `Promise<void>` —
718
+ * they can delegate through `message.space.send(...)`, call the underlying
719
+ * SDK, or perform any other side effect.
720
+ *
721
+ * Names that collide with reserved `Message` keys (`react`, `reply`, `edit`,
722
+ * `id`, `space`, `sender`, `content`, `platform`, `direction`, `timestamp`)
723
+ * are skipped at runtime with a warning and excluded at the type level via
724
+ * `Exclude<…, keyof Message>`.
725
+ */
726
+ type MessageActionFn = (message: Message, ...args: never[]) => Promise<void>;
715
727
  type ResolvedSpace = Pick<Space, "id">;
716
728
  type SpaceRef = Pick<Space, "id" | "__platform">;
717
729
  type ResolvedUser = Pick<User, "id">;
@@ -785,7 +797,7 @@ interface CreateClientContext<_ConfigSchema extends z__default.ZodType<object>>
785
797
  */
786
798
  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>>> & {
787
799
  messages?: never;
788
- }) | undefined = undefined> {
800
+ }) | undefined = undefined, _SpaceActions extends Record<string, SpaceActionFn> = Record<never, never>, _MessageActions extends Record<string, MessageActionFn> = Record<never, never>> {
789
801
  /**
790
802
  * Optional escape hatch: platform actions beyond `send`. Currently the
791
803
  * framework recognizes one slot:
@@ -829,6 +841,26 @@ interface PlatformDef<_Name extends string = string, _ConfigSchema extends z__de
829
841
  };
830
842
  message?: {
831
843
  schema?: _MessageSchema;
844
+ /**
845
+ * Optional platform-specific sugar methods bound to `PlatformMessage<Def>`.
846
+ *
847
+ * Each entry is a `ContentBuilder` factory whose **first parameter** is
848
+ * the message itself (`self`); `buildMessage` injects a thin wrapper
849
+ * that supplies `self` and calls `space.send(factory(self, ...args))`.
850
+ * The wrapper is typed as `(...args) => Promise<void>` on
851
+ * `PlatformMessage<Def>` via `MessageActionMethods<Def>`.
852
+ *
853
+ * Mirrors `space.actions` — `space.actions` lives on the space slot for
854
+ * chat-level sugar (e.g. `space.background(...)`); `message.actions`
855
+ * lives here for per-message sugar that needs `self` (e.g.
856
+ * `message.read()`).
857
+ *
858
+ * Names that collide with reserved `Message` keys (`react`, `reply`,
859
+ * `edit`, `id`, `space`, `sender`, `content`, `platform`, `direction`,
860
+ * `timestamp`) are skipped at runtime with a warning and excluded at
861
+ * the type level.
862
+ */
863
+ actions?: _MessageActions;
832
864
  };
833
865
  /**
834
866
  * Inbound message stream. Returns an `AsyncIterable<ProviderMessageRecord>`
@@ -874,23 +906,25 @@ interface PlatformDef<_Name extends string = string, _ConfigSchema extends z__de
874
906
  store: Store;
875
907
  }) => Promise<_ResolvedSpace>;
876
908
  /**
877
- * Optional platform-specific sugar methods bound to `PlatformSpace<Def>`.
909
+ * Optional platform-specific methods bound to `PlatformSpace<Def>`.
878
910
  *
879
- * Each entry is a `ContentBuilder` factory; `buildSpace` injects a thin
880
- * wrapper that calls `space.send(factory(...args))`. The wrapper is
881
- * typed as `(...args) => Promise<OutboundMessage | undefined>` on
882
- * `PlatformSpace<Def>` via `SpaceActionMethods<Def>`.
911
+ * Each entry is a plain async function `(space, ...args) => Promise<void>`;
912
+ * `buildSpace` injects the built `PlatformSpace<Def>` as the first
913
+ * argument and exposes the trailing args as the public surface. Action
914
+ * implementations choose how to dispatch — `space.send(...)`, a direct
915
+ * SDK call, or any other side effect — and always return `Promise<void>`
916
+ * to callers.
883
917
  *
884
918
  * Mirrors the top-level `PlatformDef.actions` slot — `actions` lives at
885
919
  * the platform level for capabilities (e.g. `getMessage`); `space.actions`
886
- * lives here for sugar that delegates through `send`.
920
+ * lives here for platform-specific surface area.
887
921
  *
888
922
  * Names that collide with reserved `Space` keys (`send`, `edit`,
889
923
  * `getMessage`, `startTyping`, `stopTyping`, `responding`, `id`,
890
924
  * `__platform`) are skipped at runtime with a warning and excluded at
891
925
  * the type level.
892
926
  */
893
- actions?: Record<string, SpaceActionFactory>;
927
+ actions?: _SpaceActions;
894
928
  };
895
929
  user: {
896
930
  schema?: _UserSchema;
@@ -918,6 +952,7 @@ interface AnyPlatformDef {
918
952
  };
919
953
  message?: {
920
954
  schema?: z__default.ZodType<object>;
955
+ actions?: Record<string, MessageActionFn>;
921
956
  };
922
957
  messages: (ctx: any) => AsyncIterable<any>;
923
958
  name: string;
@@ -926,7 +961,7 @@ interface AnyPlatformDef {
926
961
  schema?: z__default.ZodType<object>;
927
962
  params?: z__default.ZodType<object>;
928
963
  resolve: (_: any) => Promise<any>;
929
- actions?: Record<string, SpaceActionFactory>;
964
+ actions?: Record<string, SpaceActionFn>;
930
965
  };
931
966
  user: {
932
967
  schema?: z__default.ZodType<object>;
@@ -982,21 +1017,27 @@ type SpaceVarargArgs<Def extends AnyPlatformDef> = [
982
1017
  SpaceParamsInputOf<Def>
983
1018
  ] extends [never] ? SpaceUserLike<Def>[] : SpaceUserLike<Def>[] | [...SpaceUserLike<Def>[], SpaceParamsInputOf<Def>];
984
1019
  type SpaceArgs<Def extends AnyPlatformDef> = SpaceArrayArgs<Def> | SpaceVarargArgs<Def>;
985
- type SpaceActionFactories<Def extends AnyPlatformDef> = Def["space"] extends {
1020
+ type SpaceActionFns<Def extends AnyPlatformDef> = Def["space"] extends {
986
1021
  actions?: infer A;
987
- } ? A extends Record<string, SpaceActionFactory> ? A : Record<string, never> : Record<string, never>;
1022
+ } ? A extends Record<string, SpaceActionFn> ? A : Record<string, never> : Record<string, never>;
1023
+ type TailArgs<T extends readonly unknown[]> = T extends readonly [
1024
+ unknown,
1025
+ ...infer Rest
1026
+ ] ? Rest : [];
988
1027
  type SpaceActionMethods<Def extends AnyPlatformDef> = {
989
- [K in Exclude<keyof SpaceActionFactories<Def>, keyof Space>]: (...args: Parameters<SpaceActionFactories<Def>[K]>) => Promise<OutboundMessage | undefined>;
1028
+ [K in Exclude<keyof SpaceActionFns<Def>, keyof Space>]: (...args: TailArgs<Parameters<SpaceActionFns<Def>[K]>>) => Promise<void>;
1029
+ };
1030
+ type MessageActionFns<Def extends AnyPlatformDef> = NonNullable<Def["message"]> extends {
1031
+ actions?: infer A;
1032
+ } ? A extends Record<string, MessageActionFn> ? A : Record<string, never> : Record<string, never>;
1033
+ type MessageActionMethods<Def extends AnyPlatformDef> = {
1034
+ [K in Exclude<keyof MessageActionFns<Def>, keyof Message>]: (...args: TailArgs<Parameters<MessageActionFns<Def>[K]>>) => Promise<void>;
990
1035
  };
991
1036
  type PlatformSpace<Def extends AnyPlatformDef> = Omit<SpaceShapeOf<Def>, keyof Space | keyof SpaceActionMethods<Def>> & Space & SpaceActionMethods<Def>;
992
- type PlatformMessage<Def extends AnyPlatformDef> = Omit<SchemaInfer<Def["message"]>, keyof Message> & Message<Def["name"], PlatformUser<Def>, PlatformSpace<Def>>;
993
- type InboundPlatformMessage<Def extends AnyPlatformDef> = Omit<SchemaInfer<Def["message"]>, keyof InboundMessage> & InboundMessage<Def["name"], PlatformUser<Def>, PlatformSpace<Def>>;
1037
+ type PlatformMessage<Def extends AnyPlatformDef> = Omit<SchemaInfer<Def["message"]>, keyof Message | keyof MessageActionMethods<Def>> & Message<Def["name"], PlatformUser<Def>, PlatformSpace<Def>> & MessageActionMethods<Def>;
994
1038
  type PlatformUser<Def extends AnyPlatformDef> = Omit<ResolvedUserOf<Def>, keyof User> & User;
995
1039
  type PlatformInstance<Def extends AnyPlatformDef> = {
996
- readonly messages: AsyncIterable<[
997
- PlatformSpace<Def>,
998
- InboundPlatformMessage<Def>
999
- ]>;
1040
+ readonly messages: AsyncIterable<[PlatformSpace<Def>, PlatformMessage<Def>]>;
1000
1041
  space(...args: SpaceArgs<Def>): Promise<PlatformSpace<Def>>;
1001
1042
  user(userID: string): Promise<PlatformUser<Def>>;
1002
1043
  } & CustomEventInstanceProperties<Def>;
@@ -1008,7 +1049,7 @@ interface PlatformRuntime {
1008
1049
  config: unknown;
1009
1050
  definition: AnyPlatformDef;
1010
1051
  store: Store;
1011
- subscribeMessages: () => ManagedStream<[Space, InboundMessage]>;
1052
+ subscribeMessages: () => ManagedStream<[Space, Message]>;
1012
1053
  }
1013
1054
  interface SpectrumLike<Providers extends PlatformProviderConfig[] = PlatformProviderConfig[]> {
1014
1055
  readonly __internal: {
@@ -1026,4 +1067,4 @@ interface Platform<Def extends AnyPlatformDef> {
1026
1067
  (message: Message): PlatformMessage<Def>;
1027
1068
  }
1028
1069
 
1029
- export { type AnyPlatformDef as A, type Broadcaster as B, type ContentBuilder as C, type EventProducer as E, type InboundMessage as I, type Message as M, type OutboundMessage as O, type Platform as P, type SchemaMessage as S, type User as U, type PlatformDef as a, type ContentInput as b, type Content as c, type ProviderMessage as d, type CreateClientContext as e, type Store as f, type PlatformProviderConfig as g, type SpectrumLike as h, type CustomEventStreams as i, type Space as j, type InboundPlatformMessage as k, type ManagedStream as l, type PlatformInstance as m, type PlatformMessage as n, type PlatformRuntime as o, type PlatformSpace as p, type PlatformUser as q, broadcast as r, mergeStreams as s, stream as t };
1070
+ export { type AgentSender as A, type Broadcaster as B, type ContentBuilder as C, type EventProducer as E, type Message as M, type Platform as P, type SchemaMessage as S, type User as U, type PlatformDef as a, type Space as b, type ContentInput as c, type Content as d, type ProviderMessage as e, type SpaceActionFn as f, type MessageActionFn as g, type CreateClientContext as h, type Store as i, type PlatformProviderConfig as j, type SpectrumLike as k, type CustomEventStreams as l, type AnyPlatformDef as m, type ManagedStream as n, type PlatformInstance as o, type PlatformMessage as p, type PlatformRuntime as q, type PlatformSpace as r, type PlatformUser as s, broadcast as t, mergeStreams as u, stream as v };
package/package.json CHANGED
@@ -1,6 +1,16 @@
1
1
  {
2
2
  "name": "spectrum-ts",
3
- "version": "1.9.2",
3
+ "version": "1.11.3",
4
+ "description": "Bring agents to any interface — unified messaging SDK for TypeScript.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/photon-hq/spectrum-ts.git",
8
+ "directory": "packages/spectrum-ts"
9
+ },
10
+ "homepage": "https://photon.codes/spectrum",
11
+ "bugs": {
12
+ "url": "https://github.com/photon-hq/spectrum-ts/issues"
13
+ },
4
14
  "type": "module",
5
15
  "main": "./dist/index.js",
6
16
  "module": "./dist/index.js",
@@ -26,6 +36,7 @@
26
36
  "@photon-ai/advanced-imessage": "^0.8.0",
27
37
  "@photon-ai/imessage-kit": "^3.0.0",
28
38
  "@photon-ai/otel": "^0.1.1",
39
+ "@photon-ai/slack": "^0.2.0",
29
40
  "@photon-ai/whatsapp-business": "^0.1.1",
30
41
  "@repeaterjs/repeater": "^3.0.6",
31
42
  "better-grpc": "^0.3.2",