@brika/plugin-example-echo 0.3.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.
package/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # @brika/plugin-example-echo
2
+
3
+ A simple example plugin demonstrating how to create reactive blocks for BRIKA.
4
+
5
+ ## Overview
6
+
7
+ This plugin provides a basic echo block that passes input data to output, optionally with prefix/suffix transformation. It's useful for learning how BRIKA plugins work and for testing workflows.
8
+
9
+ ## Available Blocks
10
+
11
+ ### Echo
12
+
13
+ Echoes input data to output with optional prefix/suffix for string messages.
14
+
15
+ **Inputs:**
16
+ - `in` (generic) — Any data to echo
17
+
18
+ **Outputs:**
19
+ - `out` (generic) — The echoed data
20
+
21
+ **Config:**
22
+ - `prefix` (string, optional) — Prefix to add to string messages
23
+ - `suffix` (string, optional) — Suffix to add to string messages
24
+
25
+ ## Usage
26
+
27
+ ### In Workflows
28
+
29
+ ```yaml
30
+ blocks:
31
+ - id: clock
32
+ type: "@brika/blocks-builtin:clock"
33
+ config:
34
+ interval: 5000
35
+
36
+ - id: echo
37
+ type: "@brika/plugin-example-echo:echo"
38
+ config:
39
+ prefix: "[Echo] "
40
+
41
+ - id: log
42
+ type: "@brika/blocks-builtin:log"
43
+ config:
44
+ message: "Received: {{ JSON.stringify(inputs.in) }}"
45
+
46
+ connections:
47
+ - from: clock
48
+ fromPort: tick
49
+ to: echo
50
+ toPort: in
51
+ - from: echo
52
+ fromPort: out
53
+ to: log
54
+ toPort: in
55
+ ```
56
+
57
+ ## Implementation
58
+
59
+ ```typescript
60
+ import { defineReactiveBlock, input, output, log, onStop, z } from "@brika/sdk";
61
+
62
+ export const echo = defineReactiveBlock(
63
+ {
64
+ id: "echo",
65
+ inputs: {
66
+ in: input(z.generic(), { name: "Input" }),
67
+ },
68
+ outputs: {
69
+ out: output(z.passthrough("in"), { name: "Output" }),
70
+ },
71
+ config: z.object({
72
+ prefix: z.string().optional().describe("Optional prefix for string messages"),
73
+ suffix: z.string().optional().describe("Optional suffix for string messages"),
74
+ }),
75
+ },
76
+ ({ inputs, outputs, config }) => {
77
+ inputs.in.on((data) => {
78
+ if (typeof data === "string" && (config.prefix || config.suffix)) {
79
+ const prefix = config.prefix ?? "";
80
+ const suffix = config.suffix ?? "";
81
+ const result = `${prefix}${data}${suffix}`;
82
+ log.info(`Echo: ${result}`);
83
+ outputs.out.emit(result);
84
+ } else {
85
+ log.info(`Echo: ${JSON.stringify(data)}`);
86
+ outputs.out.emit(data);
87
+ }
88
+ });
89
+ }
90
+ );
91
+
92
+ onStop(() => log.info("Echo plugin stopping"));
93
+ log.info("Echo plugin loaded");
94
+ ```
95
+
96
+ ## Installation
97
+
98
+ Add to your `brika.yml`:
99
+
100
+ ```yaml
101
+ install:
102
+ - ref: "workspace:example-echo"
103
+ enabled: true
104
+ ```
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "Echo Plugin",
3
+ "description": "Simple example plugin that echoes messages",
4
+ "tools": {
5
+ "echo": {
6
+ "name": "Echo",
7
+ "description": "Echo back the provided message"
8
+ }
9
+ },
10
+ "fields": {
11
+ "message": {
12
+ "label": "Message",
13
+ "description": "The message to echo back"
14
+ }
15
+ }
16
+ }
17
+
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "Plugin Écho",
3
+ "description": "Plugin d'exemple simple qui renvoie des messages en écho",
4
+ "tools": {
5
+ "echo": {
6
+ "name": "Écho",
7
+ "description": "Renvoyer le message fourni en écho"
8
+ }
9
+ },
10
+ "fields": {
11
+ "message": {
12
+ "label": "Message",
13
+ "description": "Le message à renvoyer"
14
+ }
15
+ }
16
+ }
17
+
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "$schema": "https://schema.brika.dev/plugin.schema.json",
3
+ "name": "@brika/plugin-example-echo",
4
+ "displayName": "Echo Example",
5
+ "version": "0.3.0",
6
+ "description": "Example echo plugin demonstrating reactive blocks",
7
+ "author": "BRIKA Team",
8
+ "license": "MIT",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/brikalabs/brika.git",
12
+ "directory": "plugins/example-echo"
13
+ },
14
+ "keywords": [
15
+ "brika",
16
+ "brika-plugin",
17
+ "example",
18
+ "echo",
19
+ "demo"
20
+ ],
21
+ "engines": {
22
+ "brika": "^0.3.0"
23
+ },
24
+ "type": "module",
25
+ "main": "./src/index.ts",
26
+ "exports": {
27
+ ".": "./src/index.ts"
28
+ },
29
+ "files": ["src", "locales", "README.md"],
30
+ "scripts": {
31
+ "link": "bun link",
32
+ "typecheck": "tsgo --noEmit",
33
+ "prepublishOnly": "brika-verify-plugin"
34
+ },
35
+ "blocks": [
36
+ {
37
+ "id": "echo",
38
+ "name": "Echo",
39
+ "description": "Echoes input to output with optional prefix/suffix",
40
+ "category": "transform",
41
+ "icon": "message-circle",
42
+ "color": "#3b82f6"
43
+ }
44
+ ],
45
+ "sparks": [
46
+ {
47
+ "id": "echoed",
48
+ "name": "Message Echoed",
49
+ "description": "Emitted when a message is echoed"
50
+ }
51
+ ],
52
+ "dependencies": {
53
+ "@brika/sdk": "0.3.1"
54
+ }
55
+ }
package/src/index.ts ADDED
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Echo Plugin - Example plugin demonstrating reactive blocks and sparks
3
+ */
4
+
5
+ import { defineReactiveBlock, defineSpark, input, log, onStop, output, z } from '@brika/sdk';
6
+
7
+ // ─────────────────────────────────────────────────────────────────────────────
8
+ // Sparks - Typed Events
9
+ // ─────────────────────────────────────────────────────────────────────────────
10
+
11
+ /** Emitted when a message is echoed */
12
+ export const echoed = defineSpark({
13
+ id: 'echoed',
14
+ schema: z.object({
15
+ original: z.any(),
16
+ result: z.any(),
17
+ timestamp: z.number(),
18
+ }),
19
+ });
20
+
21
+ // ─────────────────────────────────────────────────────────────────────────────
22
+ // Echo Block - Echoes input to output with optional transformation
23
+ // ─────────────────────────────────────────────────────────────────────────────
24
+
25
+ export const echo = defineReactiveBlock(
26
+ {
27
+ id: 'echo',
28
+ inputs: {
29
+ in: input(z.generic(), { name: 'Input' }),
30
+ },
31
+ outputs: {
32
+ out: output(z.passthrough('in'), { name: 'Output' }),
33
+ },
34
+ config: z.object({
35
+ prefix: z.string().optional().describe('Optional prefix to add to string messages'),
36
+ suffix: z.string().optional().describe('Optional suffix to add to string messages'),
37
+ }),
38
+ },
39
+ ({ inputs, outputs, config }) => {
40
+ inputs.in.on((data) => {
41
+ let result: unknown;
42
+
43
+ // If data is a string and we have prefix/suffix, apply them
44
+ if (typeof data === 'string' && (config.prefix || config.suffix)) {
45
+ const prefix = config.prefix ?? '';
46
+ const suffix = config.suffix ?? '';
47
+ result = `${prefix}${data}${suffix}`;
48
+ log.info(`Echo: ${result}`);
49
+ } else {
50
+ result = data;
51
+ log.info(`Echo: ${JSON.stringify(data)}`);
52
+ }
53
+
54
+ // Emit spark when message is echoed
55
+ echoed.emit({
56
+ original: data,
57
+ result,
58
+ timestamp: Date.now(),
59
+ });
60
+
61
+ outputs.out.emit(result);
62
+ });
63
+ }
64
+ );
65
+
66
+ // ─────────────────────────────────────────────────────────────────────────────
67
+ // Lifecycle
68
+ // ─────────────────────────────────────────────────────────────────────────────
69
+
70
+ onStop(() => {
71
+ log.info('Echo plugin stopping');
72
+ });
73
+
74
+ log.info('Echo plugin loaded');