@signetai/connector-hermes-agent 0.144.0 → 0.145.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.
Files changed (2) hide show
  1. package/dist/index.js +206 -4
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -9497,6 +9497,96 @@ function up79(db) {
9497
9497
  ON transcript_capture_jobs(agent_id, session_key, created_at);
9498
9498
  `);
9499
9499
  }
9500
+ function hasColumn10(db, table, column) {
9501
+ const rows = db.prepare(`PRAGMA table_info(${table})`).all();
9502
+ return rows.some((row) => row.name === column);
9503
+ }
9504
+ function up80(db) {
9505
+ if (!hasColumn10(db, "documents", "agent_id")) {
9506
+ db.exec("ALTER TABLE documents ADD COLUMN agent_id TEXT NOT NULL DEFAULT 'default'");
9507
+ }
9508
+ if (!hasColumn10(db, "documents", "project")) {
9509
+ db.exec("ALTER TABLE documents ADD COLUMN project TEXT");
9510
+ }
9511
+ db.exec(`
9512
+ UPDATE documents
9513
+ SET agent_id = NULLIF(TRIM(json_extract(metadata_json, '$.signet.agentId')), '')
9514
+ WHERE metadata_json IS NOT NULL
9515
+ AND json_valid(metadata_json)
9516
+ AND json_type(metadata_json, '$.signet.agentId') = 'text'
9517
+ AND NULLIF(TRIM(json_extract(metadata_json, '$.signet.agentId')), '') IS NOT NULL
9518
+ `);
9519
+ db.exec(`
9520
+ UPDATE documents
9521
+ SET project = NULLIF(TRIM(json_extract(metadata_json, '$.signet.project')), '')
9522
+ WHERE metadata_json IS NOT NULL
9523
+ AND json_valid(metadata_json)
9524
+ AND json_type(metadata_json, '$.signet.project') = 'text'
9525
+ `);
9526
+ db.exec(`
9527
+ WITH linked_scope AS (
9528
+ SELECT
9529
+ dm.document_id,
9530
+ m.agent_id,
9531
+ m.project,
9532
+ ROW_NUMBER() OVER (
9533
+ PARTITION BY dm.document_id
9534
+ ORDER BY COUNT(*) DESC, m.agent_id, COALESCE(m.project, '')
9535
+ ) AS rank
9536
+ FROM document_memories dm
9537
+ JOIN memories m ON m.id = dm.memory_id
9538
+ WHERE m.agent_id IS NOT NULL
9539
+ AND NULLIF(TRIM(m.agent_id), '') IS NOT NULL
9540
+ GROUP BY dm.document_id, m.agent_id, m.project
9541
+ )
9542
+ UPDATE documents
9543
+ SET
9544
+ agent_id = COALESCE((
9545
+ SELECT agent_id FROM linked_scope
9546
+ WHERE linked_scope.document_id = documents.id AND rank = 1
9547
+ ), agent_id),
9548
+ project = (
9549
+ SELECT project FROM linked_scope
9550
+ WHERE linked_scope.document_id = documents.id AND rank = 1
9551
+ )
9552
+ WHERE EXISTS (
9553
+ SELECT 1 FROM linked_scope
9554
+ WHERE linked_scope.document_id = documents.id AND rank = 1
9555
+ )
9556
+ AND NOT (
9557
+ metadata_json IS NOT NULL
9558
+ AND json_valid(metadata_json)
9559
+ AND json_type(metadata_json, '$.signet.agentId') = 'text'
9560
+ AND NULLIF(TRIM(json_extract(metadata_json, '$.signet.agentId')), '') IS NOT NULL
9561
+ )
9562
+ `);
9563
+ if (hasColumn10(db, "memories", "visibility") && hasColumn10(db, "memories", "type") && hasColumn10(db, "memories", "source_type")) {
9564
+ db.exec(`
9565
+ UPDATE memories
9566
+ SET visibility = 'private'
9567
+ WHERE id IN (SELECT memory_id FROM document_memories)
9568
+ AND type = 'document_chunk'
9569
+ AND source_type = 'document'
9570
+ AND (visibility IS NULL OR visibility = 'global')
9571
+ `);
9572
+ }
9573
+ if (hasColumn10(db, "memories", "content_hash") && hasColumn10(db, "memories", "agent_id") && hasColumn10(db, "memories", "project") && hasColumn10(db, "memories", "scope") && hasColumn10(db, "memories", "visibility") && hasColumn10(db, "memories", "is_deleted")) {
9574
+ db.exec("DROP INDEX IF EXISTS idx_memories_content_hash_unique");
9575
+ db.exec(`
9576
+ CREATE UNIQUE INDEX idx_memories_content_hash_unique
9577
+ ON memories(
9578
+ content_hash,
9579
+ COALESCE(NULLIF(agent_id, ''), 'default'),
9580
+ COALESCE(project, ''),
9581
+ COALESCE(scope, '__NULL__'),
9582
+ COALESCE(visibility, 'global')
9583
+ )
9584
+ WHERE content_hash IS NOT NULL AND is_deleted = 0
9585
+ `);
9586
+ }
9587
+ db.exec("CREATE INDEX IF NOT EXISTS idx_documents_agent_project ON documents(agent_id, project)");
9588
+ db.exec("CREATE INDEX IF NOT EXISTS idx_documents_source_scope ON documents(source_url, agent_id, project)");
9589
+ }
9500
9590
  var MIGRATIONS = [
9501
9591
  {
9502
9592
  version: 1,
@@ -10131,6 +10221,17 @@ var MIGRATIONS = [
10131
10221
  artifacts: {
10132
10222
  tables: ["transcript_capture_jobs"]
10133
10223
  }
10224
+ },
10225
+ {
10226
+ version: 80,
10227
+ name: "document-scope-columns",
10228
+ up: up80,
10229
+ artifacts: {
10230
+ columns: [
10231
+ { table: "documents", column: "agent_id" },
10232
+ { table: "documents", column: "project" }
10233
+ ]
10234
+ }
10134
10235
  }
10135
10236
  ];
10136
10237
  var LATEST_SCHEMA_VERSION = MIGRATIONS[MIGRATIONS.length - 1]?.version ?? 0;
@@ -17416,7 +17517,7 @@ function memoriesFtsNeedsTokenizerRepair2(sql) {
17416
17517
  return true;
17417
17518
  return !normalized.includes(`tokenize='${MEMORIES_FTS_TOKENIZER2}'`);
17418
17519
  }
17419
- function up80(db) {
17520
+ function up81(db) {
17420
17521
  db.exec(`
17421
17522
  CREATE TABLE IF NOT EXISTS schema_migrations (
17422
17523
  version INTEGER PRIMARY KEY,
@@ -17505,12 +17606,12 @@ function up80(db) {
17505
17606
  } catch {}
17506
17607
  createMemoriesFts2(db);
17507
17608
  }
17508
- function hasColumn10(db, table, column) {
17609
+ function hasColumn11(db, table, column) {
17509
17610
  const rows = db.prepare(`PRAGMA table_info(${table})`).all();
17510
17611
  return rows.some((r) => r.name === column);
17511
17612
  }
17512
17613
  function addColumnIfMissing20(db, table, column, definition) {
17513
- if (!hasColumn10(db, table, column)) {
17614
+ if (!hasColumn11(db, table, column)) {
17514
17615
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
17515
17616
  }
17516
17617
  }
@@ -19974,11 +20075,101 @@ function up792(db) {
19974
20075
  ON transcript_capture_jobs(agent_id, session_key, created_at);
19975
20076
  `);
19976
20077
  }
20078
+ function hasColumn102(db, table, column) {
20079
+ const rows = db.prepare(`PRAGMA table_info(${table})`).all();
20080
+ return rows.some((row) => row.name === column);
20081
+ }
20082
+ function up802(db) {
20083
+ if (!hasColumn102(db, "documents", "agent_id")) {
20084
+ db.exec("ALTER TABLE documents ADD COLUMN agent_id TEXT NOT NULL DEFAULT 'default'");
20085
+ }
20086
+ if (!hasColumn102(db, "documents", "project")) {
20087
+ db.exec("ALTER TABLE documents ADD COLUMN project TEXT");
20088
+ }
20089
+ db.exec(`
20090
+ UPDATE documents
20091
+ SET agent_id = NULLIF(TRIM(json_extract(metadata_json, '$.signet.agentId')), '')
20092
+ WHERE metadata_json IS NOT NULL
20093
+ AND json_valid(metadata_json)
20094
+ AND json_type(metadata_json, '$.signet.agentId') = 'text'
20095
+ AND NULLIF(TRIM(json_extract(metadata_json, '$.signet.agentId')), '') IS NOT NULL
20096
+ `);
20097
+ db.exec(`
20098
+ UPDATE documents
20099
+ SET project = NULLIF(TRIM(json_extract(metadata_json, '$.signet.project')), '')
20100
+ WHERE metadata_json IS NOT NULL
20101
+ AND json_valid(metadata_json)
20102
+ AND json_type(metadata_json, '$.signet.project') = 'text'
20103
+ `);
20104
+ db.exec(`
20105
+ WITH linked_scope AS (
20106
+ SELECT
20107
+ dm.document_id,
20108
+ m.agent_id,
20109
+ m.project,
20110
+ ROW_NUMBER() OVER (
20111
+ PARTITION BY dm.document_id
20112
+ ORDER BY COUNT(*) DESC, m.agent_id, COALESCE(m.project, '')
20113
+ ) AS rank
20114
+ FROM document_memories dm
20115
+ JOIN memories m ON m.id = dm.memory_id
20116
+ WHERE m.agent_id IS NOT NULL
20117
+ AND NULLIF(TRIM(m.agent_id), '') IS NOT NULL
20118
+ GROUP BY dm.document_id, m.agent_id, m.project
20119
+ )
20120
+ UPDATE documents
20121
+ SET
20122
+ agent_id = COALESCE((
20123
+ SELECT agent_id FROM linked_scope
20124
+ WHERE linked_scope.document_id = documents.id AND rank = 1
20125
+ ), agent_id),
20126
+ project = (
20127
+ SELECT project FROM linked_scope
20128
+ WHERE linked_scope.document_id = documents.id AND rank = 1
20129
+ )
20130
+ WHERE EXISTS (
20131
+ SELECT 1 FROM linked_scope
20132
+ WHERE linked_scope.document_id = documents.id AND rank = 1
20133
+ )
20134
+ AND NOT (
20135
+ metadata_json IS NOT NULL
20136
+ AND json_valid(metadata_json)
20137
+ AND json_type(metadata_json, '$.signet.agentId') = 'text'
20138
+ AND NULLIF(TRIM(json_extract(metadata_json, '$.signet.agentId')), '') IS NOT NULL
20139
+ )
20140
+ `);
20141
+ if (hasColumn102(db, "memories", "visibility") && hasColumn102(db, "memories", "type") && hasColumn102(db, "memories", "source_type")) {
20142
+ db.exec(`
20143
+ UPDATE memories
20144
+ SET visibility = 'private'
20145
+ WHERE id IN (SELECT memory_id FROM document_memories)
20146
+ AND type = 'document_chunk'
20147
+ AND source_type = 'document'
20148
+ AND (visibility IS NULL OR visibility = 'global')
20149
+ `);
20150
+ }
20151
+ if (hasColumn102(db, "memories", "content_hash") && hasColumn102(db, "memories", "agent_id") && hasColumn102(db, "memories", "project") && hasColumn102(db, "memories", "scope") && hasColumn102(db, "memories", "visibility") && hasColumn102(db, "memories", "is_deleted")) {
20152
+ db.exec("DROP INDEX IF EXISTS idx_memories_content_hash_unique");
20153
+ db.exec(`
20154
+ CREATE UNIQUE INDEX idx_memories_content_hash_unique
20155
+ ON memories(
20156
+ content_hash,
20157
+ COALESCE(NULLIF(agent_id, ''), 'default'),
20158
+ COALESCE(project, ''),
20159
+ COALESCE(scope, '__NULL__'),
20160
+ COALESCE(visibility, 'global')
20161
+ )
20162
+ WHERE content_hash IS NOT NULL AND is_deleted = 0
20163
+ `);
20164
+ }
20165
+ db.exec("CREATE INDEX IF NOT EXISTS idx_documents_agent_project ON documents(agent_id, project)");
20166
+ db.exec("CREATE INDEX IF NOT EXISTS idx_documents_source_scope ON documents(source_url, agent_id, project)");
20167
+ }
19977
20168
  var MIGRATIONS2 = [
19978
20169
  {
19979
20170
  version: 1,
19980
20171
  name: "baseline",
19981
- up: up80,
20172
+ up: up81,
19982
20173
  artifacts: { tables: ["memories", "conversations", "embeddings"] }
19983
20174
  },
19984
20175
  {
@@ -20608,6 +20799,17 @@ var MIGRATIONS2 = [
20608
20799
  artifacts: {
20609
20800
  tables: ["transcript_capture_jobs"]
20610
20801
  }
20802
+ },
20803
+ {
20804
+ version: 80,
20805
+ name: "document-scope-columns",
20806
+ up: up802,
20807
+ artifacts: {
20808
+ columns: [
20809
+ { table: "documents", column: "agent_id" },
20810
+ { table: "documents", column: "project" }
20811
+ ]
20812
+ }
20611
20813
  }
20612
20814
  ];
20613
20815
  var LATEST_SCHEMA_VERSION2 = MIGRATIONS2[MIGRATIONS2.length - 1]?.version ?? 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signetai/connector-hermes-agent",
3
- "version": "0.144.0",
3
+ "version": "0.145.0",
4
4
  "description": "Signet connector for Hermes Agent — installs Signet as a pluggable memory provider",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -25,8 +25,8 @@
25
25
  "typecheck": "tsc --noEmit"
26
26
  },
27
27
  "dependencies": {
28
- "@signetai/connector-base": "0.144.0",
29
- "@signetai/core": "0.144.0"
28
+ "@signetai/connector-base": "0.145.0",
29
+ "@signetai/core": "0.145.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/node": "^22.0.0",