@ravi-hq/ravi 0.5.3 → 0.5.5
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 +62 -68
- package/dist/auth.d.ts +2 -0
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js.map +1 -1
- package/dist/bin/ravi-secrets.d.ts +3 -3
- package/dist/bin/ravi-secrets.js +7 -7
- package/dist/bin/ravi-secrets.js.map +1 -1
- package/dist/channels/email-trusted.d.ts.map +1 -1
- package/dist/channels/email-trusted.js +5 -7
- package/dist/channels/email-trusted.js.map +1 -1
- package/dist/channels/email-untrusted.d.ts.map +1 -1
- package/dist/channels/email-untrusted.js +5 -7
- package/dist/channels/email-untrusted.js.map +1 -1
- package/dist/channels/email.d.ts +12 -22
- package/dist/channels/email.d.ts.map +1 -1
- package/dist/channels/email.js +48 -54
- package/dist/channels/email.js.map +1 -1
- package/dist/cli.d.ts +15 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +271 -211
- package/dist/cli.js.map +1 -1
- package/dist/client.d.ts +62 -22
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +75 -33
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +7 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -76
- package/dist/index.js.map +1 -1
- package/dist/sse-pool.d.ts +5 -2
- package/dist/sse-pool.d.ts.map +1 -1
- package/dist/sse-pool.js +9 -7
- package/dist/sse-pool.js.map +1 -1
- package/dist/sse.d.ts +7 -21
- package/dist/sse.d.ts.map +1 -1
- package/dist/sse.js +10 -33
- package/dist/sse.js.map +1 -1
- package/dist/tools/contacts.d.ts +14 -0
- package/dist/tools/contacts.d.ts.map +1 -0
- package/dist/tools/contacts.js +186 -0
- package/dist/tools/contacts.js.map +1 -0
- package/dist/tools/email-send.d.ts.map +1 -1
- package/dist/tools/email-send.js +11 -4
- package/dist/tools/email-send.js.map +1 -1
- package/dist/tools/identity.d.ts +2 -2
- package/dist/tools/identity.d.ts.map +1 -1
- package/dist/tools/identity.js +14 -6
- package/dist/tools/identity.js.map +1 -1
- package/dist/tools/inbox.js +7 -7
- package/dist/tools/inbox.js.map +1 -1
- package/dist/tools/passwords.d.ts.map +1 -1
- package/dist/tools/passwords.js +20 -7
- package/dist/tools/passwords.js.map +1 -1
- package/dist/tools/secrets.d.ts +15 -0
- package/dist/tools/secrets.d.ts.map +1 -0
- package/dist/tools/{vault.js → secrets.js} +23 -23
- package/dist/tools/secrets.js.map +1 -0
- package/dist/tools/sms-send.d.ts.map +1 -1
- package/dist/tools/sms-send.js +3 -1
- package/dist/tools/sms-send.js.map +1 -1
- package/dist/types.d.ts +18 -12
- package/dist/types.d.ts.map +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +4 -13
- package/dist/channels/sms-trusted.d.ts +0 -161
- package/dist/channels/sms-trusted.d.ts.map +0 -1
- package/dist/channels/sms-trusted.js +0 -306
- package/dist/channels/sms-trusted.js.map +0 -1
- package/dist/channels/sms-untrusted.d.ts +0 -124
- package/dist/channels/sms-untrusted.d.ts.map +0 -1
- package/dist/channels/sms-untrusted.js +0 -269
- package/dist/channels/sms-untrusted.js.map +0 -1
- package/dist/channels/sms.d.ts +0 -279
- package/dist/channels/sms.d.ts.map +0 -1
- package/dist/channels/sms.js +0 -385
- package/dist/channels/sms.js.map +0 -1
- package/dist/service.d.ts +0 -107
- package/dist/service.d.ts.map +0 -1
- package/dist/service.js +0 -211
- package/dist/service.js.map +0 -1
- package/dist/tools/vault.d.ts +0 -15
- package/dist/tools/vault.d.ts.map +0 -1
- package/dist/tools/vault.js.map +0 -1
package/dist/channels/sms.js
DELETED
|
@@ -1,385 +0,0 @@
|
|
|
1
|
-
// ─── Channel Definition ──────────────────────────────────────────────────────
|
|
2
|
-
/**
|
|
3
|
-
* Creates the ravi-sms channel definition for OpenClaw.
|
|
4
|
-
*
|
|
5
|
-
* All messages from one phone number are grouped into a single session:
|
|
6
|
-
* - A new `from_number` triggers creation of a new session.
|
|
7
|
-
* - A known `from_number` resumes the existing session.
|
|
8
|
-
*
|
|
9
|
-
* The channel is a plain object (not a class) following OpenClaw's
|
|
10
|
-
* declarative channel convention.
|
|
11
|
-
*
|
|
12
|
-
* @returns The ravi-sms channel definition object.
|
|
13
|
-
*/
|
|
14
|
-
export function createSmsChannel() {
|
|
15
|
-
return {
|
|
16
|
-
id: "ravi-sms",
|
|
17
|
-
meta: {
|
|
18
|
-
id: "ravi-sms",
|
|
19
|
-
label: "Ravi SMS",
|
|
20
|
-
selectionLabel: "Ravi SMS (AI Agent Identity)",
|
|
21
|
-
blurb: "SMS channel via Ravi identity provider. All messages from one phone number form a single agent session.",
|
|
22
|
-
aliases: ["ravi-text"],
|
|
23
|
-
},
|
|
24
|
-
capabilities: {
|
|
25
|
-
chatTypes: ["direct"],
|
|
26
|
-
},
|
|
27
|
-
config: {
|
|
28
|
-
/**
|
|
29
|
-
* List all configured account IDs (identity UUIDs) for the ravi-sms channel.
|
|
30
|
-
*
|
|
31
|
-
* Reads from the plugin config path first (set by `openclaw ravi login`),
|
|
32
|
-
* then falls back to the standard `channels.ravi-sms.accounts` path.
|
|
33
|
-
* Deduplicates when both sources contain the same UUID.
|
|
34
|
-
*
|
|
35
|
-
* @param cfg - The full OpenClaw gateway configuration object.
|
|
36
|
-
* @returns Array of identity UUID strings.
|
|
37
|
-
*/
|
|
38
|
-
listAccountIds: (cfg) => {
|
|
39
|
-
// Primary: read from plugin config (set by `openclaw ravi login`)
|
|
40
|
-
const plugins = cfg.plugins;
|
|
41
|
-
const uuid = plugins?.entries?.ravi?.config?.identityUuid;
|
|
42
|
-
// Fallback: standard channel accounts path
|
|
43
|
-
const channels = cfg.channels;
|
|
44
|
-
const channelIds = Object.keys(channels?.["ravi-sms"]?.accounts ?? {});
|
|
45
|
-
// Deduplicate — plugin config uuid takes priority
|
|
46
|
-
if (uuid) {
|
|
47
|
-
return [uuid, ...channelIds.filter((id) => id !== uuid)];
|
|
48
|
-
}
|
|
49
|
-
return channelIds;
|
|
50
|
-
},
|
|
51
|
-
/**
|
|
52
|
-
* Resolve an account configuration by its ID (identity UUID).
|
|
53
|
-
*
|
|
54
|
-
* Returns a minimal config with just the UUID if the account is not
|
|
55
|
-
* found in the standard channels path. The gateway adapter will fetch
|
|
56
|
-
* identity details at startup.
|
|
57
|
-
*
|
|
58
|
-
* @param cfg - The full OpenClaw gateway configuration object.
|
|
59
|
-
* @param accountId - The identity UUID to look up.
|
|
60
|
-
* @returns The resolved {@link SmsAccountConfig}.
|
|
61
|
-
*/
|
|
62
|
-
resolveAccount: (cfg, accountId) => {
|
|
63
|
-
const channels = cfg.channels;
|
|
64
|
-
const found = channels?.["ravi-sms"]?.accounts?.[accountId];
|
|
65
|
-
if (found)
|
|
66
|
-
return found;
|
|
67
|
-
// Fallback: return minimal config — gateway adapter fetches details at startup
|
|
68
|
-
return {
|
|
69
|
-
identityUuid: accountId,
|
|
70
|
-
identityName: "",
|
|
71
|
-
phone: "",
|
|
72
|
-
};
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
/**
|
|
76
|
-
* Normalize an inbound SSE SMS event into a channel message envelope.
|
|
77
|
-
*
|
|
78
|
-
* Only owner events reach this channel — trust-level routing happens
|
|
79
|
-
* at the SSE layer. No read-only or sender classification needed.
|
|
80
|
-
*
|
|
81
|
-
* @param event - The raw {@link SmsEvent} from the SSE stream.
|
|
82
|
-
* @param account - The {@link SmsAccountConfig} for the receiving identity.
|
|
83
|
-
* @returns A normalized {@link SmsInboundEnvelope}. Current implementation always returns non-null.
|
|
84
|
-
*/
|
|
85
|
-
normalizeInbound(event, account) {
|
|
86
|
-
return {
|
|
87
|
-
senderId: event.from_number,
|
|
88
|
-
text: event.body,
|
|
89
|
-
threadId: event.from_number,
|
|
90
|
-
metadata: {
|
|
91
|
-
conversationId: event.conversation_id,
|
|
92
|
-
},
|
|
93
|
-
};
|
|
94
|
-
},
|
|
95
|
-
outbound: {
|
|
96
|
-
deliveryMode: "direct",
|
|
97
|
-
/**
|
|
98
|
-
* Send an SMS reply to the phone number that triggered this session.
|
|
99
|
-
*
|
|
100
|
-
* Calls {@link RaviClient.sendSms} with the plain-text body (no HTML
|
|
101
|
-
* wrapping, unlike the email channel).
|
|
102
|
-
*
|
|
103
|
-
* @param params.text - Plain-text message body.
|
|
104
|
-
* @param params.client - An authenticated {@link RaviClient} instance.
|
|
105
|
-
* @param params.threadContext - Thread context containing the recipient's phone number.
|
|
106
|
-
* @returns A result object indicating success or failure.
|
|
107
|
-
*/
|
|
108
|
-
sendText: async (params) => {
|
|
109
|
-
const { text, client, threadContext } = params;
|
|
110
|
-
if (!threadContext?.phoneNumber) {
|
|
111
|
-
return {
|
|
112
|
-
ok: false,
|
|
113
|
-
error: "No SMS thread context — cannot send without a recipient phone number",
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
try {
|
|
117
|
-
await client.sendSms(threadContext.phoneNumber, text);
|
|
118
|
-
return { ok: true };
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
const message = error instanceof Error ? error.message : "Unknown error";
|
|
122
|
-
return { ok: false, error: `Failed to send SMS: ${message}` };
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
/**
|
|
127
|
-
* Generate the session key for this channel.
|
|
128
|
-
*
|
|
129
|
-
* The key uniquely identifies a session by combining the agent, account,
|
|
130
|
-
* and phone number. OpenClaw uses this to route inbound events to the
|
|
131
|
-
* correct session and persist session state.
|
|
132
|
-
*
|
|
133
|
-
* For SMS, all messages from the same phone number share one session,
|
|
134
|
-
* so `phoneNumber` is used as the conversation discriminator (unlike
|
|
135
|
-
* email which uses `threadId`).
|
|
136
|
-
*
|
|
137
|
-
* Format: `agent:{agentId}:ravi-sms:{accountId}:dm:{phoneNumber}`
|
|
138
|
-
*
|
|
139
|
-
* @param agentId - The OpenClaw agent identifier.
|
|
140
|
-
* @param accountId - The identity UUID (account ID).
|
|
141
|
-
* @param phoneNumber - The other party's phone number (E.164 format).
|
|
142
|
-
* @returns The deterministic session key string.
|
|
143
|
-
*/
|
|
144
|
-
getSessionKey(agentId, accountId, phoneNumber) {
|
|
145
|
-
return `agent:${agentId}:ravi-sms:${accountId}:dm:${phoneNumber}`;
|
|
146
|
-
},
|
|
147
|
-
// ─── Gateway Adapter ──────────────────────────────────────────────────
|
|
148
|
-
gateway: {
|
|
149
|
-
/**
|
|
150
|
-
* Start monitoring inbound SMS for a single identity account.
|
|
151
|
-
*
|
|
152
|
-
* Called by the ChannelManager once per account. Opens an SSE stream
|
|
153
|
-
* to the Ravi backend, dispatches inbound SMS through the OpenClaw
|
|
154
|
-
* reply pipeline, and blocks until the abort signal fires.
|
|
155
|
-
*
|
|
156
|
-
* Bails out early if the identity has no phone number — SMS requires
|
|
157
|
-
* a provisioned phone number.
|
|
158
|
-
*
|
|
159
|
-
* Only owner events reach this adapter — trust-level routing at the
|
|
160
|
-
* SSE layer filters out non-owner senders before they arrive here.
|
|
161
|
-
*
|
|
162
|
-
* This gateway adapter is the ChannelManager-driven path, used when
|
|
163
|
-
* OpenClaw manages channel lifecycles directly. The `normalizeInbound` +
|
|
164
|
-
* `RaviListenerService` path in service.ts is the legacy self-managed
|
|
165
|
-
* approach for environments where the gateway doesn't call startAccount.
|
|
166
|
-
*
|
|
167
|
-
* @param ctx - Gateway context provided by the ChannelManager.
|
|
168
|
-
* @returns Promise that resolves when the account is stopped.
|
|
169
|
-
*/
|
|
170
|
-
startAccount: async (ctx) => {
|
|
171
|
-
const log = ctx.log ?? {
|
|
172
|
-
info: (...args) => console.log("[ravi-sms]", ...args),
|
|
173
|
-
warn: (...args) => console.warn("[ravi-sms]", ...args),
|
|
174
|
-
error: (...args) => console.error("[ravi-sms]", ...args),
|
|
175
|
-
};
|
|
176
|
-
// Lazy imports — only loaded when the gateway actually starts an account.
|
|
177
|
-
// This avoids pulling in runtime/auth/config/client/sse in test environments
|
|
178
|
-
// where gateway.startAccount() is never called.
|
|
179
|
-
let getRaviRuntime, loadAuth, updateAuth, RAVI_API_URL, RaviClient, acquireSSEClient, releaseSSEClient;
|
|
180
|
-
try {
|
|
181
|
-
({ getRaviRuntime } = await import("../runtime.js"));
|
|
182
|
-
({ loadAuth, updateAuth } = await import("../auth.js"));
|
|
183
|
-
({ RAVI_API_URL } = await import("../config.js"));
|
|
184
|
-
({ RaviClient } = await import("../client.js"));
|
|
185
|
-
({ acquireSSEClient, releaseSSEClient } = await import("../sse-pool.js"));
|
|
186
|
-
}
|
|
187
|
-
catch (err) {
|
|
188
|
-
const detail = err instanceof Error ? err.message : String(err);
|
|
189
|
-
log.error(`[ravi-sms] Failed to load dependencies: ${detail}. Is the plugin built correctly?`);
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
const runtime = getRaviRuntime();
|
|
193
|
-
const auth = loadAuth();
|
|
194
|
-
if (!auth?.access_token) {
|
|
195
|
-
log.error("[ravi-sms] No auth credentials — cannot start SMS channel. Run 'openclaw ravi login'.");
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
// Track the current token — onTokenRefresh updates this when the
|
|
199
|
-
// REST client auto-refreshes on 401, so the SSE client (created after
|
|
200
|
-
// the first REST call) gets the fresh token instead of the stale one.
|
|
201
|
-
let currentToken = auth.access_token;
|
|
202
|
-
let sse = null;
|
|
203
|
-
// Build HTTP client for identity lookup + outbound replies
|
|
204
|
-
const client = new RaviClient({
|
|
205
|
-
apiUrl: RAVI_API_URL,
|
|
206
|
-
token: auth.access_token,
|
|
207
|
-
refreshToken: auth.refresh_token,
|
|
208
|
-
identityUuid: ctx.accountId,
|
|
209
|
-
onTokenRefresh: (newToken) => {
|
|
210
|
-
currentToken = newToken;
|
|
211
|
-
try {
|
|
212
|
-
updateAuth({ access_token: newToken });
|
|
213
|
-
}
|
|
214
|
-
catch (err) {
|
|
215
|
-
const detail = err instanceof Error ? err.message : String(err);
|
|
216
|
-
log.error(`[ravi-sms] Failed to persist refreshed token: ${detail}`);
|
|
217
|
-
}
|
|
218
|
-
sse?.updateToken(newToken);
|
|
219
|
-
},
|
|
220
|
-
});
|
|
221
|
-
// Fetch identity details (phone number, name) if not in config
|
|
222
|
-
let phone = ctx.account.phone;
|
|
223
|
-
let identityName = ctx.account.identityName;
|
|
224
|
-
if (!phone) {
|
|
225
|
-
try {
|
|
226
|
-
const identities = await client.listIdentities();
|
|
227
|
-
const identity = identities.find((i) => i.uuid === ctx.accountId);
|
|
228
|
-
phone = identity?.phone ?? "";
|
|
229
|
-
identityName = identity?.display_name ?? identity?.name ?? ctx.accountId;
|
|
230
|
-
}
|
|
231
|
-
catch (err) {
|
|
232
|
-
if (err?.name === "RaviApiError") {
|
|
233
|
-
const status = err.status;
|
|
234
|
-
log.error(`[ravi-sms] Failed to fetch identity details (HTTP ${status}): ${err.message}` +
|
|
235
|
-
(status === 401 ? ". Token may be expired — run 'openclaw ravi login'." : ""));
|
|
236
|
-
}
|
|
237
|
-
else {
|
|
238
|
-
const detail = err instanceof Error ? err.message : String(err);
|
|
239
|
-
log.error(`[ravi-sms] Failed to fetch identity details: ${detail}`);
|
|
240
|
-
}
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
// SMS requires a phone number — bail out if the identity doesn't have one
|
|
245
|
-
if (!phone) {
|
|
246
|
-
log.info(`[ravi-sms] Identity ${identityName} has no phone number — skipping SMS channel`);
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
log.info(`[ravi-sms] Starting SMS channel for ${identityName} (${phone})`);
|
|
250
|
-
// Build SSE client using currentToken — which may have been refreshed
|
|
251
|
-
// by the listIdentities() call above if the original token was expired.
|
|
252
|
-
// onAuthFailure triggers a REST call to force auto-refresh, then returns
|
|
253
|
-
// the updated currentToken (already set by onTokenRefresh callback).
|
|
254
|
-
sse = acquireSSEClient({
|
|
255
|
-
apiUrl: RAVI_API_URL,
|
|
256
|
-
token: currentToken,
|
|
257
|
-
identityUuid: ctx.accountId,
|
|
258
|
-
onAuthFailure: async () => {
|
|
259
|
-
const tokenBefore = currentToken;
|
|
260
|
-
try {
|
|
261
|
-
await client.listIdentities();
|
|
262
|
-
}
|
|
263
|
-
catch (err) {
|
|
264
|
-
const detail = err instanceof Error ? err.message : String(err);
|
|
265
|
-
log.error(`[ravi-sms] Auth refresh failed during SSE reconnect: ${detail}. Run 'openclaw ravi login' to re-authenticate.`);
|
|
266
|
-
return null;
|
|
267
|
-
}
|
|
268
|
-
if (currentToken === tokenBefore) {
|
|
269
|
-
log.warn(`[ravi-sms] Auth refresh did not produce a new token — SSE auth failure is not recoverable via REST refresh`);
|
|
270
|
-
return null;
|
|
271
|
-
}
|
|
272
|
-
return currentToken;
|
|
273
|
-
},
|
|
274
|
-
});
|
|
275
|
-
sse.onSmsOwner((event) => {
|
|
276
|
-
try {
|
|
277
|
-
// Resolve agent route — maps (channel, accountId) → agentId + session key
|
|
278
|
-
const route = runtime.channel.routing.resolveAgentRoute({
|
|
279
|
-
cfg: ctx.cfg,
|
|
280
|
-
channel: "ravi-sms",
|
|
281
|
-
accountId: ctx.accountId,
|
|
282
|
-
peer: { kind: "direct", id: event.from_number },
|
|
283
|
-
});
|
|
284
|
-
const sessionKey = route.sessionKey;
|
|
285
|
-
// Build MsgContext for dispatch
|
|
286
|
-
const msgCtx = {
|
|
287
|
-
Body: event.body,
|
|
288
|
-
BodyForAgent: event.body,
|
|
289
|
-
From: `ravi-sms:${event.from_number}`,
|
|
290
|
-
To: `ravi-sms:${phone}`,
|
|
291
|
-
SessionKey: sessionKey,
|
|
292
|
-
AccountId: ctx.accountId,
|
|
293
|
-
ChatType: "direct",
|
|
294
|
-
Provider: "ravi-sms",
|
|
295
|
-
Surface: "ravi-sms",
|
|
296
|
-
OriginatingChannel: "ravi-sms",
|
|
297
|
-
OriginatingTo: ctx.accountId,
|
|
298
|
-
SenderName: event.from_number,
|
|
299
|
-
SenderId: event.from_number,
|
|
300
|
-
Timestamp: Date.now(),
|
|
301
|
-
CommandAuthorized: true,
|
|
302
|
-
MessageSid: `ravi-sms:${event.id}`,
|
|
303
|
-
};
|
|
304
|
-
// Record inbound session so follow-ups route back through SMS
|
|
305
|
-
try {
|
|
306
|
-
runtime.channel.session.recordInboundSession({
|
|
307
|
-
storePath: runtime.channel.session.resolveStorePath(ctx.cfg.session?.store, { agentId: route.agentId }),
|
|
308
|
-
sessionKey,
|
|
309
|
-
ctx: msgCtx,
|
|
310
|
-
updateLastRoute: {
|
|
311
|
-
sessionKey,
|
|
312
|
-
channel: "ravi-sms",
|
|
313
|
-
to: ctx.accountId,
|
|
314
|
-
accountId: ctx.accountId,
|
|
315
|
-
phoneNumber: event.from_number,
|
|
316
|
-
},
|
|
317
|
-
onRecordError: (err) => {
|
|
318
|
-
const detail = err instanceof Error ? err.message : String(err);
|
|
319
|
-
log.error(`[ravi-sms] Session record error for ${event.from_number}: ${detail}`);
|
|
320
|
-
},
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
catch (err) {
|
|
324
|
-
const detail = err instanceof Error ? err.message : String(err);
|
|
325
|
-
log.error(`[ravi-sms] recordInboundSession threw for ${event.from_number}: ${detail}`);
|
|
326
|
-
}
|
|
327
|
-
// Dispatch — triggers AI agent turn. Owner always gets full reply delivery.
|
|
328
|
-
runtime.channel.reply.dispatchReplyWithBufferedBlockDispatcher({
|
|
329
|
-
ctx: msgCtx,
|
|
330
|
-
cfg: ctx.cfg,
|
|
331
|
-
dispatcherOptions: {
|
|
332
|
-
deliver: async (payload) => {
|
|
333
|
-
if (!payload.text) {
|
|
334
|
-
log.info(`[ravi-sms] Deliver called with empty text for ${event.from_number} — skipping`);
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
|
-
try {
|
|
338
|
-
await client.sendSms(event.from_number, payload.text);
|
|
339
|
-
}
|
|
340
|
-
catch (err) {
|
|
341
|
-
const detail = err instanceof Error ? err.message : String(err);
|
|
342
|
-
const status = err?.status;
|
|
343
|
-
log.error(`[ravi-sms] Failed to deliver reply to ${event.from_number}` +
|
|
344
|
-
`${status ? ` (HTTP ${status})` : ""}: ${detail}`);
|
|
345
|
-
}
|
|
346
|
-
},
|
|
347
|
-
onError: (err) => {
|
|
348
|
-
log.error(`[ravi-sms] Dispatch error: ${err}`);
|
|
349
|
-
},
|
|
350
|
-
},
|
|
351
|
-
}).catch((err) => {
|
|
352
|
-
const detail = err instanceof Error ? err.message : String(err);
|
|
353
|
-
log.error(`[ravi-sms] dispatchReply failed for ${event.from_number}: ${detail}`);
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
catch (err) {
|
|
357
|
-
const detail = err instanceof Error ? err.message : String(err);
|
|
358
|
-
log.error(`[ravi-sms] Unhandled error processing event ${event.id}: ${detail}`);
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
sse.onReconnect(() => {
|
|
362
|
-
log.info(`[ravi-sms] SSE reconnecting for ${identityName}`);
|
|
363
|
-
});
|
|
364
|
-
log.info(`[ravi-sms] SSE connected for ${identityName} (${ctx.accountId})`);
|
|
365
|
-
// Block until gateway signals shutdown
|
|
366
|
-
await new Promise((resolve) => {
|
|
367
|
-
if (ctx.abortSignal.aborted) {
|
|
368
|
-
log.info(`[ravi-sms] Stopping SMS channel for ${identityName} (already aborted)`);
|
|
369
|
-
releaseSSEClient(ctx.accountId);
|
|
370
|
-
resolve();
|
|
371
|
-
return;
|
|
372
|
-
}
|
|
373
|
-
ctx.abortSignal.addEventListener("abort", () => {
|
|
374
|
-
log.info(`[ravi-sms] Stopping SMS channel for ${identityName}`);
|
|
375
|
-
releaseSSEClient(ctx.accountId);
|
|
376
|
-
resolve();
|
|
377
|
-
});
|
|
378
|
-
});
|
|
379
|
-
},
|
|
380
|
-
},
|
|
381
|
-
};
|
|
382
|
-
}
|
|
383
|
-
/** The singleton ravi-sms channel instance. */
|
|
384
|
-
export const raviSmsChannel = createSmsChannel();
|
|
385
|
-
//# sourceMappingURL=sms.js.map
|
package/dist/channels/sms.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-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AAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;oBAClC,IAAI,GAAG,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;wBAC5B,GAAG,CAAC,IAAI,CAAC,uCAAuC,YAAY,oBAAoB,CAAC,CAAC;wBAClF,gBAAgB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;wBAChC,OAAO,EAAE,CAAC;wBACV,OAAO;oBACT,CAAC;oBACD,GAAG,CAAC,WAAW,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE;wBAC7C,GAAG,CAAC,IAAI,CAAC,uCAAuC,YAAY,EAAE,CAAC,CAAC;wBAChE,gBAAgB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;wBAChC,OAAO,EAAE,CAAC;oBACZ,CAAC,CAAC,CAAC;gBACL,CAAC,CAAC,CAAC;YACL,CAAC;SACF;KACF,CAAC;AACJ,CAAC;AAED,+CAA+C;AAC/C,MAAM,CAAC,MAAM,cAAc,GAAG,gBAAgB,EAAE,CAAC"}
|
package/dist/service.d.ts
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { type EmailAccountConfig } from "./channels/email.js";
|
|
2
|
-
import { type SmsAccountConfig } from "./channels/sms.js";
|
|
3
|
-
/** Message envelope dispatched to the OpenClaw gateway. */
|
|
4
|
-
export interface InboundMessage {
|
|
5
|
-
/** Channel that produced this message. */
|
|
6
|
-
channel: "ravi-email" | "ravi-email-trusted" | "ravi-email-untrusted" | "ravi-sms" | "ravi-sms-trusted" | "ravi-sms-untrusted";
|
|
7
|
-
/** Identity UUID identifying the receiving account. */
|
|
8
|
-
accountId: string;
|
|
9
|
-
/** Sender identifier (email address or phone number). */
|
|
10
|
-
senderId: string;
|
|
11
|
-
/** Plain-text body of the inbound message. */
|
|
12
|
-
text: string;
|
|
13
|
-
/** Thread or conversation identifier for session mapping. */
|
|
14
|
-
threadId: string;
|
|
15
|
-
/** Deterministic session key used by the OpenClaw gateway. */
|
|
16
|
-
sessionKey: string;
|
|
17
|
-
/** Channel-specific metadata passed through to the agent. */
|
|
18
|
-
metadata: Record<string, unknown>;
|
|
19
|
-
/** When true, the agent should treat this as read-only context — no outbound replies or write tools. */
|
|
20
|
-
readOnly: boolean;
|
|
21
|
-
}
|
|
22
|
-
/** Callback for dispatching normalized messages to the OpenClaw gateway. */
|
|
23
|
-
export type MessageDispatcher = (message: InboundMessage) => void;
|
|
24
|
-
/** Configuration for a single listener (one identity). */
|
|
25
|
-
export interface ListenerConfig {
|
|
26
|
-
/** Base URL of the Ravi API (e.g. "https://api.ravi.dev"). */
|
|
27
|
-
apiUrl: string;
|
|
28
|
-
/** JWT bearer token for authentication. */
|
|
29
|
-
token: string;
|
|
30
|
-
/** Identity UUID for scoped event streaming. */
|
|
31
|
-
identityUuid: string;
|
|
32
|
-
/** OpenClaw agent identifier used in session key generation. */
|
|
33
|
-
agentId: string;
|
|
34
|
-
/** Email account config; omit to skip email event handling. */
|
|
35
|
-
emailAccount?: EmailAccountConfig;
|
|
36
|
-
/** SMS account config; omit to skip SMS event handling. */
|
|
37
|
-
smsAccount?: SmsAccountConfig;
|
|
38
|
-
/** When false, emails from unknown senders are silently dropped. Defaults to true. */
|
|
39
|
-
externalEmail?: boolean;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Background service that manages SSE connections per identity.
|
|
43
|
-
*
|
|
44
|
-
* Creates one {@link RaviSSEClient} per configured identity, listens for
|
|
45
|
-
* inbound email and SMS events, normalizes them through the respective
|
|
46
|
-
* channel definitions, and dispatches the resulting {@link InboundMessage}
|
|
47
|
-
* envelopes to the OpenClaw gateway via a {@link MessageDispatcher} callback.
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* ```ts
|
|
51
|
-
* const service = new RaviListenerService((msg) => {
|
|
52
|
-
* console.log(`[${msg.channel}] ${msg.senderId}: ${msg.text}`);
|
|
53
|
-
* });
|
|
54
|
-
*
|
|
55
|
-
* service.addListener({
|
|
56
|
-
* apiUrl: "https://api.ravi.dev",
|
|
57
|
-
* token: "ey...",
|
|
58
|
-
* identityUuid: "abc-123",
|
|
59
|
-
* agentId: "my-agent",
|
|
60
|
-
* emailAccount: { ... },
|
|
61
|
-
* });
|
|
62
|
-
*
|
|
63
|
-
* // Later: graceful shutdown
|
|
64
|
-
* service.stopAll();
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
export declare class RaviListenerService {
|
|
68
|
-
private clients;
|
|
69
|
-
private dispatcher;
|
|
70
|
-
constructor(dispatcher: MessageDispatcher);
|
|
71
|
-
/**
|
|
72
|
-
* Start listening for a configured identity.
|
|
73
|
-
*
|
|
74
|
-
* Creates an SSE client, wires up email and/or SMS handlers based on
|
|
75
|
-
* the provided account configs, and opens the connection. If a listener
|
|
76
|
-
* for this identity already exists, the call is a no-op.
|
|
77
|
-
*
|
|
78
|
-
* @param config - Listener configuration for the identity.
|
|
79
|
-
*/
|
|
80
|
-
addListener(config: ListenerConfig): void;
|
|
81
|
-
/**
|
|
82
|
-
* Update the bearer token for all active SSE connections.
|
|
83
|
-
*
|
|
84
|
-
* Called when the RaviClient refreshes the access token so SSE
|
|
85
|
-
* reconnections use the new token instead of the expired one.
|
|
86
|
-
*/
|
|
87
|
-
updateToken(newToken: string): void;
|
|
88
|
-
/**
|
|
89
|
-
* Remove a listener for an identity.
|
|
90
|
-
*
|
|
91
|
-
* Disconnects the SSE client and removes it from the active set.
|
|
92
|
-
* No-op if the identity is not being listened to.
|
|
93
|
-
*
|
|
94
|
-
* @param identityUuid - The identity UUID to stop listening for.
|
|
95
|
-
*/
|
|
96
|
-
removeListener(identityUuid: string): void;
|
|
97
|
-
/**
|
|
98
|
-
* Stop all listeners.
|
|
99
|
-
*
|
|
100
|
-
* Disconnects every active SSE client and clears the internal map.
|
|
101
|
-
* Safe to call multiple times.
|
|
102
|
-
*/
|
|
103
|
-
stopAll(): void;
|
|
104
|
-
/** Get the number of active listeners. */
|
|
105
|
-
get activeCount(): number;
|
|
106
|
-
}
|
|
107
|
-
//# sourceMappingURL=service.d.ts.map
|
package/dist/service.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,KAAK,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAGhF,OAAO,EAAkB,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAO1E,2DAA2D;AAC3D,MAAM,WAAW,cAAc;IAC7B,0CAA0C;IAC1C,OAAO,EAAE,YAAY,GAAG,oBAAoB,GAAG,sBAAsB,GAAG,UAAU,GAAG,kBAAkB,GAAG,oBAAoB,CAAC;IAC/H,uDAAuD;IACvD,SAAS,EAAE,MAAM,CAAC;IAClB,yDAAyD;IACzD,QAAQ,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,6DAA6D;IAC7D,QAAQ,EAAE,MAAM,CAAC;IACjB,8DAA8D;IAC9D,UAAU,EAAE,MAAM,CAAC;IACnB,6DAA6D;IAC7D,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,wGAAwG;IACxG,QAAQ,EAAE,OAAO,CAAC;CACnB;AAID,4EAA4E;AAC5E,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;AAElE,0DAA0D;AAC1D,MAAM,WAAW,cAAc;IAC7B,8DAA8D;IAC9D,MAAM,EAAE,MAAM,CAAC;IACf,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,gDAAgD;IAChD,YAAY,EAAE,MAAM,CAAC;IACrB,gEAAgE;IAChE,OAAO,EAAE,MAAM,CAAC;IAChB,+DAA+D;IAC/D,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAClC,2DAA2D;IAC3D,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,sFAAsF;IACt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