@signetai/connector-base 0.211.16 → 0.211.20

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 +321 -0
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -15778,6 +15778,319 @@ function up137(db) {
15778
15778
  if (!cols.has(name))
15779
15779
  db.exec(`ALTER TABLE dreaming_passes ADD COLUMN ${name} ${type}`);
15780
15780
  }
15781
+ function hasColumn25(db, table, column) {
15782
+ const rows = db.prepare(`PRAGMA table_info(${table})`).all();
15783
+ return rows.some((row) => row.name === column);
15784
+ }
15785
+ function addColumnIfMissing27(db, table, column, definition) {
15786
+ if (!hasColumn25(db, table, column))
15787
+ db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
15788
+ }
15789
+ function up138(db) {
15790
+ addColumnIfMissing27(db, "memories", "manual_override", "INTEGER DEFAULT 0");
15791
+ db.exec(`
15792
+ CREATE TABLE IF NOT EXISTS transcript_capture_status (
15793
+ agent_id TEXT PRIMARY KEY,
15794
+ pending INTEGER NOT NULL DEFAULT 0,
15795
+ processing INTEGER NOT NULL DEFAULT 0,
15796
+ completed INTEGER NOT NULL DEFAULT 0,
15797
+ failed INTEGER NOT NULL DEFAULT 0,
15798
+ dead INTEGER NOT NULL DEFAULT 0,
15799
+ oldest_pending_at TEXT,
15800
+ last_error TEXT,
15801
+ last_error_at TEXT
15802
+ );
15803
+
15804
+ CREATE INDEX IF NOT EXISTS idx_transcript_capture_jobs_agent_status_created_at
15805
+ ON transcript_capture_jobs(agent_id, status, created_at);
15806
+
15807
+ CREATE INDEX IF NOT EXISTS idx_transcript_capture_jobs_error_updated_at
15808
+ ON transcript_capture_jobs(agent_id, updated_at DESC)
15809
+ WHERE error IS NOT NULL;
15810
+
15811
+ CREATE TABLE IF NOT EXISTS memories_duplicate_hash_counts (
15812
+ content_hash TEXT PRIMARY KEY,
15813
+ dup_count INTEGER NOT NULL
15814
+ );
15815
+
15816
+ CREATE INDEX IF NOT EXISTS idx_memories_dup_counts_active
15817
+ ON memories_duplicate_hash_counts(dup_count)
15818
+ WHERE dup_count > 1;
15819
+
15820
+ CREATE TABLE IF NOT EXISTS memories_diagnostics_state (
15821
+ id INTEGER PRIMARY KEY CHECK (id = 1),
15822
+ total_active INTEGER NOT NULL DEFAULT 0,
15823
+ exact_duplicates INTEGER NOT NULL DEFAULT 0,
15824
+ exact_clusters INTEGER NOT NULL DEFAULT 0
15825
+ );
15826
+
15827
+ CREATE INDEX IF NOT EXISTS idx_memories_active_hash_diagnostics
15828
+ ON memories(content_hash)
15829
+ WHERE is_deleted = 0
15830
+ AND content_hash IS NOT NULL
15831
+ AND pinned = 0
15832
+ AND manual_override = 0;
15833
+ `);
15834
+ db.exec(`
15835
+ CREATE TRIGGER IF NOT EXISTS transcript_capture_status_ai
15836
+ AFTER INSERT ON transcript_capture_jobs
15837
+ BEGIN
15838
+ INSERT INTO transcript_capture_status (agent_id)
15839
+ VALUES (NEW.agent_id)
15840
+ ON CONFLICT(agent_id) DO NOTHING;
15841
+
15842
+ UPDATE transcript_capture_status
15843
+ SET pending = pending + (NEW.status = 'pending'),
15844
+ processing = processing + (NEW.status = 'processing'),
15845
+ completed = completed + (NEW.status = 'completed'),
15846
+ failed = failed + (NEW.status = 'failed'),
15847
+ dead = dead + (NEW.status = 'dead')
15848
+ WHERE agent_id = NEW.agent_id;
15849
+
15850
+ UPDATE transcript_capture_status
15851
+ SET oldest_pending_at = (
15852
+ SELECT MIN(created_at) FROM transcript_capture_jobs
15853
+ WHERE agent_id = NEW.agent_id AND status = 'pending'
15854
+ )
15855
+ WHERE agent_id = NEW.agent_id;
15856
+
15857
+ UPDATE transcript_capture_status
15858
+ SET last_error = (
15859
+ SELECT error FROM transcript_capture_jobs
15860
+ WHERE agent_id = NEW.agent_id AND error IS NOT NULL
15861
+ ORDER BY updated_at DESC LIMIT 1
15862
+ ),
15863
+ last_error_at = (
15864
+ SELECT updated_at FROM transcript_capture_jobs
15865
+ WHERE agent_id = NEW.agent_id AND error IS NOT NULL
15866
+ ORDER BY updated_at DESC LIMIT 1
15867
+ )
15868
+ WHERE agent_id = NEW.agent_id
15869
+ AND NEW.error IS NOT NULL;
15870
+ END;
15871
+
15872
+ CREATE TRIGGER IF NOT EXISTS transcript_capture_status_au
15873
+ AFTER UPDATE OF status, error, updated_at, created_at ON transcript_capture_jobs
15874
+ BEGIN
15875
+ UPDATE transcript_capture_status
15876
+ SET pending = pending + (NEW.status = 'pending') - (OLD.status = 'pending'),
15877
+ processing = processing + (NEW.status = 'processing') - (OLD.status = 'processing'),
15878
+ completed = completed + (NEW.status = 'completed') - (OLD.status = 'completed'),
15879
+ failed = failed + (NEW.status = 'failed') - (OLD.status = 'failed'),
15880
+ dead = dead + (NEW.status = 'dead') - (OLD.status = 'dead')
15881
+ WHERE agent_id = NEW.agent_id;
15882
+
15883
+ UPDATE transcript_capture_status
15884
+ SET oldest_pending_at = (
15885
+ SELECT MIN(created_at) FROM transcript_capture_jobs
15886
+ WHERE agent_id = NEW.agent_id AND status = 'pending'
15887
+ )
15888
+ WHERE agent_id = NEW.agent_id;
15889
+
15890
+ UPDATE transcript_capture_status
15891
+ SET last_error = (
15892
+ SELECT error FROM transcript_capture_jobs
15893
+ WHERE agent_id = NEW.agent_id AND error IS NOT NULL
15894
+ ORDER BY updated_at DESC LIMIT 1
15895
+ ),
15896
+ last_error_at = (
15897
+ SELECT updated_at FROM transcript_capture_jobs
15898
+ WHERE agent_id = NEW.agent_id AND error IS NOT NULL
15899
+ ORDER BY updated_at DESC LIMIT 1
15900
+ )
15901
+ WHERE agent_id = NEW.agent_id
15902
+ AND (NEW.error IS NOT NULL OR OLD.error IS NOT NULL);
15903
+ END;
15904
+
15905
+ CREATE TRIGGER IF NOT EXISTS transcript_capture_status_ad
15906
+ AFTER DELETE ON transcript_capture_jobs
15907
+ BEGIN
15908
+ UPDATE transcript_capture_status
15909
+ SET pending = pending - (OLD.status = 'pending'),
15910
+ processing = processing - (OLD.status = 'processing'),
15911
+ completed = completed - (OLD.status = 'completed'),
15912
+ failed = failed - (OLD.status = 'failed'),
15913
+ dead = dead - (OLD.status = 'dead')
15914
+ WHERE agent_id = OLD.agent_id;
15915
+
15916
+ UPDATE transcript_capture_status
15917
+ SET oldest_pending_at = (
15918
+ SELECT MIN(created_at) FROM transcript_capture_jobs
15919
+ WHERE agent_id = OLD.agent_id AND status = 'pending'
15920
+ )
15921
+ WHERE agent_id = OLD.agent_id;
15922
+
15923
+ UPDATE transcript_capture_status
15924
+ SET last_error = (
15925
+ SELECT error FROM transcript_capture_jobs
15926
+ WHERE agent_id = OLD.agent_id AND error IS NOT NULL
15927
+ ORDER BY updated_at DESC LIMIT 1
15928
+ ),
15929
+ last_error_at = (
15930
+ SELECT updated_at FROM transcript_capture_jobs
15931
+ WHERE agent_id = OLD.agent_id AND error IS NOT NULL
15932
+ ORDER BY updated_at DESC LIMIT 1
15933
+ )
15934
+ WHERE agent_id = OLD.agent_id
15935
+ AND OLD.error IS NOT NULL;
15936
+ END;
15937
+ `);
15938
+ db.exec(`
15939
+ CREATE TRIGGER IF NOT EXISTS memories_dup_projection_ai
15940
+ AFTER INSERT ON memories
15941
+ BEGIN
15942
+ UPDATE memories_diagnostics_state
15943
+ SET total_active = total_active + CASE WHEN NEW.is_deleted = 0 THEN 1 ELSE 0 END,
15944
+ exact_duplicates = exact_duplicates + CASE
15945
+ WHEN NEW.is_deleted = 0 AND NEW.content_hash IS NOT NULL
15946
+ AND NEW.pinned = 0 AND NEW.manual_override = 0
15947
+ AND COALESCE((SELECT dup_count FROM memories_duplicate_hash_counts WHERE content_hash = NEW.content_hash), 0) >= 1
15948
+ THEN 1 ELSE 0 END,
15949
+ exact_clusters = exact_clusters + CASE
15950
+ WHEN NEW.is_deleted = 0 AND NEW.content_hash IS NOT NULL
15951
+ AND NEW.pinned = 0 AND NEW.manual_override = 0
15952
+ AND COALESCE((SELECT dup_count FROM memories_duplicate_hash_counts WHERE content_hash = NEW.content_hash), 0) = 1
15953
+ THEN 1 ELSE 0 END
15954
+ WHERE id = 1;
15955
+
15956
+ INSERT INTO memories_duplicate_hash_counts (content_hash, dup_count)
15957
+ SELECT NEW.content_hash, 1
15958
+ WHERE NEW.is_deleted = 0
15959
+ AND NEW.content_hash IS NOT NULL
15960
+ AND NEW.pinned = 0
15961
+ AND NEW.manual_override = 0
15962
+ ON CONFLICT(content_hash) DO UPDATE SET dup_count = dup_count + 1;
15963
+ END;
15964
+
15965
+ CREATE TRIGGER IF NOT EXISTS memories_dup_projection_au
15966
+ AFTER UPDATE OF is_deleted, content_hash, pinned, manual_override ON memories
15967
+ BEGIN
15968
+ UPDATE memories_diagnostics_state
15969
+ SET total_active = total_active
15970
+ + CASE WHEN NEW.is_deleted = 0 THEN 1 ELSE 0 END
15971
+ - CASE WHEN OLD.is_deleted = 0 THEN 1 ELSE 0 END,
15972
+ exact_duplicates = exact_duplicates - CASE
15973
+ WHEN OLD.is_deleted = 0 AND OLD.content_hash IS NOT NULL
15974
+ AND OLD.pinned = 0 AND OLD.manual_override = 0
15975
+ AND COALESCE((SELECT dup_count FROM memories_duplicate_hash_counts WHERE content_hash = OLD.content_hash), 0) > 1
15976
+ THEN 1 ELSE 0 END,
15977
+ exact_clusters = exact_clusters - CASE
15978
+ WHEN OLD.is_deleted = 0 AND OLD.content_hash IS NOT NULL
15979
+ AND OLD.pinned = 0 AND OLD.manual_override = 0
15980
+ AND COALESCE((SELECT dup_count FROM memories_duplicate_hash_counts WHERE content_hash = OLD.content_hash), 0) = 2
15981
+ THEN 1 ELSE 0 END
15982
+ WHERE id = 1;
15983
+
15984
+ UPDATE memories_duplicate_hash_counts
15985
+ SET dup_count = dup_count - 1
15986
+ WHERE OLD.is_deleted = 0
15987
+ AND OLD.content_hash IS NOT NULL
15988
+ AND OLD.pinned = 0
15989
+ AND OLD.manual_override = 0
15990
+ AND content_hash = OLD.content_hash;
15991
+
15992
+ DELETE FROM memories_duplicate_hash_counts
15993
+ WHERE content_hash = OLD.content_hash
15994
+ AND dup_count <= 0;
15995
+
15996
+ UPDATE memories_diagnostics_state
15997
+ SET exact_duplicates = exact_duplicates + CASE
15998
+ WHEN NEW.is_deleted = 0 AND NEW.content_hash IS NOT NULL
15999
+ AND NEW.pinned = 0 AND NEW.manual_override = 0
16000
+ AND COALESCE((SELECT dup_count FROM memories_duplicate_hash_counts WHERE content_hash = NEW.content_hash), 0) >= 1
16001
+ THEN 1 ELSE 0 END,
16002
+ exact_clusters = exact_clusters + CASE
16003
+ WHEN NEW.is_deleted = 0 AND NEW.content_hash IS NOT NULL
16004
+ AND NEW.pinned = 0 AND NEW.manual_override = 0
16005
+ AND COALESCE((SELECT dup_count FROM memories_duplicate_hash_counts WHERE content_hash = NEW.content_hash), 0) = 1
16006
+ THEN 1 ELSE 0 END
16007
+ WHERE id = 1;
16008
+
16009
+ INSERT INTO memories_duplicate_hash_counts (content_hash, dup_count)
16010
+ SELECT NEW.content_hash, 1
16011
+ WHERE NEW.is_deleted = 0
16012
+ AND NEW.content_hash IS NOT NULL
16013
+ AND NEW.pinned = 0
16014
+ AND NEW.manual_override = 0
16015
+ ON CONFLICT(content_hash) DO UPDATE SET dup_count = dup_count + 1;
16016
+ END;
16017
+
16018
+ CREATE TRIGGER IF NOT EXISTS memories_dup_projection_ad
16019
+ AFTER DELETE ON memories
16020
+ BEGIN
16021
+ UPDATE memories_diagnostics_state
16022
+ SET total_active = total_active - CASE WHEN OLD.is_deleted = 0 THEN 1 ELSE 0 END,
16023
+ exact_duplicates = exact_duplicates - CASE
16024
+ WHEN OLD.is_deleted = 0 AND OLD.content_hash IS NOT NULL
16025
+ AND OLD.pinned = 0 AND OLD.manual_override = 0
16026
+ AND COALESCE((SELECT dup_count FROM memories_duplicate_hash_counts WHERE content_hash = OLD.content_hash), 0) > 1
16027
+ THEN 1 ELSE 0 END,
16028
+ exact_clusters = exact_clusters - CASE
16029
+ WHEN OLD.is_deleted = 0 AND OLD.content_hash IS NOT NULL
16030
+ AND OLD.pinned = 0 AND OLD.manual_override = 0
16031
+ AND COALESCE((SELECT dup_count FROM memories_duplicate_hash_counts WHERE content_hash = OLD.content_hash), 0) = 2
16032
+ THEN 1 ELSE 0 END
16033
+ WHERE id = 1;
16034
+
16035
+ UPDATE memories_duplicate_hash_counts
16036
+ SET dup_count = dup_count - 1
16037
+ WHERE OLD.is_deleted = 0
16038
+ AND OLD.content_hash IS NOT NULL
16039
+ AND OLD.pinned = 0
16040
+ AND OLD.manual_override = 0
16041
+ AND content_hash = OLD.content_hash;
16042
+
16043
+ DELETE FROM memories_duplicate_hash_counts
16044
+ WHERE content_hash = OLD.content_hash
16045
+ AND dup_count <= 0;
16046
+ END;
16047
+ `);
16048
+ db.exec(`
16049
+ DELETE FROM transcript_capture_status;
16050
+ DELETE FROM memories_duplicate_hash_counts;
16051
+ INSERT INTO memories_duplicate_hash_counts (content_hash, dup_count)
16052
+ SELECT content_hash, COUNT(*)
16053
+ FROM memories
16054
+ WHERE is_deleted = 0
16055
+ AND content_hash IS NOT NULL
16056
+ AND pinned = 0
16057
+ AND manual_override = 0
16058
+ GROUP BY content_hash;
16059
+
16060
+ INSERT INTO memories_diagnostics_state (id, total_active, exact_duplicates, exact_clusters)
16061
+ VALUES (
16062
+ 1,
16063
+ (SELECT COUNT(*) FROM memories WHERE is_deleted = 0),
16064
+ COALESCE((SELECT SUM(dup_count - 1) FROM memories_duplicate_hash_counts WHERE dup_count > 1), 0),
16065
+ (SELECT COUNT(*) FROM memories_duplicate_hash_counts WHERE dup_count > 1)
16066
+ )
16067
+ ON CONFLICT(id) DO UPDATE SET
16068
+ total_active = excluded.total_active,
16069
+ exact_duplicates = excluded.exact_duplicates,
16070
+ exact_clusters = excluded.exact_clusters;
16071
+
16072
+ INSERT INTO transcript_capture_status (
16073
+ agent_id, pending, processing, completed, failed, dead,
16074
+ oldest_pending_at, last_error, last_error_at
16075
+ )
16076
+ SELECT
16077
+ j.agent_id,
16078
+ SUM(j.status = 'pending'),
16079
+ SUM(j.status = 'processing'),
16080
+ SUM(j.status = 'completed'),
16081
+ SUM(j.status = 'failed'),
16082
+ SUM(j.status = 'dead'),
16083
+ MIN(CASE WHEN j.status = 'pending' THEN j.created_at END),
16084
+ (SELECT e2.error FROM transcript_capture_jobs e2
16085
+ WHERE e2.agent_id = j.agent_id AND e2.error IS NOT NULL
16086
+ ORDER BY e2.updated_at DESC LIMIT 1),
16087
+ (SELECT e3.updated_at FROM transcript_capture_jobs e3
16088
+ WHERE e3.agent_id = j.agent_id AND e3.error IS NOT NULL
16089
+ ORDER BY e3.updated_at DESC LIMIT 1)
16090
+ FROM transcript_capture_jobs j
16091
+ GROUP BY j.agent_id;
16092
+ `);
16093
+ }
15781
16094
  var MIGRATIONS = [
15782
16095
  {
15783
16096
  version: 1,
@@ -16867,6 +17180,14 @@ var MIGRATIONS = [
16867
17180
  { table: "dreaming_passes", column: "head_hash" }
16868
17181
  ]
16869
17182
  }
17183
+ },
17184
+ {
17185
+ version: 138,
17186
+ name: "bounded-status-projections",
17187
+ up: up138,
17188
+ artifacts: {
17189
+ tables: ["transcript_capture_status", "memories_duplicate_hash_counts", "memories_diagnostics_state"]
17190
+ }
16870
17191
  }
16871
17192
  ];
16872
17193
  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.211.16",
3
+ "version": "0.211.20",
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.211.16",
29
+ "@signetai/core": "0.211.20",
30
30
  "json5": "^2.2.3",
31
31
  "jsonc-parser": "3.3.1"
32
32
  },