@hasna/conversations 0.2.42 → 0.2.44
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/bin/hook.js +170 -20
- package/bin/index.js +478 -130
- package/bin/mcp.js +455 -107
- package/dist/index.js +385 -91
- package/dist/lib/messages.d.ts +1 -1
- package/dist/lib/presence.d.ts +2 -1
- package/dist/lib/webhooks.d.ts +1 -0
- package/package.json +1 -1
package/bin/hook.js
CHANGED
|
@@ -4,32 +4,42 @@ var __defProp = Object.defineProperty;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
|
|
7
|
+
function __accessProp(key) {
|
|
8
|
+
return this[key];
|
|
9
|
+
}
|
|
8
10
|
var __toCommonJS = (from) => {
|
|
9
|
-
var entry = __moduleCache.get(from), desc;
|
|
11
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
10
12
|
if (entry)
|
|
11
13
|
return entry;
|
|
12
14
|
entry = __defProp({}, "__esModule", { value: true });
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (var key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(entry, key))
|
|
18
|
+
__defProp(entry, key, {
|
|
19
|
+
get: __accessProp.bind(from, key),
|
|
20
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
21
|
+
});
|
|
22
|
+
}
|
|
18
23
|
__moduleCache.set(from, entry);
|
|
19
24
|
return entry;
|
|
20
25
|
};
|
|
26
|
+
var __moduleCache;
|
|
27
|
+
var __returnValue = (v) => v;
|
|
28
|
+
function __exportSetter(name, newValue) {
|
|
29
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
30
|
+
}
|
|
21
31
|
var __export = (target, all) => {
|
|
22
32
|
for (var name in all)
|
|
23
33
|
__defProp(target, name, {
|
|
24
34
|
get: all[name],
|
|
25
35
|
enumerable: true,
|
|
26
36
|
configurable: true,
|
|
27
|
-
set: (
|
|
37
|
+
set: __exportSetter.bind(all, name)
|
|
28
38
|
});
|
|
29
39
|
};
|
|
30
40
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
31
41
|
|
|
32
|
-
//
|
|
42
|
+
// node_modules/@hasna/cloud/dist/index.js
|
|
33
43
|
import { createRequire } from "module";
|
|
34
44
|
import { Database } from "bun:sqlite";
|
|
35
45
|
import {
|
|
@@ -50,11 +60,11 @@ import { homedir as homedir4 } from "os";
|
|
|
50
60
|
import { join as join4 } from "path";
|
|
51
61
|
import { join as join6, dirname } from "path";
|
|
52
62
|
import { homedir as homedir5, platform } from "os";
|
|
53
|
-
function
|
|
63
|
+
function __accessProp2(key) {
|
|
54
64
|
return this[key];
|
|
55
65
|
}
|
|
56
|
-
function
|
|
57
|
-
this[name] =
|
|
66
|
+
function __exportSetter2(name, newValue) {
|
|
67
|
+
this[name] = __returnValue2.bind(null, newValue);
|
|
58
68
|
}
|
|
59
69
|
function translateSql(sql, dialect) {
|
|
60
70
|
if (dialect === "sqlite")
|
|
@@ -1097,19 +1107,19 @@ var __create, __getProtoOf, __defProp2, __getOwnPropNames2, __hasOwnProp2, __toE
|
|
|
1097
1107
|
for (let key of __getOwnPropNames2(mod))
|
|
1098
1108
|
if (!__hasOwnProp2.call(to, key))
|
|
1099
1109
|
__defProp2(to, key, {
|
|
1100
|
-
get:
|
|
1110
|
+
get: __accessProp2.bind(mod, key),
|
|
1101
1111
|
enumerable: true
|
|
1102
1112
|
});
|
|
1103
1113
|
if (canCache)
|
|
1104
1114
|
cache.set(mod, to);
|
|
1105
1115
|
return to;
|
|
1106
|
-
}, __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports),
|
|
1116
|
+
}, __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports), __returnValue2 = (v) => v, __export2 = (target, all) => {
|
|
1107
1117
|
for (var name in all)
|
|
1108
1118
|
__defProp2(target, name, {
|
|
1109
1119
|
get: all[name],
|
|
1110
1120
|
enumerable: true,
|
|
1111
1121
|
configurable: true,
|
|
1112
|
-
set:
|
|
1122
|
+
set: __exportSetter2.bind(all, name)
|
|
1113
1123
|
});
|
|
1114
1124
|
}, __esm2 = (fn, res) => () => (fn && (res = fn(fn = 0)), res), __require, require_postgres_array, require_arrayParser, require_postgres_date, require_mutable, require_postgres_interval, require_postgres_bytea, require_textParsers, require_pg_int8, require_binaryParsers, require_builtins, require_pg_types, require_defaults, require_utils, require_utils_legacy, require_utils_webcrypto, require_utils2, require_cert_signatures, require_sasl, require_type_overrides, require_pg_connection_string, require_connection_parameters, require_result, require_query, require_messages, require_buffer_writer, require_serializer, require_buffer_reader, require_parser, require_dist, require_empty, require_stream, require_connection, require_split2, require_helper, require_lib, require_client, require_pg_pool, require_query2, require_client2, require_lib2, import_lib, Client, Pool, Connection, types, Query, DatabaseError, escapeIdentifier, escapeLiteral, Result, TypeOverrides, defaults, esm_default, init_esm, init_adapter, util, objectUtil, ZodParsedType, getParsedType = (data) => {
|
|
1115
1125
|
const t = typeof data;
|
|
@@ -9446,6 +9456,137 @@ function getDbPath2() {
|
|
|
9446
9456
|
return process.env.CONVERSATIONS_DB_PATH;
|
|
9447
9457
|
return join5(getDataDir2(), "messages.db");
|
|
9448
9458
|
}
|
|
9459
|
+
function parsePresenceTimestamp(value) {
|
|
9460
|
+
if (typeof value !== "string" || !value)
|
|
9461
|
+
return 0;
|
|
9462
|
+
return new Date(`${value}Z`).getTime() || 0;
|
|
9463
|
+
}
|
|
9464
|
+
function normalizePresenceText(value) {
|
|
9465
|
+
if (typeof value !== "string")
|
|
9466
|
+
return null;
|
|
9467
|
+
const normalized = value.trim();
|
|
9468
|
+
return normalized ? normalized : null;
|
|
9469
|
+
}
|
|
9470
|
+
function shouldRebuildAgentPresenceTable(columns) {
|
|
9471
|
+
const byName = new Map(columns.map((column) => [column.name, column]));
|
|
9472
|
+
const agentCol = byName.get("agent");
|
|
9473
|
+
const projectCol = byName.get("project_id");
|
|
9474
|
+
if (!agentCol)
|
|
9475
|
+
return false;
|
|
9476
|
+
if (!projectCol)
|
|
9477
|
+
return true;
|
|
9478
|
+
return agentCol.pk !== 1 || projectCol.pk !== 2 || projectCol.notnull !== 1 || byName.has("pid");
|
|
9479
|
+
}
|
|
9480
|
+
function rebuildLegacyAgentPresenceTable(db2) {
|
|
9481
|
+
const fallbackNow = db2.prepare("SELECT strftime('%Y-%m-%dT%H:%M:%f', 'now') AS now").get().now;
|
|
9482
|
+
const legacyRows = db2.prepare("SELECT rowid AS _rowid, * FROM agent_presence").all();
|
|
9483
|
+
legacyRows.sort((left, right) => {
|
|
9484
|
+
const lastSeenDelta = parsePresenceTimestamp(right.last_seen_at) - parsePresenceTimestamp(left.last_seen_at);
|
|
9485
|
+
if (lastSeenDelta !== 0)
|
|
9486
|
+
return lastSeenDelta;
|
|
9487
|
+
const createdDelta = parsePresenceTimestamp(right.created_at) - parsePresenceTimestamp(left.created_at);
|
|
9488
|
+
if (createdDelta !== 0)
|
|
9489
|
+
return createdDelta;
|
|
9490
|
+
const projectDelta = Number(Boolean(normalizePresenceText(right.project_id))) - Number(Boolean(normalizePresenceText(left.project_id)));
|
|
9491
|
+
if (projectDelta !== 0)
|
|
9492
|
+
return projectDelta;
|
|
9493
|
+
return right._rowid - left._rowid;
|
|
9494
|
+
});
|
|
9495
|
+
const dedupedRows = new Map;
|
|
9496
|
+
for (const row of legacyRows) {
|
|
9497
|
+
const normalizedAgent = normalizePresenceText(row.agent)?.toLowerCase();
|
|
9498
|
+
if (!normalizedAgent)
|
|
9499
|
+
continue;
|
|
9500
|
+
const storedProjectId = normalizePresenceText(row.project_id) ?? "";
|
|
9501
|
+
const dedupeKey = `${normalizedAgent}\x00${storedProjectId}`;
|
|
9502
|
+
if (dedupedRows.has(dedupeKey))
|
|
9503
|
+
continue;
|
|
9504
|
+
dedupedRows.set(dedupeKey, row);
|
|
9505
|
+
}
|
|
9506
|
+
db2.exec("BEGIN");
|
|
9507
|
+
try {
|
|
9508
|
+
db2.exec(`
|
|
9509
|
+
CREATE TABLE agent_presence_new (
|
|
9510
|
+
id TEXT NOT NULL,
|
|
9511
|
+
agent TEXT NOT NULL,
|
|
9512
|
+
session_id TEXT,
|
|
9513
|
+
role TEXT NOT NULL DEFAULT 'agent',
|
|
9514
|
+
project_id TEXT NOT NULL DEFAULT '',
|
|
9515
|
+
status TEXT NOT NULL DEFAULT 'online',
|
|
9516
|
+
last_seen_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%f', 'now')),
|
|
9517
|
+
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%f', 'now')),
|
|
9518
|
+
metadata TEXT,
|
|
9519
|
+
PRIMARY KEY (agent, project_id)
|
|
9520
|
+
)
|
|
9521
|
+
`);
|
|
9522
|
+
const insertPresence = db2.prepare(`
|
|
9523
|
+
INSERT INTO agent_presence_new (id, agent, session_id, role, project_id, status, last_seen_at, created_at, metadata)
|
|
9524
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
9525
|
+
`);
|
|
9526
|
+
for (const [dedupeKey, row] of dedupedRows) {
|
|
9527
|
+
const [agent, projectKey] = dedupeKey.split("\x00");
|
|
9528
|
+
const id = normalizePresenceText(row.id) ?? crypto.randomUUID().slice(0, 8);
|
|
9529
|
+
const sessionId = normalizePresenceText(row.session_id);
|
|
9530
|
+
const role = normalizePresenceText(row.role) ?? "agent";
|
|
9531
|
+
const projectId = projectKey;
|
|
9532
|
+
const status = normalizePresenceText(row.status) ?? "online";
|
|
9533
|
+
const lastSeenAt = normalizePresenceText(row.last_seen_at) ?? fallbackNow;
|
|
9534
|
+
const createdAt = normalizePresenceText(row.created_at) ?? lastSeenAt;
|
|
9535
|
+
const metadata = typeof row.metadata === "string" ? row.metadata : row.metadata == null ? null : JSON.stringify(row.metadata);
|
|
9536
|
+
insertPresence.run(id, agent, sessionId, role, projectId, status, lastSeenAt, createdAt, metadata);
|
|
9537
|
+
}
|
|
9538
|
+
db2.exec("DROP TABLE agent_presence");
|
|
9539
|
+
db2.exec("ALTER TABLE agent_presence_new RENAME TO agent_presence");
|
|
9540
|
+
db2.exec("COMMIT");
|
|
9541
|
+
} catch (error) {
|
|
9542
|
+
db2.exec("ROLLBACK");
|
|
9543
|
+
throw error;
|
|
9544
|
+
}
|
|
9545
|
+
}
|
|
9546
|
+
function collapseDuplicateAgentPresenceRows(db2) {
|
|
9547
|
+
const rows = db2.prepare("SELECT rowid AS _rowid, * FROM agent_presence").all();
|
|
9548
|
+
rows.sort((left, right) => {
|
|
9549
|
+
const lastSeenDelta = parsePresenceTimestamp(right.last_seen_at) - parsePresenceTimestamp(left.last_seen_at);
|
|
9550
|
+
if (lastSeenDelta !== 0)
|
|
9551
|
+
return lastSeenDelta;
|
|
9552
|
+
const createdDelta = parsePresenceTimestamp(right.created_at) - parsePresenceTimestamp(left.created_at);
|
|
9553
|
+
if (createdDelta !== 0)
|
|
9554
|
+
return createdDelta;
|
|
9555
|
+
const projectDelta = Number(Boolean(normalizePresenceText(right.project_id))) - Number(Boolean(normalizePresenceText(left.project_id)));
|
|
9556
|
+
if (projectDelta !== 0)
|
|
9557
|
+
return projectDelta;
|
|
9558
|
+
return right._rowid - left._rowid;
|
|
9559
|
+
});
|
|
9560
|
+
const rowIdsToDelete = [];
|
|
9561
|
+
const seenAgents = new Set;
|
|
9562
|
+
for (const row of rows) {
|
|
9563
|
+
const normalizedAgent = normalizePresenceText(row.agent)?.toLowerCase();
|
|
9564
|
+
if (!normalizedAgent)
|
|
9565
|
+
continue;
|
|
9566
|
+
if (seenAgents.has(normalizedAgent)) {
|
|
9567
|
+
rowIdsToDelete.push(row._rowid);
|
|
9568
|
+
continue;
|
|
9569
|
+
}
|
|
9570
|
+
seenAgents.add(normalizedAgent);
|
|
9571
|
+
}
|
|
9572
|
+
if (rowIdsToDelete.length === 0)
|
|
9573
|
+
return;
|
|
9574
|
+
db2.exec("BEGIN");
|
|
9575
|
+
try {
|
|
9576
|
+
const deleteRow = db2.prepare("DELETE FROM agent_presence WHERE rowid = ?");
|
|
9577
|
+
for (const rowId of rowIdsToDelete) {
|
|
9578
|
+
deleteRow.run(rowId);
|
|
9579
|
+
}
|
|
9580
|
+
db2.exec("COMMIT");
|
|
9581
|
+
} catch (error) {
|
|
9582
|
+
db2.exec("ROLLBACK");
|
|
9583
|
+
throw error;
|
|
9584
|
+
}
|
|
9585
|
+
}
|
|
9586
|
+
function ensureAgentPresenceAgentUniqueIndex(db2) {
|
|
9587
|
+
collapseDuplicateAgentPresenceRows(db2);
|
|
9588
|
+
db2.exec("CREATE UNIQUE INDEX IF NOT EXISTS idx_agent_presence_agent_unique ON agent_presence(agent)");
|
|
9589
|
+
}
|
|
9449
9590
|
function getDb() {
|
|
9450
9591
|
if (db)
|
|
9451
9592
|
return db;
|
|
@@ -9518,16 +9659,18 @@ function getDb() {
|
|
|
9518
9659
|
db.exec(`
|
|
9519
9660
|
CREATE TABLE IF NOT EXISTS agent_presence (
|
|
9520
9661
|
id TEXT NOT NULL,
|
|
9521
|
-
agent TEXT
|
|
9662
|
+
agent TEXT NOT NULL,
|
|
9522
9663
|
session_id TEXT,
|
|
9523
9664
|
role TEXT NOT NULL DEFAULT 'agent',
|
|
9524
|
-
project_id TEXT,
|
|
9665
|
+
project_id TEXT NOT NULL DEFAULT '',
|
|
9525
9666
|
status TEXT NOT NULL DEFAULT 'online',
|
|
9526
9667
|
last_seen_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%f', 'now')),
|
|
9527
9668
|
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%f', 'now')),
|
|
9528
|
-
metadata TEXT
|
|
9669
|
+
metadata TEXT,
|
|
9670
|
+
PRIMARY KEY (agent, project_id)
|
|
9529
9671
|
)
|
|
9530
9672
|
`);
|
|
9673
|
+
ensureAgentPresenceAgentUniqueIndex(db);
|
|
9531
9674
|
db.exec(`
|
|
9532
9675
|
CREATE TABLE IF NOT EXISTS resource_locks (
|
|
9533
9676
|
resource_type TEXT NOT NULL,
|
|
@@ -9629,8 +9772,13 @@ function getDb() {
|
|
|
9629
9772
|
db.exec("UPDATE messages SET uuid = lower(hex(randomblob(16))) WHERE uuid IS NULL");
|
|
9630
9773
|
db.exec("CREATE UNIQUE INDEX IF NOT EXISTS idx_messages_uuid ON messages(uuid)");
|
|
9631
9774
|
}
|
|
9632
|
-
|
|
9633
|
-
|
|
9775
|
+
let presenceCols = db.prepare("PRAGMA table_info(agent_presence)").all();
|
|
9776
|
+
let presenceColNames = presenceCols.map((c) => c.name);
|
|
9777
|
+
if (shouldRebuildAgentPresenceTable(presenceCols)) {
|
|
9778
|
+
rebuildLegacyAgentPresenceTable(db);
|
|
9779
|
+
presenceCols = db.prepare("PRAGMA table_info(agent_presence)").all();
|
|
9780
|
+
presenceColNames = presenceCols.map((c) => c.name);
|
|
9781
|
+
}
|
|
9634
9782
|
if (!presenceColNames.includes("id")) {
|
|
9635
9783
|
db.exec("ALTER TABLE agent_presence ADD COLUMN id TEXT NOT NULL DEFAULT ''");
|
|
9636
9784
|
const rows = db.prepare("SELECT agent FROM agent_presence").all();
|
|
@@ -9651,7 +9799,9 @@ function getDb() {
|
|
|
9651
9799
|
}
|
|
9652
9800
|
if (!presenceColNames.includes("project_id")) {
|
|
9653
9801
|
db.exec("ALTER TABLE agent_presence ADD COLUMN project_id TEXT");
|
|
9802
|
+
db.exec("UPDATE agent_presence SET project_id = '' WHERE project_id IS NULL");
|
|
9654
9803
|
}
|
|
9804
|
+
ensureAgentPresenceAgentUniqueIndex(db);
|
|
9655
9805
|
db.exec(`
|
|
9656
9806
|
CREATE TABLE IF NOT EXISTS message_read_receipts (
|
|
9657
9807
|
message_id INTEGER NOT NULL REFERENCES messages(id) ON DELETE CASCADE,
|