@hasna/conversations 0.2.25 → 0.2.27
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 +15 -0
- package/bin/index.js +351 -6
- package/bin/mcp.js +318 -5
- package/dashboard/dist/assets/index-Bw0wMcXE.js +186 -0
- package/dashboard/dist/assets/index-CF_GDtNp.css +1 -0
- package/dashboard/dist/index.html +13 -0
- package/dashboard/dist/logo.jpg +0 -0
- package/dist/index.js +29 -0
- package/dist/lib/messages.d.ts +2 -0
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/tools/cloud.test.d.ts +1 -0
- package/package.json +2 -2
package/bin/mcp.js
CHANGED
|
@@ -17662,6 +17662,7 @@ function getDb() {
|
|
|
17662
17662
|
db.exec(`
|
|
17663
17663
|
CREATE TABLE IF NOT EXISTS messages (
|
|
17664
17664
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
17665
|
+
uuid TEXT NOT NULL DEFAULT (lower(hex(randomblob(16)))),
|
|
17665
17666
|
session_id TEXT NOT NULL,
|
|
17666
17667
|
from_agent TEXT NOT NULL,
|
|
17667
17668
|
to_agent TEXT NOT NULL,
|
|
@@ -17828,6 +17829,11 @@ function getDb() {
|
|
|
17828
17829
|
db.exec("ALTER TABLE messages ADD COLUMN project_id TEXT");
|
|
17829
17830
|
db.exec("CREATE INDEX IF NOT EXISTS idx_messages_project ON messages(project_id)");
|
|
17830
17831
|
}
|
|
17832
|
+
if (!colNames2.includes("uuid")) {
|
|
17833
|
+
db.exec("ALTER TABLE messages ADD COLUMN uuid TEXT");
|
|
17834
|
+
db.exec("UPDATE messages SET uuid = lower(hex(randomblob(16))) WHERE uuid IS NULL");
|
|
17835
|
+
db.exec("CREATE UNIQUE INDEX IF NOT EXISTS idx_messages_uuid ON messages(uuid)");
|
|
17836
|
+
}
|
|
17831
17837
|
const presenceCols = db.prepare("PRAGMA table_info(agent_presence)").all();
|
|
17832
17838
|
const presenceColNames = presenceCols.map((c) => c.name);
|
|
17833
17839
|
if (!presenceColNames.includes("id")) {
|
|
@@ -17932,6 +17938,187 @@ var init_db = __esm(() => {
|
|
|
17932
17938
|
init_dist();
|
|
17933
17939
|
});
|
|
17934
17940
|
|
|
17941
|
+
// src/lib/pg-migrations.ts
|
|
17942
|
+
var exports_pg_migrations = {};
|
|
17943
|
+
__export(exports_pg_migrations, {
|
|
17944
|
+
PG_MIGRATIONS: () => PG_MIGRATIONS
|
|
17945
|
+
});
|
|
17946
|
+
var PG_MIGRATIONS;
|
|
17947
|
+
var init_pg_migrations = __esm(() => {
|
|
17948
|
+
PG_MIGRATIONS = [
|
|
17949
|
+
`
|
|
17950
|
+
CREATE TABLE IF NOT EXISTS projects (
|
|
17951
|
+
id TEXT PRIMARY KEY,
|
|
17952
|
+
name TEXT NOT NULL UNIQUE,
|
|
17953
|
+
description TEXT,
|
|
17954
|
+
path TEXT,
|
|
17955
|
+
created_by TEXT NOT NULL,
|
|
17956
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
17957
|
+
metadata TEXT,
|
|
17958
|
+
tags TEXT,
|
|
17959
|
+
status TEXT NOT NULL DEFAULT 'active',
|
|
17960
|
+
repository TEXT,
|
|
17961
|
+
settings TEXT
|
|
17962
|
+
);
|
|
17963
|
+
CREATE INDEX IF NOT EXISTS idx_projects_name ON projects(name);
|
|
17964
|
+
CREATE INDEX IF NOT EXISTS idx_projects_status ON projects(status);
|
|
17965
|
+
|
|
17966
|
+
CREATE TABLE IF NOT EXISTS spaces (
|
|
17967
|
+
name TEXT PRIMARY KEY,
|
|
17968
|
+
description TEXT,
|
|
17969
|
+
parent_id TEXT REFERENCES spaces(name),
|
|
17970
|
+
project_id TEXT REFERENCES projects(id),
|
|
17971
|
+
created_by TEXT NOT NULL,
|
|
17972
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
17973
|
+
archived_at TEXT,
|
|
17974
|
+
topic TEXT
|
|
17975
|
+
);
|
|
17976
|
+
CREATE INDEX IF NOT EXISTS idx_spaces_parent ON spaces(parent_id);
|
|
17977
|
+
CREATE INDEX IF NOT EXISTS idx_spaces_project ON spaces(project_id);
|
|
17978
|
+
|
|
17979
|
+
CREATE TABLE IF NOT EXISTS space_members (
|
|
17980
|
+
space TEXT NOT NULL REFERENCES spaces(name),
|
|
17981
|
+
agent TEXT NOT NULL,
|
|
17982
|
+
joined_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
17983
|
+
PRIMARY KEY (space, agent)
|
|
17984
|
+
);
|
|
17985
|
+
|
|
17986
|
+
CREATE TABLE IF NOT EXISTS messages (
|
|
17987
|
+
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
|
17988
|
+
uuid TEXT NOT NULL DEFAULT gen_random_uuid()::text UNIQUE,
|
|
17989
|
+
session_id TEXT NOT NULL,
|
|
17990
|
+
from_agent TEXT NOT NULL,
|
|
17991
|
+
to_agent TEXT NOT NULL,
|
|
17992
|
+
space TEXT,
|
|
17993
|
+
project_id TEXT,
|
|
17994
|
+
content TEXT NOT NULL,
|
|
17995
|
+
priority TEXT NOT NULL DEFAULT 'normal',
|
|
17996
|
+
working_dir TEXT,
|
|
17997
|
+
repository TEXT,
|
|
17998
|
+
branch TEXT,
|
|
17999
|
+
metadata TEXT,
|
|
18000
|
+
edited_at TEXT,
|
|
18001
|
+
pinned_at TEXT,
|
|
18002
|
+
blocking BOOLEAN NOT NULL DEFAULT FALSE,
|
|
18003
|
+
attachments TEXT,
|
|
18004
|
+
reply_to BIGINT,
|
|
18005
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
18006
|
+
read_at TEXT
|
|
18007
|
+
);
|
|
18008
|
+
CREATE INDEX IF NOT EXISTS idx_messages_session ON messages(session_id);
|
|
18009
|
+
CREATE INDEX IF NOT EXISTS idx_messages_to ON messages(to_agent);
|
|
18010
|
+
CREATE INDEX IF NOT EXISTS idx_messages_created ON messages(created_at);
|
|
18011
|
+
CREATE INDEX IF NOT EXISTS idx_messages_space ON messages(space);
|
|
18012
|
+
CREATE INDEX IF NOT EXISTS idx_messages_pinned ON messages(pinned_at);
|
|
18013
|
+
CREATE INDEX IF NOT EXISTS idx_messages_blocking ON messages(blocking);
|
|
18014
|
+
CREATE INDEX IF NOT EXISTS idx_messages_reply_to ON messages(reply_to);
|
|
18015
|
+
CREATE INDEX IF NOT EXISTS idx_messages_project ON messages(project_id);
|
|
18016
|
+
|
|
18017
|
+
CREATE TABLE IF NOT EXISTS agent_presence (
|
|
18018
|
+
id TEXT NOT NULL DEFAULT '',
|
|
18019
|
+
agent TEXT PRIMARY KEY,
|
|
18020
|
+
session_id TEXT,
|
|
18021
|
+
role TEXT NOT NULL DEFAULT 'agent',
|
|
18022
|
+
project_id TEXT,
|
|
18023
|
+
status TEXT NOT NULL DEFAULT 'online',
|
|
18024
|
+
last_seen_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
18025
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
18026
|
+
metadata TEXT
|
|
18027
|
+
);
|
|
18028
|
+
|
|
18029
|
+
CREATE TABLE IF NOT EXISTS resource_locks (
|
|
18030
|
+
resource_type TEXT NOT NULL,
|
|
18031
|
+
resource_id TEXT NOT NULL,
|
|
18032
|
+
agent_id TEXT NOT NULL,
|
|
18033
|
+
lock_type TEXT NOT NULL DEFAULT 'advisory',
|
|
18034
|
+
locked_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
18035
|
+
expires_at TIMESTAMPTZ NOT NULL,
|
|
18036
|
+
UNIQUE(resource_type, resource_id, lock_type)
|
|
18037
|
+
);
|
|
18038
|
+
CREATE INDEX IF NOT EXISTS idx_locks_resource ON resource_locks(resource_type, resource_id);
|
|
18039
|
+
CREATE INDEX IF NOT EXISTS idx_locks_agent ON resource_locks(agent_id);
|
|
18040
|
+
CREATE INDEX IF NOT EXISTS idx_locks_expires ON resource_locks(expires_at);
|
|
18041
|
+
|
|
18042
|
+
CREATE TABLE IF NOT EXISTS reactions (
|
|
18043
|
+
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
|
18044
|
+
message_id BIGINT NOT NULL REFERENCES messages(id) ON DELETE CASCADE,
|
|
18045
|
+
agent TEXT NOT NULL,
|
|
18046
|
+
emoji TEXT NOT NULL,
|
|
18047
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
18048
|
+
UNIQUE(message_id, agent, emoji)
|
|
18049
|
+
);
|
|
18050
|
+
CREATE INDEX IF NOT EXISTS idx_reactions_message ON reactions(message_id);
|
|
18051
|
+
|
|
18052
|
+
CREATE TABLE IF NOT EXISTS message_read_receipts (
|
|
18053
|
+
message_id BIGINT NOT NULL REFERENCES messages(id) ON DELETE CASCADE,
|
|
18054
|
+
agent TEXT NOT NULL,
|
|
18055
|
+
read_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
18056
|
+
PRIMARY KEY (message_id, agent)
|
|
18057
|
+
);
|
|
18058
|
+
CREATE INDEX IF NOT EXISTS idx_read_receipts_message ON message_read_receipts(message_id);
|
|
18059
|
+
CREATE INDEX IF NOT EXISTS idx_read_receipts_agent ON message_read_receipts(agent);
|
|
18060
|
+
|
|
18061
|
+
CREATE TABLE IF NOT EXISTS message_mentions (
|
|
18062
|
+
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
|
18063
|
+
message_id BIGINT NOT NULL REFERENCES messages(id) ON DELETE CASCADE,
|
|
18064
|
+
mentioned_agent TEXT NOT NULL,
|
|
18065
|
+
from_agent TEXT NOT NULL,
|
|
18066
|
+
space TEXT,
|
|
18067
|
+
notified_at TEXT,
|
|
18068
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
18069
|
+
);
|
|
18070
|
+
CREATE INDEX IF NOT EXISTS idx_mentions_agent ON message_mentions(mentioned_agent);
|
|
18071
|
+
CREATE INDEX IF NOT EXISTS idx_mentions_message ON message_mentions(message_id);
|
|
18072
|
+
CREATE INDEX IF NOT EXISTS idx_mentions_notified ON message_mentions(notified_at);
|
|
18073
|
+
|
|
18074
|
+
-- Full-text search using PostgreSQL tsvector
|
|
18075
|
+
ALTER TABLE messages ADD COLUMN IF NOT EXISTS search_vector tsvector;
|
|
18076
|
+
CREATE INDEX IF NOT EXISTS idx_messages_search ON messages USING GIN(search_vector);
|
|
18077
|
+
|
|
18078
|
+
CREATE OR REPLACE FUNCTION messages_search_vector_update() RETURNS trigger AS $$
|
|
18079
|
+
BEGIN
|
|
18080
|
+
NEW.search_vector :=
|
|
18081
|
+
setweight(to_tsvector('english', COALESCE(NEW.content, '')), 'A') ||
|
|
18082
|
+
setweight(to_tsvector('english', COALESCE(NEW.from_agent, '')), 'B') ||
|
|
18083
|
+
setweight(to_tsvector('english', COALESCE(NEW.to_agent, '')), 'B') ||
|
|
18084
|
+
setweight(to_tsvector('english', COALESCE(NEW.space, '')), 'C');
|
|
18085
|
+
RETURN NEW;
|
|
18086
|
+
END;
|
|
18087
|
+
$$ LANGUAGE plpgsql;
|
|
18088
|
+
|
|
18089
|
+
DROP TRIGGER IF EXISTS messages_search_vector_trigger ON messages;
|
|
18090
|
+
CREATE TRIGGER messages_search_vector_trigger
|
|
18091
|
+
BEFORE INSERT OR UPDATE OF content, from_agent, to_agent, space ON messages
|
|
18092
|
+
FOR EACH ROW EXECUTE FUNCTION messages_search_vector_update();
|
|
18093
|
+
|
|
18094
|
+
-- Backfill existing rows
|
|
18095
|
+
UPDATE messages SET search_vector =
|
|
18096
|
+
setweight(to_tsvector('english', COALESCE(content, '')), 'A') ||
|
|
18097
|
+
setweight(to_tsvector('english', COALESCE(from_agent, '')), 'B') ||
|
|
18098
|
+
setweight(to_tsvector('english', COALESCE(to_agent, '')), 'B') ||
|
|
18099
|
+
setweight(to_tsvector('english', COALESCE(space, '')), 'C')
|
|
18100
|
+
WHERE search_vector IS NULL;
|
|
18101
|
+
|
|
18102
|
+
-- Feedback table
|
|
18103
|
+
CREATE TABLE IF NOT EXISTS feedback (
|
|
18104
|
+
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
|
|
18105
|
+
message TEXT NOT NULL,
|
|
18106
|
+
email TEXT,
|
|
18107
|
+
category TEXT DEFAULT 'general',
|
|
18108
|
+
version TEXT,
|
|
18109
|
+
machine_id TEXT,
|
|
18110
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
18111
|
+
);
|
|
18112
|
+
|
|
18113
|
+
CREATE TABLE IF NOT EXISTS _migrations (
|
|
18114
|
+
id INTEGER PRIMARY KEY,
|
|
18115
|
+
applied_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
18116
|
+
);
|
|
18117
|
+
INSERT INTO _migrations (id) VALUES (1) ON CONFLICT DO NOTHING;
|
|
18118
|
+
`
|
|
18119
|
+
];
|
|
18120
|
+
});
|
|
18121
|
+
|
|
17935
18122
|
// node_modules/zod/v3/helpers/util.js
|
|
17936
18123
|
var util;
|
|
17937
18124
|
(function(util2) {
|
|
@@ -40016,7 +40203,30 @@ function guessMimeType(name) {
|
|
|
40016
40203
|
};
|
|
40017
40204
|
return mimeMap[ext || ""] || "application/octet-stream";
|
|
40018
40205
|
}
|
|
40206
|
+
var MAX_MESSAGE_BYTES = 65536;
|
|
40207
|
+
var RATE_LIMIT_MAX = 60;
|
|
40208
|
+
var RATE_LIMIT_WINDOW_MS = 60000;
|
|
40209
|
+
var _rateLimitCounters = new Map;
|
|
40210
|
+
function checkRateLimit(agentId) {
|
|
40211
|
+
const dbPath = process.env.CONVERSATIONS_DB_PATH ?? process.env.HASNA_CONVERSATIONS_DB_PATH ?? "";
|
|
40212
|
+
if (dbPath === ":memory:" || dbPath.includes("test") || dbPath.includes("tmp"))
|
|
40213
|
+
return;
|
|
40214
|
+
const now = Date.now();
|
|
40215
|
+
const entry = _rateLimitCounters.get(agentId);
|
|
40216
|
+
if (!entry || now - entry.windowStart > RATE_LIMIT_WINDOW_MS) {
|
|
40217
|
+
_rateLimitCounters.set(agentId, { count: 1, windowStart: now });
|
|
40218
|
+
return;
|
|
40219
|
+
}
|
|
40220
|
+
entry.count++;
|
|
40221
|
+
if (entry.count > RATE_LIMIT_MAX) {
|
|
40222
|
+
throw new Error(`Rate limit exceeded: ${agentId} may send at most ${RATE_LIMIT_MAX} messages per minute.`);
|
|
40223
|
+
}
|
|
40224
|
+
}
|
|
40019
40225
|
function sendMessage(opts) {
|
|
40226
|
+
if (Buffer.byteLength(opts.content, "utf8") > MAX_MESSAGE_BYTES) {
|
|
40227
|
+
throw new Error(`Message content exceeds maximum size of ${MAX_MESSAGE_BYTES} bytes (64 KB).`);
|
|
40228
|
+
}
|
|
40229
|
+
checkRateLimit(opts.from);
|
|
40020
40230
|
const db2 = getDb();
|
|
40021
40231
|
const explicitSession = opts.session_id && opts.session_id.trim().length > 0 ? opts.session_id : undefined;
|
|
40022
40232
|
const sessionId = explicitSession ?? (opts.space ? `space:${opts.space}` : `${[opts.from, opts.to].sort().join("-")}-${randomUUID().slice(0, 8)}`);
|
|
@@ -43555,7 +43765,16 @@ function registerAdvancedTools(server, pkgVersion) {
|
|
|
43555
43765
|
}
|
|
43556
43766
|
|
|
43557
43767
|
// src/mcp/tools/cloud.ts
|
|
43558
|
-
var
|
|
43768
|
+
var SYNC_EXCLUDED = new Set([
|
|
43769
|
+
"messages",
|
|
43770
|
+
"reactions",
|
|
43771
|
+
"message_read_receipts",
|
|
43772
|
+
"message_mentions",
|
|
43773
|
+
"messages_fts",
|
|
43774
|
+
"_sync_conflicts",
|
|
43775
|
+
"_migrations"
|
|
43776
|
+
]);
|
|
43777
|
+
var CONFLICT_TABLES = new Set(["spaces", "projects", "agent_presence"]);
|
|
43559
43778
|
async function detectAndLogConflicts(local, cloud, table) {
|
|
43560
43779
|
if (!CONFLICT_TABLES.has(table))
|
|
43561
43780
|
return 0;
|
|
@@ -43638,7 +43857,7 @@ function registerCloudSyncTools(server) {
|
|
|
43638
43857
|
const localPath = cloudGetDbPath("conversations");
|
|
43639
43858
|
const local = new SqliteAdapter2(localPath);
|
|
43640
43859
|
const cloud = new PgAdapterAsync2(getConnectionString2("conversations"));
|
|
43641
|
-
const tableList = tablesStr ? tablesStr.split(",").map((t) => t.trim()) : listSqliteTables2(local).filter((t) => !
|
|
43860
|
+
const tableList = tablesStr ? tablesStr.split(",").map((t) => t.trim()) : listSqliteTables2(local).filter((t) => !SYNC_EXCLUDED.has(t));
|
|
43642
43861
|
let totalConflicts = 0;
|
|
43643
43862
|
for (const table of tableList) {
|
|
43644
43863
|
totalConflicts += await detectAndLogConflicts(local, cloud, table);
|
|
@@ -43683,7 +43902,7 @@ function registerCloudSyncTools(server) {
|
|
|
43683
43902
|
tableList = tablesStr.split(",").map((t) => t.trim());
|
|
43684
43903
|
} else {
|
|
43685
43904
|
try {
|
|
43686
|
-
tableList = (await listPgTables2(cloud)).filter((t) => !
|
|
43905
|
+
tableList = (await listPgTables2(cloud)).filter((t) => !SYNC_EXCLUDED.has(t));
|
|
43687
43906
|
} catch {
|
|
43688
43907
|
local.close();
|
|
43689
43908
|
await cloud.close();
|
|
@@ -43705,6 +43924,100 @@ function registerCloudSyncTools(server) {
|
|
|
43705
43924
|
if (errors3.length > 0)
|
|
43706
43925
|
lines.push(`Errors: ${errors3.join("; ")}`);
|
|
43707
43926
|
return { content: [{ type: "text", text: lines.join(`
|
|
43927
|
+
`) }] };
|
|
43928
|
+
} catch (e) {
|
|
43929
|
+
return { content: [{ type: "text", text: formatError2(e) }], isError: true };
|
|
43930
|
+
}
|
|
43931
|
+
});
|
|
43932
|
+
server.tool("conversations_cloud_sync", "Bidirectional cloud sync \u2014 pull remote changes then push local changes. Detects and logs conflicts.", {
|
|
43933
|
+
tables: exports_external.string().optional().describe("Comma-separated table names (default: all syncable tables)")
|
|
43934
|
+
}, async ({ tables: tablesStr }) => {
|
|
43935
|
+
try {
|
|
43936
|
+
const {
|
|
43937
|
+
getCloudConfig: getCloudConfig2,
|
|
43938
|
+
getConnectionString: getConnectionString2,
|
|
43939
|
+
syncPush: syncPush2,
|
|
43940
|
+
syncPull: syncPull2,
|
|
43941
|
+
listSqliteTables: listSqliteTables2,
|
|
43942
|
+
listPgTables: listPgTables2,
|
|
43943
|
+
SqliteAdapter: SqliteAdapter2,
|
|
43944
|
+
PgAdapterAsync: PgAdapterAsync2,
|
|
43945
|
+
getDbPath: cloudGetDbPath
|
|
43946
|
+
} = await Promise.resolve().then(() => (init_dist(), exports_dist));
|
|
43947
|
+
const config2 = getCloudConfig2();
|
|
43948
|
+
if (config2.mode === "local") {
|
|
43949
|
+
return { content: [{ type: "text", text: "Error: cloud mode not configured." }], isError: true };
|
|
43950
|
+
}
|
|
43951
|
+
const local = new SqliteAdapter2(cloudGetDbPath("conversations"));
|
|
43952
|
+
const cloud = new PgAdapterAsync2(getConnectionString2("conversations"));
|
|
43953
|
+
let tableList;
|
|
43954
|
+
if (tablesStr) {
|
|
43955
|
+
tableList = tablesStr.split(",").map((t) => t.trim());
|
|
43956
|
+
} else {
|
|
43957
|
+
const localTables = new Set(listSqliteTables2(local).filter((t) => !SYNC_EXCLUDED.has(t)));
|
|
43958
|
+
let remoteTables;
|
|
43959
|
+
try {
|
|
43960
|
+
remoteTables = new Set((await listPgTables2(cloud)).filter((t) => !SYNC_EXCLUDED.has(t)));
|
|
43961
|
+
} catch {
|
|
43962
|
+
local.close();
|
|
43963
|
+
await cloud.close();
|
|
43964
|
+
return { content: [{ type: "text", text: "Error: failed to list cloud tables." }], isError: true };
|
|
43965
|
+
}
|
|
43966
|
+
tableList = [...new Set([...localTables, ...remoteTables])];
|
|
43967
|
+
}
|
|
43968
|
+
let totalConflicts = 0;
|
|
43969
|
+
for (const table of tableList) {
|
|
43970
|
+
totalConflicts += await detectAndLogConflicts(local, cloud, table);
|
|
43971
|
+
}
|
|
43972
|
+
const pullResults = await syncPull2(cloud, local, { tables: tableList });
|
|
43973
|
+
const pullTotal = pullResults.reduce((s, r) => s + r.rowsWritten, 0);
|
|
43974
|
+
const pushResults = await syncPush2(local, cloud, { tables: tableList });
|
|
43975
|
+
const pushTotal = pushResults.reduce((s, r) => s + r.rowsWritten, 0);
|
|
43976
|
+
local.close();
|
|
43977
|
+
await cloud.close();
|
|
43978
|
+
const allErrors = [
|
|
43979
|
+
...pullResults.flatMap((r) => r.errors.map((e) => `pull: ${e}`)),
|
|
43980
|
+
...pushResults.flatMap((r) => r.errors.map((e) => `push: ${e}`))
|
|
43981
|
+
];
|
|
43982
|
+
const lines = [
|
|
43983
|
+
`Sync complete: pulled ${pullTotal} rows, pushed ${pushTotal} rows across ${tableList.length} table(s).`
|
|
43984
|
+
];
|
|
43985
|
+
if (totalConflicts > 0)
|
|
43986
|
+
lines.push(`Conflicts detected: ${totalConflicts} (logged to _sync_conflicts)`);
|
|
43987
|
+
if (allErrors.length > 0)
|
|
43988
|
+
lines.push(`Errors: ${allErrors.join("; ")}`);
|
|
43989
|
+
return { content: [{ type: "text", text: lines.join(`
|
|
43990
|
+
`) }] };
|
|
43991
|
+
} catch (e) {
|
|
43992
|
+
return { content: [{ type: "text", text: formatError2(e) }], isError: true };
|
|
43993
|
+
}
|
|
43994
|
+
});
|
|
43995
|
+
server.tool("conversations_cloud_migrate", "Run PostgreSQL migrations against the configured RDS instance to initialize the cloud schema", {
|
|
43996
|
+
dry_run: exports_external.boolean().optional().describe("Print SQL without executing")
|
|
43997
|
+
}, async ({ dry_run }) => {
|
|
43998
|
+
try {
|
|
43999
|
+
const { getCloudConfig: getCloudConfig2, getConnectionString: getConnectionString2, PgAdapterAsync: PgAdapterAsync2 } = await Promise.resolve().then(() => (init_dist(), exports_dist));
|
|
44000
|
+
const { PG_MIGRATIONS: PG_MIGRATIONS2 } = await Promise.resolve().then(() => (init_pg_migrations(), exports_pg_migrations));
|
|
44001
|
+
const config2 = getCloudConfig2();
|
|
44002
|
+
if (config2.mode === "local") {
|
|
44003
|
+
return { content: [{ type: "text", text: "Error: cloud mode not configured." }], isError: true };
|
|
44004
|
+
}
|
|
44005
|
+
if (dry_run) {
|
|
44006
|
+
return { content: [{ type: "text", text: PG_MIGRATIONS2.join(`
|
|
44007
|
+
|
|
44008
|
+
---
|
|
44009
|
+
|
|
44010
|
+
`) }] };
|
|
44011
|
+
}
|
|
44012
|
+
const pg = new PgAdapterAsync2(getConnectionString2("conversations"));
|
|
44013
|
+
const lines = [];
|
|
44014
|
+
for (let i = 0;i < PG_MIGRATIONS2.length; i++) {
|
|
44015
|
+
await pg.run(PG_MIGRATIONS2[i]);
|
|
44016
|
+
lines.push(`Migration ${i + 1}/${PG_MIGRATIONS2.length}: applied`);
|
|
44017
|
+
}
|
|
44018
|
+
await pg.close();
|
|
44019
|
+
lines.push("All migrations applied successfully.");
|
|
44020
|
+
return { content: [{ type: "text", text: lines.join(`
|
|
43708
44021
|
`) }] };
|
|
43709
44022
|
} catch (e) {
|
|
43710
44023
|
return { content: [{ type: "text", text: formatError2(e) }], isError: true };
|
|
@@ -43738,7 +44051,7 @@ function formatError2(e) {
|
|
|
43738
44051
|
// package.json
|
|
43739
44052
|
var package_default = {
|
|
43740
44053
|
name: "@hasna/conversations",
|
|
43741
|
-
version: "0.2.
|
|
44054
|
+
version: "0.2.27",
|
|
43742
44055
|
description: "Real-time CLI messaging for AI agents",
|
|
43743
44056
|
type: "module",
|
|
43744
44057
|
bin: {
|
|
@@ -43767,7 +44080,7 @@ var package_default = {
|
|
|
43767
44080
|
test: "bun test",
|
|
43768
44081
|
dev: "bun run ./src/cli/index.tsx",
|
|
43769
44082
|
typecheck: "tsc --noEmit",
|
|
43770
|
-
prepublishOnly: "bun run build",
|
|
44083
|
+
prepublishOnly: "bun run build:dashboard && bun run build",
|
|
43771
44084
|
postinstall: "mkdir -p $HOME/.hasna/conversations $HOME/.hasna/conversations/training 2>/dev/null || true"
|
|
43772
44085
|
},
|
|
43773
44086
|
keywords: [
|