@signetai/connector-base 0.216.7 → 0.217.1

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 +289 -0
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -16198,6 +16198,241 @@ function up145(db) {
16198
16198
  ON dreaming_evidence_reviews (agent_id, reviewed_at DESC);
16199
16199
  `);
16200
16200
  }
16201
+ function up146(db) {
16202
+ db.exec(`
16203
+ CREATE TABLE IF NOT EXISTS source_import_jobs (
16204
+ id TEXT PRIMARY KEY, kind TEXT NOT NULL CHECK (kind = 'import'), agent_id TEXT NOT NULL,
16205
+ schema_id TEXT NOT NULL, adapter_version INTEGER NOT NULL CHECK (adapter_version = 1),
16206
+ state TEXT NOT NULL CHECK (state IN ('staging','inventorying','queued','running','paused','completed','completed_with_rejections','cancelled','failed')),
16207
+ control_request TEXT CHECK (control_request IN ('pause','resume','retry','cancel') OR control_request IS NULL),
16208
+ generation INTEGER NOT NULL DEFAULT 0, total INTEGER NOT NULL DEFAULT 0, imported INTEGER NOT NULL DEFAULT 0,
16209
+ duplicate INTEGER NOT NULL DEFAULT 0, rejected INTEGER NOT NULL DEFAULT 0, pending INTEGER NOT NULL DEFAULT 0,
16210
+ lease_token TEXT, lease_expires_at TEXT, error TEXT, created_at TEXT NOT NULL DEFAULT (datetime('now')),
16211
+ updated_at TEXT NOT NULL DEFAULT (datetime('now')), started_at TEXT, completed_at TEXT, reconciled_at TEXT
16212
+ );
16213
+ CREATE INDEX IF NOT EXISTS idx_source_import_jobs_agent_state ON source_import_jobs(agent_id, state);
16214
+
16215
+ CREATE TABLE IF NOT EXISTS source_import_files (
16216
+ id TEXT PRIMARY KEY, job_id TEXT NOT NULL REFERENCES source_import_jobs(id) ON DELETE CASCADE,
16217
+ source_id TEXT NOT NULL, agent_id TEXT NOT NULL, ordinal INTEGER NOT NULL, name TEXT NOT NULL,
16218
+ managed_path TEXT NOT NULL, size_bytes INTEGER NOT NULL DEFAULT 0, content_hash TEXT,
16219
+ state TEXT NOT NULL CHECK (state IN ('staging','ready','inventorying','completed','failed')),
16220
+ record_count INTEGER NOT NULL DEFAULT 0, blank_count INTEGER NOT NULL DEFAULT 0, malformed_count INTEGER NOT NULL DEFAULT 0,
16221
+ inventory_version INTEGER NOT NULL DEFAULT 1, checkpoint_ordinal INTEGER NOT NULL DEFAULT 0,
16222
+ checkpoint_byte_offset INTEGER NOT NULL DEFAULT 0, created_at TEXT NOT NULL DEFAULT (datetime('now')), updated_at TEXT NOT NULL DEFAULT (datetime('now')),
16223
+ UNIQUE(job_id, ordinal)
16224
+ );
16225
+ CREATE INDEX IF NOT EXISTS idx_source_import_files_job_state ON source_import_files(job_id, state);
16226
+
16227
+ CREATE TABLE IF NOT EXISTS source_import_records (
16228
+ id TEXT PRIMARY KEY, job_id TEXT NOT NULL REFERENCES source_import_jobs(id) ON DELETE CASCADE,
16229
+ file_id TEXT NOT NULL REFERENCES source_import_files(id) ON DELETE CASCADE, source_id TEXT NOT NULL, agent_id TEXT NOT NULL,
16230
+ ordinal INTEGER NOT NULL, line_number INTEGER NOT NULL, byte_offset INTEGER NOT NULL, byte_length INTEGER NOT NULL,
16231
+ raw_hash TEXT NOT NULL, external_identity TEXT, conversation_fingerprint TEXT, status TEXT NOT NULL CHECK (status IN ('pending','imported','duplicate','rejected','cancelled')),
16232
+ canonical_id TEXT, canonical_key TEXT, rejection_code TEXT, attempt_count INTEGER NOT NULL DEFAULT 0,
16233
+ created_at TEXT NOT NULL DEFAULT (datetime('now')), updated_at TEXT NOT NULL DEFAULT (datetime('now')),
16234
+ UNIQUE(file_id, ordinal), UNIQUE(file_id, byte_offset)
16235
+ );
16236
+ CREATE INDEX IF NOT EXISTS idx_source_import_records_job_status ON source_import_records(job_id, status);
16237
+ CREATE INDEX IF NOT EXISTS idx_source_import_records_source_status ON source_import_records(agent_id, source_id, status);
16238
+
16239
+ CREATE TABLE IF NOT EXISTS transcript_import_conversations (
16240
+ agent_id TEXT NOT NULL, external_identity TEXT NOT NULL, canonical_key TEXT NOT NULL,
16241
+ conversation_fingerprint TEXT NOT NULL, canonical_id TEXT NOT NULL, owner_source_id TEXT NOT NULL,
16242
+ owner_record_id TEXT NOT NULL, state TEXT NOT NULL CHECK (state IN ('committing','committed','removed')),
16243
+ content_hash TEXT NOT NULL, harness TEXT NOT NULL, timestamp TEXT NOT NULL,
16244
+ created_at TEXT NOT NULL DEFAULT (datetime('now')), updated_at TEXT NOT NULL DEFAULT (datetime('now')),
16245
+ PRIMARY KEY (agent_id, external_identity), UNIQUE(agent_id, canonical_key)
16246
+ );
16247
+ CREATE INDEX IF NOT EXISTS idx_transcript_import_conversations_source ON transcript_import_conversations(agent_id, owner_source_id);
16248
+
16249
+ CREATE TABLE IF NOT EXISTS source_import_record_attempts (
16250
+ id INTEGER PRIMARY KEY AUTOINCREMENT, agent_id TEXT NOT NULL, job_id TEXT NOT NULL, file_id TEXT NOT NULL,
16251
+ record_id TEXT NOT NULL, generation INTEGER NOT NULL, outcome TEXT NOT NULL, error_code TEXT, created_at TEXT NOT NULL DEFAULT (datetime('now'))
16252
+ );
16253
+ CREATE INDEX IF NOT EXISTS idx_source_import_attempts_record ON source_import_record_attempts(agent_id, record_id, created_at);
16254
+ `);
16255
+ for (const column of ["source_id", "source_record_id", "source_meta_json"]) {
16256
+ const exists = db.prepare("SELECT 1 AS found FROM pragma_table_info('session_transcripts') WHERE name = ?").get(column);
16257
+ if (exists == null)
16258
+ db.exec(`ALTER TABLE session_transcripts ADD COLUMN ${column} TEXT`);
16259
+ }
16260
+ db.exec("CREATE INDEX IF NOT EXISTS idx_session_transcripts_agent_source ON session_transcripts(agent_id, source_id)");
16261
+ }
16262
+ function up147(db) {
16263
+ db.exec("CREATE INDEX IF NOT EXISTS idx_source_import_files_job_state ON source_import_files(job_id, state)");
16264
+ }
16265
+ function up148(db) {
16266
+ const columns = db.prepare("PRAGMA table_info(source_import_record_attempts)").all();
16267
+ if (!columns.some((column) => column.name === "source_id")) {
16268
+ db.exec("ALTER TABLE source_import_record_attempts ADD COLUMN source_id TEXT");
16269
+ }
16270
+ }
16271
+ function up149(db) {
16272
+ const addColumn = (table, column, definition) => {
16273
+ const exists = db.prepare("SELECT 1 AS found FROM pragma_table_info(?) WHERE name = ?").get(table, column);
16274
+ if (exists == null)
16275
+ db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
16276
+ };
16277
+ addColumn("source_import_jobs", "duplicate_mode", "TEXT NOT NULL DEFAULT 'skip' CHECK (duplicate_mode IN ('skip','replace','reimport'))");
16278
+ addColumn("source_import_jobs", "next_attempt_at", "TEXT");
16279
+ addColumn("source_import_files", "error", "TEXT");
16280
+ }
16281
+ function addColumnIfMissing28(db, table, column, definition) {
16282
+ const columns = db.prepare(`PRAGMA table_info(${table})`).all();
16283
+ if (!columns.some((row) => row.name === column))
16284
+ db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
16285
+ }
16286
+ function up150(db) {
16287
+ addColumnIfMissing28(db, "memory_md_heads", "is_current", "INTEGER NOT NULL DEFAULT 0");
16288
+ addColumnIfMissing28(db, "dreaming_passes", "head_base_revision", "INTEGER");
16289
+ db.exec("CREATE INDEX IF NOT EXISTS idx_memory_head_revisions_content_hash ON memory_head_revisions(content_hash)");
16290
+ db.exec("CREATE INDEX IF NOT EXISTS idx_memory_md_heads_content_hash ON memory_md_heads(content_hash)");
16291
+ db.exec(`
16292
+ CREATE TRIGGER IF NOT EXISTS dreaming_passes_head_fence_ai
16293
+ AFTER INSERT ON dreaming_passes
16294
+ WHEN NEW.mode = 'incremental-content'
16295
+ BEGIN
16296
+ INSERT OR IGNORE INTO memory_md_heads (agent_id, content, content_hash, revision, updated_at, is_current)
16297
+ VALUES (NEW.agent_id, '', '', 0, datetime('now'), 0);
16298
+ UPDATE dreaming_passes
16299
+ SET head_base_revision = (SELECT revision FROM memory_md_heads WHERE agent_id = NEW.agent_id)
16300
+ WHERE id = NEW.id;
16301
+ END;
16302
+
16303
+ CREATE TRIGGER IF NOT EXISTS memories_head_freshness_au
16304
+ AFTER UPDATE OF content, superseded_by, stale_at, is_deleted, agent_id, visibility, scope, memory_kind ON memories
16305
+ WHEN OLD.content IS NOT NEW.content OR OLD.superseded_by IS NOT NEW.superseded_by
16306
+ OR OLD.stale_at IS NOT NEW.stale_at OR OLD.is_deleted IS NOT NEW.is_deleted
16307
+ OR OLD.agent_id IS NOT NEW.agent_id OR OLD.visibility IS NOT NEW.visibility OR OLD.scope IS NOT NEW.scope OR OLD.memory_kind IS NOT NEW.memory_kind
16308
+ BEGIN
16309
+ UPDATE memory_md_heads SET revision = revision + 1, is_current = 0
16310
+ WHERE agent_id IN (OLD.agent_id, NEW.agent_id)
16311
+ OR (COALESCE(OLD.visibility, 'global') = 'global' OR COALESCE(NEW.visibility, 'global') = 'global')
16312
+ AND (agent_id IN (SELECT id FROM agents WHERE read_policy = 'shared')
16313
+ OR agent_id IN (SELECT id FROM agents WHERE read_policy = 'group' AND policy_group IN
16314
+ (SELECT policy_group FROM agents WHERE id IN (OLD.agent_id, NEW.agent_id))));
16315
+ END;
16316
+
16317
+ CREATE TRIGGER IF NOT EXISTS memories_head_freshness_ad
16318
+ AFTER DELETE ON memories
16319
+ BEGIN
16320
+ UPDATE memory_md_heads SET revision = revision + 1, is_current = 0
16321
+ WHERE agent_id = OLD.agent_id
16322
+ OR (COALESCE(OLD.visibility, 'global') = 'global'
16323
+ AND (agent_id IN (SELECT id FROM agents WHERE read_policy = 'shared')
16324
+ OR agent_id IN (SELECT id FROM agents WHERE read_policy = 'group' AND policy_group IN
16325
+ (SELECT policy_group FROM agents WHERE id = OLD.agent_id))));
16326
+ END;
16327
+
16328
+ CREATE TRIGGER IF NOT EXISTS agents_head_freshness_ad
16329
+ AFTER DELETE ON agents
16330
+ BEGIN
16331
+ UPDATE memory_md_heads SET revision = revision + 1, is_current = 0
16332
+ WHERE agent_id = OLD.id OR agent_id IN (SELECT id FROM agents WHERE read_policy='group' AND policy_group=OLD.policy_group);
16333
+ END;
16334
+
16335
+ CREATE TRIGGER IF NOT EXISTS agents_head_freshness_au
16336
+ AFTER UPDATE OF read_policy, policy_group ON agents
16337
+ WHEN OLD.read_policy IS NOT NEW.read_policy OR OLD.policy_group IS NOT NEW.policy_group
16338
+ BEGIN
16339
+ UPDATE memory_md_heads SET revision = revision + 1, is_current = 0
16340
+ WHERE agent_id IN (OLD.id, NEW.id)
16341
+ OR agent_id IN (SELECT id FROM agents WHERE read_policy = 'shared')
16342
+ OR agent_id IN (SELECT id FROM agents WHERE read_policy = 'group' AND policy_group IN (OLD.policy_group, NEW.policy_group));
16343
+ END;
16344
+ `);
16345
+ for (const table of ["memory_artifacts", "session_transcripts"]) {
16346
+ const exists = db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name=?").get(table);
16347
+ if (!exists)
16348
+ continue;
16349
+ const hasIsDeleted = db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === "is_deleted");
16350
+ const updateColumns = table === "session_transcripts" ? "content, agent_id, completed_at" : hasIsDeleted ? "content, agent_id, is_deleted" : "content, agent_id";
16351
+ const contentChanged = table === "session_transcripts" ? "OLD.completed_at IS NOT NULL AND (OLD.content IS NOT NEW.content OR NEW.completed_at IS NULL)" : `OLD.content IS NOT NEW.content${hasIsDeleted ? " OR OLD.is_deleted IS NOT NEW.is_deleted" : ""}`;
16352
+ db.exec(`
16353
+ CREATE TRIGGER IF NOT EXISTS ${table}_head_freshness_au
16354
+ AFTER UPDATE OF ${updateColumns} ON ${table}
16355
+ WHEN OLD.agent_id IS NOT NEW.agent_id OR ${contentChanged}
16356
+ BEGIN
16357
+ UPDATE memory_md_heads SET revision = revision + 1, is_current = 0
16358
+ WHERE agent_id IN (OLD.agent_id, NEW.agent_id);
16359
+ END;
16360
+ CREATE TRIGGER IF NOT EXISTS ${table}_head_freshness_ad
16361
+ AFTER DELETE ON ${table}
16362
+ BEGIN
16363
+ UPDATE memory_md_heads SET revision = revision + 1, is_current = 0 WHERE agent_id = OLD.agent_id;
16364
+ END;
16365
+ `);
16366
+ }
16367
+ if (db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='session_summaries'").get()) {
16368
+ db.exec(`
16369
+ CREATE TRIGGER IF NOT EXISTS session_summaries_head_freshness_au
16370
+ AFTER UPDATE OF content, source_ref, source_type, depth, agent_id ON session_summaries
16371
+ WHEN OLD.depth = 0 AND (OLD.content IS NOT NEW.content OR OLD.source_ref IS NOT NEW.source_ref OR OLD.source_type IS NOT NEW.source_type OR OLD.depth IS NOT NEW.depth OR OLD.agent_id IS NOT NEW.agent_id)
16372
+ BEGIN
16373
+ UPDATE memory_md_heads SET revision = revision + 1, is_current = 0 WHERE agent_id IN (OLD.agent_id, NEW.agent_id);
16374
+ END;
16375
+ CREATE TRIGGER IF NOT EXISTS session_summaries_head_freshness_ad
16376
+ AFTER DELETE ON session_summaries
16377
+ WHEN OLD.depth = 0
16378
+ BEGIN
16379
+ UPDATE memory_md_heads SET revision = revision + 1, is_current = 0 WHERE agent_id = OLD.agent_id;
16380
+ END;
16381
+ `);
16382
+ }
16383
+ const safetyExists = db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='memory_content_safety'").get();
16384
+ if (safetyExists) {
16385
+ db.exec(`
16386
+ CREATE TRIGGER IF NOT EXISTS memory_content_safety_head_freshness_ai
16387
+ AFTER INSERT ON memory_content_safety
16388
+ WHEN NEW.status IS NOT 'clean' OR NEW.context_eligible IS NOT 1
16389
+ BEGIN
16390
+ UPDATE memory_md_heads SET revision = revision + 1, is_current = 0
16391
+ WHERE agent_id IN (NEW.agent_id)
16392
+ OR agent_id IN (SELECT id FROM agents WHERE read_policy IN ('shared', 'group'));
16393
+ END;
16394
+
16395
+ CREATE TRIGGER IF NOT EXISTS memory_content_safety_head_freshness_au
16396
+ AFTER UPDATE OF context_eligible, agent_id, status ON memory_content_safety
16397
+ WHEN (OLD.context_eligible IS NOT NEW.context_eligible OR OLD.agent_id IS NOT NEW.agent_id OR OLD.status IS NOT NEW.status)
16398
+ AND (OLD.status IS NOT 'clean' OR NEW.status IS NOT 'clean' OR OLD.context_eligible IS NOT 1 OR NEW.context_eligible IS NOT 1)
16399
+ BEGIN
16400
+ UPDATE memory_md_heads SET revision = revision + 1, is_current = 0
16401
+ WHERE agent_id IN (OLD.agent_id, NEW.agent_id)
16402
+ OR agent_id IN (SELECT id FROM agents WHERE read_policy = 'shared')
16403
+ OR agent_id IN (SELECT id FROM agents WHERE read_policy = 'group');
16404
+ END;
16405
+ `);
16406
+ }
16407
+ for (const table of ["memory_artifact_tombstones", "imported_source_lifecycle"]) {
16408
+ const exists = db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name=?").get(table);
16409
+ if (!exists)
16410
+ continue;
16411
+ const lifecycleClause = table === "imported_source_lifecycle" ? " WHEN NEW.status = 'unsupported'" : "";
16412
+ const updateColumns = table === "imported_source_lifecycle" ? "agent_id, status" : "agent_id";
16413
+ const lifecycleUpdateClause = table === "imported_source_lifecycle" ? " AND NEW.status = 'unsupported'" : "";
16414
+ const lifecycleWhen = table === "imported_source_lifecycle" ? `(OLD.agent_id IS NOT NEW.agent_id OR OLD.status IS NOT NEW.status)${lifecycleUpdateClause}` : "OLD.agent_id IS NOT NEW.agent_id";
16415
+ db.exec(`
16416
+ CREATE TRIGGER IF NOT EXISTS ${table}_head_freshness_ai
16417
+ AFTER INSERT ON ${table}${lifecycleClause}
16418
+ BEGIN
16419
+ UPDATE memory_md_heads SET revision = revision + 1, is_current = 0 WHERE agent_id = NEW.agent_id;
16420
+ END;
16421
+ CREATE TRIGGER IF NOT EXISTS ${table}_head_freshness_au
16422
+ AFTER UPDATE OF ${updateColumns} ON ${table}
16423
+ WHEN ${lifecycleWhen}
16424
+ BEGIN
16425
+ UPDATE memory_md_heads SET revision = revision + 1, is_current = 0
16426
+ WHERE agent_id IN (OLD.agent_id, NEW.agent_id);
16427
+ END;
16428
+ CREATE TRIGGER IF NOT EXISTS ${table}_head_freshness_ad
16429
+ AFTER DELETE ON ${table}
16430
+ BEGIN
16431
+ UPDATE memory_md_heads SET revision = revision + 1, is_current = 0 WHERE agent_id = OLD.agent_id;
16432
+ END;
16433
+ `);
16434
+ }
16435
+ }
16201
16436
  var MIGRATIONS = [
16202
16437
  {
16203
16438
  version: 1,
@@ -17347,6 +17582,60 @@ var MIGRATIONS = [
17347
17582
  name: "dreaming-evidence-reviews",
17348
17583
  up: up145,
17349
17584
  artifacts: { tables: ["dreaming_evidence_reviews"] }
17585
+ },
17586
+ {
17587
+ version: 146,
17588
+ name: "source-transcript-import",
17589
+ up: up146,
17590
+ artifacts: {
17591
+ tables: [
17592
+ "source_import_jobs",
17593
+ "source_import_files",
17594
+ "source_import_records",
17595
+ "transcript_import_conversations",
17596
+ "source_import_record_attempts"
17597
+ ],
17598
+ columns: [
17599
+ { table: "session_transcripts", column: "source_id" },
17600
+ { table: "session_transcripts", column: "source_record_id" },
17601
+ { table: "session_transcripts", column: "source_meta_json" }
17602
+ ]
17603
+ }
17604
+ },
17605
+ {
17606
+ version: 147,
17607
+ name: "source-import-replay-file-slots",
17608
+ up: up147,
17609
+ artifacts: { tables: ["source_import_files"] }
17610
+ },
17611
+ {
17612
+ version: 148,
17613
+ name: "source-import-attempt-provenance",
17614
+ up: up148,
17615
+ artifacts: { columns: [{ table: "source_import_record_attempts", column: "source_id" }] }
17616
+ },
17617
+ {
17618
+ version: 149,
17619
+ name: "transcript-import-state-machine",
17620
+ up: up149,
17621
+ artifacts: {
17622
+ columns: [
17623
+ { table: "source_import_jobs", column: "duplicate_mode" },
17624
+ { table: "source_import_jobs", column: "next_attempt_at" },
17625
+ { table: "source_import_files", column: "error" }
17626
+ ]
17627
+ }
17628
+ },
17629
+ {
17630
+ version: 150,
17631
+ name: "memory-head-freshness",
17632
+ up: up150,
17633
+ artifacts: {
17634
+ columns: [
17635
+ { table: "memory_md_heads", column: "is_current" },
17636
+ { table: "dreaming_passes", column: "head_base_revision" }
17637
+ ]
17638
+ }
17350
17639
  }
17351
17640
  ];
17352
17641
  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.216.7",
3
+ "version": "0.217.1",
4
4
  "description": "Base class for Signet harness connectors",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -26,7 +26,7 @@
26
26
  "typecheck": "tsc --noEmit"
27
27
  },
28
28
  "dependencies": {
29
- "@signetai/core": "0.216.7",
29
+ "@signetai/core": "0.217.1",
30
30
  "json5": "^2.2.3",
31
31
  "jsonc-parser": "3.3.1"
32
32
  },