@signetai/connector-base 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 +101 -0
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -9494,6 +9494,96 @@ function up79(db) {
9494
9494
  ON transcript_capture_jobs(agent_id, session_key, created_at);
9495
9495
  `);
9496
9496
  }
9497
+ function hasColumn10(db, table, column) {
9498
+ const rows = db.prepare(`PRAGMA table_info(${table})`).all();
9499
+ return rows.some((row) => row.name === column);
9500
+ }
9501
+ function up80(db) {
9502
+ if (!hasColumn10(db, "documents", "agent_id")) {
9503
+ db.exec("ALTER TABLE documents ADD COLUMN agent_id TEXT NOT NULL DEFAULT 'default'");
9504
+ }
9505
+ if (!hasColumn10(db, "documents", "project")) {
9506
+ db.exec("ALTER TABLE documents ADD COLUMN project TEXT");
9507
+ }
9508
+ db.exec(`
9509
+ UPDATE documents
9510
+ SET agent_id = NULLIF(TRIM(json_extract(metadata_json, '$.signet.agentId')), '')
9511
+ WHERE metadata_json IS NOT NULL
9512
+ AND json_valid(metadata_json)
9513
+ AND json_type(metadata_json, '$.signet.agentId') = 'text'
9514
+ AND NULLIF(TRIM(json_extract(metadata_json, '$.signet.agentId')), '') IS NOT NULL
9515
+ `);
9516
+ db.exec(`
9517
+ UPDATE documents
9518
+ SET project = NULLIF(TRIM(json_extract(metadata_json, '$.signet.project')), '')
9519
+ WHERE metadata_json IS NOT NULL
9520
+ AND json_valid(metadata_json)
9521
+ AND json_type(metadata_json, '$.signet.project') = 'text'
9522
+ `);
9523
+ db.exec(`
9524
+ WITH linked_scope AS (
9525
+ SELECT
9526
+ dm.document_id,
9527
+ m.agent_id,
9528
+ m.project,
9529
+ ROW_NUMBER() OVER (
9530
+ PARTITION BY dm.document_id
9531
+ ORDER BY COUNT(*) DESC, m.agent_id, COALESCE(m.project, '')
9532
+ ) AS rank
9533
+ FROM document_memories dm
9534
+ JOIN memories m ON m.id = dm.memory_id
9535
+ WHERE m.agent_id IS NOT NULL
9536
+ AND NULLIF(TRIM(m.agent_id), '') IS NOT NULL
9537
+ GROUP BY dm.document_id, m.agent_id, m.project
9538
+ )
9539
+ UPDATE documents
9540
+ SET
9541
+ agent_id = COALESCE((
9542
+ SELECT agent_id FROM linked_scope
9543
+ WHERE linked_scope.document_id = documents.id AND rank = 1
9544
+ ), agent_id),
9545
+ project = (
9546
+ SELECT project FROM linked_scope
9547
+ WHERE linked_scope.document_id = documents.id AND rank = 1
9548
+ )
9549
+ WHERE EXISTS (
9550
+ SELECT 1 FROM linked_scope
9551
+ WHERE linked_scope.document_id = documents.id AND rank = 1
9552
+ )
9553
+ AND NOT (
9554
+ metadata_json IS NOT NULL
9555
+ AND json_valid(metadata_json)
9556
+ AND json_type(metadata_json, '$.signet.agentId') = 'text'
9557
+ AND NULLIF(TRIM(json_extract(metadata_json, '$.signet.agentId')), '') IS NOT NULL
9558
+ )
9559
+ `);
9560
+ if (hasColumn10(db, "memories", "visibility") && hasColumn10(db, "memories", "type") && hasColumn10(db, "memories", "source_type")) {
9561
+ db.exec(`
9562
+ UPDATE memories
9563
+ SET visibility = 'private'
9564
+ WHERE id IN (SELECT memory_id FROM document_memories)
9565
+ AND type = 'document_chunk'
9566
+ AND source_type = 'document'
9567
+ AND (visibility IS NULL OR visibility = 'global')
9568
+ `);
9569
+ }
9570
+ 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")) {
9571
+ db.exec("DROP INDEX IF EXISTS idx_memories_content_hash_unique");
9572
+ db.exec(`
9573
+ CREATE UNIQUE INDEX idx_memories_content_hash_unique
9574
+ ON memories(
9575
+ content_hash,
9576
+ COALESCE(NULLIF(agent_id, ''), 'default'),
9577
+ COALESCE(project, ''),
9578
+ COALESCE(scope, '__NULL__'),
9579
+ COALESCE(visibility, 'global')
9580
+ )
9581
+ WHERE content_hash IS NOT NULL AND is_deleted = 0
9582
+ `);
9583
+ }
9584
+ db.exec("CREATE INDEX IF NOT EXISTS idx_documents_agent_project ON documents(agent_id, project)");
9585
+ db.exec("CREATE INDEX IF NOT EXISTS idx_documents_source_scope ON documents(source_url, agent_id, project)");
9586
+ }
9497
9587
  var MIGRATIONS = [
9498
9588
  {
9499
9589
  version: 1,
@@ -10128,6 +10218,17 @@ var MIGRATIONS = [
10128
10218
  artifacts: {
10129
10219
  tables: ["transcript_capture_jobs"]
10130
10220
  }
10221
+ },
10222
+ {
10223
+ version: 80,
10224
+ name: "document-scope-columns",
10225
+ up: up80,
10226
+ artifacts: {
10227
+ columns: [
10228
+ { table: "documents", column: "agent_id" },
10229
+ { table: "documents", column: "project" }
10230
+ ]
10231
+ }
10131
10232
  }
10132
10233
  ];
10133
10234
  var LATEST_SCHEMA_VERSION = MIGRATIONS[MIGRATIONS.length - 1]?.version ?? 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signetai/connector-base",
3
- "version": "0.144.0",
3
+ "version": "0.145.0",
4
4
  "description": "Base class for Signet harness connectors",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -22,7 +22,7 @@
22
22
  "typecheck": "tsc --noEmit"
23
23
  },
24
24
  "dependencies": {
25
- "@signetai/core": "0.144.0"
25
+ "@signetai/core": "0.145.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/node": "^22.0.0",