@meetsmore-oss/use-ai-plugin-workflows 1.2.1

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.
@@ -0,0 +1,77 @@
1
+ import type { WorkflowRunner, WorkflowInput, WorkflowResult, EventEmitter } from '../types';
2
+ /**
3
+ * Configuration for DifyWorkflowRunner.
4
+ */
5
+ export interface DifyWorkflowRunnerConfig {
6
+ /**
7
+ * Base URL of the Dify API (e.g., 'https://api.dify.ai/v1' or 'http://localhost:3001/v1').
8
+ */
9
+ apiBaseUrl: string;
10
+ /**
11
+ * Map of workflow names to Dify app API keys.
12
+ * This allows you to use meaningful workflow names in your code while
13
+ * keeping API keys in environment variables.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * {
18
+ * workflows: {
19
+ * 'greeting-workflow': process.env.DIFY_GREETING_WORKFLOW_KEY!,
20
+ * 'pdf-processor': process.env.DIFY_PDF_PROCESSOR_KEY!,
21
+ * }
22
+ * }
23
+ * ```
24
+ */
25
+ workflows: Record<string, string>;
26
+ }
27
+ /**
28
+ * Workflow runner for Dify AI workflows.
29
+ *
30
+ * Integrates with Dify (https://dify.ai) to execute workflows as headless operations.
31
+ * Dify is designed for API-first workflow execution with proper variable handling.
32
+ *
33
+ * Features:
34
+ * - Execute Dify workflows via API
35
+ * - Support for streaming responses
36
+ * - Pass workflow inputs as variables (properly supported unlike Flowise)
37
+ * - Emit AG-UI events for text responses
38
+ *
39
+ * Note: This runner currently does not support tool calls back to the client.
40
+ * Dify workflows execute independently and return text results.
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const runner = new DifyWorkflowRunner({
45
+ * apiBaseUrl: 'http://localhost:3001/v1',
46
+ * workflows: {
47
+ * 'greeting-workflow': process.env.DIFY_GREETING_WORKFLOW_KEY!,
48
+ * 'pdf-processor': process.env.DIFY_PDF_PROCESSOR_KEY!,
49
+ * },
50
+ * });
51
+ *
52
+ * // Use with WorkflowsPlugin
53
+ * new WorkflowsPlugin({
54
+ * runners: new Map([
55
+ * ['dify', runner],
56
+ * ]),
57
+ * });
58
+ *
59
+ * // Use meaningful workflow names (mapped to API keys on server):
60
+ * const { trigger } = useAIWorkflow('dify', 'greeting-workflow');
61
+ * await trigger({
62
+ * inputs: { username: 'Alice' },
63
+ * });
64
+ *
65
+ * // Fallback: If workflow name not found in mapping, uses workflowId directly as API key:
66
+ * const { trigger: directTrigger } = useAIWorkflow('dify', 'app-xxxxx');
67
+ * ```
68
+ */
69
+ export declare class DifyWorkflowRunner implements WorkflowRunner {
70
+ private apiBaseUrl;
71
+ private workflows;
72
+ constructor(config: DifyWorkflowRunnerConfig);
73
+ getName(): string;
74
+ execute(input: WorkflowInput, events: EventEmitter): Promise<WorkflowResult>;
75
+ private handleStreamingResponse;
76
+ }
77
+ //# sourceMappingURL=DifyWorkflowRunner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DifyWorkflowRunner.d.ts","sourceRoot":"","sources":["../../src/runners/DifyWorkflowRunner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAI5F;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;;;;;;;;;;OAcG;IACH,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,qBAAa,kBAAmB,YAAW,cAAc;IACvD,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,SAAS,CAAyB;gBAE9B,MAAM,EAAE,wBAAwB;IAK5C,OAAO,IAAI,MAAM;IAIX,OAAO,CAAC,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC;YA4HpE,uBAAuB;CAkHtC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=test-preload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-preload.d.ts","sourceRoot":"","sources":["../src/test-preload.ts"],"names":[],"mappings":""}
@@ -0,0 +1,109 @@
1
+ import type { ClientSession } from '@meetsmore-oss/use-ai-server';
2
+ import type { ToolDefinition, AGUIEvent } from '@meetsmore-oss/use-ai-core';
3
+ /**
4
+ * Interface for emitting AG-UI protocol events.
5
+ * All workflow runners must use this to communicate results to clients.
6
+ */
7
+ export interface EventEmitter {
8
+ /** Emit an AG-UI event to the client */
9
+ emit<T extends AGUIEvent = AGUIEvent>(event: T): void;
10
+ }
11
+ /**
12
+ * Input for executing a workflow.
13
+ * Provides all context needed for a single workflow run.
14
+ */
15
+ export interface WorkflowInput {
16
+ /** The client session context */
17
+ session: ClientSession;
18
+ /** Unique identifier for this workflow run */
19
+ runId: string;
20
+ /** Unique identifier for the conversation thread */
21
+ threadId: string;
22
+ /** Workflow identifier (depends on which platform you are using) */
23
+ workflowId: string;
24
+ /** Workflow inputs (arbitrary JSON data) */
25
+ inputs: Record<string, any>;
26
+ /** Tools available for the workflow to call */
27
+ tools: ToolDefinition[];
28
+ }
29
+ /**
30
+ * Result from a workflow execution.
31
+ * Indicates whether the workflow completed successfully and any final output.
32
+ */
33
+ export interface WorkflowResult {
34
+ /** Whether the workflow completed successfully */
35
+ success: boolean;
36
+ /** Error message if the workflow failed */
37
+ error?: string;
38
+ /** Optional output data from the workflow */
39
+ output?: Record<string, any>;
40
+ }
41
+ /**
42
+ * Abstract interface for workflow runners.
43
+ *
44
+ * Workflow runners integrate with external workflow platforms (Dify, Flowise, n8n, etc.)
45
+ * or execute custom workflow logic. Unlike Agents (for conversational chat), workflow runners:
46
+ * - Are stateless (no conversation history)
47
+ * - Are triggered programmatically (not by user chat)
48
+ * - Execute single-run operations
49
+ * - Can still call frontend tools via AG-UI protocol
50
+ *
51
+ * All workflow runners must:
52
+ * - Accept WorkflowInput with workflowId, inputs, and tools
53
+ * - Emit AG-UI protocol events (TEXT_MESSAGE_*, TOOL_CALL_*, RUN_*, etc.)
54
+ * - Handle tool call coordination (emit TOOL_CALL_START, wait for result, continue)
55
+ * - Return WorkflowResult indicating success/failure
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * class MyWorkflowRunner implements WorkflowRunner {
60
+ * getName() {
61
+ * return 'my-platform';
62
+ * }
63
+ *
64
+ * async execute(input: WorkflowInput, events: EventEmitter): Promise<WorkflowResult> {
65
+ * // 1. Emit RUN_STARTED
66
+ * events.emit({ type: EventType.RUN_STARTED, ... });
67
+ *
68
+ * // 2. Execute workflow (call external platform API, etc.)
69
+ * const result = await myPlatform.executeWorkflow(input.workflowId, input.inputs);
70
+ *
71
+ * // 3. Emit TEXT_MESSAGE_* events for responses
72
+ * events.emit({ type: EventType.TEXT_MESSAGE_START, ... });
73
+ *
74
+ * // 4. For tool calls, emit TOOL_CALL_START and wait for results
75
+ * events.emit({ type: EventType.TOOL_CALL_START, ... });
76
+ * const toolResult = await waitForToolResult(toolCallId, input.session);
77
+ *
78
+ * // 5. Emit RUN_FINISHED
79
+ * events.emit({ type: EventType.RUN_FINISHED, ... });
80
+ *
81
+ * return { success: true, output: result };
82
+ * }
83
+ * }
84
+ * ```
85
+ */
86
+ export interface WorkflowRunner {
87
+ /**
88
+ * Returns the unique identifier for this workflow runner.
89
+ * Used for selecting runners when triggering workflows.
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * getName(): string {
94
+ * return 'dify';
95
+ * }
96
+ * ```
97
+ */
98
+ getName(): string;
99
+ /**
100
+ * Executes a workflow with the given input.
101
+ * Must emit AG-UI events and coordinate tool execution.
102
+ *
103
+ * @param input - The workflow context (session, workflowId, inputs, tools)
104
+ * @param events - Event emitter for sending AG-UI events to client
105
+ * @returns Promise resolving to the workflow result
106
+ */
107
+ execute(input: WorkflowInput, events: EventEmitter): Promise<WorkflowResult>;
108
+ }
109
+ //# sourceMappingUR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{};
2
+ //# sourceMappingURL=workflows.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflows.test.d.ts","sourceRoot":"","sources":["../src/workflows.test.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@meetsmore-oss/use-ai-plugin-workflows",
3
+ "version": "1.2.1",
4
+ "license": "BUSL-1.1",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "author": {
9
+ "name": "Zachary Davison",
10
+ "url": "https://github.com/mm-zacharydavison"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/meetsmore/use-ai.git",
15
+ "directory": "packages/plugin-workflows"
16
+ },
17
+ "description": "Workflow execution plugin for @use-ai/server",
18
+ "type": "module",
19
+ "main": "./dist/index.js",
20
+ "types": "./dist/index.d.ts",
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "default": "./dist/index.js"
25
+ }
26
+ },
27
+ "scripts": {
28
+ "clean": "rm -rf dist *.tsbuildinfo",
29
+ "build": "bun build src/index.ts --outdir dist --target node --format esm --external @meetsmore-oss/use-ai-server && tsc --emitDeclarationOnly --skipLibCheck",
30
+ "dev": "bun --watch src/index.ts",
31
+ "test": "bun test --only-failures"
32
+ },
33
+ "dependencies": {
34
+ "@meetsmore-oss/use-ai-core": "1.2.1",
35
+ "ai": "6.0.0-beta.116",
36
+ "uuid": "^11.0.3"
37
+ },
38
+ "devDependencies": {
39
+ "@types/uuid": "^10.0.0",
40
+ "@meetsmore-oss/use-ai-server": "1.2.1",
41
+ "typescript": "^5.9.3"
42
+ },
43
+ "peerDependencies": {
44
+ "@meetsmore-oss/use-ai-server": "1.2.1"
45
+ }
46
+ }