@jungjaehoon/mama-core 2.4.0 → 2.4.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.
- package/db/migrations/068-tool-trace-diagnostics.sql +13 -0
- package/dist/db-adapter/node-sqlite-adapter.d.ts +2 -0
- package/dist/db-adapter/node-sqlite-adapter.js +79 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -3
- package/dist/mama-api.d.ts +4 -2
- package/dist/mama-api.js +5 -1
- package/dist/model-runs/tool-trace-store.d.ts +5 -1
- package/dist/model-runs/tool-trace-store.js +110 -5
- package/dist/model-runs/types.d.ts +31 -0
- package/package.json +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
-- TG-03/04/05: additive diagnostic evidence, scoped by host metadata.
|
|
2
|
+
-- The migration runner reconciles existing MetricsStore scope columns idempotently.
|
|
3
|
+
-- NULL scope preserves legacy records without granting discovery access.
|
|
4
|
+
ALTER TABLE tool_traces ADD COLUMN diagnostic_json TEXT;
|
|
5
|
+
ALTER TABLE tool_traces ADD COLUMN evidence_json TEXT;
|
|
6
|
+
ALTER TABLE tool_traces ADD COLUMN catalog_revision TEXT;
|
|
7
|
+
ALTER TABLE tool_traces ADD COLUMN owner_scope TEXT;
|
|
8
|
+
ALTER TABLE tool_traces ADD COLUMN project_id TEXT;
|
|
9
|
+
ALTER TABLE tool_traces ADD COLUMN channel_id TEXT;
|
|
10
|
+
CREATE INDEX IF NOT EXISTS idx_tool_traces_scope_recency
|
|
11
|
+
ON tool_traces(owner_scope, project_id, created_at DESC, trace_id DESC);
|
|
12
|
+
CREATE INDEX IF NOT EXISTS idx_tool_traces_channel_recency
|
|
13
|
+
ON tool_traces(owner_scope, project_id, channel_id, created_at DESC, trace_id DESC);
|
|
@@ -66,6 +66,8 @@ export declare class NodeSQLiteAdapter extends DatabaseAdapter {
|
|
|
66
66
|
private hasOperatorMemoryCommitIntentClaimInvariant;
|
|
67
67
|
private assertMigration040BaseComplete;
|
|
68
68
|
private assertMigration041Complete;
|
|
69
|
+
private needsToolTraceDiagnosticsRepair068;
|
|
70
|
+
private recoverToolTraceDiagnosticsMigration068;
|
|
69
71
|
private recoverMemoryProvenanceMigration032;
|
|
70
72
|
private assertMigration032Complete;
|
|
71
73
|
private recoverConnectorEventScopeMigration034;
|
|
@@ -376,6 +376,18 @@ class NodeSQLiteAdapter extends base_adapter_js_1.DatabaseAdapter {
|
|
|
376
376
|
if (version <= currentVersion) {
|
|
377
377
|
continue;
|
|
378
378
|
}
|
|
379
|
+
// Runtime MetricsStore may already own project_id/channel_id. Reconcile
|
|
380
|
+
// this additive migration atomically instead of accepting a duplicate skip.
|
|
381
|
+
if (version === 68) {
|
|
382
|
+
if (!this.tableExists('tool_traces')) {
|
|
383
|
+
// Legacy version ledgers can have skipped 033; the structural repair
|
|
384
|
+
// below creates its table before reconciling 068. Do not stamp it yet.
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
this.recoverToolTraceDiagnosticsMigration068();
|
|
388
|
+
(0, debug_logger_js_1.info)(`[node-sqlite-adapter] Migration ${file} reconciled successfully`);
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
379
391
|
const migrationPath = path_1.default.join(migrationsDir, file);
|
|
380
392
|
const migrationSQL = fs_1.default.readFileSync(migrationPath, 'utf8');
|
|
381
393
|
(0, debug_logger_js_1.info)(`[node-sqlite-adapter] Applying migration: ${file}`);
|
|
@@ -479,6 +491,14 @@ class NodeSQLiteAdapter extends base_adapter_js_1.DatabaseAdapter {
|
|
|
479
491
|
if (!this.tableExists('model_runs') || !this.tableExists('tool_traces')) {
|
|
480
492
|
this.applyRepairMigration(migrationsDir, '033-create-model-runs-and-tool-traces.sql', 'model run provenance');
|
|
481
493
|
}
|
|
494
|
+
// Also repairs databases already stamped 68 by the former generic duplicate
|
|
495
|
+
// skip, which rolled back the new columns before advancing schema_version.
|
|
496
|
+
// Only enter the recovery transaction when something is actually missing —
|
|
497
|
+
// a complete database must not take the write path on every runMigrations().
|
|
498
|
+
if (fs_1.default.existsSync(path_1.default.join(migrationsDir, '068-tool-trace-diagnostics.sql')) &&
|
|
499
|
+
this.needsToolTraceDiagnosticsRepair068()) {
|
|
500
|
+
this.recoverToolTraceDiagnosticsMigration068();
|
|
501
|
+
}
|
|
482
502
|
if (this.tableExists('connector_event_index')) {
|
|
483
503
|
const connectorColumns = this.tableColumns('connector_event_index');
|
|
484
504
|
const hasMissingConnectorScopeColumn = [
|
|
@@ -647,6 +667,65 @@ class NodeSQLiteAdapter extends base_adapter_js_1.DatabaseAdapter {
|
|
|
647
667
|
throw new Error('Migration 041 recovery failed: incompatible operator_memory_commit_intents table definition missing claim invariant');
|
|
648
668
|
}
|
|
649
669
|
}
|
|
670
|
+
needsToolTraceDiagnosticsRepair068() {
|
|
671
|
+
if (!this.tableExists('tool_traces')) {
|
|
672
|
+
// The table itself is missing: let the recovery helper fail loudly.
|
|
673
|
+
return true;
|
|
674
|
+
}
|
|
675
|
+
const columns = this.tableColumns('tool_traces');
|
|
676
|
+
const hasMissingColumn = [
|
|
677
|
+
'diagnostic_json',
|
|
678
|
+
'evidence_json',
|
|
679
|
+
'catalog_revision',
|
|
680
|
+
'owner_scope',
|
|
681
|
+
'project_id',
|
|
682
|
+
'channel_id',
|
|
683
|
+
].some((column) => !columns.has(column));
|
|
684
|
+
const hasMissingIndex = [
|
|
685
|
+
'idx_tool_traces_scope_recency',
|
|
686
|
+
'idx_tool_traces_channel_recency',
|
|
687
|
+
].some((indexName) => !this.indexExists(indexName));
|
|
688
|
+
return hasMissingColumn || hasMissingIndex || !this.schemaVersionExists(68);
|
|
689
|
+
}
|
|
690
|
+
recoverToolTraceDiagnosticsMigration068() {
|
|
691
|
+
this.transaction(() => {
|
|
692
|
+
if (!this.tableExists('tool_traces')) {
|
|
693
|
+
throw new Error('Migration 068 recovery failed: missing table tool_traces');
|
|
694
|
+
}
|
|
695
|
+
const expectedColumns = [
|
|
696
|
+
'diagnostic_json',
|
|
697
|
+
'evidence_json',
|
|
698
|
+
'catalog_revision',
|
|
699
|
+
'owner_scope',
|
|
700
|
+
'project_id',
|
|
701
|
+
'channel_id',
|
|
702
|
+
];
|
|
703
|
+
const columns = this.tableColumns('tool_traces');
|
|
704
|
+
for (const column of expectedColumns) {
|
|
705
|
+
if (!columns.has(column)) {
|
|
706
|
+
this.exec(`ALTER TABLE tool_traces ADD COLUMN ${column} TEXT`);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
this.exec(`
|
|
710
|
+
CREATE INDEX IF NOT EXISTS idx_tool_traces_scope_recency
|
|
711
|
+
ON tool_traces(owner_scope, project_id, created_at DESC, trace_id DESC);
|
|
712
|
+
CREATE INDEX IF NOT EXISTS idx_tool_traces_channel_recency
|
|
713
|
+
ON tool_traces(owner_scope, project_id, channel_id, created_at DESC, trace_id DESC);
|
|
714
|
+
`);
|
|
715
|
+
const actualColumns = this.tableColumns('tool_traces');
|
|
716
|
+
for (const column of expectedColumns) {
|
|
717
|
+
if (!actualColumns.has(column)) {
|
|
718
|
+
throw new Error(`Migration 068 recovery failed: missing tool_traces.${column}`);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
for (const index of ['idx_tool_traces_scope_recency', 'idx_tool_traces_channel_recency']) {
|
|
722
|
+
if (!this.indexExists(index)) {
|
|
723
|
+
throw new Error(`Migration 068 recovery failed: missing index ${index}`);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
this.prepare('INSERT OR IGNORE INTO schema_version (version) VALUES (?)').run(68);
|
|
727
|
+
});
|
|
728
|
+
}
|
|
650
729
|
recoverMemoryProvenanceMigration032() {
|
|
651
730
|
this.transaction(() => {
|
|
652
731
|
const expectedDecisionColumns = [
|
package/dist/index.d.ts
CHANGED
|
@@ -25,9 +25,9 @@ export { createTrustedProvenanceCapability, assertTrustedProvenanceCapability, t
|
|
|
25
25
|
export { getMemoryProvenance, listMemoriesByEnvelopeHash, listMemoriesByGatewayCallId, listMemoriesByModelRunId, } from './memory/provenance-query.js';
|
|
26
26
|
export { type BackfillResult, type ConnectorEventScopeBackfillInput, } from './memory/scope-backfill.js';
|
|
27
27
|
export { getMemoryProvenanceAudit, listMemoryProvenanceAudit, type MemoryProvenanceAuditRecord, type MemoryProvenanceAuditListOptions, } from './memory/provenance-audit.js';
|
|
28
|
-
export { MODEL_RUN_STATUSES, type ModelRunStatus, type BeginModelRunInput, type ModelRunRecord, type AppendToolTraceInput, type ToolTraceRecord, } from './model-runs/types.js';
|
|
28
|
+
export { MODEL_RUN_STATUSES, type ModelRunStatus, type BeginModelRunInput, type ModelRunRecord, type AppendToolTraceInput, type ToolTraceRecord, type ToolTraceScope, type ListToolTracesInput, type ToolTracePage, } from './model-runs/types.js';
|
|
29
29
|
export { beginModelRun, beginModelRunInAdapter, commitModelRun, commitModelRunInAdapter, failModelRun, failModelRunInAdapter, getModelRun, getModelRunInAdapter, } from './model-runs/store.js';
|
|
30
|
-
export { appendToolTrace, listToolTracesForRun } from './model-runs/tool-trace-store.js';
|
|
30
|
+
export { appendToolTrace, listToolTracesForRun, listToolTraces, readToolTrace, } from './model-runs/tool-trace-store.js';
|
|
31
31
|
export { TWIN_EDGE_SOURCES, TWIN_EDGE_TYPES, TWIN_REF_KINDS, type InsertTwinEdgeInput, type ListVisibleTwinEdgesOptions, type TwinEdgeRecord, type TwinEdgeSource, type TwinEdgeType, type TwinRef, type TwinRefKind, type TwinScopeRef, } from './edges/types.js';
|
|
32
32
|
export { getTwinEdge, listTwinEdgesForRefs, mapTwinEdgeRow } from './edges/store.js';
|
|
33
33
|
export { listVisibleTwinEdgesForRefs } from './edges/ref-validation.js';
|
package/dist/index.js
CHANGED
|
@@ -27,9 +27,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.createAuditAck = exports.buildMemoryBootstrap = exports.evolveMemory = exports.ingestWithTrustedProvenance = exports.ingestMemory = exports.buildProfile = exports.recallMemory = exports.promoteMemoryStatus = exports.saveMemoryWithTrustedProvenance = exports.saveMemory = exports.createEmptyRecallBundle = exports.MEMORY_EDGE_TYPES = exports.MEMORY_STATUSES = exports.MEMORY_KINDS = exports.MEMORY_SCOPE_KINDS = exports.mama = exports.DEFAULT_DB_PATH = exports.LEGACY_DB_PATH = exports.DB_DIR = exports.DB_PATH = exports.traverseDecisionChain = exports.SQLiteAdapter = exports.DatabaseAdapter = exports.createAdapter = exports.fts5Search = exports.getDbPath = exports.getPreparedStmt = exports.updateDecisionOutcome = exports.querySemanticEdges = exports.queryDecisionGraph = exports.insertDecisionWithEmbedding = exports.queryVectorSearch = exports.vectorSearch = exports.insertEmbedding = exports.closeDB = exports.getAdapter = exports.getDB = exports.initDB = exports.TIMEOUT_MS = exports.HOST = exports.DEFAULT_PORT = exports.getServerPort = exports.EmbeddingCache = exports.EMBEDDING_PREFIX_SCHEME = exports.MODEL_NAME = exports.EMBEDDING_DIM = exports.embeddingCache = exports.cosineSimilarity = exports.generateEnhancedEmbedding = exports.generateEmbedding = void 0;
|
|
30
|
-
exports.
|
|
31
|
-
exports.
|
|
32
|
-
exports.notifyInsight = exports.FALLBACK_MODEL = exports.DEFAULT_MODEL = exports.listModels = exports.isAvailable = exports.generate = exports.analyzeIntent = exports.RECENT_WINDOW_MS = exports.PARTIAL_INDICATORS = exports.SUCCESS_INDICATORS = exports.FAILURE_INDICATORS = exports.markOutcome = exports.getEvidenceImpact = exports.calculateDurationDays = exports.getRecentDecision = exports.extractFailureReason = exports.matchesPartialIndicators = exports.matchesSuccessIndicators = exports.matchesFailureIndicators = exports.analyzeOutcome = exports.extractCodeExample = exports.extractQuickAnswer = exports.estimateTokens = exports.ensureTokenBudget = void 0;
|
|
30
|
+
exports.getCacheDir = exports.getEmbeddingDim = exports.getModelName = exports.loadConfig = exports.CanonicalizeError = exports.targetRefHash = exports.canonicalizeJSON = exports.listVisibleTwinEdgesForRefs = exports.mapTwinEdgeRow = exports.listTwinEdgesForRefs = exports.getTwinEdge = exports.TWIN_REF_KINDS = exports.TWIN_EDGE_TYPES = exports.TWIN_EDGE_SOURCES = exports.readToolTrace = exports.listToolTraces = exports.listToolTracesForRun = exports.appendToolTrace = exports.getModelRunInAdapter = exports.getModelRun = exports.failModelRunInAdapter = exports.failModelRun = exports.commitModelRunInAdapter = exports.commitModelRun = exports.beginModelRunInAdapter = exports.beginModelRun = exports.MODEL_RUN_STATUSES = exports.listMemoryProvenanceAudit = exports.getMemoryProvenanceAudit = exports.listMemoriesByModelRunId = exports.listMemoriesByGatewayCallId = exports.listMemoriesByEnvelopeHash = exports.getMemoryProvenance = exports.assertTrustedProvenanceCapability = exports.createTrustedProvenanceCapability = exports.listRecentMemoryEvents = exports.listMemoryEventsForMemory = exports.insertMemoryEventInTransaction = exports.appendMemoryEvent = exports.listOpenAuditFindings = exports.createAuditFinding = exports.queryRelevantTruth = exports.parseExtractionResponse = exports.buildExtractionPrompt = exports.getChannelSummary = exports.upsertChannelSummary = exports.setExtractionFn = exports.ingestConversationWithTrustedProvenance = exports.ingestConversation = exports.recordMemoryAudit = void 0;
|
|
31
|
+
exports.formatRecall = exports.formatLegacyContext = exports.formatContext = exports.isMAMAError = exports.wrapError = exports.ErrorCodes = exports.TimeoutError = exports.RateLimitError = exports.LinkError = exports.ConfigurationError = exports.EmbeddingError = exports.DatabaseError = exports.ValidationError = exports.NotFoundError = exports.MAMAError = exports.formatTimeAgo = exports.DebugLogger = exports.error = exports.warn = exports.info = exports.debug = exports.logSearching = exports.logLoading = exports.logError = exports.logFailed = exports.logComplete = exports.logProgress = exports.getTierDescription = exports.checkDatabase = exports.checkEmbeddings = exports.checkSQLite = exports.checkNodeVersion = exports.VALID_EDGE_TYPES = exports.updateConfidence = exports.createEdgesFromReasoning = exports.parseReasoningForRelationships = exports.detectRefinement = exports.calculateCombinedConfidence = exports.markSuperseded = exports.createSupersedesEdge = exports.createEdge = exports.getPreviousDecision = exports.generateDecisionId = exports.learnDecision = exports.formatTopNContext = exports.selectTopDecisions = exports.calculateRelevance = exports.DEFAULT_CONFIG = exports.getConfigPath = exports.updateConfig = void 0;
|
|
32
|
+
exports.notifyInsight = exports.FALLBACK_MODEL = exports.DEFAULT_MODEL = exports.listModels = exports.isAvailable = exports.generate = exports.analyzeIntent = exports.RECENT_WINDOW_MS = exports.PARTIAL_INDICATORS = exports.SUCCESS_INDICATORS = exports.FAILURE_INDICATORS = exports.markOutcome = exports.getEvidenceImpact = exports.calculateDurationDays = exports.getRecentDecision = exports.extractFailureReason = exports.matchesPartialIndicators = exports.matchesSuccessIndicators = exports.matchesFailureIndicators = exports.analyzeOutcome = exports.extractCodeExample = exports.extractQuickAnswer = exports.estimateTokens = exports.ensureTokenBudget = exports.formatTrustContext = exports.formatList = void 0;
|
|
33
33
|
var embeddings_js_1 = require("./embeddings.js");
|
|
34
34
|
Object.defineProperty(exports, "generateEmbedding", { enumerable: true, get: function () { return embeddings_js_1.generateEmbedding; } });
|
|
35
35
|
Object.defineProperty(exports, "generateEnhancedEmbedding", { enumerable: true, get: function () { return embeddings_js_1.generateEnhancedEmbedding; } });
|
|
@@ -133,6 +133,8 @@ Object.defineProperty(exports, "getModelRunInAdapter", { enumerable: true, get:
|
|
|
133
133
|
var tool_trace_store_js_1 = require("./model-runs/tool-trace-store.js");
|
|
134
134
|
Object.defineProperty(exports, "appendToolTrace", { enumerable: true, get: function () { return tool_trace_store_js_1.appendToolTrace; } });
|
|
135
135
|
Object.defineProperty(exports, "listToolTracesForRun", { enumerable: true, get: function () { return tool_trace_store_js_1.listToolTracesForRun; } });
|
|
136
|
+
Object.defineProperty(exports, "listToolTraces", { enumerable: true, get: function () { return tool_trace_store_js_1.listToolTraces; } });
|
|
137
|
+
Object.defineProperty(exports, "readToolTrace", { enumerable: true, get: function () { return tool_trace_store_js_1.readToolTrace; } });
|
|
136
138
|
var types_js_3 = require("./edges/types.js");
|
|
137
139
|
Object.defineProperty(exports, "TWIN_EDGE_SOURCES", { enumerable: true, get: function () { return types_js_3.TWIN_EDGE_SOURCES; } });
|
|
138
140
|
Object.defineProperty(exports, "TWIN_EDGE_TYPES", { enumerable: true, get: function () { return types_js_3.TWIN_EDGE_TYPES; } });
|
package/dist/mama-api.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ import { listMemoryEventsForMemory, listRecentMemoryEvents } from './memory/even
|
|
|
25
25
|
import type { TrustedMemoryWriteOptions } from './memory/provenance.js';
|
|
26
26
|
import { getMemoryProvenance, listMemoriesByEnvelopeHash, listMemoriesByGatewayCallId, listMemoriesByModelRunId } from './memory/provenance-query.js';
|
|
27
27
|
import { beginModelRun, beginModelRunInAdapter, commitModelRun, commitModelRunInAdapter, failModelRun, failModelRunInAdapter, getModelRun, getModelRunInAdapter } from './model-runs/store.js';
|
|
28
|
-
import { appendToolTrace, listToolTracesForRun } from './model-runs/tool-trace-store.js';
|
|
28
|
+
import { appendToolTrace, listToolTracesForRun, listToolTraces, readToolTrace } from './model-runs/tool-trace-store.js';
|
|
29
29
|
import { type SearchHitDiagnostics, type SearchQualityOptions } from './search/search-quality.js';
|
|
30
30
|
/**
|
|
31
31
|
* Parameters for mama.save()
|
|
@@ -1083,6 +1083,8 @@ declare const mama: {
|
|
|
1083
1083
|
getModelRunInAdapter: typeof getModelRunInAdapter;
|
|
1084
1084
|
appendToolTrace: typeof appendToolTrace;
|
|
1085
1085
|
listToolTracesForRun: typeof listToolTracesForRun;
|
|
1086
|
+
listToolTraces: typeof listToolTraces;
|
|
1087
|
+
readToolTrace: typeof readToolTrace;
|
|
1086
1088
|
saveCheckpoint: typeof saveCheckpoint;
|
|
1087
1089
|
loadCheckpoint: typeof loadCheckpoint;
|
|
1088
1090
|
recall: typeof recall;
|
|
@@ -1107,6 +1109,6 @@ declare const mama: {
|
|
|
1107
1109
|
validateCleanupResult: typeof validateCleanupResult;
|
|
1108
1110
|
expandWithGraph: typeof expandWithGraph;
|
|
1109
1111
|
};
|
|
1110
|
-
export { save, saveWithTrustedProvenance, suggest, annotateTopicCurrency, saveMemory, saveMemoryWithTrustedProvenance, recallMemory, listDecisions as list, listCheckpoints, updateOutcome, buildProfile, ingestMemory, ingestWithTrustedProvenance, ingestConversation, ingestConversationWithTrustedProvenance, evolveMemory, buildMemoryBootstrap, createAuditAck, recordMemoryAudit, upsertChannelSummary, getChannelSummary, listOpenAuditFindings, createAuditFinding, getMemoryProvenance, listMemoriesByEnvelopeHash, listMemoriesByGatewayCallId, listMemoriesByModelRunId, listMemoryEventsForMemory, listRecentMemoryEvents, beginModelRun, beginModelRunInAdapter, commitModelRun, commitModelRunInAdapter, failModelRun, failModelRunInAdapter, getModelRun, getModelRunInAdapter, appendToolTrace, listToolTracesForRun, saveCheckpoint, loadCheckpoint, recall, proposeLink, approveLink, rejectLink, getPendingLinks, deprecateAutoLinks, calculateCoverage, calculateQuality, generateQualityReport, logRestartAttempt, calculateRestartSuccessRate, calculateRestartLatency, getRestartMetrics, scanAutoLinks, createLinkBackup, generatePreCleanupReport, restoreLinkBackup, verifyBackupExists, deleteAutoLinks, validateCleanupResult, expandWithGraph, };
|
|
1112
|
+
export { save, saveWithTrustedProvenance, suggest, annotateTopicCurrency, saveMemory, saveMemoryWithTrustedProvenance, recallMemory, listDecisions as list, listCheckpoints, updateOutcome, buildProfile, ingestMemory, ingestWithTrustedProvenance, ingestConversation, ingestConversationWithTrustedProvenance, evolveMemory, buildMemoryBootstrap, createAuditAck, recordMemoryAudit, upsertChannelSummary, getChannelSummary, listOpenAuditFindings, createAuditFinding, getMemoryProvenance, listMemoriesByEnvelopeHash, listMemoriesByGatewayCallId, listMemoriesByModelRunId, listMemoryEventsForMemory, listRecentMemoryEvents, beginModelRun, beginModelRunInAdapter, commitModelRun, commitModelRunInAdapter, failModelRun, failModelRunInAdapter, getModelRun, getModelRunInAdapter, appendToolTrace, listToolTracesForRun, listToolTraces, readToolTrace, saveCheckpoint, loadCheckpoint, recall, proposeLink, approveLink, rejectLink, getPendingLinks, deprecateAutoLinks, calculateCoverage, calculateQuality, generateQualityReport, logRestartAttempt, calculateRestartSuccessRate, calculateRestartLatency, getRestartMetrics, scanAutoLinks, createLinkBackup, generatePreCleanupReport, restoreLinkBackup, verifyBackupExists, deleteAutoLinks, validateCleanupResult, expandWithGraph, };
|
|
1111
1113
|
export default mama;
|
|
1112
1114
|
//# sourceMappingURL=mama-api.d.ts.map
|
package/dist/mama-api.js
CHANGED
|
@@ -22,7 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.listToolTracesForRun = exports.appendToolTrace = exports.getModelRunInAdapter = exports.getModelRun = exports.failModelRunInAdapter = exports.failModelRun = exports.commitModelRunInAdapter = exports.commitModelRun = exports.beginModelRunInAdapter = exports.beginModelRun = exports.listRecentMemoryEvents = exports.listMemoryEventsForMemory = exports.listMemoriesByModelRunId = exports.listMemoriesByGatewayCallId = exports.listMemoriesByEnvelopeHash = exports.getMemoryProvenance = exports.createAuditFinding = exports.listOpenAuditFindings = exports.getChannelSummary = exports.upsertChannelSummary = exports.recordMemoryAudit = exports.createAuditAck = exports.buildMemoryBootstrap = exports.evolveMemory = exports.ingestConversationWithTrustedProvenance = exports.ingestConversation = exports.ingestWithTrustedProvenance = exports.ingestMemory = exports.buildProfile = exports.recallMemory = exports.saveMemoryWithTrustedProvenance = exports.saveMemory = void 0;
|
|
25
|
+
exports.readToolTrace = exports.listToolTraces = exports.listToolTracesForRun = exports.appendToolTrace = exports.getModelRunInAdapter = exports.getModelRun = exports.failModelRunInAdapter = exports.failModelRun = exports.commitModelRunInAdapter = exports.commitModelRun = exports.beginModelRunInAdapter = exports.beginModelRun = exports.listRecentMemoryEvents = exports.listMemoryEventsForMemory = exports.listMemoriesByModelRunId = exports.listMemoriesByGatewayCallId = exports.listMemoriesByEnvelopeHash = exports.getMemoryProvenance = exports.createAuditFinding = exports.listOpenAuditFindings = exports.getChannelSummary = exports.upsertChannelSummary = exports.recordMemoryAudit = exports.createAuditAck = exports.buildMemoryBootstrap = exports.evolveMemory = exports.ingestConversationWithTrustedProvenance = exports.ingestConversation = exports.ingestWithTrustedProvenance = exports.ingestMemory = exports.buildProfile = exports.recallMemory = exports.saveMemoryWithTrustedProvenance = exports.saveMemory = void 0;
|
|
26
26
|
exports.save = save;
|
|
27
27
|
exports.saveWithTrustedProvenance = saveWithTrustedProvenance;
|
|
28
28
|
exports.suggest = suggest;
|
|
@@ -106,6 +106,8 @@ Object.defineProperty(exports, "getModelRunInAdapter", { enumerable: true, get:
|
|
|
106
106
|
const tool_trace_store_js_1 = require("./model-runs/tool-trace-store.js");
|
|
107
107
|
Object.defineProperty(exports, "appendToolTrace", { enumerable: true, get: function () { return tool_trace_store_js_1.appendToolTrace; } });
|
|
108
108
|
Object.defineProperty(exports, "listToolTracesForRun", { enumerable: true, get: function () { return tool_trace_store_js_1.listToolTracesForRun; } });
|
|
109
|
+
Object.defineProperty(exports, "listToolTraces", { enumerable: true, get: function () { return tool_trace_store_js_1.listToolTraces; } });
|
|
110
|
+
Object.defineProperty(exports, "readToolTrace", { enumerable: true, get: function () { return tool_trace_store_js_1.readToolTrace; } });
|
|
109
111
|
const search_rollup_js_1 = require("./cases/search-rollup.js");
|
|
110
112
|
const ranker_rescore_js_1 = require("./search/ranker-rescore.js");
|
|
111
113
|
const ranker_features_js_1 = require("./search/ranker-features.js");
|
|
@@ -2832,6 +2834,8 @@ const mama = {
|
|
|
2832
2834
|
getModelRunInAdapter: store_js_1.getModelRunInAdapter,
|
|
2833
2835
|
appendToolTrace: tool_trace_store_js_1.appendToolTrace,
|
|
2834
2836
|
listToolTracesForRun: tool_trace_store_js_1.listToolTracesForRun,
|
|
2837
|
+
listToolTraces: tool_trace_store_js_1.listToolTraces,
|
|
2838
|
+
readToolTrace: tool_trace_store_js_1.readToolTrace,
|
|
2835
2839
|
saveCheckpoint,
|
|
2836
2840
|
loadCheckpoint,
|
|
2837
2841
|
// Legacy functions (retained for internal use, not exposed via MCP)
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import type { AppendToolTraceInput, ToolTraceRecord } from './types.js';
|
|
1
|
+
import type { AppendToolTraceInput, ToolTraceRecord, ToolTraceScope, ListToolTracesInput, ToolTracePage } from './types.js';
|
|
2
2
|
export declare function appendToolTrace(input: AppendToolTraceInput): Promise<ToolTraceRecord>;
|
|
3
3
|
export declare function listToolTracesForRun(modelRunId: string): Promise<ToolTraceRecord[]>;
|
|
4
|
+
/** Access is exact host-derived scope; knowing a trace ID never grants access. */
|
|
5
|
+
export declare function readToolTrace(traceId: string, scope: ToolTraceScope): Promise<ToolTraceRecord | null>;
|
|
6
|
+
/** Bounded metadata discovery; detailed evidence is read explicitly by trace ID. */
|
|
7
|
+
export declare function listToolTraces(input: ListToolTracesInput): Promise<ToolTracePage>;
|
|
4
8
|
//# sourceMappingURL=tool-trace-store.d.ts.map
|
|
@@ -5,6 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.appendToolTrace = appendToolTrace;
|
|
7
7
|
exports.listToolTracesForRun = listToolTracesForRun;
|
|
8
|
+
exports.readToolTrace = readToolTrace;
|
|
9
|
+
exports.listToolTraces = listToolTraces;
|
|
8
10
|
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
9
11
|
const db_manager_js_1 = require("../db-manager.js");
|
|
10
12
|
function traceId() {
|
|
@@ -47,8 +49,33 @@ function requiredNonNegativeInteger(value, field) {
|
|
|
47
49
|
}
|
|
48
50
|
return normalized;
|
|
49
51
|
}
|
|
52
|
+
function nullableJsonObject(value, field) {
|
|
53
|
+
if (value === undefined || value === null) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
if (typeof value !== 'string') {
|
|
57
|
+
throw new Error(`tool_traces.${field} must be a JSON object string`);
|
|
58
|
+
}
|
|
59
|
+
let parsed;
|
|
60
|
+
try {
|
|
61
|
+
parsed = JSON.parse(value);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
throw new Error(`tool_traces.${field} contains malformed JSON`);
|
|
65
|
+
}
|
|
66
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
67
|
+
throw new Error(`tool_traces.${field} must contain a JSON object`);
|
|
68
|
+
}
|
|
69
|
+
return value;
|
|
70
|
+
}
|
|
50
71
|
function mapToolTraceRow(row) {
|
|
51
72
|
return {
|
|
73
|
+
diagnostic_json: nullableJsonObject(row.diagnostic_json, 'diagnostic_json'),
|
|
74
|
+
evidence_json: nullableJsonObject(row.evidence_json, 'evidence_json'),
|
|
75
|
+
catalog_revision: nullableString(row.catalog_revision),
|
|
76
|
+
owner_scope: nullableString(row.owner_scope),
|
|
77
|
+
project_id: nullableString(row.project_id),
|
|
78
|
+
channel_id: nullableString(row.channel_id),
|
|
52
79
|
trace_id: requiredString(row.trace_id, 'trace_id'),
|
|
53
80
|
model_run_id: requiredString(row.model_run_id, 'model_run_id'),
|
|
54
81
|
gateway_call_id: nullableString(row.gateway_call_id),
|
|
@@ -72,7 +99,7 @@ function selectToolTrace(adapter, id) {
|
|
|
72
99
|
SELECT
|
|
73
100
|
trace_id, model_run_id, gateway_call_id, tool_name, input_summary,
|
|
74
101
|
output_summary, execution_status, duration_ms, envelope_hash, failure_code,
|
|
75
|
-
created_at
|
|
102
|
+
created_at, diagnostic_json, evidence_json, catalog_revision, owner_scope, project_id, channel_id
|
|
76
103
|
FROM tool_traces
|
|
77
104
|
WHERE trace_id = ?
|
|
78
105
|
`)
|
|
@@ -92,11 +119,11 @@ async function appendToolTrace(input) {
|
|
|
92
119
|
INSERT INTO tool_traces (
|
|
93
120
|
trace_id, model_run_id, gateway_call_id, tool_name, input_summary,
|
|
94
121
|
output_summary, execution_status, duration_ms, envelope_hash, failure_code,
|
|
95
|
-
created_at
|
|
122
|
+
created_at, diagnostic_json, evidence_json, catalog_revision, owner_scope, project_id, channel_id
|
|
96
123
|
)
|
|
97
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
124
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
98
125
|
`)
|
|
99
|
-
.run(id, modelRunId, nullableString(input.gateway_call_id), toolName, nullableString(input.input_summary), nullableString(input.output_summary), nullableString(input.execution_status), normalizeDuration(input.duration_ms), nullableString(input.envelope_hash), nullableString(input.failure_code), normalizeTimestamp(input.created_at));
|
|
126
|
+
.run(id, modelRunId, nullableString(input.gateway_call_id), toolName, nullableString(input.input_summary), nullableString(input.output_summary), nullableString(input.execution_status), normalizeDuration(input.duration_ms), nullableString(input.envelope_hash), nullableString(input.failure_code), normalizeTimestamp(input.created_at), nullableJsonObject(input.diagnostic_json, 'diagnostic_json'), nullableJsonObject(input.evidence_json, 'evidence_json'), nullableString(input.catalog_revision), nullableString(input.owner_scope), nullableString(input.project_id), nullableString(input.channel_id));
|
|
100
127
|
return selectToolTrace(adapter, id);
|
|
101
128
|
}
|
|
102
129
|
async function listToolTracesForRun(modelRunId) {
|
|
@@ -107,7 +134,7 @@ async function listToolTracesForRun(modelRunId) {
|
|
|
107
134
|
SELECT
|
|
108
135
|
trace_id, model_run_id, gateway_call_id, tool_name, input_summary,
|
|
109
136
|
output_summary, execution_status, duration_ms, envelope_hash, failure_code,
|
|
110
|
-
created_at
|
|
137
|
+
created_at, diagnostic_json, evidence_json, catalog_revision, owner_scope, project_id, channel_id
|
|
111
138
|
FROM tool_traces
|
|
112
139
|
WHERE model_run_id = ?
|
|
113
140
|
ORDER BY created_at DESC, rowid DESC
|
|
@@ -115,4 +142,82 @@ async function listToolTracesForRun(modelRunId) {
|
|
|
115
142
|
.all(id);
|
|
116
143
|
return rows.map(mapToolTraceRow);
|
|
117
144
|
}
|
|
145
|
+
function scopedWhere(scope) {
|
|
146
|
+
const clauses = ['owner_scope = ?', 'project_id = ?'];
|
|
147
|
+
const values = [
|
|
148
|
+
requiredString(scope.owner_scope, 'owner_scope'),
|
|
149
|
+
requiredString(scope.project_id, 'project_id'),
|
|
150
|
+
];
|
|
151
|
+
if (scope.channel_id !== undefined) {
|
|
152
|
+
clauses.push('channel_id = ?');
|
|
153
|
+
values.push(requiredString(scope.channel_id, 'channel_id'));
|
|
154
|
+
}
|
|
155
|
+
return { clauses, values };
|
|
156
|
+
}
|
|
157
|
+
/** Access is exact host-derived scope; knowing a trace ID never grants access. */
|
|
158
|
+
async function readToolTrace(traceId, scope) {
|
|
159
|
+
const { clauses, values } = scopedWhere(scope);
|
|
160
|
+
clauses.push('trace_id = ?');
|
|
161
|
+
values.push(requiredString(traceId, 'trace_id'));
|
|
162
|
+
const adapter = await initializedAdapter();
|
|
163
|
+
const row = adapter
|
|
164
|
+
.prepare(`SELECT * FROM tool_traces WHERE ${clauses.join(' AND ')}`)
|
|
165
|
+
.get(...values);
|
|
166
|
+
return row ? mapToolTraceRow(row) : null;
|
|
167
|
+
}
|
|
168
|
+
/** Bounded metadata discovery; detailed evidence is read explicitly by trace ID. */
|
|
169
|
+
async function listToolTraces(input) {
|
|
170
|
+
const { clauses, values } = scopedWhere(input);
|
|
171
|
+
if (input.evidence_only !== undefined && typeof input.evidence_only !== 'boolean') {
|
|
172
|
+
throw new Error('tool_traces.evidence_only must be a boolean');
|
|
173
|
+
}
|
|
174
|
+
if (input.evidence_only === true) {
|
|
175
|
+
clauses.push('evidence_json IS NOT NULL');
|
|
176
|
+
}
|
|
177
|
+
const limit = input.limit ?? 20;
|
|
178
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 100) {
|
|
179
|
+
throw new Error('tool_traces.limit must be an integer between 1 and 100');
|
|
180
|
+
}
|
|
181
|
+
for (const field of ['model_run_id', 'tool_name']) {
|
|
182
|
+
if (input[field] !== undefined) {
|
|
183
|
+
clauses.push(`${field} = ?`);
|
|
184
|
+
values.push(requiredString(input[field], field));
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (input.cursor !== undefined) {
|
|
188
|
+
let cursor;
|
|
189
|
+
try {
|
|
190
|
+
cursor = JSON.parse(Buffer.from(input.cursor, 'base64url').toString('utf8'));
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
throw new Error('tool_traces.cursor is malformed');
|
|
194
|
+
}
|
|
195
|
+
if (!Array.isArray(cursor) || cursor.length !== 2) {
|
|
196
|
+
throw new Error('tool_traces.cursor is malformed');
|
|
197
|
+
}
|
|
198
|
+
const [cursorCreatedAt, cursorTraceId] = cursor;
|
|
199
|
+
if (typeof cursorCreatedAt !== 'number' ||
|
|
200
|
+
!Number.isSafeInteger(cursorCreatedAt) ||
|
|
201
|
+
typeof cursorTraceId !== 'string' ||
|
|
202
|
+
cursorTraceId.length === 0) {
|
|
203
|
+
throw new Error('tool_traces.cursor is malformed');
|
|
204
|
+
}
|
|
205
|
+
clauses.push('(created_at < ? OR (created_at = ? AND trace_id < ?))');
|
|
206
|
+
values.push(cursorCreatedAt, cursorCreatedAt, cursorTraceId);
|
|
207
|
+
}
|
|
208
|
+
const adapter = await initializedAdapter();
|
|
209
|
+
const rows = adapter
|
|
210
|
+
.prepare(`SELECT trace_id, model_run_id, gateway_call_id, tool_name,
|
|
211
|
+
input_summary, output_summary, execution_status, duration_ms, envelope_hash, failure_code,
|
|
212
|
+
created_at, diagnostic_json, NULL AS evidence_json, catalog_revision, owner_scope, project_id, channel_id
|
|
213
|
+
FROM tool_traces WHERE ${clauses.join(' AND ')}
|
|
214
|
+
ORDER BY created_at DESC, trace_id DESC LIMIT ?`)
|
|
215
|
+
.all(...values, limit + 1);
|
|
216
|
+
const traces = rows.slice(0, limit).map(mapToolTraceRow);
|
|
217
|
+
const last = traces.at(-1);
|
|
218
|
+
const next_cursor = rows.length > limit && last
|
|
219
|
+
? Buffer.from(JSON.stringify([last.created_at, last.trace_id])).toString('base64url')
|
|
220
|
+
: null;
|
|
221
|
+
return { traces, next_cursor };
|
|
222
|
+
}
|
|
118
223
|
//# sourceMappingURL=tool-trace-store.js.map
|
|
@@ -43,6 +43,13 @@ export interface ModelRunRecord {
|
|
|
43
43
|
completed_at: number | null;
|
|
44
44
|
}
|
|
45
45
|
export interface AppendToolTraceInput {
|
|
46
|
+
/** Host-derived access scope; legacy rows remain unscoped. */
|
|
47
|
+
owner_scope?: string | null;
|
|
48
|
+
project_id?: string | null;
|
|
49
|
+
channel_id?: string | null;
|
|
50
|
+
diagnostic_json?: string | null;
|
|
51
|
+
evidence_json?: string | null;
|
|
52
|
+
catalog_revision?: string | null;
|
|
46
53
|
trace_id?: string;
|
|
47
54
|
model_run_id: string;
|
|
48
55
|
gateway_call_id?: string | null;
|
|
@@ -57,6 +64,13 @@ export interface AppendToolTraceInput {
|
|
|
57
64
|
created_at?: number;
|
|
58
65
|
}
|
|
59
66
|
export interface ToolTraceRecord {
|
|
67
|
+
/** Host-derived access scope; legacy rows remain unscoped. */
|
|
68
|
+
owner_scope?: string | null;
|
|
69
|
+
project_id?: string | null;
|
|
70
|
+
channel_id?: string | null;
|
|
71
|
+
diagnostic_json?: string | null;
|
|
72
|
+
evidence_json?: string | null;
|
|
73
|
+
catalog_revision?: string | null;
|
|
60
74
|
trace_id: string;
|
|
61
75
|
model_run_id: string;
|
|
62
76
|
gateway_call_id: string | null;
|
|
@@ -69,4 +83,21 @@ export interface ToolTraceRecord {
|
|
|
69
83
|
failure_code: string | null;
|
|
70
84
|
created_at: number;
|
|
71
85
|
}
|
|
86
|
+
export interface ToolTraceScope {
|
|
87
|
+
owner_scope: string;
|
|
88
|
+
project_id: string;
|
|
89
|
+
channel_id?: string;
|
|
90
|
+
}
|
|
91
|
+
export interface ListToolTracesInput extends ToolTraceScope {
|
|
92
|
+
evidence_only?: boolean;
|
|
93
|
+
model_run_id?: string;
|
|
94
|
+
tool_name?: string;
|
|
95
|
+
cursor?: string;
|
|
96
|
+
limit?: number;
|
|
97
|
+
}
|
|
98
|
+
export interface ToolTracePage {
|
|
99
|
+
/** Metadata only: evidence_json is null. Read a scoped trace for details. */
|
|
100
|
+
traces: ToolTraceRecord[];
|
|
101
|
+
next_cursor: string | null;
|
|
102
|
+
}
|
|
72
103
|
//# sourceMappingURL=types.d.ts.map
|