@diegoaltoworks/chatter 0.28.0 → 0.30.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/dist/bin/wa-pair.js +320 -0
- package/dist/channels/whatsapp/authState.d.ts +39 -0
- package/dist/channels/whatsapp/authState.d.ts.map +1 -0
- package/dist/channels/whatsapp/authState.test.d.ts +2 -0
- package/dist/channels/whatsapp/authState.test.d.ts.map +1 -0
- package/dist/channels/whatsapp/baileys.d.ts +21 -0
- package/dist/channels/whatsapp/baileys.d.ts.map +1 -0
- package/dist/channels/whatsapp/baileys.test.d.ts +2 -0
- package/dist/channels/whatsapp/baileys.test.d.ts.map +1 -0
- package/dist/channels/whatsapp/channel.d.ts +95 -0
- package/dist/channels/whatsapp/channel.d.ts.map +1 -0
- package/dist/channels/whatsapp/channel.test.d.ts +2 -0
- package/dist/channels/whatsapp/channel.test.d.ts.map +1 -0
- package/dist/channels/whatsapp/crypto.d.ts +10 -0
- package/dist/channels/whatsapp/crypto.d.ts.map +1 -0
- package/dist/channels/whatsapp/crypto.test.d.ts +2 -0
- package/dist/channels/whatsapp/crypto.test.d.ts.map +1 -0
- package/dist/channels/whatsapp/inbound.d.ts +131 -0
- package/dist/channels/whatsapp/inbound.d.ts.map +1 -0
- package/dist/channels/whatsapp/inbound.test.d.ts +2 -0
- package/dist/channels/whatsapp/inbound.test.d.ts.map +1 -0
- package/dist/channels/whatsapp/index.d.ts +34 -0
- package/dist/channels/whatsapp/index.d.ts.map +1 -0
- package/dist/channels/whatsapp/index.js +810 -0
- package/dist/channels/whatsapp/index.mjs +753 -0
- package/dist/channels/whatsapp/lease.d.ts +42 -0
- package/dist/channels/whatsapp/lease.d.ts.map +1 -0
- package/dist/channels/whatsapp/lease.test.d.ts +2 -0
- package/dist/channels/whatsapp/lease.test.d.ts.map +1 -0
- package/package.json +23 -4
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deploy-overlap protection: at most one running instance may hold a given
|
|
3
|
+
* WhatsApp session's Baileys connection at a time.
|
|
4
|
+
*
|
|
5
|
+
* Rolling deploys can briefly run the outgoing and incoming revision side by
|
|
6
|
+
* side, and Baileys/WhatsApp treats a second concurrent connection as a
|
|
7
|
+
* takeover — it logs the first one out. The lease lives in Turso (`wa_lease`)
|
|
8
|
+
* so it's visible to every instance. Acquiring/renewing is a single atomic
|
|
9
|
+
* upsert — see `createTursoWaLeaseStore` — so two instances racing the same
|
|
10
|
+
* row can never both believe they hold it.
|
|
11
|
+
*/
|
|
12
|
+
import type { Client } from "@libsql/client";
|
|
13
|
+
/** Stale after this long without a heartbeat — a crashed holder's lease frees up. */
|
|
14
|
+
export declare const LEASE_STALE_MS = 90000;
|
|
15
|
+
/** How often a holder renews its lease while connected. */
|
|
16
|
+
export declare const LEASE_HEARTBEAT_MS = 30000;
|
|
17
|
+
/** How long a non-holder waits before re-checking whether the lease freed up. */
|
|
18
|
+
export declare const LEASE_WAIT_MS = 30000;
|
|
19
|
+
export interface WaLeaseRow {
|
|
20
|
+
instanceId: string;
|
|
21
|
+
heartbeatAt: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Pure: may `instanceId` take (or keep) the lease right now, given the
|
|
25
|
+
* current row (null = never held)? Mirrors the SQL WHERE clause in
|
|
26
|
+
* `createTursoWaLeaseStore` — keep the two in sync.
|
|
27
|
+
*/
|
|
28
|
+
export declare function canAcquireLease(existing: WaLeaseRow | null, instanceId: string, now: number, staleMs?: number): boolean;
|
|
29
|
+
export interface WaLeaseStore {
|
|
30
|
+
/** Atomically acquires or renews the lease; resolves true iff `instanceId` now holds it. */
|
|
31
|
+
tryAcquire(sessionId: string, instanceId: string, now: number, staleMs: number): Promise<boolean>;
|
|
32
|
+
/** Releases the lease iff still held by `instanceId` (no-op otherwise — a late release must never undo a takeover). */
|
|
33
|
+
release(sessionId: string, instanceId: string): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A Turso-backed `WaLeaseStore`. The WHERE clause on DO UPDATE encodes
|
|
37
|
+
* `canAcquireLease`: SQLite skips the update (and RETURNING yields no row)
|
|
38
|
+
* when it's false, so a losing racer sees zero rows back — no separate
|
|
39
|
+
* read-then-write, no race window.
|
|
40
|
+
*/
|
|
41
|
+
export declare function createTursoWaLeaseStore(client: Client): WaLeaseStore;
|
|
42
|
+
//# sourceMappingURL=lease.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lease.d.ts","sourceRoot":"","sources":["../../../src/channels/whatsapp/lease.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE7C,qFAAqF;AACrF,eAAO,MAAM,cAAc,QAAS,CAAC;AACrC,2DAA2D;AAC3D,eAAO,MAAM,kBAAkB,QAAS,CAAC;AACzC,iFAAiF;AACjF,eAAO,MAAM,aAAa,QAAS,CAAC;AAEpC,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,UAAU,GAAG,IAAI,EAC3B,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,MAAuB,GAC/B,OAAO,CAIT;AAED,MAAM,WAAW,YAAY;IAC3B,4FAA4F;IAC5F,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAClG,uHAAuH;IACvH,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/D;AAuBD;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAyBpE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lease.test.d.ts","sourceRoot":"","sources":["../../../src/channels/whatsapp/lease.test.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diegoaltoworks/chatter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"description": "Embeddable AI chatbot framework with RAG, authentication, and customizable widgets",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"bin": {
|
|
9
|
-
"chatter": "./dist/bin/create-apikey.js"
|
|
9
|
+
"chatter": "./dist/bin/create-apikey.js",
|
|
10
|
+
"wa-pair": "./dist/bin/wa-pair.js"
|
|
10
11
|
},
|
|
11
12
|
"exports": {
|
|
12
13
|
".": {
|
|
@@ -38,6 +39,11 @@
|
|
|
38
39
|
"types": "./dist/channels/index.d.ts",
|
|
39
40
|
"import": "./dist/channels/index.mjs",
|
|
40
41
|
"require": "./dist/channels/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./whatsapp": {
|
|
44
|
+
"types": "./dist/channels/whatsapp/index.d.ts",
|
|
45
|
+
"import": "./dist/channels/whatsapp/index.mjs",
|
|
46
|
+
"require": "./dist/channels/whatsapp/index.js"
|
|
41
47
|
}
|
|
42
48
|
},
|
|
43
49
|
"files": [
|
|
@@ -47,7 +53,7 @@
|
|
|
47
53
|
],
|
|
48
54
|
"scripts": {
|
|
49
55
|
"dev": "bun --watch src/index.ts",
|
|
50
|
-
"build": "bun run build:clean && bun run build:types && bun run build:esm && bun run build:cjs && bun run build:mcp && bun run build:usage && bun run build:channels && bun run build:bin && bun run build:client && bun run build:copy-client",
|
|
56
|
+
"build": "bun run build:clean && bun run build:types && bun run build:esm && bun run build:cjs && bun run build:mcp && bun run build:usage && bun run build:channels && bun run build:whatsapp && bun run build:bin && bun run build:client && bun run build:copy-client",
|
|
51
57
|
"build:clean": "rm -rf dist",
|
|
52
58
|
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
53
59
|
"build:esm": "esbuild src/index.ts --bundle --format=esm --outfile=dist/index.mjs --external:hono --external:openai --external:@libsql/client --external:jose --platform=node --target=node24",
|
|
@@ -55,7 +61,8 @@
|
|
|
55
61
|
"build:mcp": "esbuild src/mcp-server.ts --bundle --format=esm --outfile=dist/mcp-server.mjs --external:@modelcontextprotocol/sdk --external:openai --external:@libsql/client --external:zod --platform=node --target=node24 && esbuild src/mcp-server.ts --bundle --format=cjs --outfile=dist/mcp-server.js --external:@modelcontextprotocol/sdk --external:openai --external:@libsql/client --external:zod --platform=node --target=node24",
|
|
56
62
|
"build:usage": "esbuild src/usage/index.ts --bundle --format=esm --outfile=dist/usage/index.mjs --external:@libsql/client --platform=node --target=node24 && esbuild src/usage/index.ts --bundle --format=cjs --outfile=dist/usage/index.js --external:@libsql/client --platform=node --target=node24",
|
|
57
63
|
"build:channels": "esbuild src/channels/index.ts --bundle --format=esm --outfile=dist/channels/index.mjs --external:hono --external:openai --external:@libsql/client --platform=node --target=node24 && esbuild src/channels/index.ts --bundle --format=cjs --outfile=dist/channels/index.js --external:hono --external:openai --external:@libsql/client --platform=node --target=node24",
|
|
58
|
-
"build:
|
|
64
|
+
"build:whatsapp": "esbuild src/channels/whatsapp/index.ts --bundle --format=esm --outfile=dist/channels/whatsapp/index.mjs --external:@libsql/client --external:@whiskeysockets/baileys --platform=node --target=node24 && esbuild src/channels/whatsapp/index.ts --bundle --format=cjs --outfile=dist/channels/whatsapp/index.js --external:@libsql/client --external:@whiskeysockets/baileys --platform=node --target=node24",
|
|
65
|
+
"build:bin": "esbuild bin/create-apikey.ts --bundle --format=cjs --outfile=dist/bin/create-apikey.js --external:jose --platform=node --target=node18 --banner:js='#!/usr/bin/env node' && esbuild bin/wa-pair.ts --bundle --format=cjs --outfile=dist/bin/wa-pair.js --external:@libsql/client --external:@whiskeysockets/baileys --external:qrcode-terminal --platform=node --target=node18 --banner:js='#!/usr/bin/env node'",
|
|
59
66
|
"build:client": "cd src/client && bun run build",
|
|
60
67
|
"build:copy-client": "mkdir -p dist/static && cp src/client/dist/chatter.js src/client/dist/chatter.css dist/static/",
|
|
61
68
|
"test": "bun test",
|
|
@@ -108,10 +115,20 @@
|
|
|
108
115
|
"peerDependencies": {
|
|
109
116
|
"@libsql/client": "^0.17.2",
|
|
110
117
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
118
|
+
"@whiskeysockets/baileys": "^7.0.0-rc14",
|
|
111
119
|
"hono": "^4.12.14",
|
|
112
120
|
"openai": "^7.3.0",
|
|
121
|
+
"qrcode-terminal": "^0.12.0",
|
|
113
122
|
"zod": "^3.25.76 || ^4.4.3"
|
|
114
123
|
},
|
|
124
|
+
"peerDependenciesMeta": {
|
|
125
|
+
"@whiskeysockets/baileys": {
|
|
126
|
+
"optional": true
|
|
127
|
+
},
|
|
128
|
+
"qrcode-terminal": {
|
|
129
|
+
"optional": true
|
|
130
|
+
}
|
|
131
|
+
},
|
|
115
132
|
"dependencies": {
|
|
116
133
|
"jose": "6.2.8"
|
|
117
134
|
},
|
|
@@ -121,11 +138,13 @@
|
|
|
121
138
|
"@modelcontextprotocol/sdk": "1.30.0",
|
|
122
139
|
"@types/bun": "1.3.14",
|
|
123
140
|
"@types/node": "26.2.0",
|
|
141
|
+
"@whiskeysockets/baileys": "7.0.0-rc14",
|
|
124
142
|
"esbuild": "0.28.1",
|
|
125
143
|
"hono": "4.13.1",
|
|
126
144
|
"husky": "9.1.7",
|
|
127
145
|
"lint-staged": "17.3.0",
|
|
128
146
|
"openai": "7.4.0",
|
|
147
|
+
"qrcode-terminal": "0.12.0",
|
|
129
148
|
"typescript": "7.0.2",
|
|
130
149
|
"zod": "4.4.3"
|
|
131
150
|
},
|