@slflows/sdk 0.0.7 → 0.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.
Files changed (2) hide show
  1. package/dist/v1/index.d.ts +454 -439
  2. package/package.json +2 -3
@@ -1,448 +1,50 @@
1
1
  /**
2
- * Main schema interface for defining a Flows app.
3
- *
4
- * An app consists of blocks (entities) that can process events, manage state,
5
- * expose HTTP endpoints, and handle scheduled tasks. Apps are the fundamental
6
- * unit of deployment in Flows.
7
- *
8
- * @example
9
- * ```typescript
10
- * export default defineApp({
11
- * name: "Data Processor",
12
- * blocks: {
13
- * processor: {
14
- * name: "Process Data",
15
- * description: "Transforms incoming data",
16
- * inputs: {
17
- * data: {
18
- * name: "Input Data",
19
- * onEvent: async (input) => {
20
- * // Process the event
21
- * await events.emit(processedData);
22
- * }
23
- * }
24
- * },
25
- * outputs: {
26
- * processed: {
27
- * name: "Processed Data",
28
- * default: true
29
- * }
30
- * }
31
- * }
32
- * }
33
- * });
34
- * ```
2
+ * Key-value pair for storage operations.
3
+ * Supports TTL (time-to-live) and optimistic locking for safe concurrent access.
35
4
  */
36
- interface AppSchema {
37
- /** Display name for the app */
38
- name?: string;
39
- /**
40
- * Instructions shown to users when installing the app.
41
- * Supports Markdown formatting.
42
- */
43
- installationInstructions?: string;
44
- /**
45
- * Configuration fields for the app. These are set during installation
46
- * and available to all blocks within the app.
47
- */
48
- config?: Record<string, AppConfigField>;
49
- /**
50
- * Signals exported by the app.
51
- * These are available to all blocks within the app.
52
- */
53
- signals?: Record<string, AppSignal>;
54
- /**
55
- * Lifecycle hook called when the app needs to synchronize its state.
56
- * Use this to provision resources, validate configuration, or perform setup.
57
- */
58
- onSync?: (input: AppInput) => Promise<AppLifecycleCallbackOutput>;
59
- /**
60
- * Lifecycle hook called when the app is being drained (shut down).
61
- * Use this to clean up resources, save state, or perform teardown.
62
- */
63
- onDrain?: (input: AppInput) => Promise<AppLifecycleCallbackOutput>;
64
- /** Custom status description shown when the app is in draft mode */
65
- draftCustomStatusDescription?: string;
66
- /**
67
- * Handler for internal messages sent to the app from blocks.
68
- * Used for app-level coordination and communication.
69
- */
70
- onInternalMessage?: (input: AppOnInternalMessageInput) => Promise<void>;
71
- /**
72
- * Map of block definitions. Each block becomes an entity that can be
73
- * placed on the flow canvas. Key is the block type ID.
74
- */
75
- blocks: Record<string, AppBlock>;
76
- /** HTTP server configuration for app-level endpoints */
77
- http?: AppHTTPComponent;
78
- /** UI component configuration for custom app interfaces */
79
- ui?: AppUIComponent;
80
- /**
81
- * Declarative schedules that trigger at app level.
82
- * Use for periodic maintenance, data synchronization, etc.
83
- */
84
- schedules?: Record<string, AppSchedule>;
5
+ interface KVPair {
6
+ /** The storage key */
7
+ key: string;
85
8
  /**
86
- * Handler for imperative timers set by the app.
87
- * Called when a timer created with timers.set() expires.
9
+ * The stored value. May be undefined (key doesn't exist),
10
+ * null (explicitly set to null), or any other value.
88
11
  */
89
- onTimer?: (input: AppOnTimerInput) => Promise<void>;
90
- }
91
- interface AppUIComponent {
92
- onRequest: (input: AppOnUIRequestInput) => Promise<any>;
93
- }
94
- type SimpleType = "string" | "number" | "boolean" | "any";
95
- type SimpleTypeArray = [SimpleType];
96
- interface JsonSchema {
97
- type?: string;
98
- properties?: Record<string, JsonSchema>;
99
- items?: JsonSchema;
100
- required?: string[];
101
- enum?: (string | number)[];
102
- anyOf?: JsonSchema[];
103
- oneOf?: JsonSchema[];
104
- description?: string;
105
- additionalProperties?: boolean | {
106
- type: "string" | "number" | "boolean" | "object" | "array";
107
- };
108
- }
109
- type Type = SimpleType | SimpleTypeArray | JsonSchema;
110
- interface AppConfigField {
111
- name: string;
112
- description?: string;
113
- type: Type;
114
- fixed?: boolean;
115
- required: boolean;
116
- default?: unknown;
117
- sensitive?: boolean;
118
- }
119
- interface AppSignal {
120
- name: string;
121
- description: string;
122
- sensitive?: boolean;
123
- }
124
- interface AppHTTPComponent {
125
- onRequest: (input: AppOnHTTPRequestInput) => Promise<void>;
126
- }
127
- type ScheduleDefinition = {
128
- type: "cron";
129
- cron: {
130
- expression: string;
131
- location: string;
132
- };
133
- } | {
134
- type: "frequency";
135
- frequency: {
136
- interval: number;
137
- unit?: "seconds" | "minutes" | "hours";
12
+ value?: any;
13
+ /** Unix timestamp of when this key was last updated */
14
+ updatedAt?: number;
15
+ /** Time-to-live in seconds. If set, key will expire after this duration */
16
+ ttl?: number;
17
+ /** Optional lock information for atomic operations */
18
+ lock?: {
19
+ /** Unique lock identifier */
20
+ id: string;
21
+ /** Lock timeout in seconds */
22
+ timeout?: number;
138
23
  };
139
- };
140
- interface AppSchedule {
141
- description?: string;
142
- customizable?: boolean;
143
- definition: ScheduleDefinition;
144
- onTrigger: (input: AppOnTriggerInput) => Promise<void>;
145
- }
146
- interface AppBlock {
147
- name?: string;
148
- description?: string;
149
- category?: string;
150
- config?: Record<string, AppBlockConfigField>;
151
- onInternalMessage?: (input: EntityOnInternalMessageInput) => Promise<void>;
152
- inputs?: Record<string, AppBlockComponentInput>;
153
- outputs?: Record<string, AppBlockComponentOutput>;
154
- signals?: Record<string, AppBlockSignal>;
155
- onSync?: (input: EntityInput) => EntityLifecycleCallbackOutput | Promise<EntityLifecycleCallbackOutput>;
156
- onDrain?: (input: EntityInput) => EntityLifecycleCallbackOutput | Promise<EntityLifecycleCallbackOutput>;
157
- draftCustomStatusDescription?: string;
158
- http?: AppBlockHTTPComponent;
159
- ui?: AppBlockUIComponent;
160
- schedules?: Record<string, AppBlockSchedule>;
161
- onTimer?: (input: EntityOnTimerInput) => Promise<void>;
162
- }
163
- interface AppBlockConfigField {
164
- name: string;
165
- description?: string;
166
- type: Type;
167
- fixed?: boolean;
168
- required: boolean;
169
- default?: unknown;
170
- fieldKey?: string;
171
- sensitive?: boolean;
172
- }
173
- interface AppBlockComponentInput {
174
- name?: string;
175
- description?: string;
176
- config?: Record<string, AppBlockConfigField>;
177
- onEvent: (input: EventInput) => Promise<void>;
178
- }
179
- interface AppBlockComponentOutput {
180
- name?: string;
181
- description?: string;
182
- default?: boolean;
183
- /**
184
- * Defines which inputs can provide parent events for this output.
185
- * Used for type inference - determines what fields and types will be
186
- * available in the output event based on parent input types.
187
- * Should be a list of input keys that can be used as parents.
188
- */
189
- possiblePrimaryParents?: string[];
190
- secondary?: boolean;
191
- type?: Type;
192
- }
193
- interface AppBlockHTTPComponent {
194
- onRequest: (input: EntityOnHTTPRequestInput) => Promise<void>;
195
- }
196
- interface AppBlockUIComponent {
197
- onRequest: (input: EntityOnUIRequestInput) => Promise<any>;
198
- views?: EntityView[] | null;
199
- }
200
- interface AppBlockSignal {
201
- name: string;
202
- description: string;
203
- sensitive?: boolean;
204
- }
205
- interface AppBlockSchedule {
206
- description?: string;
207
- customizable?: boolean;
208
- definition: ScheduleDefinition;
209
- onTrigger: (input: EntityOnTriggerInput) => Promise<void>;
210
24
  }
211
- interface EntityView {
212
- id: string;
213
- label: string;
214
- type: EntityViewType;
25
+ /**
26
+ * Input parameters for listing key-value pairs with optional pagination.
27
+ * Used with kv.app.list() and kv.block.list() to retrieve multiple keys.
28
+ */
29
+ interface KVListInput {
30
+ /** Prefix to filter keys (e.g., "user:" to get all user-related keys) */
31
+ keyPrefix: string;
32
+ /** Starting key for pagination (from previous nextStartingKey) */
33
+ startingKey?: string;
215
34
  }
216
- type EntityViewType = "default" | "fullScreen" | "regular";
217
35
  /**
218
- * Input context provided to app-level handlers.
219
- * Contains app configuration and runtime information.
36
+ * Output from key-value list operations with pagination support.
37
+ * Contains the retrieved key-value pairs and pagination information.
220
38
  */
221
- interface AppInput {
222
- /** App installation context and configuration */
223
- app: AppContext;
39
+ interface KVListOutput {
40
+ /** Array of key-value pairs matching the prefix */
41
+ pairs: Array<KVPair>;
42
+ /** Next starting key for pagination (undefined if no more results) */
43
+ nextStartingKey?: string;
224
44
  }
225
45
  /**
226
- * App runtime context containing configuration and endpoints.
227
- * Available in all app-level handlers (onSync, onDrain, onInternalMessage, etc.).
228
- */
229
- interface AppContext {
230
- /** App configuration values set during installation */
231
- config: Record<string, any>;
232
- /** Current status of the app installation */
233
- status: "draft" | "in_progress" | "ready" | "failed" | "draining" | "draining_failed" | "drained";
234
- /** HTTP endpoint information for this app */
235
- http: AppHTTPEndpoint;
236
- /** URL for managing this app installation */
237
- installationUrl: string;
238
- /** Signals exported by this app */
239
- signals: Record<string, any>;
240
- }
241
- /**
242
- * HTTP endpoint information for app-level HTTP handlers.
243
- */
244
- interface AppHTTPEndpoint {
245
- /** Base URL for this app's HTTP endpoints */
246
- url: string;
247
- }
248
- /**
249
- * Input context provided to block-level handlers.
250
- * Extends AppInput with block-specific context.
251
- */
252
- interface EntityInput extends AppInput {
253
- /** Block (entity) instance context and configuration */
254
- block: EntityContext;
255
- }
256
- /**
257
- * Block (entity) runtime context containing configuration and state.
258
- * Available in all block-level handlers (onEvent, onSync, onDrain, etc.).
259
- */
260
- interface EntityContext {
261
- /** Unique identifier for this block instance */
262
- id: string;
263
- /** Display name of this block instance */
264
- name: string;
265
- /** Description of this block instance */
266
- description: string;
267
- /** Block configuration values set in the flow */
268
- config: Record<string, any>;
269
- /** Lifecycle state information (null if block has no lifecycle) */
270
- lifecycle: EntityLifecycleComponent | null;
271
- /** HTTP endpoint information (null if block has no HTTP handler) */
272
- http: EntityHTTPEndpoint | null;
273
- }
274
- interface EntityLifecycleComponent {
275
- status: EntityLifecycleStatus;
276
- signals: Record<string, any> | null;
277
- }
278
- type EntityLifecycleStatus = "draft" | "in_progress" | "ready" | "drifted" | "failed" | "draining" | "draining_failed" | "drained";
279
- interface EntityHTTPEndpoint {
280
- url: string;
281
- }
282
- /**
283
- * Input context provided to event handlers (onEvent).
284
- * Extends EntityInput with event-specific information.
285
- */
286
- interface EventInput extends EntityInput {
287
- /** Event data and metadata */
288
- event: EventContext;
289
- }
290
- /**
291
- * Event context containing the event data and metadata.
292
- * Available in all onEvent handlers when processing incoming events.
293
- */
294
- interface EventContext {
295
- /** Unique identifier for this event */
296
- id: string;
297
- /** Configuration values for the specific input that received this event */
298
- inputConfig: Record<string, any>;
299
- /**
300
- * Echo information for request-response patterns.
301
- * Present when this event was emitted with echo: true.
302
- */
303
- echo?: {
304
- /** The event body that was echoed */
305
- body: any;
306
- /** The output key where the original event was emitted */
307
- outputKey: string;
308
- };
309
- }
310
- interface EntityLifecycleCallbackOutput {
311
- signalUpdates?: Record<string, any>;
312
- newStatus?: EntityLifecycleStatus;
313
- customStatusDescription?: string | null;
314
- nextScheduleDelay?: number;
315
- }
316
- interface AppLifecycleCallbackOutput {
317
- signalUpdates?: Record<string, any>;
318
- newStatus?: AppLifecycleStatus;
319
- customStatusDescription?: string | null;
320
- nextScheduleDelay?: number;
321
- }
322
- type AppLifecycleStatus = "draft" | "in_progress" | "ready" | "failed" | "draining" | "draining_failed" | "drained";
323
- interface AppOnCreateOutput {
324
- ok?: {};
325
- redirect?: {
326
- url: string;
327
- method: string;
328
- };
329
- }
330
- interface AppOnInternalMessageInput extends AppInput {
331
- message: {
332
- publisherId: string;
333
- body: any;
334
- };
335
- }
336
- interface EntityOnInternalMessageInput extends EntityInput {
337
- message: {
338
- body: any;
339
- };
340
- }
341
- interface AppOnTimerInput extends AppInput {
342
- timer: {
343
- id: string;
344
- payload: any;
345
- prompt?: {
346
- id: string;
347
- description?: string;
348
- };
349
- };
350
- }
351
- interface EntityOnTimerInput extends EntityInput {
352
- timer: {
353
- id: string;
354
- payload: any;
355
- pendingEvent?: {
356
- id: string;
357
- body?: any;
358
- status?: string;
359
- };
360
- };
361
- }
362
- interface AppOnTriggerInput extends AppInput {
363
- schedule: {
364
- time: string;
365
- };
366
- }
367
- interface EntityOnTriggerInput extends EntityInput {
368
- schedule: {
369
- time: string;
370
- };
371
- }
372
- interface AppOnHTTPRequestInput extends AppInput {
373
- request: HTTPRequest;
374
- }
375
- interface EntityOnHTTPRequestInput extends EntityInput {
376
- request: HTTPRequest;
377
- }
378
- interface HTTPRequest {
379
- requestId: string;
380
- path: string;
381
- method: string;
382
- headers: Record<string, string>;
383
- query: Record<string, string>;
384
- params: Record<string, string>;
385
- rawBody: string;
386
- body: any;
387
- }
388
- interface AppOnUIRequestInput extends AppInput {
389
- request: UIRequest;
390
- }
391
- interface EntityOnUIRequestInput extends EntityInput {
392
- request: UIRequest;
393
- }
394
- interface UIRequest {
395
- type: string;
396
- payload?: any;
397
- }
398
-
399
- /**
400
- * Key-value pair for storage operations.
401
- * Supports TTL (time-to-live) and optimistic locking for safe concurrent access.
402
- */
403
- interface KVPair {
404
- /** The storage key */
405
- key: string;
406
- /**
407
- * The stored value. May be undefined (key doesn't exist),
408
- * null (explicitly set to null), or any other value.
409
- */
410
- value?: any;
411
- /** Unix timestamp of when this key was last updated */
412
- updatedAt?: number;
413
- /** Time-to-live in seconds. If set, key will expire after this duration */
414
- ttl?: number;
415
- /** Optional lock information for atomic operations */
416
- lock?: {
417
- /** Unique lock identifier */
418
- id: string;
419
- /** Lock timeout in seconds */
420
- timeout?: number;
421
- };
422
- }
423
- /**
424
- * Input parameters for listing key-value pairs with optional pagination.
425
- * Used with kv.app.list() and kv.block.list() to retrieve multiple keys.
426
- */
427
- interface KVListInput {
428
- /** Prefix to filter keys (e.g., "user:" to get all user-related keys) */
429
- keyPrefix: string;
430
- /** Starting key for pagination (from previous nextStartingKey) */
431
- startingKey?: string;
432
- }
433
- /**
434
- * Output from key-value list operations with pagination support.
435
- * Contains the retrieved key-value pairs and pagination information.
436
- */
437
- interface KVListOutput {
438
- /** Array of key-value pairs matching the prefix */
439
- pairs: Array<KVPair>;
440
- /** Next starting key for pagination (undefined if no more results) */
441
- nextStartingKey?: string;
442
- }
443
- /**
444
- * Input parameters for listing blocks within the same app installation.
445
- * Used to discover other blocks for coordination and messaging.
46
+ * Input parameters for listing blocks within the same app installation.
47
+ * Used to discover other blocks for coordination and messaging.
446
48
  */
447
49
  interface ListBlocksInput {
448
50
  /** Filter by specific block type IDs (omit to list all blocks) */
@@ -501,7 +103,7 @@ interface CreatePendingEventOptions {
501
103
  /** Optional predicted event payload */
502
104
  event?: Record<string, any>;
503
105
  /** Which output this will emit on (optional) */
504
- outputId?: string;
106
+ outputKey?: string;
505
107
  /** Parent event (auto-populated in handlers) */
506
108
  parentEventId?: string;
507
109
  /** Additional parent event IDs for complex lineage */
@@ -517,7 +119,7 @@ interface UpdatePendingEventOptions {
517
119
  /** Updated event data (replaces previous event data) */
518
120
  event?: Record<string, any>;
519
121
  /** Updated output ID to emit on when completed */
520
- outputId?: string;
122
+ outputKey?: string;
521
123
  /** Updated parent event ID for lineage tracking */
522
124
  parentEventId?: string;
523
125
  /** Updated additional parent event IDs */
@@ -581,7 +183,7 @@ declare const getInvocationMetadata: () => Promise<InvocationMetadata>;
581
183
  * await events.emit({ message: "Hello World" });
582
184
  *
583
185
  * // Emit to specific output
584
- * await events.emit(data, { outputId: "success" });
186
+ * await events.emit(data, { outputKey: "success" });
585
187
  *
586
188
  * // Create pending event for long operation
587
189
  * const pendingId = await events.createPending({
@@ -1017,13 +619,13 @@ declare const lifecycle: {
1017
619
  * @example
1018
620
  * ```typescript
1019
621
  * // Set a timer for 30 seconds
1020
- * const timerId = await timers.set(30, {
622
+ * const timerId = await timers.app.set(30, {
1021
623
  * inputPayload: { action: "retry" },
1022
624
  * description: "Retry failed operation"
1023
625
  * });
1024
626
  *
1025
627
  * // Cancel the timer
1026
- * await timers.unset(timerId);
628
+ * await timers.app.unset(timerId);
1027
629
  * ```
1028
630
  */
1029
631
  declare const timers: {
@@ -1034,6 +636,22 @@ declare const timers: {
1034
636
  description?: string;
1035
637
  }) => Promise<string>;
1036
638
  unset: (id: string) => Promise<void>;
639
+ block: {
640
+ set: (delaySeconds: number, options: {
641
+ inputPayload?: unknown;
642
+ pendingEventId?: string;
643
+ description?: string;
644
+ }) => Promise<string>;
645
+ unset: (id: string) => Promise<void>;
646
+ };
647
+ app: {
648
+ set: (delaySeconds: number, options: {
649
+ inputPayload?: unknown;
650
+ promptId?: string;
651
+ description?: string;
652
+ }) => Promise<string>;
653
+ unset: (id: string) => Promise<void>;
654
+ };
1037
655
  };
1038
656
  /**
1039
657
  * UI service for managing custom block widgets.
@@ -1107,4 +725,401 @@ declare const ui: {
1107
725
  */
1108
726
  declare function defineApp(app: AppSchema): AppSchema;
1109
727
 
728
+ /**
729
+ * Main schema interface for defining a Flows app.
730
+ *
731
+ * An app consists of blocks (entities) that can process events, manage state,
732
+ * expose HTTP endpoints, and handle scheduled tasks. Apps are the fundamental
733
+ * unit of deployment in Flows.
734
+ *
735
+ * @example
736
+ * ```typescript
737
+ * export default defineApp({
738
+ * name: "Data Processor",
739
+ * blocks: {
740
+ * processor: {
741
+ * name: "Process Data",
742
+ * description: "Transforms incoming data",
743
+ * inputs: {
744
+ * data: {
745
+ * name: "Input Data",
746
+ * onEvent: async (input) => {
747
+ * // Process the event
748
+ * await events.emit(processedData);
749
+ * }
750
+ * }
751
+ * },
752
+ * outputs: {
753
+ * processed: {
754
+ * name: "Processed Data",
755
+ * default: true
756
+ * }
757
+ * }
758
+ * }
759
+ * }
760
+ * });
761
+ * ```
762
+ */
763
+ interface AppSchema {
764
+ /** Display name for the app */
765
+ name?: string;
766
+ /**
767
+ * Instructions shown to users when installing the app.
768
+ * Supports Markdown formatting.
769
+ */
770
+ installationInstructions?: string;
771
+ /**
772
+ * Configuration fields for the app. These are set during installation
773
+ * and available to all blocks within the app.
774
+ */
775
+ config?: Record<string, AppConfigField>;
776
+ /**
777
+ * Signals exported by the app.
778
+ * These are available to all blocks within the app.
779
+ */
780
+ signals?: Record<string, AppSignal>;
781
+ /**
782
+ * Lifecycle hook called when the app needs to synchronize its state.
783
+ * Use this to provision resources, validate configuration, or perform setup.
784
+ */
785
+ onSync?: (input: AppInput) => Promise<AppLifecycleCallbackOutput>;
786
+ /**
787
+ * Lifecycle hook called when the app is being drained (shut down).
788
+ * Use this to clean up resources, save state, or perform teardown.
789
+ */
790
+ onDrain?: (input: AppInput) => Promise<AppLifecycleCallbackOutput>;
791
+ /** Custom status description shown when the app is in draft mode */
792
+ draftCustomStatusDescription?: string;
793
+ /**
794
+ * Handler for internal messages sent to the app from blocks.
795
+ * Used for app-level coordination and communication.
796
+ */
797
+ onInternalMessage?: (input: AppOnInternalMessageInput) => Promise<void>;
798
+ /**
799
+ * Map of block definitions. Each block becomes an entity that can be
800
+ * placed on the flow canvas. Key is the block type ID.
801
+ */
802
+ blocks: Record<string, AppBlock>;
803
+ /** HTTP server configuration for app-level endpoints */
804
+ http?: AppHTTPComponent;
805
+ /** UI component configuration for custom app interfaces */
806
+ ui?: AppUIComponent;
807
+ /**
808
+ * Declarative schedules that trigger at app level.
809
+ * Use for periodic maintenance, data synchronization, etc.
810
+ */
811
+ schedules?: Record<string, AppSchedule>;
812
+ /**
813
+ * Handler for imperative timers set by the app.
814
+ * Called when a timer created with timers.app.set() expires.
815
+ */
816
+ onTimer?: (input: AppOnTimerInput) => Promise<void>;
817
+ }
818
+ interface AppUIComponent {
819
+ onRequest: (input: AppOnUIRequestInput) => Promise<any>;
820
+ }
821
+ type SimpleType = "string" | "number" | "boolean" | "any";
822
+ type SimpleTypeArray = [SimpleType];
823
+ interface JsonSchema {
824
+ type?: string;
825
+ properties?: Record<string, JsonSchema>;
826
+ items?: JsonSchema;
827
+ required?: string[];
828
+ enum?: (string | number)[];
829
+ anyOf?: JsonSchema[];
830
+ oneOf?: JsonSchema[];
831
+ description?: string;
832
+ additionalProperties?: boolean | {
833
+ type: "string" | "number" | "boolean" | "object" | "array";
834
+ };
835
+ }
836
+ type Type = SimpleType | SimpleTypeArray | JsonSchema;
837
+ interface AppConfigField {
838
+ name: string;
839
+ description?: string;
840
+ type: Type;
841
+ fixed?: boolean;
842
+ required: boolean;
843
+ default?: unknown;
844
+ sensitive?: boolean;
845
+ }
846
+ interface AppSignal {
847
+ name: string;
848
+ description: string;
849
+ sensitive?: boolean;
850
+ }
851
+ interface AppHTTPComponent {
852
+ onRequest: (input: AppOnHTTPRequestInput) => Promise<void>;
853
+ }
854
+ type ScheduleDefinition = {
855
+ type: "cron";
856
+ cron: {
857
+ expression: string;
858
+ location: string;
859
+ };
860
+ } | {
861
+ type: "frequency";
862
+ frequency: {
863
+ interval: number;
864
+ unit?: "seconds" | "minutes" | "hours";
865
+ };
866
+ };
867
+ interface AppSchedule {
868
+ description?: string;
869
+ customizable?: boolean;
870
+ definition: ScheduleDefinition;
871
+ onTrigger: (input: AppOnTriggerInput) => Promise<void>;
872
+ }
873
+ interface AppBlock {
874
+ name?: string;
875
+ description?: string;
876
+ category?: string;
877
+ config?: Record<string, AppBlockConfigField>;
878
+ onInternalMessage?: (input: EntityOnInternalMessageInput) => Promise<void>;
879
+ inputs?: Record<string, AppBlockComponentInput>;
880
+ outputs?: Record<string, AppBlockComponentOutput>;
881
+ signals?: Record<string, AppBlockSignal>;
882
+ onSync?: (input: EntityInput) => EntityLifecycleCallbackOutput | Promise<EntityLifecycleCallbackOutput>;
883
+ onDrain?: (input: EntityInput) => EntityLifecycleCallbackOutput | Promise<EntityLifecycleCallbackOutput>;
884
+ draftCustomStatusDescription?: string;
885
+ http?: AppBlockHTTPComponent;
886
+ ui?: AppBlockUIComponent;
887
+ schedules?: Record<string, AppBlockSchedule>;
888
+ onTimer?: (input: EntityOnTimerInput) => Promise<void>;
889
+ }
890
+ interface AppBlockConfigField {
891
+ name: string;
892
+ description?: string;
893
+ type: Type;
894
+ fixed?: boolean;
895
+ required: boolean;
896
+ default?: unknown;
897
+ fieldKey?: string;
898
+ sensitive?: boolean;
899
+ }
900
+ interface AppBlockComponentInput {
901
+ name?: string;
902
+ description?: string;
903
+ config?: Record<string, AppBlockConfigField>;
904
+ onEvent: (input: EventInput) => Promise<void>;
905
+ }
906
+ interface AppBlockComponentOutput {
907
+ name?: string;
908
+ description?: string;
909
+ default?: boolean;
910
+ /**
911
+ * Defines which inputs can provide parent events for this output.
912
+ * Used for type inference - determines what fields and types will be
913
+ * available in the output event based on parent input types.
914
+ * Should be a list of input keys that can be used as parents.
915
+ */
916
+ possiblePrimaryParents?: string[];
917
+ secondary?: boolean;
918
+ type?: Type;
919
+ }
920
+ interface AppBlockHTTPComponent {
921
+ onRequest: (input: EntityOnHTTPRequestInput) => Promise<void>;
922
+ }
923
+ interface AppBlockUIComponent {
924
+ onRequest: (input: EntityOnUIRequestInput) => Promise<any>;
925
+ views?: EntityView[] | null;
926
+ }
927
+ interface AppBlockSignal {
928
+ name: string;
929
+ description: string;
930
+ sensitive?: boolean;
931
+ }
932
+ interface AppBlockSchedule {
933
+ description?: string;
934
+ customizable?: boolean;
935
+ definition: ScheduleDefinition;
936
+ onTrigger: (input: EntityOnTriggerInput) => Promise<void>;
937
+ }
938
+ interface EntityView {
939
+ id: string;
940
+ label: string;
941
+ type: EntityViewType;
942
+ }
943
+ type EntityViewType = "default" | "fullScreen" | "regular";
944
+ /**
945
+ * Input context provided to app-level handlers.
946
+ * Contains app configuration and runtime information.
947
+ */
948
+ interface AppInput {
949
+ /** App installation context and configuration */
950
+ app: AppContext;
951
+ }
952
+ /**
953
+ * App runtime context containing configuration and endpoints.
954
+ * Available in all app-level handlers (onSync, onDrain, onInternalMessage, etc.).
955
+ */
956
+ interface AppContext {
957
+ /** App configuration values set during installation */
958
+ config: Record<string, any>;
959
+ /** Current status of the app installation */
960
+ status: "draft" | "in_progress" | "ready" | "failed" | "draining" | "draining_failed" | "drained";
961
+ /** HTTP endpoint information for this app */
962
+ http: AppHTTPEndpoint;
963
+ /** URL for managing this app installation */
964
+ installationUrl: string;
965
+ /** Signals exported by this app */
966
+ signals: Record<string, any>;
967
+ }
968
+ /**
969
+ * HTTP endpoint information for app-level HTTP handlers.
970
+ */
971
+ interface AppHTTPEndpoint {
972
+ /** Base URL for this app's HTTP endpoints */
973
+ url: string;
974
+ }
975
+ /**
976
+ * Input context provided to block-level handlers.
977
+ * Extends AppInput with block-specific context.
978
+ */
979
+ interface EntityInput extends AppInput {
980
+ /** Block (entity) instance context and configuration */
981
+ block: EntityContext;
982
+ }
983
+ /**
984
+ * Block (entity) runtime context containing configuration and state.
985
+ * Available in all block-level handlers (onEvent, onSync, onDrain, etc.).
986
+ */
987
+ interface EntityContext {
988
+ /** Unique identifier for this block instance */
989
+ id: string;
990
+ /** Display name of this block instance */
991
+ name: string;
992
+ /** Description of this block instance */
993
+ description: string;
994
+ /** Block configuration values set in the flow */
995
+ config: Record<string, any>;
996
+ /** Lifecycle state information (null if block has no lifecycle) */
997
+ lifecycle: EntityLifecycleComponent | null;
998
+ /** HTTP endpoint information (null if block has no HTTP handler) */
999
+ http: EntityHTTPEndpoint | null;
1000
+ }
1001
+ interface EntityLifecycleComponent {
1002
+ status: EntityLifecycleStatus;
1003
+ signals: Record<string, any> | null;
1004
+ }
1005
+ type EntityLifecycleStatus = "draft" | "in_progress" | "ready" | "drifted" | "failed" | "draining" | "draining_failed" | "drained";
1006
+ interface EntityHTTPEndpoint {
1007
+ url: string;
1008
+ }
1009
+ /**
1010
+ * Input context provided to event handlers (onEvent).
1011
+ * Extends EntityInput with event-specific information.
1012
+ */
1013
+ interface EventInput extends EntityInput {
1014
+ /** Event data and metadata */
1015
+ event: EventContext;
1016
+ }
1017
+ /**
1018
+ * Event context containing the event data and metadata.
1019
+ * Available in all onEvent handlers when processing incoming events.
1020
+ */
1021
+ interface EventContext {
1022
+ /** Unique identifier for this event */
1023
+ id: string;
1024
+ /** Configuration values for the specific input that received this event */
1025
+ inputConfig: Record<string, any>;
1026
+ /**
1027
+ * Echo information for request-response patterns.
1028
+ * Present when this event was emitted with echo: true.
1029
+ */
1030
+ echo?: {
1031
+ /** The event body that was echoed */
1032
+ body: any;
1033
+ /** The output key where the original event was emitted */
1034
+ outputKey: string;
1035
+ };
1036
+ }
1037
+ interface EntityLifecycleCallbackOutput {
1038
+ signalUpdates?: Record<string, any>;
1039
+ newStatus?: EntityLifecycleStatus;
1040
+ customStatusDescription?: string | null;
1041
+ nextScheduleDelay?: number;
1042
+ }
1043
+ interface AppLifecycleCallbackOutput {
1044
+ signalUpdates?: Record<string, any>;
1045
+ newStatus?: AppLifecycleStatus;
1046
+ customStatusDescription?: string | null;
1047
+ nextScheduleDelay?: number;
1048
+ }
1049
+ type AppLifecycleStatus = "draft" | "in_progress" | "ready" | "failed" | "draining" | "draining_failed" | "drained";
1050
+ interface AppOnCreateOutput {
1051
+ ok?: {};
1052
+ redirect?: {
1053
+ url: string;
1054
+ method: string;
1055
+ };
1056
+ }
1057
+ interface AppOnInternalMessageInput extends AppInput {
1058
+ message: {
1059
+ body: any;
1060
+ };
1061
+ }
1062
+ interface EntityOnInternalMessageInput extends EntityInput {
1063
+ message: {
1064
+ body: any;
1065
+ };
1066
+ }
1067
+ interface AppOnTimerInput extends AppInput {
1068
+ timer: {
1069
+ id: string;
1070
+ payload: any;
1071
+ prompt?: {
1072
+ id: string;
1073
+ description?: string;
1074
+ };
1075
+ };
1076
+ }
1077
+ interface EntityOnTimerInput extends EntityInput {
1078
+ timer: {
1079
+ id: string;
1080
+ payload: any;
1081
+ pendingEvent?: {
1082
+ id: string;
1083
+ body?: any;
1084
+ status?: string;
1085
+ };
1086
+ };
1087
+ }
1088
+ interface AppOnTriggerInput extends AppInput {
1089
+ schedule: {
1090
+ time: string;
1091
+ };
1092
+ }
1093
+ interface EntityOnTriggerInput extends EntityInput {
1094
+ schedule: {
1095
+ time: string;
1096
+ };
1097
+ }
1098
+ interface AppOnHTTPRequestInput extends AppInput {
1099
+ request: HTTPRequest;
1100
+ }
1101
+ interface EntityOnHTTPRequestInput extends EntityInput {
1102
+ request: HTTPRequest;
1103
+ }
1104
+ interface HTTPRequest {
1105
+ requestId: string;
1106
+ path: string;
1107
+ method: string;
1108
+ headers: Record<string, string>;
1109
+ query: Record<string, string>;
1110
+ params: Record<string, string>;
1111
+ rawBody: string;
1112
+ body: any;
1113
+ }
1114
+ interface AppOnUIRequestInput extends AppInput {
1115
+ request: UIRequest;
1116
+ }
1117
+ interface EntityOnUIRequestInput extends EntityInput {
1118
+ request: UIRequest;
1119
+ }
1120
+ interface UIRequest {
1121
+ type: string;
1122
+ payload?: any;
1123
+ }
1124
+
1110
1125
  export { type AppBlock, type AppBlockComponentInput, type AppBlockComponentOutput, type AppBlockConfigField, type AppBlockHTTPComponent, type AppBlockSchedule, type AppBlockSignal, type AppBlockUIComponent, type AppConfigField, type AppContext, type AppHTTPComponent, type AppHTTPEndpoint, type AppInput, type AppLifecycleCallbackOutput, type AppLifecycleStatus, type AppOnCreateOutput, type AppOnHTTPRequestInput, type AppOnInternalMessageInput, type AppOnTimerInput, type AppOnTriggerInput, type AppOnUIRequestInput, type AppSchedule, type AppSchema, type AppSignal, type AppUIComponent, type EntityContext, type EntityHTTPEndpoint, type EntityInput, type EntityLifecycleCallbackOutput, type EntityLifecycleComponent, type EntityLifecycleStatus, type EntityOnHTTPRequestInput, type EntityOnInternalMessageInput, type EntityOnTimerInput, type EntityOnTriggerInput, type EntityOnUIRequestInput, type EntityView, type EntityViewType, type EventContext, type EventInput, type HTTPRequest, type JsonSchema, type ScheduleDefinition, type Type, type UIRequest, blocks, defineApp, events, getInvocationMetadata, http, kv, lifecycle, messaging, timers, ui };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slflows/sdk",
3
- "version": "0.0.7",
3
+ "version": "0.1.0",
4
4
  "files": [
5
5
  "dist"
6
6
  ],
@@ -15,7 +15,6 @@
15
15
  "typescript": "^5.8.3"
16
16
  },
17
17
  "scripts": {
18
- "build": "tsc && rollup -c",
19
- "prepare": "pkgroll --clean-dist --src types"
18
+ "build": "tsc && rollup -c && pkgroll --clean-dist --src types"
20
19
  }
21
20
  }