spectrum-ts 1.18.0 → 2.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 (36) hide show
  1. package/README.md +11 -1
  2. package/dist/{attachment-DfWSZS5L.d.ts → attachment-B4nSrKVd.d.ts} +1 -1
  3. package/dist/{authoring-C9uDdZ2F.d.ts → authoring-BjE5BvlO.d.ts} +2 -2
  4. package/dist/authoring.d.ts +3 -3
  5. package/dist/authoring.js +6 -3
  6. package/dist/chunk-34FQGGD7.js +34 -0
  7. package/dist/chunk-3B4QH4JG.js +35 -0
  8. package/dist/chunk-3GEJYGZK.js +84 -0
  9. package/dist/chunk-5LT5J3NR.js +695 -0
  10. package/dist/{chunk-MC6ZKFSG.js → chunk-5XEFJBN2.js} +25 -103
  11. package/dist/{chunk-JQN6CRSC.js → chunk-6BI4PFTP.js} +10 -39
  12. package/dist/{chunk-QGJFZMD5.js → chunk-6UZFVXQF.js} +17 -101
  13. package/dist/{chunk-YN6WOTBF.js → chunk-ATNAE7OR.js} +77 -7
  14. package/dist/{chunk-IPOFBAIM.js → chunk-NGC4DJIX.js} +23 -19
  15. package/dist/{chunk-5TIF3FIE.js → chunk-Q537JPTG.js} +8 -6
  16. package/dist/{chunk-5BKZJMZV.js → chunk-U3LXXT3W.js} +61 -32
  17. package/dist/chunk-U7AWXDH6.js +91 -0
  18. package/dist/{chunk-3OTECDNH.js → chunk-WXY5QP3M.js} +5 -3
  19. package/dist/index.d.ts +69 -124
  20. package/dist/index.js +350 -90
  21. package/dist/manifest.json +6 -0
  22. package/dist/providers/imessage/index.d.ts +2 -2
  23. package/dist/providers/imessage/index.js +8 -5
  24. package/dist/providers/index.d.ts +5 -2
  25. package/dist/providers/index.js +16 -8
  26. package/dist/providers/slack/index.d.ts +1 -1
  27. package/dist/providers/slack/index.js +4 -3
  28. package/dist/providers/telegram/index.d.ts +47 -0
  29. package/dist/providers/telegram/index.js +13 -0
  30. package/dist/providers/terminal/index.d.ts +17 -419
  31. package/dist/providers/terminal/index.js +5 -3
  32. package/dist/providers/whatsapp-business/index.d.ts +1 -1
  33. package/dist/providers/whatsapp-business/index.js +6 -4
  34. package/dist/types-BD0-kKyv.d.ts +82 -0
  35. package/dist/{types-DcQ5a7PK.d.ts → types-Bje8aq1k.d.ts} +34 -4
  36. package/package.json +2 -1
@@ -0,0 +1,82 @@
1
+ import { b as ProjectData, c as Store, d as ProviderMessageRecord, e as Space, M as Message } from './types-Bje8aq1k.js';
2
+
3
+ declare const FUSOR_EVENT_BRAND: unique symbol;
4
+ interface FusorEvent<TName extends string = string, TData = unknown> {
5
+ readonly data: TData;
6
+ readonly name: TName;
7
+ readonly [FUSOR_EVENT_BRAND]: true;
8
+ }
9
+ declare function fusorEvent<TName extends string, TData>(name: TName, data: TData): FusorEvent<TName, TData>;
10
+ declare function isFusorEvent(value: unknown): value is FusorEvent;
11
+
12
+ interface FusorVerifyRequest {
13
+ headers: Record<string, string>;
14
+ method: string;
15
+ path: string;
16
+ rawBody: Uint8Array;
17
+ }
18
+ type FusorVerify<TPayload = unknown> = (req: FusorVerifyRequest) => TPayload | Promise<TPayload>;
19
+ interface FusorReply {
20
+ body?: string | Uint8Array;
21
+ headers?: Record<string, string>;
22
+ status?: number;
23
+ }
24
+ type FusorRespond = (reply: FusorReply) => void;
25
+ interface FusorMessagesCtx<TPayload, TConfig = unknown> {
26
+ /** Parsed provider config (`z.infer` of the platform's config schema). */
27
+ config: TConfig;
28
+ payload: TPayload;
29
+ /**
30
+ * Spectrum Cloud project metadata, fetched once at `Spectrum()` init.
31
+ * `undefined` for local-only setups (no `projectId`/`projectSecret`). Read
32
+ * project-level toggles from `projectConfig.profile.<key>`.
33
+ */
34
+ projectConfig: ProjectData | undefined;
35
+ respond: FusorRespond;
36
+ /** Per-platform in-memory key/value store, shared with the rest of the platform. */
37
+ store: Store;
38
+ }
39
+ type FusorMessagesReturn = ProviderMessageRecord | FusorEvent | (ProviderMessageRecord | FusorEvent)[] | undefined;
40
+ type FusorMessages<TPayload, TConfig = unknown> = (ctx: FusorMessagesCtx<TPayload, TConfig>) => FusorMessagesReturn | Promise<FusorMessagesReturn>;
41
+ declare const FUSOR_BRAND: unique symbol;
42
+ interface FusorClient<TPayload = unknown> {
43
+ readonly platform: string;
44
+ readonly verify: FusorVerify<TPayload>;
45
+ readonly [FUSOR_BRAND]: true;
46
+ }
47
+ /**
48
+ * Request-scoped handler invoked once per inbound message that
49
+ * `spectrum.webhook()` resolves. Receives the same fully-built `[space,
50
+ * message]` pair that `spectrum.messages` yields.
51
+ *
52
+ * Runs **fire-and-forget**: it is dispatched after the HTTP response (the
53
+ * platform's `respond()` reply) has already been computed, so its outcome never
54
+ * affects the response, and a throw is caught + logged rather than surfaced —
55
+ * mirroring the body of a `for await (… of spectrum.messages)` loop.
56
+ *
57
+ * On a long-running server the event loop keeps the handler alive. On
58
+ * serverless/edge runtimes the function may be frozen once the response is
59
+ * returned, so keeping background work alive is the caller's responsibility —
60
+ * the usual pattern is to enqueue the work and process it in a separate worker.
61
+ */
62
+ type WebhookHandler = (space: Space, message: Message) => void | Promise<void>;
63
+ /**
64
+ * Raw webhook input for HTTP servers without Web `Request`/`Response` (Express,
65
+ * raw Node). `body` MUST be the exact bytes fusor POSTed — never a re-encoded
66
+ * JSON/text body — so the protobuf decode works. `headers` are accepted (so the
67
+ * natural `{ headers: req.headers, body: req.body }` shape keeps working) but are
68
+ * not read: inbound authenticity is established by the per-platform `verify()`,
69
+ * which reads the inner request reconstructed from the envelope.
70
+ */
71
+ interface WebhookRawRequest {
72
+ body: Uint8Array | ArrayBuffer;
73
+ headers?: Record<string, string>;
74
+ }
75
+ /** Raw webhook result, written back by the caller as the HTTP response. */
76
+ interface WebhookRawResult {
77
+ body: Uint8Array;
78
+ headers: Record<string, string>;
79
+ status: number;
80
+ }
81
+
82
+ export { type FusorClient as F, type WebhookHandler as W, type FusorVerify as a, type FusorMessages as b, type WebhookRawRequest as c, type WebhookRawResult as d, type FusorEvent as e, type FusorMessagesCtx as f, type FusorMessagesReturn as g, type FusorReply as h, type FusorRespond as i, type FusorVerifyRequest as j, fusorEvent as k, isFusorEvent as l };
@@ -4,6 +4,9 @@ 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<"streamText">;
9
+ stream: z__default.ZodCustom<() => AsyncIterable<string>, () => AsyncIterable<string>>;
7
10
  }, z__default.core.$strip>, z__default.ZodObject<{
8
11
  type: z__default.ZodLiteral<"custom">;
9
12
  raw: z__default.ZodUnknown;
@@ -171,6 +174,9 @@ declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObj
171
174
  read: z__default.core.$InferOuterFunctionType<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>>>;
172
175
  stream: z__default.core.$InferOuterFunctionType<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>>>;
173
176
  size?: number | undefined;
177
+ } | {
178
+ type: "streamText";
179
+ stream: () => AsyncIterable<string>;
174
180
  } | {
175
181
  type: "custom";
176
182
  raw: unknown;
@@ -303,6 +309,9 @@ declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObj
303
309
  read: z__default.core.$InferOuterFunctionType<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>>>;
304
310
  stream: z__default.core.$InferOuterFunctionType<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>>>;
305
311
  size?: number | undefined;
312
+ } | {
313
+ type: "streamText";
314
+ stream: () => AsyncIterable<string>;
306
315
  } | {
307
316
  type: "custom";
308
317
  raw: unknown;
@@ -439,6 +448,9 @@ declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObj
439
448
  read: z__default.core.$InferOuterFunctionType<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>>>;
440
449
  stream: z__default.core.$InferOuterFunctionType<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>>>;
441
450
  size?: number | undefined;
451
+ } | {
452
+ type: "streamText";
453
+ stream: () => AsyncIterable<string>;
442
454
  } | {
443
455
  type: "custom";
444
456
  raw: unknown;
@@ -571,6 +583,9 @@ declare const contentSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObj
571
583
  read: z__default.core.$InferOuterFunctionType<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>>>;
572
584
  stream: z__default.core.$InferOuterFunctionType<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>>>;
573
585
  size?: number | undefined;
586
+ } | {
587
+ type: "streamText";
588
+ stream: () => AsyncIterable<string>;
574
589
  } | {
575
590
  type: "custom";
576
591
  raw: unknown;
@@ -823,6 +838,12 @@ interface ProjectData {
823
838
  id: string;
824
839
  name: string;
825
840
  profile: ProjectProfile;
841
+ /**
842
+ * URL-safe project identifier (e.g. `what-c62a6`). Used as the subdomain of
843
+ * the Fusor "super webhook" edge a platform registers its provider webhook
844
+ * against — see Telegram's `webhookUrl`.
845
+ */
846
+ slug: string;
826
847
  }
827
848
  declare class SpectrumCloudError extends Error {
828
849
  readonly status: number;
@@ -1010,10 +1031,17 @@ type ProviderMessageRecord = {
1010
1031
  } & Record<string, unknown>;
1011
1032
  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
1033
  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;
1034
+ type InferEventPayload<T> = T extends z__default.ZodType ? z__default.infer<T> : T extends (ctx: never) => AsyncIterable<infer P> ? P : never;
1014
1035
  type ReservedNames = "stop" | "send" | "config" | "__internal" | "__providers";
1015
1036
  interface CreateClientContext<_ConfigSchema extends z__default.ZodType<object>> {
1016
1037
  config: z__default.infer<_ConfigSchema>;
1038
+ /**
1039
+ * The resolved cloud project record (slug, profile, …) when `Spectrum()` runs
1040
+ * with `projectId` + `projectSecret`; `undefined` in local/direct mode. Lets
1041
+ * `createClient` self-register provider webhooks against the Fusor edge keyed
1042
+ * by `projectConfig.slug` — see Telegram.
1043
+ */
1044
+ projectConfig: ProjectData | undefined;
1017
1045
  projectId: string | undefined;
1018
1046
  projectSecret: string | undefined;
1019
1047
  store: Store;
@@ -1034,7 +1062,7 @@ interface CreateClientContext<_ConfigSchema extends z__default.ZodType<object>>
1034
1062
  * Minimum viable platform integration:
1035
1063
  * `name`, `config`, `lifecycle`, `user`, `space`, `messages`, `send`.
1036
1064
  */
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>>> & {
1065
+ 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
1066
  messages?: never;
1039
1067
  }) | 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
1068
  /**
@@ -1191,7 +1219,7 @@ interface AnyPlatformDef {
1191
1219
  actions?: Record<string, InstanceActionFn>;
1192
1220
  config: z__default.ZodType<object>;
1193
1221
  events?: {
1194
- [key: string]: (ctx: any) => AsyncIterable<any>;
1222
+ [key: string]: ((ctx: any) => AsyncIterable<any>) | z__default.ZodType<object>;
1195
1223
  };
1196
1224
  lifecycle: {
1197
1225
  createClient: (ctx: any) => Promise<any>;
@@ -1304,7 +1332,9 @@ interface PlatformRuntime {
1304
1332
  client: unknown;
1305
1333
  config: unknown;
1306
1334
  definition: AnyPlatformDef;
1335
+ projectConfig: ProjectData | undefined;
1307
1336
  store: Store;
1337
+ subscribeEvent?: (channel: string) => AsyncIterable<unknown> | undefined;
1308
1338
  subscribeMessages: () => ManagedStream<[Space, Message]>;
1309
1339
  }
1310
1340
  interface SpectrumLike<Providers extends PlatformProviderConfig[] = PlatformProviderConfig[]> {
@@ -1323,4 +1353,4 @@ interface Platform<Def extends AnyPlatformDef> {
1323
1353
  (message: Message): PlatformMessage<Def>;
1324
1354
  }
1325
1355
 
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 };
1356
+ 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 ProjectProfile as G, type SharedTokenData as H, type InstanceActionFn as I, type SlackTeamMeta as J, type SlackTokenData as K, SpectrumCloudError as L, type Message as M, type SubscriptionData as N, type SubscriptionStatus as O, type Platform as P, broadcast as Q, cloud as R, type SchemaMessage as S, type TokenData as T, type User as U, mergeStreams as V, stream as W, 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": "2.0.0",
4
4
  "description": "Bring agents to any interface — unified messaging SDK for TypeScript.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -42,6 +42,7 @@
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",