@zaflun/lumio-sdk 0.2.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
@@ -1,3 +1,5 @@
1
+ import { LumioEventType } from '@zaflun/lumio-protocol';
2
+
1
3
  interface Validator {
2
4
  type: string;
3
5
  isOptional: boolean;
@@ -135,4 +137,251 @@ declare function filter(field: string, op: string, value: unknown): {
135
137
  value: unknown;
136
138
  };
137
139
 
138
- export { type ActionDefinition, type DeleteRowDefinition, type DeleteRowOptions, type FetchActionDefinition, type FetchActionOptions, type HandlerConfig, type HandlerContext, type InsertRowDefinition, type InsertRowOptions, type MutationDefinition, type PatchRowDefinition, type PatchRowOptions, type QueryDefinition, type QueryRowsDefinition, type SchemaDefinition, type TableDefinition, type Validator, action, arg, defineSchema, defineTable, deleteRow, fetchAction, filter, identity, insertRow, mutation, patchRow, query, queryRows, secret, v };
140
+ interface BotModuleContext {
141
+ auth: {
142
+ userId: string | null;
143
+ accountId: string | null;
144
+ role: string;
145
+ };
146
+ user: {
147
+ id: string;
148
+ name: string;
149
+ displayName: string;
150
+ platform: string;
151
+ role: string;
152
+ isMod: boolean;
153
+ isVip: boolean;
154
+ isSub: boolean;
155
+ } | null;
156
+ config: Record<string, unknown>;
157
+ db: {
158
+ get: (table: string, id: string) => Promise<Record<string, unknown> | null>;
159
+ list: (table: string) => Promise<Record<string, unknown>[]>;
160
+ insert: (table: string, row: Record<string, unknown>) => Promise<string>;
161
+ patch: (table: string, id: string, row: Record<string, unknown>) => Promise<void>;
162
+ delete: (table: string, id: string) => Promise<void>;
163
+ };
164
+ cache: {
165
+ get: (key: string) => Promise<unknown | null>;
166
+ set: (key: string, value: unknown, ttl?: number) => Promise<void>;
167
+ delete: (key: string) => Promise<void>;
168
+ increment: (key: string, by?: number) => Promise<number>;
169
+ };
170
+ secrets: {
171
+ get: (key: string) => Promise<string | null>;
172
+ };
173
+ fetch: (url: string, options?: RequestInit) => Promise<Response>;
174
+ defer: (fn: () => Promise<void>) => void;
175
+ }
176
+ interface HandlerResponse {
177
+ reply?: string;
178
+ actions?: Array<{
179
+ action: string;
180
+ params: Record<string, unknown>;
181
+ }>;
182
+ }
183
+ interface ModerationResponse {
184
+ block: boolean;
185
+ action?: "delete" | "timeout" | "ban";
186
+ duration?: number;
187
+ reason?: string;
188
+ }
189
+ interface ChatMessage {
190
+ text: string;
191
+ platformMessageId: string;
192
+ }
193
+ type CommandHandler = (ctx: BotModuleContext, args: string[]) => Promise<HandlerResponse | null>;
194
+ type KeywordHandler = (ctx: BotModuleContext, message: ChatMessage) => Promise<HandlerResponse | null>;
195
+ type PatternHandler = (ctx: BotModuleContext, message: ChatMessage, matched: string) => Promise<HandlerResponse | null>;
196
+ type EventHandler = (ctx: BotModuleContext, event: Record<string, unknown>) => Promise<HandlerResponse | null>;
197
+ type TimerHandler = (ctx: BotModuleContext) => Promise<HandlerResponse | null>;
198
+ type ModerateHandler = (ctx: BotModuleContext, message: ChatMessage) => Promise<ModerationResponse>;
199
+ declare function command(name: string, handler: CommandHandler): CommandHandler & {
200
+ __type: string;
201
+ __trigger: string;
202
+ };
203
+ declare function keyword(trigger: string, handler: KeywordHandler): KeywordHandler & {
204
+ __type: string;
205
+ __trigger: string;
206
+ };
207
+ declare function pattern(regex: string, handler: PatternHandler): PatternHandler & {
208
+ __type: string;
209
+ __trigger: string;
210
+ };
211
+ declare function event(eventType: LumioEventType | string, handler: EventHandler): EventHandler & {
212
+ __type: string;
213
+ __trigger: string;
214
+ };
215
+ declare function timer(name: string, handler: TimerHandler): TimerHandler & {
216
+ __type: string;
217
+ __trigger: string;
218
+ };
219
+ declare function moderate(handler: ModerateHandler): ModerateHandler & {
220
+ __type: string;
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;
386
+
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
@@ -112,20 +112,89 @@ function secret(name) {
112
112
  function filter(field, op, value) {
113
113
  return { __expr: "filter", field, op, value };
114
114
  }
115
+
116
+ // src/server/bot-module.ts
117
+ function command(name, handler) {
118
+ const fn = handler;
119
+ fn.__type = "command";
120
+ fn.__trigger = name;
121
+ return fn;
122
+ }
123
+ function keyword(trigger, handler) {
124
+ const fn = handler;
125
+ fn.__type = "keyword";
126
+ fn.__trigger = trigger;
127
+ return fn;
128
+ }
129
+ function pattern(regex, handler) {
130
+ const fn = handler;
131
+ fn.__type = "pattern";
132
+ fn.__trigger = regex;
133
+ return fn;
134
+ }
135
+ function event(eventType, handler) {
136
+ const fn = handler;
137
+ fn.__type = "event";
138
+ fn.__trigger = eventType;
139
+ return fn;
140
+ }
141
+ function timer(name, handler) {
142
+ const fn = handler;
143
+ fn.__type = "timer";
144
+ fn.__trigger = name;
145
+ return fn;
146
+ }
147
+ function moderate(handler) {
148
+ const fn = handler;
149
+ fn.__type = "moderate";
150
+ return fn;
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
+ }
115
173
  export {
116
174
  action,
117
175
  arg,
176
+ command,
177
+ defineAutomationAction,
178
+ defineAutomationLogic,
179
+ defineAutomationTrigger,
180
+ defineModerate,
118
181
  defineSchema,
119
182
  defineTable,
183
+ defineTimer,
120
184
  deleteRow,
185
+ event,
121
186
  fetchAction,
122
187
  filter,
123
188
  identity,
124
189
  insertRow,
190
+ keyword,
191
+ moderate,
125
192
  mutation,
126
193
  patchRow,
194
+ pattern,
127
195
  query,
128
196
  queryRows,
129
197
  secret,
198
+ timer,
130
199
  v
131
200
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zaflun/lumio-sdk",
3
- "version": "0.2.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.1.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",