spectrum-ts 0.1.1 → 0.1.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/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import z__default from 'zod';
2
- import { P as ProviderMessage, a as PlatformDef, b as Platform, c as PlatformProviderConfig, S as SpectrumLike, C as CustomEventStreams, d as Space, M as Message, e as ContentBuilder } from './types-DiKuSemh.js';
3
- export { A as AnyPlatformDef, f as Content, E as EventProducer, g as PlatformInstance, h as PlatformMessage, i as PlatformSpace, j as PlatformUser, k as SchemaMessage, U as User, l as attachment, m as custom, t as text } from './types-DiKuSemh.js';
2
+ import { P as ProviderMessage, a as PlatformDef, b as Platform, c as PlatformProviderConfig, S as SpectrumLike, C as CustomEventStreams, d as Space, M as Message, e as ContentBuilder } from './types-eXHZpal1.js';
3
+ export { A as AnyPlatformDef, f as Content, E as EventProducer, g as PlatformInstance, h as PlatformMessage, i as PlatformSpace, j as PlatformUser, k as SchemaMessage, U as User, l as attachment, m as custom, t as text } from './types-eXHZpal1.js';
4
4
  export { M as ManagedStream, m as mergeStreams, s as stream } from './stream-DGy4geUK.js';
5
5
  import 'hotscript';
6
6
  import 'type-fest';
@@ -29,7 +29,13 @@ type SpectrumInstance<Providers extends PlatformProviderConfig[] = PlatformProvi
29
29
  send(space: Space, ...content: [ContentBuilder, ...ContentBuilder[]]): Promise<void>;
30
30
  responding<T>(space: Space, fn: () => T | Promise<T>): Promise<T>;
31
31
  };
32
- declare function Spectrum<const Providers extends PlatformProviderConfig[]>(projectId: string, projectSecret: string, options: {
32
+ declare function Spectrum<const Providers extends PlatformProviderConfig[]>(options: {
33
+ projectId: string;
34
+ projectSecret: string;
35
+ providers: [...Providers];
36
+ } | {
37
+ projectId?: never;
38
+ projectSecret?: never;
33
39
  providers: [...Providers];
34
40
  }): Promise<SpectrumInstance<Providers>>;
35
41
 
package/dist/index.js CHANGED
@@ -15,21 +15,25 @@ var providerMessageCoreKeys = /* @__PURE__ */ new Set([
15
15
  "space",
16
16
  "timestamp"
17
17
  ]);
18
- var spectrumConfigSchema = z.object({
19
- projectId: z.string().min(1),
20
- projectSecret: z.string().min(1),
21
- providers: z.array(z.custom())
22
- });
23
- async function Spectrum(projectId, projectSecret, options) {
24
- spectrumConfigSchema.parse({
25
- projectId,
26
- projectSecret,
27
- providers: options.providers
28
- });
18
+ var spectrumConfigSchema = z.union([
19
+ z.object({
20
+ projectId: z.string().min(1),
21
+ projectSecret: z.string().min(1),
22
+ providers: z.array(z.custom())
23
+ }),
24
+ z.object({
25
+ projectId: z.undefined().optional(),
26
+ projectSecret: z.undefined().optional(),
27
+ providers: z.array(z.custom())
28
+ })
29
+ ]);
30
+ async function Spectrum(options) {
31
+ spectrumConfigSchema.parse(options);
32
+ const { projectId, projectSecret, providers } = options;
29
33
  const platformStates = /* @__PURE__ */ new Map();
30
34
  const customEventStreams = /* @__PURE__ */ new Map();
31
35
  let stopped = false;
32
- for (const provider of options.providers) {
36
+ for (const provider of providers) {
33
37
  const providerConfig = provider;
34
38
  const def = providerConfig.__definition;
35
39
  const userConfig = def.config.parse(providerConfig.config);
@@ -250,7 +254,7 @@ async function Spectrum(projectId, projectSecret, options) {
250
254
  }
251
255
  );
252
256
  const base = {
253
- __providers: options.providers,
257
+ __providers: providers,
254
258
  __internal: { platforms: platformStates },
255
259
  messages,
256
260
  stop: stopOnce,
@@ -3,7 +3,7 @@ import { AdvancedIMessage } from '@photon-ai/advanced-imessage';
3
3
  import { IMessageSDK } from '@photon-ai/imessage-kit';
4
4
  import * as z from 'zod';
5
5
  import z__default from 'zod';
6
- import { k as SchemaMessage, b as Platform, a as PlatformDef, P as ProviderMessage } from '../../types-DiKuSemh.js';
6
+ import { k as SchemaMessage, b as Platform, a as PlatformDef, P as ProviderMessage } from '../../types-eXHZpal1.js';
7
7
  import * as zod_v4_core from 'zod/v4/core';
8
8
  import 'hotscript';
9
9
  import 'type-fest';
@@ -356,6 +356,11 @@ var imessage = definePlatform("iMessage", {
356
356
  (e) => createClient2({ address: e.address, tls: true, token: e.token })
357
357
  );
358
358
  }
359
+ if (!(projectId && projectSecret)) {
360
+ throw new Error(
361
+ "iMessage requires projectId and projectSecret. Either pass credentials to Spectrum(), use local mode: imessage.config({ local: true }), or provide explicit client config: imessage.config({ clients: [...] })"
362
+ );
363
+ }
359
364
  return await createCloudClients(projectId, projectSecret);
360
365
  },
361
366
  destroyClient: async ({ client }) => {
@@ -1,4 +1,4 @@
1
- import { b as Platform, a as PlatformDef, P as ProviderMessage } from '../../types-DiKuSemh.js';
1
+ import { b as Platform, a as PlatformDef, P as ProviderMessage } from '../../types-eXHZpal1.js';
2
2
  import * as node_readline from 'node:readline';
3
3
  import z__default from 'zod';
4
4
  import 'hotscript';
@@ -117,8 +117,8 @@ interface PlatformDef<_Name extends string = string, _ConfigSchema extends z__de
117
117
  lifecycle: {
118
118
  createClient: (ctx: {
119
119
  config: z__default.infer<_ConfigSchema>;
120
- projectId: string;
121
- projectSecret: string;
120
+ projectId: string | undefined;
121
+ projectSecret: string | undefined;
122
122
  }) => Promise<_Client>;
123
123
  destroyClient: (ctx: {
124
124
  client: _Client;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spectrum-ts",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -140,8 +140,8 @@ export interface PlatformDef<
140
140
  lifecycle: {
141
141
  createClient: (ctx: {
142
142
  config: z.infer<_ConfigSchema>;
143
- projectId: string;
144
- projectSecret: string;
143
+ projectId: string | undefined;
144
+ projectSecret: string | undefined;
145
145
  }) => Promise<_Client>;
146
146
  destroyClient: (ctx: { client: _Client }) => Promise<void>;
147
147
  };
@@ -87,6 +87,14 @@ export const imessage = definePlatform("iMessage", {
87
87
  );
88
88
  }
89
89
 
90
+ if (!(projectId && projectSecret)) {
91
+ throw new Error(
92
+ "iMessage requires projectId and projectSecret. " +
93
+ "Either pass credentials to Spectrum(), use local mode: imessage.config({ local: true }), " +
94
+ "or provide explicit client config: imessage.config({ clients: [...] })"
95
+ );
96
+ }
97
+
90
98
  return await createCloudClients(projectId, projectSecret);
91
99
  },
92
100
 
package/src/spectrum.ts CHANGED
@@ -47,11 +47,18 @@ export type SpectrumInstance<
47
47
  // Config validation
48
48
  // ---------------------------------------------------------------------------
49
49
 
50
- const spectrumConfigSchema = z.object({
51
- projectId: z.string().min(1),
52
- projectSecret: z.string().min(1),
53
- providers: z.array(z.custom<PlatformProviderConfig>()),
54
- });
50
+ const spectrumConfigSchema = z.union([
51
+ z.object({
52
+ projectId: z.string().min(1),
53
+ projectSecret: z.string().min(1),
54
+ providers: z.array(z.custom<PlatformProviderConfig>()),
55
+ }),
56
+ z.object({
57
+ projectId: z.undefined().optional(),
58
+ projectSecret: z.undefined().optional(),
59
+ providers: z.array(z.custom<PlatformProviderConfig>()),
60
+ }),
61
+ ]);
55
62
 
56
63
  // ---------------------------------------------------------------------------
57
64
  // Spectrum() factory
@@ -60,15 +67,21 @@ const spectrumConfigSchema = z.object({
60
67
  export async function Spectrum<
61
68
  const Providers extends PlatformProviderConfig[],
62
69
  >(
63
- projectId: string,
64
- projectSecret: string,
65
- options: { providers: [...Providers] }
70
+ options:
71
+ | {
72
+ projectId: string;
73
+ projectSecret: string;
74
+ providers: [...Providers];
75
+ }
76
+ | {
77
+ projectId?: never;
78
+ projectSecret?: never;
79
+ providers: [...Providers];
80
+ }
66
81
  ): Promise<SpectrumInstance<Providers>> {
67
- spectrumConfigSchema.parse({
68
- projectId,
69
- projectSecret,
70
- providers: options.providers,
71
- });
82
+ spectrumConfigSchema.parse(options);
83
+
84
+ const { projectId, projectSecret, providers } = options;
72
85
 
73
86
  const platformStates = new Map<
74
87
  string,
@@ -81,7 +94,7 @@ export async function Spectrum<
81
94
  let stopped = false;
82
95
 
83
96
  // Initialize all provider clients eagerly
84
- for (const provider of options.providers) {
97
+ for (const provider of providers) {
85
98
  const providerConfig = provider as PlatformProviderConfig;
86
99
  const def = providerConfig.__definition;
87
100
  const userConfig = def.config.parse(providerConfig.config);
@@ -344,7 +357,7 @@ export async function Spectrum<
344
357
  );
345
358
 
346
359
  const base = {
347
- __providers: options.providers,
360
+ __providers: providers,
348
361
  __internal: { platforms: platformStates },
349
362
  messages,
350
363
  stop: stopOnce,