@zaflun/lumio-sdk 0.3.0 → 0.6.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.
package/dist/server.d.ts CHANGED
@@ -219,5 +219,169 @@ declare function timer(name: string, handler: TimerHandler): TimerHandler & {
219
219
  declare function moderate(handler: ModerateHandler): ModerateHandler & {
220
220
  __type: string;
221
221
  };
222
+ interface ModerateContext extends BotModuleContext {
223
+ message: ChatMessage;
224
+ }
225
+ interface ModerateResult {
226
+ action: "allow" | "delete" | "timeout" | "warn" | "ban";
227
+ duration?: number;
228
+ reason?: string;
229
+ message?: string;
230
+ }
231
+ interface ModerateDefinition {
232
+ __type: "moderate";
233
+ handler: (ctx: ModerateContext) => Promise<ModerateResult>;
234
+ }
235
+ /**
236
+ * Define a moderation handler with a unified context.
237
+ *
238
+ * The handler receives a single `ctx` object that includes `config`,
239
+ * `user`, and `message`. Return `{ action: "allow" }` to pass, or
240
+ * `{ action: "delete" | "timeout" | "ban" | "warn", reason?, duration?, message? }`.
241
+ *
242
+ * ```ts
243
+ * import { defineModerate } from "@zaflun/lumio-sdk/server";
244
+ *
245
+ * export default defineModerate(async (ctx) => {
246
+ * if (ctx.message.text.includes("spam")) {
247
+ * return { action: "delete", reason: "Spam detected" };
248
+ * }
249
+ * return { action: "allow" };
250
+ * });
251
+ * ```
252
+ */
253
+ declare function defineModerate(handler: (ctx: ModerateContext) => Promise<ModerateResult>): ModerateDefinition;
254
+ type TimerContext = BotModuleContext;
255
+ interface TimerDefinition {
256
+ __type: "timer";
257
+ handler: (ctx: TimerContext) => Promise<HandlerResponse | null>;
258
+ }
259
+ /**
260
+ * Define a timer handler with a unified context.
261
+ *
262
+ * The handler is called on a configurable interval. Return a
263
+ * `HandlerResponse` with `reply` / `actions`, or `null` to skip.
264
+ *
265
+ * ```ts
266
+ * import { defineTimer } from "@zaflun/lumio-sdk/server";
267
+ *
268
+ * export default defineTimer(async (ctx) => {
269
+ * return { reply: "Remember to follow!", actions: [] };
270
+ * });
271
+ * ```
272
+ */
273
+ declare function defineTimer(handler: (ctx: TimerContext) => Promise<HandlerResponse | null>): TimerDefinition;
274
+
275
+ interface AutomationNodeContext {
276
+ /** HTTP fetch with egress allowlist enforcement. */
277
+ fetch: (url: string, options?: RequestInit) => Promise<Response>;
278
+ /** Scoped Redis cache (per extension per account). */
279
+ cache: {
280
+ get: (key: string) => Promise<unknown | null>;
281
+ set: (key: string, value: unknown, ttl?: number) => Promise<void>;
282
+ delete: (key: string) => Promise<void>;
283
+ };
284
+ /** Extension-level config from extension_installs.config. */
285
+ installConfig: Record<string, unknown>;
286
+ /** Per-node instance config from automation_nodes.config. */
287
+ nodeConfig: Record<string, unknown>;
288
+ /** Data from upstream node (action/logic) or webhook/poll payload (trigger). */
289
+ inputData: Record<string, unknown>;
290
+ /** Auth context. */
291
+ auth: {
292
+ accountId: string;
293
+ extensionId: string;
294
+ installId: string;
295
+ };
296
+ }
297
+ /** Extended context for trigger handlers — includes webhook body. */
298
+ interface TriggerNodeContext extends AutomationNodeContext {
299
+ /** Raw webhook request body (only available in onWebhook). */
300
+ webhookBody: Record<string, unknown>;
301
+ }
302
+ interface ActionResult {
303
+ output: Record<string, unknown>;
304
+ status: "success" | "error";
305
+ error_message?: string;
306
+ }
307
+ interface TriggerResult {
308
+ fired: boolean;
309
+ output?: Record<string, unknown>;
310
+ }
311
+ type ActionHandler = (ctx: AutomationNodeContext) => Promise<ActionResult>;
312
+ type LogicHandler = (ctx: AutomationNodeContext) => Promise<string>;
313
+ interface TriggerHandlers {
314
+ onWebhook?: (ctx: TriggerNodeContext) => Promise<TriggerResult | null>;
315
+ onPoll?: (ctx: AutomationNodeContext) => Promise<TriggerResult | null>;
316
+ }
317
+ interface AutomationActionDefinition {
318
+ __type: "automation_action";
319
+ handler: ActionHandler;
320
+ }
321
+ interface AutomationTriggerDefinition {
322
+ __type: "automation_trigger";
323
+ onWebhook?: TriggerHandlers["onWebhook"];
324
+ onPoll?: TriggerHandlers["onPoll"];
325
+ }
326
+ interface AutomationLogicDefinition {
327
+ __type: "automation_logic";
328
+ handler: LogicHandler;
329
+ }
330
+ /**
331
+ * Define an automation action node handler.
332
+ *
333
+ * The handler receives upstream data via `ctx.inputData` and must return
334
+ * an `ActionResult` with output matching the manifest's `output_schema`.
335
+ *
336
+ * ```ts
337
+ * import { defineAutomationAction } from "@zaflun/lumio-sdk/server";
338
+ *
339
+ * defineAutomationAction(async (ctx) => {
340
+ * const res = await ctx.fetch("https://api.example.com/data");
341
+ * const data = await res.json();
342
+ * return { output: { result: data.value }, status: "success" };
343
+ * });
344
+ * ```
345
+ */
346
+ declare function defineAutomationAction(handler: ActionHandler): AutomationActionDefinition;
347
+ /**
348
+ * Define an automation trigger node handler.
349
+ *
350
+ * Triggers support `onWebhook` (external HTTP) and/or `onPoll` (periodic check).
351
+ * Return `{ fired: true, output: { ... } }` to fire the automation.
352
+ *
353
+ * ```ts
354
+ * import { defineAutomationTrigger } from "@zaflun/lumio-sdk/server";
355
+ *
356
+ * defineAutomationTrigger({
357
+ * onWebhook: async (ctx) => {
358
+ * if (ctx.webhookBody.event !== "order.created") return { fired: false };
359
+ * return { fired: true, output: { order_id: ctx.webhookBody.id } };
360
+ * },
361
+ * onPoll: async (ctx) => {
362
+ * const res = await ctx.fetch("https://api.example.com/events");
363
+ * const events = await res.json();
364
+ * if (events.length === 0) return null;
365
+ * return { fired: true, output: events[0] };
366
+ * },
367
+ * });
368
+ * ```
369
+ */
370
+ declare function defineAutomationTrigger(handlers: TriggerHandlers): AutomationTriggerDefinition;
371
+ /**
372
+ * Define an automation logic node handler.
373
+ *
374
+ * The handler must return a branch key string (e.g. "true", "false", "match").
375
+ * The automation engine follows the output handle matching this key.
376
+ *
377
+ * ```ts
378
+ * import { defineAutomationLogic } from "@zaflun/lumio-sdk/server";
379
+ *
380
+ * defineAutomationLogic(async (ctx) => {
381
+ * return ctx.inputData.amount > ctx.nodeConfig.threshold ? "above" : "below";
382
+ * });
383
+ * ```
384
+ */
385
+ declare function defineAutomationLogic(handler: LogicHandler): AutomationLogicDefinition;
222
386
 
223
- export { type ActionDefinition, type BotModuleContext, type ChatMessage, type DeleteRowDefinition, type DeleteRowOptions, type FetchActionDefinition, type FetchActionOptions, type HandlerConfig, type HandlerContext, type HandlerResponse, type InsertRowDefinition, type InsertRowOptions, type ModerationResponse, type MutationDefinition, type PatchRowDefinition, type PatchRowOptions, type QueryDefinition, type QueryRowsDefinition, type SchemaDefinition, type TableDefinition, type Validator, action, arg, command, defineSchema, defineTable, deleteRow, event, fetchAction, filter, identity, insertRow, keyword, moderate, mutation, patchRow, pattern, query, queryRows, secret, timer, v };
387
+ export { type ActionDefinition, type ActionResult, type AutomationActionDefinition, type AutomationLogicDefinition, type AutomationNodeContext, type AutomationTriggerDefinition, type BotModuleContext, type ChatMessage, type DeleteRowDefinition, type DeleteRowOptions, type FetchActionDefinition, type FetchActionOptions, type HandlerConfig, type HandlerContext, type HandlerResponse, type InsertRowDefinition, type InsertRowOptions, type ModerateContext, type ModerateDefinition, type ModerateResult, type ModerationResponse, type MutationDefinition, type PatchRowDefinition, type PatchRowOptions, type QueryDefinition, type QueryRowsDefinition, type SchemaDefinition, type TableDefinition, type TimerContext, type TimerDefinition, type TriggerNodeContext, type TriggerResult, type Validator, action, arg, command, defineAutomationAction, defineAutomationLogic, defineAutomationTrigger, defineModerate, defineSchema, defineTable, defineTimer, deleteRow, event, fetchAction, filter, identity, insertRow, keyword, moderate, mutation, patchRow, pattern, query, queryRows, secret, timer, v };
package/dist/server.js CHANGED
@@ -149,12 +149,38 @@ function moderate(handler) {
149
149
  fn.__type = "moderate";
150
150
  return fn;
151
151
  }
152
+ function defineModerate(handler) {
153
+ return { __type: "moderate", handler };
154
+ }
155
+ function defineTimer(handler) {
156
+ return { __type: "timer", handler };
157
+ }
158
+
159
+ // src/server/automation-node.ts
160
+ function defineAutomationAction(handler) {
161
+ return { __type: "automation_action", handler };
162
+ }
163
+ function defineAutomationTrigger(handlers) {
164
+ return {
165
+ __type: "automation_trigger",
166
+ onWebhook: handlers.onWebhook,
167
+ onPoll: handlers.onPoll
168
+ };
169
+ }
170
+ function defineAutomationLogic(handler) {
171
+ return { __type: "automation_logic", handler };
172
+ }
152
173
  export {
153
174
  action,
154
175
  arg,
155
176
  command,
177
+ defineAutomationAction,
178
+ defineAutomationLogic,
179
+ defineAutomationTrigger,
180
+ defineModerate,
156
181
  defineSchema,
157
182
  defineTable,
183
+ defineTimer,
158
184
  deleteRow,
159
185
  event,
160
186
  fetchAction,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zaflun/lumio-sdk",
3
- "version": "0.3.0",
3
+ "version": "0.6.3",
4
4
  "description": "Lumio Extension SDK — React components, hooks, and server utilities for building Lumio extensions",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -23,8 +23,8 @@
23
23
  ],
24
24
  "dependencies": {
25
25
  "react-reconciler": "^0.32.0",
26
- "@zaflun/lumio-extension-types": "0.3.0",
27
- "@zaflun/lumio-protocol": "0.1.1"
26
+ "@zaflun/lumio-protocol": "0.2.3",
27
+ "@zaflun/lumio-extension-types": "0.3.2"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "react": "^18.0.0 || ^19.0.0",
@@ -36,10 +36,12 @@
36
36
  "@types/react-dom": "^19.1.0",
37
37
  "@types/react-reconciler": "^0.32.0",
38
38
  "jsdom": "^26.1.0",
39
+ "lucide-static": "^1.16.0",
39
40
  "react": "^19.1.0",
40
41
  "react-dom": "^19.1.0",
41
42
  "tsup": "^8.4.0",
42
43
  "typescript": "^5.8.3",
44
+ "unicode-emoji-json": "^0.9.0",
43
45
  "vitest": "^3.1.4"
44
46
  },
45
47
  "license": "MIT",
@@ -62,6 +64,8 @@
62
64
  "email": "developers@zaflun.com"
63
65
  },
64
66
  "scripts": {
67
+ "generate:data": "node scripts/generate-lucide-data.mjs && node scripts/generate-emoji-data.mjs",
68
+ "prebuild": "pnpm generate:data",
65
69
  "build": "tsup src/index.ts src/server.ts --format esm --dts --clean && pnpm build:runtime",
66
70
  "build:runtime": "tsup --config tsup.runtime.ts",
67
71
  "test": "vitest run",