@photon-ai/flux 0.3.7 → 0.3.8
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 +231 -123
- package/dist/index.js +21 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,80 +1,101 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
-

|
|
4
|
-
|
|
5
3
|
# @photon-ai/flux
|
|
6
4
|
|
|
7
|
-
>
|
|
5
|
+
> An open-source CLI for deploying LangChain agents to iMessage in seconds
|
|
8
6
|
|
|
9
7
|
</div>
|
|
10
8
|
|
|
11
9
|
[](https://www.npmjs.com/package/@photon-ai/flux)
|
|
12
10
|
[](https://www.typescriptlang.org/)
|
|
13
|
-
[](https://www.python.org/)
|
|
14
11
|
[](./LICENSE)
|
|
15
12
|
[](https://discord.gg/bZd4CMd2H5)
|
|
16
13
|
|
|
17
14
|
Flux is an open-sourced CLI tool that lets developers build and deploy LangChain agents that connect to iMessage at no cost and under 5 seconds.
|
|
18
15
|
|
|
19
|
-
|
|
16
|
+
## Features
|
|
20
17
|
|
|
21
|
-
## Features
|
|
22
18
|
|
|
23
|
-
- **Deploy with a single command**: Export a LangChain agent and deploy it to iMessage with
|
|
24
|
-
- **Text your agent from your phone**: Send an iMessage to the Flux number and get responses from your running agent
|
|
25
|
-
- **Testing mode**: Test your agent through your terminal before connecting to the iMessage
|
|
26
|
-
- **Phone Number Authentication**: Log in with just your phone number and iMessage
|
|
27
|
-
- **Agent Validation**: Automatically validate your LangChain agent in the CLI
|
|
19
|
+
- **Deploy with a single command**: Export a LangChain agent and deploy it to iMessage with one command
|
|
20
|
+
- **Text your agent from your phone**: Send an iMessage to the Flux number and get responses from your running agent
|
|
21
|
+
- **Testing mode**: Test your agent through your terminal before connecting to the iMessage bridge
|
|
22
|
+
- **Phone Number Authentication**: Log in with just your phone number and iMessage
|
|
23
|
+
- **Agent Validation**: Automatically validate your LangChain agent in the CLI
|
|
28
24
|
|
|
29
|
-
|
|
25
|
+
## Quick Start
|
|
30
26
|
|
|
31
|
-
## Installation
|
|
32
27
|
|
|
33
|
-
|
|
34
|
-
```
|
|
35
|
-
npm install @photon-ai/flux
|
|
36
|
-
#or
|
|
37
|
-
bun add @photon-ai/flux
|
|
38
|
-
```
|
|
28
|
+
Get started with Flux in seconds:
|
|
39
29
|
|
|
40
|
-
|
|
30
|
+
```bash
|
|
31
|
+
# No installation needed - use npx directly
|
|
32
|
+
npx @photon-ai/flux login
|
|
41
33
|
|
|
42
|
-
|
|
34
|
+
# Create your agent file
|
|
35
|
+
echo 'export default {
|
|
36
|
+
async invoke({ message }: { message: string }) {
|
|
37
|
+
return `You said: ${message}`;
|
|
38
|
+
}
|
|
39
|
+
};' > agent.ts
|
|
43
40
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
| `npx @photon-ai/flux` | Show help |
|
|
47
|
-
| `npx @photon-ai/flux whoami` | Check account |
|
|
48
|
-
| `npx @photon-ai/flux login` | Login and signup|
|
|
49
|
-
| `npx @photon-ai/flux logout` | Logout |
|
|
50
|
-
| `npx @photon-ai/flux run --local` | Start the development server (local mode) |
|
|
51
|
-
| `npx @photon-ai/flux run --prod` | Start with live iMessage bridge |
|
|
52
|
-
| `npx @photon-ai/flux validate` | Check your code for errors |
|
|
41
|
+
# Test locally
|
|
42
|
+
npx @photon-ai/flux run --local
|
|
53
43
|
|
|
54
|
-
|
|
44
|
+
# Deploy to production
|
|
45
|
+
npx @photon-ai/flux run --prod
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 📦 Installation
|
|
55
49
|
|
|
56
|
-
|
|
50
|
+
### Recommended: Global Installation
|
|
51
|
+
|
|
52
|
+
For the best experience, install Flux globally:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npm install -g @photon-ai/flux
|
|
56
|
+
# or
|
|
57
|
+
bun add -g @photon-ai/flux
|
|
58
|
+
```
|
|
57
59
|
|
|
58
|
-
|
|
60
|
+
Then run commands directly:
|
|
59
61
|
|
|
60
|
-
|
|
62
|
+
```bash
|
|
63
|
+
flux login
|
|
64
|
+
flux run --local
|
|
65
|
+
flux run --prod
|
|
66
|
+
```
|
|
61
67
|
|
|
62
|
-
|
|
68
|
+
### Alternative: Use npx (No Installation Required)
|
|
63
69
|
|
|
64
|
-
|
|
65
|
-
- The user (client) sends a code to the Flux number to prove phone ownership.
|
|
66
|
-
- The server generates a UUID per login attempt. It then waits for the iMessage text from the client with the UUID. Once verified, it will issue a token.
|
|
67
|
-
- Credentials (token, phone, timestamp) are saved to credentials.json. This way, the user only has to log in once.
|
|
70
|
+
You can use Flux without installing it by using `npx` or `bunx`:
|
|
68
71
|
|
|
69
|
-
|
|
72
|
+
```bash
|
|
73
|
+
npx @photon-ai/flux login
|
|
74
|
+
npx @photon-ai/flux run --local
|
|
75
|
+
// or
|
|
76
|
+
bunx @photon-ai/flux login
|
|
77
|
+
bunx @photon-ai/flux run --local
|
|
78
|
+
```
|
|
70
79
|
|
|
71
|
-
|
|
80
|
+
> **Note:** When using `npx` or `bunx`, there's no need to install the package first. `npx` or `bunx` will download and execute it automatically.
|
|
72
81
|
|
|
73
|
-
###
|
|
82
|
+
### Local Installation (For Development)
|
|
74
83
|
|
|
75
|
-
|
|
84
|
+
If you're integrating Flux into a project:
|
|
76
85
|
|
|
86
|
+
```bash
|
|
87
|
+
npm install @photon-ai/flux
|
|
88
|
+
# or
|
|
89
|
+
bun add @photon-ai/flux
|
|
77
90
|
```
|
|
91
|
+
|
|
92
|
+
## 📖 Usage Guide
|
|
93
|
+
|
|
94
|
+
### Step 1: Create Your LangChain Agent
|
|
95
|
+
|
|
96
|
+
Create an `agent.ts` file with your LangChain agent. Make sure to have `export default agent`. Here's a simple example:
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
78
99
|
// agent.ts
|
|
79
100
|
export default {
|
|
80
101
|
async invoke({ message }: { message: string }) {
|
|
@@ -83,13 +104,19 @@ export default {
|
|
|
83
104
|
};
|
|
84
105
|
```
|
|
85
106
|
|
|
86
|
-
### Step 2:
|
|
107
|
+
### Step 2: Authenticate with iMessage
|
|
87
108
|
|
|
88
|
-
Authenticate with your phone number and iMessage:
|
|
109
|
+
Authenticate with your phone number and iMessage:
|
|
89
110
|
|
|
90
|
-
```
|
|
111
|
+
```bash
|
|
112
|
+
flux login
|
|
113
|
+
# or
|
|
91
114
|
npx @photon-ai/flux login
|
|
115
|
+
```
|
|
92
116
|
|
|
117
|
+
**Example session:**
|
|
118
|
+
|
|
119
|
+
```
|
|
93
120
|
Enter your phone number (e.g. +15551234567): +1234567890
|
|
94
121
|
[FLUX] Requesting verification code...
|
|
95
122
|
[FLUX] Verification code: d33gwu
|
|
@@ -99,40 +126,52 @@ Enter your phone number (e.g. +15551234567): +1234567890
|
|
|
99
126
|
[FLUX] Successfully logged in as +1234567890
|
|
100
127
|
```
|
|
101
128
|
|
|
102
|
-
If already logged in:
|
|
129
|
+
If already logged in:
|
|
103
130
|
|
|
104
131
|
```
|
|
105
|
-
npx @photon-ai/flux login
|
|
106
|
-
|
|
107
132
|
[FLUX] Already logged in as +1234567890
|
|
108
133
|
```
|
|
109
134
|
|
|
110
|
-
|
|
135
|
+
To log out:
|
|
111
136
|
|
|
137
|
+
```bash
|
|
138
|
+
flux logout
|
|
112
139
|
```
|
|
113
|
-
npx @photon-ai/flux logout
|
|
114
140
|
|
|
141
|
+
```
|
|
115
142
|
[FLUX] Logged out.
|
|
116
143
|
```
|
|
117
144
|
|
|
118
|
-
### Step 3: Validate
|
|
145
|
+
### Step 3: Validate Your Agent
|
|
119
146
|
|
|
120
|
-
Validate that your agent works and exports correctly:
|
|
147
|
+
Validate that your agent works and exports correctly:
|
|
121
148
|
|
|
122
|
-
```
|
|
149
|
+
```bash
|
|
150
|
+
flux validate
|
|
151
|
+
# or
|
|
123
152
|
npx @photon-ai/flux validate
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**Output:**
|
|
124
156
|
|
|
157
|
+
```
|
|
125
158
|
[FLUX] Validating agent.ts...
|
|
126
159
|
[FLUX] Agent is valid!
|
|
127
160
|
```
|
|
128
161
|
|
|
129
|
-
### Step 4:
|
|
162
|
+
### Step 4: Test Locally (Development Mode)
|
|
130
163
|
|
|
131
|
-
Test your agent through your terminal (no iMessage connection):
|
|
164
|
+
Test your agent through your terminal (no iMessage connection):
|
|
132
165
|
|
|
133
|
-
```
|
|
166
|
+
```bash
|
|
167
|
+
flux run --local
|
|
168
|
+
# or
|
|
134
169
|
npx @photon-ai/flux run --local
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
**Interactive session:**
|
|
135
173
|
|
|
174
|
+
```
|
|
136
175
|
[FLUX] Welcome to Flux! Your agent is loaded.
|
|
137
176
|
[FLUX] Type a message to test it. Press Ctrl+C to exit.
|
|
138
177
|
|
|
@@ -141,122 +180,191 @@ You: Hello!
|
|
|
141
180
|
Agent: Hello! How can I assist you today?
|
|
142
181
|
```
|
|
143
182
|
|
|
144
|
-
### Step 5: Live
|
|
183
|
+
### Step 5: Deploy to Production (Live iMessage)
|
|
145
184
|
|
|
146
|
-
Run your agent locally and connect it to the iMessage bridge. When you message the
|
|
185
|
+
Run your agent locally and connect it to the iMessage bridge. When you message the Flux number (`+16286298650`) from your registered phone, you'll receive responses from your LangChain agent:
|
|
147
186
|
|
|
148
|
-
```
|
|
187
|
+
```bash
|
|
188
|
+
flux run --prod
|
|
189
|
+
# or
|
|
149
190
|
npx @photon-ai/flux run --prod
|
|
191
|
+
```
|
|
150
192
|
|
|
193
|
+
**Output:**
|
|
194
|
+
|
|
195
|
+
```
|
|
151
196
|
[FLUX] Loading agent from agent.ts...
|
|
152
197
|
[FLUX] Agent loaded successfully!
|
|
153
198
|
[FLUX] Connected to server at fluxy.photon.codes:443
|
|
154
199
|
[FLUX] Registered agent for +1234567890
|
|
155
200
|
[FLUX] Agent running in production mode. Press Ctrl+C to stop.
|
|
156
201
|
[FLUX] Messages to +1234567890 will be processed by your agent.
|
|
157
|
-
|
|
158
202
|
```
|
|
159
203
|
|
|
160
|
-
|
|
204
|
+
Now text **`+16286298650`** from your phone to interact with your agent!
|
|
161
205
|
|
|
162
|
-
##
|
|
206
|
+
## 🛠️ CLI Commands
|
|
163
207
|
|
|
164
|
-
|
|
208
|
+
| Command | Description |
|
|
209
|
+
|---------|-------------|
|
|
210
|
+
| `flux` or `npx @photon-ai/flux` | Show help |
|
|
211
|
+
| `flux whoami` | Check currently logged-in account |
|
|
212
|
+
| `flux login` | Login and signup with phone number |
|
|
213
|
+
| `flux logout` | Logout from current session |
|
|
214
|
+
| `flux validate` | Check your agent code for errors |
|
|
215
|
+
| `flux run --local` | Start development server (local testing mode) |
|
|
216
|
+
| `flux run --prod` | Start with live iMessage bridge |
|
|
165
217
|
|
|
166
|
-
|
|
218
|
+
## 🔐 Authentication
|
|
167
219
|
|
|
168
|
-
|
|
169
|
-
- **Fully iMessage native**: Direct iMessage integration, not SMS or WhatsApp.
|
|
170
|
-
- **Zero Infrastructure**: No servers to manage, webhooks to configure, or Apple Developer account needed.
|
|
171
|
-
- **Open source**: Fully community driven.
|
|
172
|
-
- **Free to use**: No subscription fees.
|
|
220
|
+
Authentication is based on iMessage to ensure secure and simple access:
|
|
173
221
|
|
|
174
|
-
|
|
222
|
+
1. **Code Generation**: The server generates a unique UUID for each login attempt
|
|
223
|
+
2. **Phone Verification**: You send the verification code to the Flux number (`+16286298650`) via iMessage to prove phone ownership
|
|
224
|
+
3. **Token Issuance**: Once verified, the server issues an authentication token
|
|
225
|
+
4. **Persistent Login**: Credentials (token, phone, timestamp) are saved to `credentials.json`, so you only need to log in once
|
|
175
226
|
|
|
176
|
-
##
|
|
227
|
+
## Proactive Messaging
|
|
177
228
|
|
|
178
|
-
|
|
229
|
+
Agents can initiate conversations without waiting for a user message. In production mode, `onInit` receives a sendMessage function that lets your agent send messages at any time.
|
|
179
230
|
|
|
180
231
|
```
|
|
181
|
-
|
|
232
|
+
let sendMessage: (to: string, text: string) => Promise<boolean>;
|
|
233
|
+
|
|
182
234
|
export default {
|
|
183
|
-
async
|
|
184
|
-
|
|
185
|
-
|
|
235
|
+
async onInit(send) {
|
|
236
|
+
sendMessage = send;
|
|
237
|
+
// Now you can call sendMessage() anywhere in your agent
|
|
238
|
+
},
|
|
239
|
+
// ...
|
|
186
240
|
};
|
|
187
241
|
```
|
|
188
242
|
|
|
189
|
-
|
|
243
|
+
**Note**: Proactive messaging is only available in production mode `(flux run --prod`). In local mode, `onInit` is called without arguments.
|
|
244
|
+
|
|
245
|
+
## 💡 Examples
|
|
246
|
+
|
|
247
|
+
### Weather Agent
|
|
248
|
+
|
|
249
|
+
An agent with a weather tool (returns mock data).
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
import * as z from "zod";
|
|
253
|
+
import { createAgent, tool } from "langchain";
|
|
190
254
|
|
|
255
|
+
const getWeather = tool(
|
|
256
|
+
({ city }) => `It's always sunny in ${city}!`,
|
|
257
|
+
{
|
|
258
|
+
name: "get_weather",
|
|
259
|
+
description: "Get the weather for a given city",
|
|
260
|
+
schema: z.object({
|
|
261
|
+
city: z.string(),
|
|
262
|
+
}),
|
|
263
|
+
},
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
const agent = createAgent({
|
|
267
|
+
model: "claude-sonnet-4-5-20250929",
|
|
268
|
+
tools: [getWeather],
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
export default agent
|
|
191
272
|
```
|
|
273
|
+
|
|
274
|
+
### Chatbot with Memory
|
|
275
|
+
|
|
276
|
+
An advanced agent with memory:
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
192
279
|
// agent.ts
|
|
280
|
+
import "dotenv/config";
|
|
193
281
|
import { ChatOpenAI } from "@langchain/openai";
|
|
194
|
-
import {
|
|
282
|
+
import { HumanMessage, AIMessage, SystemMessage } from "@langchain/core/messages";
|
|
195
283
|
|
|
196
284
|
const llm = new ChatOpenAI({ modelName: "gpt-4o-mini" });
|
|
285
|
+
const history: Array<HumanMessage | AIMessage> = [];
|
|
197
286
|
|
|
198
287
|
export default {
|
|
199
288
|
async invoke({ message }: { message: string }) {
|
|
289
|
+
history.push(new HumanMessage(message));
|
|
290
|
+
|
|
200
291
|
const response = await llm.invoke([
|
|
201
292
|
new SystemMessage("You are a helpful assistant. Be concise."),
|
|
202
|
-
|
|
293
|
+
...history,
|
|
203
294
|
]);
|
|
204
|
-
|
|
295
|
+
|
|
296
|
+
const reply = response.content as string;
|
|
297
|
+
history.push(new AIMessage(reply));
|
|
298
|
+
|
|
299
|
+
// Keep last 20 messages to avoid token limits
|
|
300
|
+
if (history.length > 20) {
|
|
301
|
+
history.splice(0, 2);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return reply;
|
|
205
305
|
}
|
|
206
306
|
};
|
|
207
307
|
```
|
|
208
308
|
|
|
209
|
-
|
|
309
|
+
## Why Flux?
|
|
210
310
|
|
|
211
|
-
|
|
212
|
-
// agent.ts
|
|
213
|
-
import { ChatOpenAI } from "@langchain/openai";
|
|
214
|
-
import { tool } from "@langchain/core/tools";
|
|
215
|
-
import { createReactAgent } from "@langchain/langgraph/prebuilt";
|
|
216
|
-
import { z } from "zod";
|
|
311
|
+
Connecting agents to messaging platforms traditionally involves complex processes like setting up servers, configuring webhooks, and dealing with platform APIs. Most solutions rely on SMS or WhatsApp, which can be unintuitive for many users.
|
|
217
312
|
|
|
218
|
-
|
|
219
|
-
async ({ expression }: { expression: string }) => {
|
|
220
|
-
return String(eval(expression));
|
|
221
|
-
},
|
|
222
|
-
{
|
|
223
|
-
name: "calculator",
|
|
224
|
-
description: "Evaluate a math expression",
|
|
225
|
-
schema: z.object({ expression: z.string() }),
|
|
226
|
-
}
|
|
227
|
-
);
|
|
313
|
+
**Flux solves these problems:**
|
|
228
314
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
schema: z.object({}),
|
|
235
|
-
}
|
|
236
|
-
);
|
|
315
|
+
- **Deploy in < 5 seconds** — Link your LangChain agent to iMessage with a single command
|
|
316
|
+
- **Fully iMessage native** — Direct iMessage integration, not SMS or WhatsApp
|
|
317
|
+
- **Zero Infrastructure** — No servers to manage, webhooks to configure, or Apple Developer account needed
|
|
318
|
+
- **Open source** — Fully community-driven and transparent
|
|
319
|
+
- **Free to use** — No subscription fees or hidden costs
|
|
237
320
|
|
|
238
|
-
|
|
239
|
-
const agent = createReactAgent({ llm, tools: [calculator, getTime] });
|
|
321
|
+
## 👤 Single-User Design
|
|
240
322
|
|
|
241
|
-
|
|
242
|
-
async invoke({ message }: { message: string }) {
|
|
243
|
-
const result = await agent.invoke({ messages: [{ role: "user", content: message }] });
|
|
244
|
-
return result.messages[result.messages.length - 1].content as string;
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
|
-
```
|
|
323
|
+
**Important:** Flux is designed for personal use and development. When you deploy an agent with Flux, **only your registered phone number** can interact with it via iMessage. This means:
|
|
248
324
|
|
|
249
|
-
|
|
325
|
+
- ✅ Perfect for personal assistants and prototypes
|
|
326
|
+
- ✅ Great for testing and development
|
|
327
|
+
- ✅ Simple single-user experience
|
|
328
|
+
- ❌ Not designed for multi-user conversations
|
|
329
|
+
- ❌ No enterprise-level user management
|
|
250
330
|
|
|
251
|
-
|
|
331
|
+
### Need Enterprise Support?
|
|
252
332
|
|
|
253
|
-
- **
|
|
254
|
-
- **Python** 3.9+ (for the agent)
|
|
255
|
-
- **LLM Keys (e.g. OpenAI API key)**
|
|
333
|
+
For **enterprise-level iMessage agents** with advanced features, consider our [Advanced iMessage Kit](https://github.com/photon-hq/advanced-imessage-kit):
|
|
256
334
|
|
|
257
|
-
|
|
335
|
+
- **Multi-user support** — Handle thousands of users simultaneously
|
|
336
|
+
- **Dedicated phone line** — Get your own iMessage number
|
|
337
|
+
- **Enterprise features** — Advanced conversation management and analytics
|
|
338
|
+
- **Production-ready** — Enhanced stability and performance
|
|
339
|
+
- **More functionalities** — Additional tools and integrations
|
|
258
340
|
|
|
341
|
+
[**Explore Advanced iMessage Kit →**](https://github.com/photon-hq/advanced-imessage-kit)
|
|
259
342
|
|
|
260
|
-
|
|
343
|
+
## ⚙️ Requirements
|
|
344
|
+
|
|
345
|
+
- **Node.js** 18+ or **Bun** (for the CLI)
|
|
346
|
+
- **Python** 3.9+ (for the agent, if using Python-based LangChain)
|
|
347
|
+
- **LLM API Keys** (e.g., OpenAI API key for GPT-powered agents)
|
|
348
|
+
|
|
349
|
+
## 🤝 Contributing
|
|
350
|
+
|
|
351
|
+
We welcome contributions! Flux is fully open source and community-driven. Feel free to:
|
|
352
|
+
|
|
353
|
+
- 🐛 [Report bugs](https://github.com/photon-hq/flux/issues)
|
|
354
|
+
- 💡 [Request features](https://github.com/photon-hq/flux/issues)
|
|
355
|
+
- 🔧 Submit pull requests
|
|
356
|
+
- ⭐ Star the repository
|
|
357
|
+
|
|
358
|
+
## 💬 Support
|
|
359
|
+
|
|
360
|
+
- **Discord**: Join our community at [discord.gg/bZd4CMd2H5](https://discord.gg/bZd4CMd2H5)
|
|
361
|
+
- **Issues**: Report problems on [GitHub Issues](https://github.com/photon-hq/flux/issues)
|
|
362
|
+
- **Documentation**: Check out this README for comprehensive guides
|
|
363
|
+
|
|
364
|
+
## 📄 License
|
|
365
|
+
|
|
366
|
+
MIT License - see the [LICENSE](./LICENSE) file for details.
|
|
367
|
+
|
|
368
|
+
<br /><div align="center">
|
|
261
369
|
<sub>Built with ⚡ by <a href="https://photon.codes">Photon</a></sub>
|
|
262
|
-
</div>
|
|
370
|
+
</div>
|
package/dist/index.js
CHANGED
|
@@ -52148,7 +52148,8 @@ var FluxClient = class {
|
|
|
52148
52148
|
async startMessageStream() {
|
|
52149
52149
|
if (!this.client) return;
|
|
52150
52150
|
(async () => {
|
|
52151
|
-
|
|
52151
|
+
const stream = this.client.FluxService.messageStream;
|
|
52152
|
+
for await (const [message] of stream) {
|
|
52152
52153
|
if ("ack" in message) {
|
|
52153
52154
|
console.log(`[FLUX] Received ack: ${message.ack}`);
|
|
52154
52155
|
} else {
|
|
@@ -52384,7 +52385,8 @@ async function loadAgent(agentPath) {
|
|
|
52384
52385
|
}
|
|
52385
52386
|
const moduleUrl = url.pathToFileURL(agentPath).href;
|
|
52386
52387
|
const agentModule = await import(moduleUrl);
|
|
52387
|
-
|
|
52388
|
+
const agent = agentModule.default;
|
|
52389
|
+
return agent;
|
|
52388
52390
|
}
|
|
52389
52391
|
|
|
52390
52392
|
// src/index.ts
|
|
@@ -52418,6 +52420,9 @@ async function runLocal() {
|
|
|
52418
52420
|
process.exit(1);
|
|
52419
52421
|
}
|
|
52420
52422
|
const agent = await loadAgent(agentPath);
|
|
52423
|
+
if (agent.onInit) {
|
|
52424
|
+
await agent.onInit();
|
|
52425
|
+
}
|
|
52421
52426
|
console.log("\n[FLUX] Welcome to Flux! Your agent is loaded.");
|
|
52422
52427
|
console.log("[FLUX] Type a message to test it. Press Ctrl+C to exit.\n");
|
|
52423
52428
|
const rl = readline__namespace.createInterface({
|
|
@@ -52441,12 +52446,18 @@ async function runLocal() {
|
|
|
52441
52446
|
} catch (error) {
|
|
52442
52447
|
console.log(`[FLUX] Error: ${error.message}
|
|
52443
52448
|
`);
|
|
52449
|
+
if (agent.onError) {
|
|
52450
|
+
await agent.onError(error);
|
|
52451
|
+
}
|
|
52444
52452
|
}
|
|
52445
52453
|
askQuestion();
|
|
52446
52454
|
});
|
|
52447
52455
|
};
|
|
52448
|
-
rl.on("close", () => {
|
|
52456
|
+
rl.on("close", async () => {
|
|
52449
52457
|
console.log("\n[FLUX] Goodbye!");
|
|
52458
|
+
if (agent.onShutdown) {
|
|
52459
|
+
await agent.onShutdown();
|
|
52460
|
+
}
|
|
52450
52461
|
process.exit(0);
|
|
52451
52462
|
});
|
|
52452
52463
|
askQuestion();
|
|
@@ -52484,11 +52495,18 @@ async function runProd() {
|
|
|
52484
52495
|
});
|
|
52485
52496
|
await flux.connect();
|
|
52486
52497
|
await flux.register();
|
|
52498
|
+
if (agent.onInit) {
|
|
52499
|
+
console.log("[FLUX] Initializing agent with proactive messaging support...");
|
|
52500
|
+
await agent.onInit((to, text) => flux.sendMessage(to, text));
|
|
52501
|
+
}
|
|
52487
52502
|
console.log("[FLUX] Agent running in production mode. Press Ctrl+C to stop.");
|
|
52488
52503
|
console.log(`[FLUX] Messages to ${phoneNumber} will be processed by your agent.
|
|
52489
52504
|
`);
|
|
52490
52505
|
process.on("SIGINT", async () => {
|
|
52491
52506
|
console.log("\n[FLUX] Shutting down...");
|
|
52507
|
+
if (agent.onShutdown) {
|
|
52508
|
+
await agent.onShutdown();
|
|
52509
|
+
}
|
|
52492
52510
|
await flux.disconnect();
|
|
52493
52511
|
process.exit(0);
|
|
52494
52512
|
});
|