motia 0.0.32 → 0.0.34

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 CHANGED
@@ -1,18 +1,91 @@
1
- # Motia Snap
1
+ # Motia
2
2
 
3
- Motia Snap is a command-line interface tool to get your Motia project setup.
3
+ <p align="center">
4
+ <img src="https://raw.githubusercontent.com/motiajs/motia/main/assets/logo.png" alt="Motia Logo" width="200" />
5
+ </p>
4
6
 
5
- ## Installation
7
+ <p align="center">
8
+ <strong>A modern, declarative workflow framework for multiple programming languages</strong>
9
+ </p>
10
+
11
+ <p align="center">
12
+ <a href="https://www.npmjs.com/package/motia"><img src="https://img.shields.io/npm/v/motia.svg" alt="npm version"></a>
13
+ <a href="https://github.com/motiajs/motia/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="license"></a>
14
+ </p>
15
+
16
+ ## What is Motia?
17
+
18
+ Motia is a lightweight, flexible framework for building complex workflows and business processes across multiple programming languages. It allows you to define, visualize, and execute workflows with a clean, declarative API in JavaScript, TypeScript, Ruby, Python, and more languages coming soon.
6
19
 
7
- To install the CLI globally, run:
20
+ Key features:
21
+ - 🔄 **Declarative Workflows**: Define complex processes with a simple, readable syntax
22
+ - 🛠️ **Type-Safe**: Built with strong typing support for all supported languages
23
+ - 🔍 **Visualizable**: Inspect and debug your workflows with Motia Workbench
24
+ - 🧩 **Composable**: Build complex workflows from reusable components
25
+ - 🚀 **Multi-Language Support**: Works with JavaScript, TypeScript, Ruby, Python, with more languages coming soon
26
+ - 🌐 **Framework Agnostic**: Integrates with any framework in your language of choice
8
27
 
28
+ ## Installation
29
+
30
+ ### JavaScript/TypeScript
9
31
  ```sh
10
- npm install -g motia
32
+ npm install motia
33
+ # or
34
+ yarn add motia
35
+ # or
36
+ pnpm add motia
11
37
  ```
12
38
 
13
- ## Usage
14
39
 
15
- Below are the available commands for the Motia Snap:
40
+ ```
41
+
42
+ ## Quick Start
43
+
44
+ ### Email Auto-Reply with Sentiment Analysis
45
+
46
+ Here's a real-world example of using Motia to create an automated email reply system with sentiment analysis:
47
+
48
+ ```typescript
49
+ import { OpenAI } from 'openai';
50
+ import { z } from 'zod';
51
+ import type { EventConfig, StepHandler } from 'motia';
52
+
53
+ const openai = new OpenAI({
54
+ apiKey: process.env.OPENAI_API_KEY,
55
+ });
56
+
57
+ export const config: EventConfig = {
58
+ type: 'event',
59
+ name: 'Auto-Reply to Support Emails',
60
+ subscribes: ['email.received'],
61
+ emits: ['email.send'],
62
+ flows: ['email-support'],
63
+ input: z.object({ subject: z.string(), body: z.string(), from: z.string() }),
64
+ };
65
+
66
+ export const handler: StepHandler<typeof config> = async (inputData, context) => {
67
+ const { subject, body, from } = inputData;
68
+ const { emit, logger } = context;
69
+
70
+ const sentimentResponse = await openai.chat.completions.create({
71
+ model: "gpt-4o",
72
+ messages: [{ role: "user", content: `Analyze the sentiment of the following email: ${body}` }]
73
+ });
74
+
75
+ const sentiment = sentimentResponse.choices[0].message.content;
76
+
77
+ logger.info('[EmailAutoReply] Sentiment analysis', { sentiment });
78
+
79
+ emit({
80
+ type: 'email.send',
81
+ data: { from, subject, body, sentiment },
82
+ });
83
+ };
84
+ ```
85
+
86
+ ## CLI Commands
87
+
88
+ Motia comes with a powerful CLI to help you manage your projects:
16
89
 
17
90
  ### `motia init`
18
91
 
@@ -38,6 +111,26 @@ Initiates a dev environment for your project allowing you to use Motia Workbench
38
111
  motia dev
39
112
  ```
40
113
 
114
+ ## Visualizing Workflows
115
+
116
+ Motia Workbench provides a visual interface to inspect and debug your workflows:
117
+
118
+ ```sh
119
+ motia dev
120
+ ```
121
+
122
+ Then open your browser at `http://localhost:3000` to see your workflows in action.
123
+
124
+ ## Language Support
125
+
126
+ Motia currently supports:
127
+ - JavaScript
128
+ - TypeScript
129
+ - Ruby
130
+ - Python
131
+
132
+ With more languages coming soon!
133
+
41
134
  ## Help
42
135
 
43
136
  For more information on a specific command, you can use the `--help` flag:
@@ -46,6 +139,14 @@ For more information on a specific command, you can use the `--help` flag:
46
139
  motia <command> --help
47
140
  ```
48
141
 
142
+ ## Documentation
143
+
144
+ For full documentation, visit [https://motia.dev/docs](https://motia.dev/docs)
145
+
146
+ ## Contributing
147
+
148
+ We welcome contributions! Please see our [Contributing Guide](https://github.com/motiajs/motia/blob/main/CONTRIBUTING.md) for details.
149
+
49
150
  ## License
50
151
 
51
152
  This project is licensed under the MIT License.
@@ -0,0 +1,2 @@
1
+ export * from '@motiadev/core';
2
+ export * from '@motiadev/workbench';
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("@motiadev/core"), exports);
18
+ __exportStar(require("@motiadev/workbench"), exports);
@@ -0,0 +1,9 @@
1
+ import { Step } from '@motiadev/core/dist/src/types';
2
+ export declare class BuildPrinter {
3
+ private readonly printer;
4
+ private readonly output;
5
+ printStepBuilding(step: Step): void;
6
+ printStepBuilt(step: Step): void;
7
+ printStepFailed(step: Step, error: Error): void;
8
+ printStepSkipped(step: Step, reason: string): void;
9
+ }
@@ -0,0 +1 @@
1
+ export declare const build: () => Promise<void>;
@@ -0,0 +1,6 @@
1
+ export declare class CLIOutputManager {
2
+ private lines;
3
+ private lineCount;
4
+ logStep(id: string, message: string): void;
5
+ updateStep(id: string, newMessage: string): void;
6
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,6 @@
1
+ type Args = {
2
+ projectName: string;
3
+ template?: string;
4
+ };
5
+ export declare const create: ({ projectName, template }: Args) => Promise<void>;
6
+ export {};
@@ -0,0 +1,4 @@
1
+ export declare const generateStepFiles: (flowDir: string, files: {
2
+ [key: string]: string;
3
+ }) => Promise<void>;
4
+ export declare const generateDefaultTemplateSteps: (flowDir: string) => Promise<void>;
@@ -0,0 +1 @@
1
+ export declare const templates: Record<string, (dir: string) => Promise<void>>;
@@ -0,0 +1,2 @@
1
+ import { StepAnswers } from './types';
2
+ export declare const getStepAnswers: () => Promise<StepAnswers>;
@@ -0,0 +1,3 @@
1
+ export declare function createStep(options: {
2
+ stepFilePath?: string;
3
+ }): Promise<void>;
@@ -0,0 +1,5 @@
1
+ import { StepAnswers } from './types';
2
+ /**
3
+ * Generates the appropriate template based on language and type
4
+ */
5
+ export declare function generateTemplate(answers: StepAnswers): Promise<string>;
@@ -0,0 +1,5 @@
1
+ import { StepAnswers } from '../../types';
2
+ /**
3
+ * Generates a React component override for the step
4
+ */
5
+ export declare function generateOverride(answers: StepAnswers): Promise<string>;
@@ -0,0 +1,21 @@
1
+ export declare const STEP_TYPES: readonly ["api", "event", "cron", "noop"];
2
+ export declare const LANGUAGES: readonly ["typescript", "javascript", "python", "ruby"];
3
+ export declare const HTTP_METHODS: readonly ["GET", "POST", "PUT", "DELETE"];
4
+ export type StepType = (typeof STEP_TYPES)[number];
5
+ export type Language = (typeof LANGUAGES)[number];
6
+ export type HttpMethod = (typeof HTTP_METHODS)[number];
7
+ export type StepAnswers = {
8
+ name: string;
9
+ language: Language;
10
+ type: StepType;
11
+ description?: string;
12
+ method?: HttpMethod;
13
+ path?: string;
14
+ subscriptions?: string[];
15
+ cronExpression?: string;
16
+ virtualEmits?: string[];
17
+ virtualSubscribes?: string[];
18
+ emits: string[];
19
+ flows: string[];
20
+ createOverride: boolean;
21
+ };
@@ -0,0 +1,2 @@
1
+ import { Language } from './types';
2
+ export declare const getFileExtension: (language: Language) => string;
@@ -0,0 +1,2 @@
1
+ import { MotiaServer, StateAdapter } from '@motiadev/core';
2
+ export declare const stateEndpoints: (server: MotiaServer, stateAdapter: StateAdapter) => void;
@@ -0,0 +1,2 @@
1
+ import { MotiaServer } from '@motiadev/core';
2
+ export declare const workflowConfigEndpoints: (server: MotiaServer, baseDir: string) => void;
@@ -0,0 +1,3 @@
1
+ import { LockedData, MotiaServer, MotiaEventManager, CronManager } from '@motiadev/core';
2
+ import { Watcher } from './watcher';
3
+ export declare const createDevWatchers: (lockedData: LockedData, server: MotiaServer, eventHandler: MotiaEventManager, cronManager: CronManager) => Watcher;
@@ -0,0 +1 @@
1
+ export declare const dev: (port: number, isVerbose: boolean) => Promise<void>;
@@ -0,0 +1,3 @@
1
+ import { LockedData, Step } from '@motiadev/core';
2
+ export declare const collectFlows: (baseDir: string, lockedData: LockedData) => Promise<Step[]>;
3
+ export declare const generateLockedData: (projectDir: string) => Promise<LockedData>;
@@ -0,0 +1,24 @@
1
+ import { LockedData, Step } from '@motiadev/core';
2
+ type StepChangeHandler = (oldStep: Step, newStep: Step) => void;
3
+ type StepCreateHandler = (step: Step) => void;
4
+ type StepDeleteHandler = (step: Step) => void;
5
+ export declare class Watcher {
6
+ private readonly dir;
7
+ private lockedData;
8
+ private watcher?;
9
+ private stepChangeHandler?;
10
+ private stepCreateHandler?;
11
+ private stepDeleteHandler?;
12
+ constructor(dir: string, lockedData: LockedData);
13
+ onStepChange(handler: StepChangeHandler): void;
14
+ onStepCreate(handler: StepCreateHandler): void;
15
+ onStepDelete(handler: StepDeleteHandler): void;
16
+ private findStep;
17
+ private onFileAdd;
18
+ private onFileChange;
19
+ private onFileDelete;
20
+ init(): void;
21
+ private isStepFile;
22
+ stop(): Promise<void>;
23
+ }
24
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "motia",
3
- "version": "0.0.32",
3
+ "version": "0.0.34",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "motia": "dist/src/cli.js"
@@ -16,8 +16,8 @@
16
16
  "inquirer": "^12.4.1",
17
17
  "ts-node": "^10.9.2",
18
18
  "yaml": "^2.7.0",
19
- "@motiadev/core": "0.0.32",
20
- "@motiadev/workbench": "0.0.32"
19
+ "@motiadev/core": "0.0.34",
20
+ "@motiadev/workbench": "0.0.34"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/archiver": "^6.0.3",