@gmickel/gno 2.14.0 → 2.16.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.
- package/README.md +1 -1
- package/assets/skill/cli-reference.md +4 -2
- package/assets/spa-production.json.gz +0 -0
- package/browser-extension/artifacts/{gno-browser-clipper-v2.14.0.zip → gno-browser-clipper-v2.16.0.zip} +0 -0
- package/browser-extension/artifacts/gno-browser-clipper-v2.16.0.zip.sha256 +1 -0
- package/browser-extension/dist/manifest.json +1 -1
- package/package.json +1 -1
- package/spec/cli.md +88 -45
- package/spec/db/schema.sql +45 -0
- package/spec/output-schemas/embed-receipt.schema.json +89 -0
- package/src/cli/commands/agents/commands.ts +1 -1
- package/src/cli/commands/ask.ts +1 -1
- package/src/cli/commands/context-build.ts +1 -1
- package/src/cli/commands/embed.ts +341 -20
- package/src/cli/commands/links.ts +1 -1
- package/src/cli/commands/mcp/install.ts +2 -2
- package/src/cli/commands/mcp/status.ts +1 -1
- package/src/cli/commands/mcp/uninstall.ts +1 -1
- package/src/cli/commands/query.ts +1 -1
- package/src/cli/commands/shared.ts +4 -4
- package/src/cli/commands/skill/install.ts +1 -1
- package/src/cli/commands/skill/paths-cmd.ts +1 -1
- package/src/cli/commands/skill/uninstall.ts +1 -1
- package/src/cli/commands/status.ts +75 -58
- package/src/cli/config-cache.ts +86 -0
- package/src/cli/globals.ts +64 -0
- package/src/cli/options.ts +23 -0
- package/src/cli/program.ts +44 -37
- package/src/cli/run.ts +121 -67
- package/src/cli/runtime-health.ts +132 -122
- package/src/cli/session-binding.ts +11 -2
- package/src/config/saver.ts +8 -0
- package/src/converters/adapters/browser-export/formats.ts +25 -15
- package/src/converters/adapters/email/adapter.ts +37 -53
- package/src/converters/adapters/email/html.ts +37 -20
- package/src/converters/adapters/email/mime.ts +71 -39
- package/src/converters/adapters/ical/adapter.ts +20 -12
- package/src/converters/adapters/jsonl/adapter.ts +8 -6
- package/src/converters/adapters/shared/html-text.ts +55 -37
- package/src/converters/adapters/shared/ooxml-protection.ts +5 -13
- package/src/converters/adapters/shared/utf8-lines.ts +69 -31
- package/src/converters/adapters/transcript/adapter.ts +12 -7
- package/src/converters/adapters/xlsx/adapter.ts +10 -7
- package/src/converters/adapters/xlsx/sheet-markdown.ts +93 -50
- package/src/converters/canonicalize.ts +17 -3
- package/src/converters/native/markdown.ts +24 -17
- package/src/converters/native/plaintext.ts +5 -6
- package/src/converters/registry.ts +130 -8
- package/src/core/activation-status.ts +4 -8
- package/src/core/change-diff.ts +38 -11
- package/src/core/context-compiler.ts +17 -18
- package/src/core/context-evidence.ts +116 -25
- package/src/core/context-verifier.ts +70 -31
- package/src/core/file-lock.ts +10 -2
- package/src/core/graph-analysis.ts +3 -3
- package/src/core/link-inventory-markdown.ts +2 -2
- package/src/core/links.ts +20 -87
- package/src/core/memory-fence.ts +16 -9
- package/src/core/memory-recall.ts +168 -34
- package/src/core/path-rules.ts +143 -0
- package/src/core/section-parse.ts +16 -6
- package/src/core/typed-metadata.ts +68 -0
- package/src/core/wiki-link-syntax.ts +88 -0
- package/src/embed/backlog.ts +173 -60
- package/src/embed/batch.ts +83 -12
- package/src/embed/resume-cursor.ts +103 -0
- package/src/embed/retry.ts +41 -32
- package/src/embed/variant-backlog.ts +697 -63
- package/src/embed/variant-plan.ts +41 -45
- package/src/embed/variant-retry.ts +157 -44
- package/src/index.ts +3 -3
- package/src/ingestion/budget-error-codes.ts +13 -0
- package/src/ingestion/chunker.ts +60 -49
- package/src/ingestion/compiled-context.ts +4 -5
- package/src/ingestion/convert-file.ts +1 -1
- package/src/ingestion/document-metadata.ts +16 -9
- package/src/ingestion/excluded-ranges.ts +97 -0
- package/src/ingestion/file-processor.ts +122 -37
- package/src/ingestion/frontmatter.ts +35 -7
- package/src/ingestion/graph-reconciliation.ts +187 -51
- package/src/ingestion/language.ts +66 -61
- package/src/ingestion/position.ts +5 -5
- package/src/ingestion/prepare-file.ts +50 -29
- package/src/ingestion/record-adapter-canonical.ts +37 -26
- package/src/ingestion/record-adapter.ts +46 -26
- package/src/ingestion/record-container.ts +121 -53
- package/src/ingestion/record-path.ts +5 -2
- package/src/ingestion/source-availability/darwin-io.ts +10 -7
- package/src/ingestion/source-availability/darwin-path.ts +21 -3
- package/src/ingestion/source-availability/readers.ts +51 -0
- package/src/ingestion/strip.ts +39 -105
- package/src/ingestion/sync.ts +692 -386
- package/src/ingestion/typed-metadata.ts +10 -4
- package/src/ingestion/walker.ts +485 -158
- package/src/llm/cache.ts +128 -84
- package/src/llm/http-inference.ts +112 -35
- package/src/llm/http-policy.ts +101 -0
- package/src/llm/httpEmbedding.ts +8 -1
- package/src/llm/httpGeneration.ts +5 -1
- package/src/llm/httpRerank.ts +5 -1
- package/src/llm/inference-scope.ts +15 -2
- package/src/llm/lazy-ports.ts +33 -3
- package/src/llm/lockfile.ts +34 -7
- package/src/llm/model-cleanup.ts +24 -0
- package/src/llm/native-worker/client.ts +23 -12
- package/src/llm/native-worker/dispatcher.ts +19 -9
- package/src/llm/native-worker/embedding-identity.ts +42 -16
- package/src/llm/native-worker/entry.ts +2 -1
- package/src/llm/native-worker/owner.ts +1 -0
- package/src/llm/native-worker/ports.ts +86 -23
- package/src/llm/native-worker/protocol.ts +386 -55
- package/src/llm/nodeLlamaCpp/adapter.ts +46 -29
- package/src/llm/nodeLlamaCpp/embedding.ts +93 -40
- package/src/llm/nodeLlamaCpp/generation.ts +194 -30
- package/src/llm/nodeLlamaCpp/lifecycle.ts +2 -0
- package/src/llm/nodeLlamaCpp/rerank-capacity.ts +101 -23
- package/src/llm/nodeLlamaCpp/rerank.ts +253 -44
- package/src/llm/types.ts +14 -0
- package/src/mcp/context.ts +342 -23
- package/src/mcp/http-transport.ts +21 -3
- package/src/mcp/tool-profile-types.ts +62 -0
- package/src/mcp/tool-profile.ts +32 -56
- package/src/mcp/tools/context.ts +5 -1
- package/src/mcp/tools/index.ts +269 -191
- package/src/mcp/tools/links.ts +7 -5
- package/src/mcp/tools/query.ts +60 -37
- package/src/mcp/tools/vsearch.ts +25 -14
- package/src/pipeline/answer.ts +133 -40
- package/src/pipeline/claim-verification.ts +293 -189
- package/src/pipeline/claim-verifier.ts +6 -7
- package/src/pipeline/egress-lineage.ts +37 -26
- package/src/pipeline/exclude.ts +34 -11
- package/src/pipeline/expansion.ts +233 -19
- package/src/pipeline/filters.ts +169 -33
- package/src/pipeline/graph-retrieval.ts +117 -61
- package/src/pipeline/hybrid.ts +598 -329
- package/src/pipeline/hydration.ts +86 -24
- package/src/pipeline/intent.ts +15 -7
- package/src/pipeline/owner-fusion.ts +61 -19
- package/src/pipeline/query-language.ts +15 -2
- package/src/pipeline/rerank.ts +15 -22
- package/src/pipeline/search.ts +193 -72
- package/src/pipeline/snippet.ts +15 -2
- package/src/pipeline/temporal.ts +51 -10
- package/src/pipeline/vsearch.ts +250 -152
- package/src/publish/attachment-raster.ts +2 -16
- package/src/publish/encrypted-export.ts +15 -5
- package/src/serve/browse-tree.ts +50 -42
- package/src/serve/connectors.ts +2 -1
- package/src/serve/context.ts +13 -4
- package/src/serve/doc-events.ts +3 -0
- package/src/serve/public/app.tsx +49 -21
- package/src/serve/public/components/BrowseTreeSidebar.tsx +163 -23
- package/src/serve/public/components/CaptureModal.tsx +14 -10
- package/src/serve/public/components/ai-elements/code-block.tsx +87 -50
- package/src/serve/public/components/editor/MarkdownPreview.tsx +99 -67
- package/src/serve/public/globals.built.css +1 -1
- package/src/serve/public/globals.css +19 -0
- package/src/serve/public/hooks/useCaptureModal.tsx +23 -10
- package/src/serve/public/lib/metadata-filter.ts +234 -9
- package/src/serve/public/pages/Browse.tsx +61 -27
- package/src/serve/public/pages/DocView.tsx +44 -25
- package/src/serve/public/pages/GraphView.tsx +8 -3
- package/src/serve/resident-runtime.ts +199 -48
- package/src/serve/routes/api.ts +98 -67
- package/src/serve/routes/links.ts +18 -4
- package/src/serve/server.ts +1370 -1180
- package/src/serve/spa-bundle-source.ts +52 -27
- package/src/serve/status.ts +101 -52
- package/src/serve/watch-reconciliation-fallback.ts +11 -7
- package/src/serve/watch-reconciliation-shared.ts +42 -4
- package/src/serve/watch-reconciliation.ts +21 -8
- package/src/serve/watch-service-events.ts +7 -1
- package/src/serve/watch-service-hosts.ts +3 -1
- package/src/serve/watch-service.ts +46 -21
- package/src/serve/watch-snapshot-scan.ts +6 -15
- package/src/sessions/archive.ts +20 -8
- package/src/sessions/sanitize.ts +38 -18
- package/src/sessions/service.ts +180 -102
- package/src/store/migrations/036-vector-mirror-state.ts +83 -0
- package/src/store/migrations/037-performance-indexes.ts +56 -0
- package/src/store/migrations/index.ts +4 -0
- package/src/store/sqlite/adapter.ts +1217 -651
- package/src/store/sqlite/chunking-policy.ts +15 -1
- package/src/store/sqlite/eligibility.ts +110 -70
- package/src/store/sqlite/graph-neighbors.ts +71 -46
- package/src/store/sqlite/graph-reference-state.ts +27 -3
- package/src/store/sqlite/graph-similarity.ts +59 -12
- package/src/store/sqlite/metadata-predicate.ts +123 -28
- package/src/store/sqlite/retrieval-trace-management-store.ts +126 -33
- package/src/store/sqlite/retrieval-trace-retention.ts +88 -76
- package/src/store/sqlite/retrieval-trace-rows.ts +7 -3
- package/src/store/types.ts +32 -0
- package/src/store/vector/eligibility.ts +39 -0
- package/src/store/vector/lazy.ts +17 -0
- package/src/store/vector/partition-index.ts +49 -47
- package/src/store/vector/proof-cache.ts +103 -0
- package/src/store/vector/sqlite-vec.ts +230 -139
- package/src/store/vector/stats.ts +29 -73
- package/src/store/vector/status.ts +151 -52
- package/src/store/vector/stored-vectors.ts +131 -45
- package/src/store/vector/types.ts +10 -0
- package/src/store/vector/variant-search.ts +771 -109
- package/src/store/vector/variants.ts +785 -144
- package/browser-extension/artifacts/gno-browser-clipper-v2.14.0.zip.sha256 +0 -1
|
@@ -5,6 +5,8 @@ import type {
|
|
|
5
5
|
|
|
6
6
|
import { normalizeMetadataPredicate } from "../../core/typed-metadata";
|
|
7
7
|
|
|
8
|
+
const SIMPLE_JSON_KEY = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
9
|
+
|
|
8
10
|
/** JSON keys and values are bound parameters, never paths or SQL fragments. */
|
|
9
11
|
export function compileMetadataPredicate(input: MetadataPredicate): {
|
|
10
12
|
sql: string;
|
|
@@ -15,52 +17,145 @@ export function compileMetadataPredicate(input: MetadataPredicate): {
|
|
|
15
17
|
params.push(value);
|
|
16
18
|
return "?";
|
|
17
19
|
};
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
const typeClause = (typeExpr: string, sample: MetadataScalar): string => {
|
|
21
|
+
if (typeof sample === "number") return `${typeExpr} IN ('integer','real')`;
|
|
22
|
+
if (typeof sample === "boolean") return `${typeExpr} IN ('true','false')`;
|
|
23
|
+
return `${typeExpr} = 'text'`;
|
|
24
|
+
};
|
|
25
|
+
const scalarEq = (
|
|
26
|
+
typeExpr: string,
|
|
27
|
+
valExpr: string,
|
|
28
|
+
value: MetadataScalar
|
|
29
|
+
): string => {
|
|
30
|
+
if (typeof value === "boolean") {
|
|
31
|
+
return `${typeExpr} = '${value ? "true" : "false"}'`;
|
|
32
|
+
}
|
|
33
|
+
return `(${typeClause(typeExpr, value)} AND ${valExpr} = ${bind(value)})`;
|
|
26
34
|
};
|
|
35
|
+
const valuesMatch = (
|
|
36
|
+
typeExpr: string,
|
|
37
|
+
valExpr: string,
|
|
38
|
+
values: MetadataScalar[]
|
|
39
|
+
): string => {
|
|
40
|
+
const first = values[0]!;
|
|
41
|
+
if (typeof first === "boolean") {
|
|
42
|
+
const wantTrue = values.includes(true);
|
|
43
|
+
const wantFalse = values.includes(false);
|
|
44
|
+
if (wantTrue && wantFalse) return `${typeExpr} IN ('true','false')`;
|
|
45
|
+
return `${typeExpr} = '${wantTrue ? "true" : "false"}'`;
|
|
46
|
+
}
|
|
47
|
+
if (values.length === 1) {
|
|
48
|
+
return scalarEq(typeExpr, valExpr, first);
|
|
49
|
+
}
|
|
50
|
+
const placeholders = values
|
|
51
|
+
.map((v) => bind(v as string | number))
|
|
52
|
+
.join(",");
|
|
53
|
+
return `(${typeClause(typeExpr, first)} AND ${valExpr} IN (${placeholders}))`;
|
|
54
|
+
};
|
|
55
|
+
const allMatch = (
|
|
56
|
+
arrayExpr: string,
|
|
57
|
+
values: MetadataScalar[],
|
|
58
|
+
pathParam?: string
|
|
59
|
+
): string => {
|
|
60
|
+
const first = values[0]!;
|
|
61
|
+
const eachCall = pathParam
|
|
62
|
+
? `json_each(${arrayExpr}, ${pathParam})`
|
|
63
|
+
: `json_each(${arrayExpr})`;
|
|
64
|
+
if (typeof first === "boolean") {
|
|
65
|
+
const wantTrue = values.includes(true);
|
|
66
|
+
const wantFalse = values.includes(false);
|
|
67
|
+
const needed = (wantTrue ? 1 : 0) + (wantFalse ? 1 : 0);
|
|
68
|
+
const cond =
|
|
69
|
+
wantTrue && wantFalse
|
|
70
|
+
? "mv.type IN ('true','false')"
|
|
71
|
+
: `mv.type = '${wantTrue ? "true" : "false"}'`;
|
|
72
|
+
return `(SELECT COUNT(DISTINCT mv.type) FROM ${eachCall} mv WHERE ${cond}) = ${needed}`;
|
|
73
|
+
}
|
|
74
|
+
const placeholders = values
|
|
75
|
+
.map((v) => bind(v as string | number))
|
|
76
|
+
.join(",");
|
|
77
|
+
return `(SELECT COUNT(DISTINCT mv.value) FROM ${eachCall} mv WHERE ${typeClause("mv.type", first)} AND mv.value IN (${placeholders})) = ${values.length}`;
|
|
78
|
+
};
|
|
79
|
+
|
|
27
80
|
const compile = (node: MetadataPredicate): string => {
|
|
28
81
|
if (node.op === "and" || node.op === "or")
|
|
29
82
|
return `(${node.predicates.map(compile).join(node.op === "and" ? " AND " : " OR ")})`;
|
|
30
83
|
if (node.op === "not") return `NOT (${compile(node.predicate)})`;
|
|
31
84
|
if (!("key" in node)) throw new Error("Invalid metadata predicate");
|
|
85
|
+
|
|
86
|
+
// Fast path for safe unquoted identifier keys: bound JSON path parameter
|
|
87
|
+
// avoids scanning every key in d.typed_metadata with json_each().
|
|
88
|
+
// COALESCE(..., 0) / IS keeps every leaf 2-valued (0/1, never NULL) so
|
|
89
|
+
// outer NOT(...) behaves identically to NOT EXISTS(...) when keys are absent.
|
|
90
|
+
if (SIMPLE_JSON_KEY.test(node.key)) {
|
|
91
|
+
const path = `$.${node.key}`;
|
|
92
|
+
if (node.op === "exists") {
|
|
93
|
+
const p = bind(path);
|
|
94
|
+
return `json_type(d.typed_metadata, ${p}) IS ${node.value ? "NOT NULL" : "NULL"}`;
|
|
95
|
+
}
|
|
96
|
+
if ("values" in node) {
|
|
97
|
+
if (node.op === "all") {
|
|
98
|
+
const pType = bind(path);
|
|
99
|
+
const pEach = bind(path);
|
|
100
|
+
return `(json_type(d.typed_metadata, ${pType}) IS 'array' AND ${allMatch("d.typed_metadata", node.values, pEach)})`;
|
|
101
|
+
}
|
|
102
|
+
const pPresent = bind(path);
|
|
103
|
+
const pType = bind(path);
|
|
104
|
+
const pEach = bind(path);
|
|
105
|
+
const arrayMatch = `EXISTS (SELECT 1 FROM json_each(d.typed_metadata, ${pEach}) mv WHERE ${valuesMatch("mv.type", "mv.value", node.values)})`;
|
|
106
|
+
const pScalarType = bind(path);
|
|
107
|
+
const scalarMatch =
|
|
108
|
+
typeof node.values[0] === "boolean"
|
|
109
|
+
? `COALESCE(${valuesMatch(`json_type(d.typed_metadata, ${pScalarType})`, "", node.values)}, 0)`
|
|
110
|
+
: `COALESCE(${valuesMatch(`json_type(d.typed_metadata, ${pScalarType})`, `json_extract(d.typed_metadata, ${bind(path)})`, node.values)}, 0)`;
|
|
111
|
+
const match = `CASE WHEN json_type(d.typed_metadata, ${pType}) IS 'array' THEN ${arrayMatch} ELSE ${scalarMatch} END`;
|
|
112
|
+
return `(json_type(d.typed_metadata, ${pPresent}) IS NOT NULL AND ${node.op === "nin" ? "NOT " : ""}(${match}))`;
|
|
113
|
+
}
|
|
114
|
+
if (node.op === "eq") {
|
|
115
|
+
const pType = bind(path);
|
|
116
|
+
if (typeof node.value === "boolean") {
|
|
117
|
+
return `json_type(d.typed_metadata, ${pType}) IS '${node.value ? "true" : "false"}'`;
|
|
118
|
+
}
|
|
119
|
+
const pVal = bind(path);
|
|
120
|
+
return `COALESCE(${scalarEq(`json_type(d.typed_metadata, ${pType})`, `json_extract(d.typed_metadata, ${pVal})`, node.value)}, 0)`;
|
|
121
|
+
}
|
|
122
|
+
if (node.op === "ne") {
|
|
123
|
+
const pType = bind(path);
|
|
124
|
+
if (typeof node.value === "boolean") {
|
|
125
|
+
return `json_type(d.typed_metadata, ${pType}) IS '${node.value ? "false" : "true"}'`;
|
|
126
|
+
}
|
|
127
|
+
const pVal = bind(path);
|
|
128
|
+
return `COALESCE(${typeClause(`json_type(d.typed_metadata, ${pType})`, node.value)} AND json_extract(d.typed_metadata, ${pVal}) != ${bind(node.value)}, 0)`;
|
|
129
|
+
}
|
|
130
|
+
if (typeof node.value !== "number")
|
|
131
|
+
throw new Error("Ordering requires a number");
|
|
132
|
+
const operators = { gt: ">", gte: ">=", lt: "<", lte: "<=" } as const;
|
|
133
|
+
const pType = bind(path);
|
|
134
|
+
const pVal = bind(path);
|
|
135
|
+
return `COALESCE(json_type(d.typed_metadata, ${pType}) IN ('integer','real') AND json_extract(d.typed_metadata, ${pVal}) ${operators[node.op]} ${bind(node.value)}, 0)`;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Fallback for keys with punctuation/quotes: exact key lookup via json_each.
|
|
32
139
|
const key = bind(node.key);
|
|
33
140
|
const select = `SELECT 1 FROM json_each(d.typed_metadata) mf WHERE mf.key = ${key}`;
|
|
34
141
|
if (node.op === "exists")
|
|
35
142
|
return `${node.value ? "" : "NOT "}EXISTS (${select})`;
|
|
36
143
|
if ("values" in node) {
|
|
37
144
|
if (node.op === "all") {
|
|
38
|
-
|
|
39
|
-
(value) =>
|
|
40
|
-
`EXISTS (SELECT 1 FROM json_each(mf.value) mv WHERE ${scalar("mv", value)})`
|
|
41
|
-
);
|
|
42
|
-
return `EXISTS (${select} AND CASE WHEN mf.type = 'array' THEN (${conditions.join(" AND ")}) ELSE 0 END)`;
|
|
145
|
+
return `EXISTS (${select} AND CASE WHEN mf.type = 'array' THEN ${allMatch("mf.value", node.values)} ELSE 0 END)`;
|
|
43
146
|
}
|
|
44
|
-
const arrayMatches = node.values
|
|
45
|
-
|
|
46
|
-
.join(" OR ");
|
|
47
|
-
const scalarMatches = node.values
|
|
48
|
-
.map((value) => scalar("mf", value))
|
|
49
|
-
.join(" OR ");
|
|
147
|
+
const arrayMatches = valuesMatch("mv.type", "mv.value", node.values);
|
|
148
|
+
const scalarMatches = valuesMatch("mf.type", "mf.value", node.values);
|
|
50
149
|
const match = `CASE WHEN mf.type = 'array' THEN EXISTS (SELECT 1 FROM json_each(mf.value) mv WHERE ${arrayMatches}) ELSE (${scalarMatches}) END`;
|
|
51
150
|
return `EXISTS (${select} AND ${node.op === "nin" ? "NOT " : ""}(${match}))`;
|
|
52
151
|
}
|
|
53
152
|
if (node.op === "eq")
|
|
54
|
-
return `EXISTS (${select} AND ${
|
|
153
|
+
return `EXISTS (${select} AND ${scalarEq("mf.type", "mf.value", node.value)})`;
|
|
55
154
|
if (node.op === "ne") {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
: typeof node.value === "boolean"
|
|
61
|
-
? "mf.type IN ('true','false')"
|
|
62
|
-
: "mf.type = 'text'";
|
|
63
|
-
return `EXISTS (${select} AND ${type} AND NOT ${equal})`;
|
|
155
|
+
if (typeof node.value === "boolean") {
|
|
156
|
+
return `EXISTS (${select} AND mf.type = '${node.value ? "false" : "true"}')`;
|
|
157
|
+
}
|
|
158
|
+
return `EXISTS (${select} AND ${typeClause("mf.type", node.value)} AND mf.value != ${bind(node.value)})`;
|
|
64
159
|
}
|
|
65
160
|
if (typeof node.value !== "number")
|
|
66
161
|
throw new Error("Ordering requires a number");
|
|
@@ -33,7 +33,6 @@ import {
|
|
|
33
33
|
traceWriteError,
|
|
34
34
|
validateTraceId,
|
|
35
35
|
} from "./retrieval-trace-rows";
|
|
36
|
-
import { getTrace } from "./retrieval-trace-store";
|
|
37
36
|
|
|
38
37
|
const SHA256_PATTERN = /^[a-f0-9]{64}$/;
|
|
39
38
|
const REDACTION_SECRET_KEY = "retrieval_trace_redaction_secret_v1";
|
|
@@ -74,32 +73,49 @@ export const getBoundedTrace = (
|
|
|
74
73
|
)
|
|
75
74
|
.get(traceId);
|
|
76
75
|
if (!trace) return null;
|
|
77
|
-
const
|
|
76
|
+
const fetchLimit = detailLimit + 1;
|
|
77
|
+
const runsRaw = db
|
|
78
78
|
.query<DbRetrievalTraceRunRow, [string, number]>(
|
|
79
79
|
`SELECT * FROM retrieval_trace_runs WHERE trace_id = ?
|
|
80
80
|
ORDER BY created_at_ms, run_id LIMIT ?`
|
|
81
81
|
)
|
|
82
|
-
.all(traceId,
|
|
83
|
-
const
|
|
82
|
+
.all(traceId, fetchLimit);
|
|
83
|
+
const eventsRaw = db
|
|
84
84
|
.query<DbRetrievalTraceEventRow, [string, number]>(
|
|
85
85
|
`SELECT * FROM retrieval_trace_events WHERE trace_id = ?
|
|
86
86
|
ORDER BY created_at_ms, event_id LIMIT ?`
|
|
87
87
|
)
|
|
88
|
-
.all(traceId,
|
|
89
|
-
const
|
|
88
|
+
.all(traceId, fetchLimit);
|
|
89
|
+
const judgmentsRaw = db
|
|
90
90
|
.query<DbRetrievalTraceJudgmentRow, [string, number]>(
|
|
91
91
|
`SELECT * FROM retrieval_trace_judgments WHERE trace_id = ?
|
|
92
92
|
ORDER BY created_at_ms, judgment_id LIMIT ?`
|
|
93
93
|
)
|
|
94
|
-
.all(traceId,
|
|
95
|
-
const
|
|
94
|
+
.all(traceId, fetchLimit);
|
|
95
|
+
const exportsRaw = db
|
|
96
96
|
.query<DbRetrievalTraceExportRow, [string, number]>(
|
|
97
97
|
`SELECT x.*, et.trace_id FROM retrieval_trace_exports x
|
|
98
98
|
JOIN retrieval_trace_export_traces et USING (export_id)
|
|
99
99
|
WHERE et.trace_id = ?
|
|
100
100
|
ORDER BY x.created_at_ms, x.export_id LIMIT ?`
|
|
101
101
|
)
|
|
102
|
-
.all(traceId,
|
|
102
|
+
.all(traceId, fetchLimit);
|
|
103
|
+
const runs =
|
|
104
|
+
runsRaw.length > detailLimit
|
|
105
|
+
? runsRaw.slice(0, detailLimit)
|
|
106
|
+
: runsRaw;
|
|
107
|
+
const events =
|
|
108
|
+
eventsRaw.length > detailLimit
|
|
109
|
+
? eventsRaw.slice(0, detailLimit)
|
|
110
|
+
: eventsRaw;
|
|
111
|
+
const judgments =
|
|
112
|
+
judgmentsRaw.length > detailLimit
|
|
113
|
+
? judgmentsRaw.slice(0, detailLimit)
|
|
114
|
+
: judgmentsRaw;
|
|
115
|
+
const exports =
|
|
116
|
+
exportsRaw.length > detailLimit
|
|
117
|
+
? exportsRaw.slice(0, detailLimit)
|
|
118
|
+
: exportsRaw;
|
|
103
119
|
return {
|
|
104
120
|
bundle: {
|
|
105
121
|
trace: mapTraceRow(trace),
|
|
@@ -109,14 +125,22 @@ export const getBoundedTrace = (
|
|
|
109
125
|
exports: exports.map(mapExportRow),
|
|
110
126
|
},
|
|
111
127
|
totals: {
|
|
112
|
-
runs:
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
128
|
+
runs:
|
|
129
|
+
runsRaw.length > detailLimit
|
|
130
|
+
? countForTrace(db, "retrieval_trace_runs", traceId)
|
|
131
|
+
: runs.length,
|
|
132
|
+
events:
|
|
133
|
+
eventsRaw.length > detailLimit
|
|
134
|
+
? countForTrace(db, "retrieval_trace_events", traceId)
|
|
135
|
+
: events.length,
|
|
136
|
+
judgments:
|
|
137
|
+
judgmentsRaw.length > detailLimit
|
|
138
|
+
? countForTrace(db, "retrieval_trace_judgments", traceId)
|
|
139
|
+
: judgments.length,
|
|
140
|
+
exports:
|
|
141
|
+
exportsRaw.length > detailLimit
|
|
142
|
+
? countForTrace(db, "retrieval_trace_export_traces", traceId)
|
|
143
|
+
: exports.length,
|
|
120
144
|
},
|
|
121
145
|
};
|
|
122
146
|
}
|
|
@@ -242,14 +266,20 @@ export const appendExportManifest = (
|
|
|
242
266
|
"Export artifact already belongs to a different manifest"
|
|
243
267
|
);
|
|
244
268
|
}
|
|
269
|
+
const traceRows = db
|
|
270
|
+
.query<
|
|
271
|
+
{ trace_id: string; status: string; egress_lineage_json: string },
|
|
272
|
+
[string]
|
|
273
|
+
>(
|
|
274
|
+
`SELECT trace_id, status, egress_lineage_json
|
|
275
|
+
FROM retrieval_traces
|
|
276
|
+
WHERE trace_id IN (SELECT value FROM json_each(?))`
|
|
277
|
+
)
|
|
278
|
+
.all(JSON.stringify(manifest.traceIds));
|
|
279
|
+
const traceById = new Map(traceRows.map((row) => [row.trace_id, row]));
|
|
245
280
|
const sourceLineages = [];
|
|
246
281
|
for (const traceId of manifest.traceIds) {
|
|
247
|
-
const trace =
|
|
248
|
-
.query<{ status: string; egress_lineage_json: string }, [string]>(
|
|
249
|
-
`SELECT status, egress_lineage_json
|
|
250
|
-
FROM retrieval_traces WHERE trace_id = ?`
|
|
251
|
-
)
|
|
252
|
-
.get(traceId);
|
|
282
|
+
const trace = traceById.get(traceId);
|
|
253
283
|
if (!trace) {
|
|
254
284
|
throw new RetrievalTraceConflictError(
|
|
255
285
|
"Export manifest references a missing retrieval trace"
|
|
@@ -306,12 +336,12 @@ export const appendExportManifest = (
|
|
|
306
336
|
"Export ID already exists with different content"
|
|
307
337
|
);
|
|
308
338
|
}
|
|
339
|
+
const insertExportLink = db.query<unknown, [string, string]>(
|
|
340
|
+
`INSERT OR IGNORE INTO retrieval_trace_export_traces
|
|
341
|
+
(export_id, trace_id) VALUES (?, ?)`
|
|
342
|
+
);
|
|
309
343
|
for (const traceId of manifest.traceIds) {
|
|
310
|
-
|
|
311
|
-
`INSERT OR IGNORE INTO retrieval_trace_export_traces
|
|
312
|
-
(export_id, trace_id) VALUES (?, ?)`,
|
|
313
|
-
[manifest.exportId, traceId]
|
|
314
|
-
);
|
|
344
|
+
insertExportLink.run(manifest.exportId, traceId);
|
|
315
345
|
}
|
|
316
346
|
const stored = readManifest(db, manifest.exportId);
|
|
317
347
|
if (
|
|
@@ -358,17 +388,80 @@ export const getExportBundle = (
|
|
|
358
388
|
(): StoreResult<RetrievalTraceExportBundle | null> => {
|
|
359
389
|
const manifest = readManifest(db, exportId);
|
|
360
390
|
if (!manifest) return ok(null);
|
|
361
|
-
const
|
|
391
|
+
const idsJson = JSON.stringify(manifest.traceIds);
|
|
392
|
+
const traceRows = db
|
|
393
|
+
.query<DbRetrievalTraceRow, [string]>(
|
|
394
|
+
`SELECT * FROM retrieval_traces
|
|
395
|
+
WHERE trace_id IN (SELECT value FROM json_each(?))`
|
|
396
|
+
)
|
|
397
|
+
.all(idsJson);
|
|
398
|
+
const traceById = new Map(traceRows.map((row) => [row.trace_id, row]));
|
|
362
399
|
for (const traceId of manifest.traceIds) {
|
|
363
|
-
|
|
364
|
-
if (!trace.ok) return trace;
|
|
365
|
-
if (!trace.value) {
|
|
400
|
+
if (!traceById.has(traceId)) {
|
|
366
401
|
throw new RetrievalTraceConflictError(
|
|
367
402
|
"Export manifest references a missing retrieval trace"
|
|
368
403
|
);
|
|
369
404
|
}
|
|
370
|
-
traces.push(trace.value);
|
|
371
405
|
}
|
|
406
|
+
const runsByTrace = new Map<string, DbRetrievalTraceRunRow[]>();
|
|
407
|
+
for (const row of db
|
|
408
|
+
.query<DbRetrievalTraceRunRow, [string]>(
|
|
409
|
+
`SELECT * FROM retrieval_trace_runs
|
|
410
|
+
WHERE trace_id IN (SELECT value FROM json_each(?))
|
|
411
|
+
ORDER BY trace_id, created_at_ms, run_id`
|
|
412
|
+
)
|
|
413
|
+
.all(idsJson)) {
|
|
414
|
+
const list = runsByTrace.get(row.trace_id);
|
|
415
|
+
if (list) list.push(row);
|
|
416
|
+
else runsByTrace.set(row.trace_id, [row]);
|
|
417
|
+
}
|
|
418
|
+
const eventsByTrace = new Map<string, DbRetrievalTraceEventRow[]>();
|
|
419
|
+
for (const row of db
|
|
420
|
+
.query<DbRetrievalTraceEventRow, [string]>(
|
|
421
|
+
`SELECT * FROM retrieval_trace_events
|
|
422
|
+
WHERE trace_id IN (SELECT value FROM json_each(?))
|
|
423
|
+
ORDER BY trace_id, created_at_ms, event_id`
|
|
424
|
+
)
|
|
425
|
+
.all(idsJson)) {
|
|
426
|
+
const list = eventsByTrace.get(row.trace_id);
|
|
427
|
+
if (list) list.push(row);
|
|
428
|
+
else eventsByTrace.set(row.trace_id, [row]);
|
|
429
|
+
}
|
|
430
|
+
const judgmentsByTrace = new Map<
|
|
431
|
+
string,
|
|
432
|
+
DbRetrievalTraceJudgmentRow[]
|
|
433
|
+
>();
|
|
434
|
+
for (const row of db
|
|
435
|
+
.query<DbRetrievalTraceJudgmentRow, [string]>(
|
|
436
|
+
`SELECT * FROM retrieval_trace_judgments
|
|
437
|
+
WHERE trace_id IN (SELECT value FROM json_each(?))
|
|
438
|
+
ORDER BY trace_id, created_at_ms, judgment_id`
|
|
439
|
+
)
|
|
440
|
+
.all(idsJson)) {
|
|
441
|
+
const list = judgmentsByTrace.get(row.trace_id);
|
|
442
|
+
if (list) list.push(row);
|
|
443
|
+
else judgmentsByTrace.set(row.trace_id, [row]);
|
|
444
|
+
}
|
|
445
|
+
const exportsByTrace = new Map<string, DbRetrievalTraceExportRow[]>();
|
|
446
|
+
for (const row of db
|
|
447
|
+
.query<DbRetrievalTraceExportRow, [string]>(
|
|
448
|
+
`SELECT x.*, et.trace_id FROM retrieval_trace_exports x
|
|
449
|
+
JOIN retrieval_trace_export_traces et USING (export_id)
|
|
450
|
+
WHERE et.trace_id IN (SELECT value FROM json_each(?))
|
|
451
|
+
ORDER BY et.trace_id, x.created_at_ms, x.export_id`
|
|
452
|
+
)
|
|
453
|
+
.all(idsJson)) {
|
|
454
|
+
const list = exportsByTrace.get(row.trace_id);
|
|
455
|
+
if (list) list.push(row);
|
|
456
|
+
else exportsByTrace.set(row.trace_id, [row]);
|
|
457
|
+
}
|
|
458
|
+
const traces = manifest.traceIds.map((traceId) => ({
|
|
459
|
+
trace: mapTraceRow(traceById.get(traceId)!),
|
|
460
|
+
runs: (runsByTrace.get(traceId) ?? []).map(mapRunRow),
|
|
461
|
+
events: (eventsByTrace.get(traceId) ?? []).map(mapEventRow),
|
|
462
|
+
judgments: (judgmentsByTrace.get(traceId) ?? []).map(mapJudgmentRow),
|
|
463
|
+
exports: (exportsByTrace.get(traceId) ?? []).map(mapExportRow),
|
|
464
|
+
}));
|
|
372
465
|
return ok({ manifest, traces });
|
|
373
466
|
}
|
|
374
467
|
);
|
|
@@ -32,7 +32,75 @@ interface StorageRow {
|
|
|
32
32
|
const storageRows = (db: Database): StorageRow[] =>
|
|
33
33
|
db
|
|
34
34
|
.query<StorageRow, []>(
|
|
35
|
-
`
|
|
35
|
+
`WITH run_stats AS (
|
|
36
|
+
SELECT
|
|
37
|
+
trace_id,
|
|
38
|
+
COUNT(*) AS cnt,
|
|
39
|
+
SUM(
|
|
40
|
+
length(CAST(run_id AS BLOB))
|
|
41
|
+
+ length(CAST(trace_id AS BLOB))
|
|
42
|
+
+ length(CAST(idempotency_key AS BLOB))
|
|
43
|
+
+ length(CAST(kind AS BLOB))
|
|
44
|
+
+ payload_bytes
|
|
45
|
+
+ length(CAST(canonical_digest AS BLOB))
|
|
46
|
+
+ 8
|
|
47
|
+
) AS bytes
|
|
48
|
+
FROM retrieval_trace_runs
|
|
49
|
+
GROUP BY trace_id
|
|
50
|
+
),
|
|
51
|
+
event_stats AS (
|
|
52
|
+
SELECT
|
|
53
|
+
trace_id,
|
|
54
|
+
COUNT(*) AS cnt,
|
|
55
|
+
SUM(
|
|
56
|
+
length(CAST(event_id AS BLOB))
|
|
57
|
+
+ length(CAST(trace_id AS BLOB))
|
|
58
|
+
+ length(CAST(COALESCE(run_id, '') AS BLOB))
|
|
59
|
+
+ length(CAST(idempotency_key AS BLOB))
|
|
60
|
+
+ length(CAST(kind AS BLOB))
|
|
61
|
+
+ payload_bytes
|
|
62
|
+
+ length(CAST(canonical_digest AS BLOB))
|
|
63
|
+
+ 8
|
|
64
|
+
) AS bytes
|
|
65
|
+
FROM retrieval_trace_events
|
|
66
|
+
GROUP BY trace_id
|
|
67
|
+
),
|
|
68
|
+
judgment_stats AS (
|
|
69
|
+
SELECT
|
|
70
|
+
trace_id,
|
|
71
|
+
COUNT(*) AS cnt,
|
|
72
|
+
SUM(
|
|
73
|
+
length(CAST(judgment_id AS BLOB))
|
|
74
|
+
+ length(CAST(trace_id AS BLOB))
|
|
75
|
+
+ length(CAST(COALESCE(run_id, '') AS BLOB))
|
|
76
|
+
+ length(CAST(idempotency_key AS BLOB))
|
|
77
|
+
+ length(CAST(label AS BLOB))
|
|
78
|
+
+ length(CAST(target_kind AS BLOB))
|
|
79
|
+
+ length(CAST(target_ref AS BLOB))
|
|
80
|
+
+ target_bytes
|
|
81
|
+
+ length(CAST(canonical_digest AS BLOB))
|
|
82
|
+
+ 8
|
|
83
|
+
) AS bytes
|
|
84
|
+
FROM retrieval_trace_judgments
|
|
85
|
+
GROUP BY trace_id
|
|
86
|
+
),
|
|
87
|
+
export_stats AS (
|
|
88
|
+
SELECT
|
|
89
|
+
et.trace_id,
|
|
90
|
+
COUNT(*) AS cnt,
|
|
91
|
+
SUM(
|
|
92
|
+
length(CAST(x.export_id AS BLOB))
|
|
93
|
+
+ length(CAST(et.trace_id AS BLOB))
|
|
94
|
+
+ length(CAST(x.format AS BLOB))
|
|
95
|
+
+ length(CAST(x.artifact_hash AS BLOB))
|
|
96
|
+
+ x.egress_lineage_bytes
|
|
97
|
+
+ 8
|
|
98
|
+
) AS bytes
|
|
99
|
+
FROM retrieval_trace_export_traces et
|
|
100
|
+
JOIN retrieval_trace_exports x USING (export_id)
|
|
101
|
+
GROUP BY et.trace_id
|
|
102
|
+
)
|
|
103
|
+
SELECT
|
|
36
104
|
t.trace_id,
|
|
37
105
|
t.created_at_ms,
|
|
38
106
|
t.expires_at_ms,
|
|
@@ -56,73 +124,19 @@ const storageRows = (db: Database): StorageRow[] =>
|
|
|
56
124
|
+ length(CAST(t.creation_digest AS BLOB))
|
|
57
125
|
+ 40
|
|
58
126
|
)
|
|
59
|
-
+ COALESCE(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
+ 8
|
|
68
|
-
) FROM retrieval_trace_runs r
|
|
69
|
-
WHERE r.trace_id = t.trace_id
|
|
70
|
-
), 0)
|
|
71
|
-
+ COALESCE((
|
|
72
|
-
SELECT SUM(
|
|
73
|
-
length(CAST(e.event_id AS BLOB))
|
|
74
|
-
+ length(CAST(e.trace_id AS BLOB))
|
|
75
|
-
+ length(CAST(COALESCE(e.run_id, '') AS BLOB))
|
|
76
|
-
+ length(CAST(e.idempotency_key AS BLOB))
|
|
77
|
-
+ length(CAST(e.kind AS BLOB))
|
|
78
|
-
+ e.payload_bytes
|
|
79
|
-
+ length(CAST(e.canonical_digest AS BLOB))
|
|
80
|
-
+ 8
|
|
81
|
-
) FROM retrieval_trace_events e
|
|
82
|
-
WHERE e.trace_id = t.trace_id
|
|
83
|
-
), 0)
|
|
84
|
-
+ COALESCE((
|
|
85
|
-
SELECT SUM(
|
|
86
|
-
length(CAST(j.judgment_id AS BLOB))
|
|
87
|
-
+ length(CAST(j.trace_id AS BLOB))
|
|
88
|
-
+ length(CAST(COALESCE(j.run_id, '') AS BLOB))
|
|
89
|
-
+ length(CAST(j.idempotency_key AS BLOB))
|
|
90
|
-
+ length(CAST(j.label AS BLOB))
|
|
91
|
-
+ length(CAST(j.target_kind AS BLOB))
|
|
92
|
-
+ length(CAST(j.target_ref AS BLOB))
|
|
93
|
-
+ j.target_bytes
|
|
94
|
-
+ length(CAST(j.canonical_digest AS BLOB))
|
|
95
|
-
+ 8
|
|
96
|
-
) FROM retrieval_trace_judgments j
|
|
97
|
-
WHERE j.trace_id = t.trace_id
|
|
98
|
-
), 0)
|
|
99
|
-
+ COALESCE((
|
|
100
|
-
SELECT SUM(
|
|
101
|
-
length(CAST(x.export_id AS BLOB))
|
|
102
|
-
+ length(CAST(et.trace_id AS BLOB))
|
|
103
|
-
+ length(CAST(x.format AS BLOB))
|
|
104
|
-
+ length(CAST(x.artifact_hash AS BLOB))
|
|
105
|
-
+ x.egress_lineage_bytes
|
|
106
|
-
+ 8
|
|
107
|
-
)
|
|
108
|
-
FROM retrieval_trace_export_traces et
|
|
109
|
-
JOIN retrieval_trace_exports x USING (export_id)
|
|
110
|
-
WHERE et.trace_id = t.trace_id
|
|
111
|
-
), 0) AS total_bytes,
|
|
112
|
-
(
|
|
113
|
-
SELECT COUNT(*) FROM retrieval_trace_runs r
|
|
114
|
-
WHERE r.trace_id = t.trace_id
|
|
115
|
-
) + (
|
|
116
|
-
SELECT COUNT(*) FROM retrieval_trace_events e
|
|
117
|
-
WHERE e.trace_id = t.trace_id
|
|
118
|
-
) + (
|
|
119
|
-
SELECT COUNT(*) FROM retrieval_trace_judgments j
|
|
120
|
-
WHERE j.trace_id = t.trace_id
|
|
121
|
-
) + (
|
|
122
|
-
SELECT COUNT(*) FROM retrieval_trace_export_traces et
|
|
123
|
-
WHERE et.trace_id = t.trace_id
|
|
124
|
-
) AS record_count
|
|
127
|
+
+ COALESCE(rs.bytes, 0)
|
|
128
|
+
+ COALESCE(es.bytes, 0)
|
|
129
|
+
+ COALESCE(js.bytes, 0)
|
|
130
|
+
+ COALESCE(xs.bytes, 0) AS total_bytes,
|
|
131
|
+
COALESCE(rs.cnt, 0)
|
|
132
|
+
+ COALESCE(es.cnt, 0)
|
|
133
|
+
+ COALESCE(js.cnt, 0)
|
|
134
|
+
+ COALESCE(xs.cnt, 0) AS record_count
|
|
125
135
|
FROM retrieval_traces t
|
|
136
|
+
LEFT JOIN run_stats rs ON rs.trace_id = t.trace_id
|
|
137
|
+
LEFT JOIN event_stats es ON es.trace_id = t.trace_id
|
|
138
|
+
LEFT JOIN judgment_stats js ON js.trace_id = t.trace_id
|
|
139
|
+
LEFT JOIN export_stats xs ON xs.trace_id = t.trace_id
|
|
126
140
|
ORDER BY t.created_at_ms ASC, t.trace_id ASC`
|
|
127
141
|
)
|
|
128
142
|
.all();
|
|
@@ -283,15 +297,17 @@ export const enforceRetention = (
|
|
|
283
297
|
0
|
|
284
298
|
);
|
|
285
299
|
|
|
300
|
+
const deleteTraceStmt = db.query<unknown, [string]>(
|
|
301
|
+
"DELETE FROM retrieval_traces WHERE trace_id = ?"
|
|
302
|
+
);
|
|
303
|
+
|
|
286
304
|
for (const row of byExpiry) {
|
|
287
305
|
const effectiveExpiry = Math.min(
|
|
288
306
|
row.expires_at_ms,
|
|
289
307
|
row.created_at_ms + ageMs
|
|
290
308
|
);
|
|
291
309
|
if (effectiveExpiry > nowMs) break;
|
|
292
|
-
|
|
293
|
-
row.trace_id,
|
|
294
|
-
]);
|
|
310
|
+
deleteTraceStmt.run(row.trace_id);
|
|
295
311
|
deleted.add(row.trace_id);
|
|
296
312
|
deletedTraceIds.push(row.trace_id);
|
|
297
313
|
remainingTraces -= 1;
|
|
@@ -305,9 +321,7 @@ export const enforceRetention = (
|
|
|
305
321
|
) {
|
|
306
322
|
continue;
|
|
307
323
|
}
|
|
308
|
-
|
|
309
|
-
row.trace_id,
|
|
310
|
-
]);
|
|
324
|
+
deleteTraceStmt.run(row.trace_id);
|
|
311
325
|
deleted.add(row.trace_id);
|
|
312
326
|
deletedTraceIds.push(row.trace_id);
|
|
313
327
|
remainingTraces -= 1;
|
|
@@ -322,9 +336,7 @@ export const enforceRetention = (
|
|
|
322
336
|
break;
|
|
323
337
|
}
|
|
324
338
|
if (deleted.has(row.trace_id)) continue;
|
|
325
|
-
|
|
326
|
-
row.trace_id,
|
|
327
|
-
]);
|
|
339
|
+
deleteTraceStmt.run(row.trace_id);
|
|
328
340
|
deleted.add(row.trace_id);
|
|
329
341
|
deletedTraceIds.push(row.trace_id);
|
|
330
342
|
remainingTraces -= 1;
|
|
@@ -17,7 +17,6 @@ import type {
|
|
|
17
17
|
} from "../types";
|
|
18
18
|
|
|
19
19
|
import { egressLineageSchema } from "../../core/egress-provenance";
|
|
20
|
-
import { traceJsonObjectSchema } from "../retrieval-trace-codec";
|
|
21
20
|
import { err } from "../types";
|
|
22
21
|
|
|
23
22
|
export interface DbRetrievalTraceRow {
|
|
@@ -94,8 +93,13 @@ export interface DbRetrievalTraceExportRow {
|
|
|
94
93
|
created_at_ms: number;
|
|
95
94
|
}
|
|
96
95
|
|
|
97
|
-
const parseJsonObject = (raw: string): Record<string, unknown> =>
|
|
98
|
-
|
|
96
|
+
const parseJsonObject = (raw: string): Record<string, unknown> => {
|
|
97
|
+
const parsed: unknown = JSON.parse(raw);
|
|
98
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
99
|
+
throw new Error("Expected JSON object in retrieval trace row");
|
|
100
|
+
}
|
|
101
|
+
return parsed as Record<string, unknown>;
|
|
102
|
+
};
|
|
99
103
|
|
|
100
104
|
export const mapTraceRow = (row: DbRetrievalTraceRow): RetrievalTraceRow => ({
|
|
101
105
|
traceId: row.trace_id,
|