sentienceapi 0.90.6 → 0.90.11
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 +81 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/textSearch.d.ts +64 -0
- package/dist/textSearch.d.ts.map +1 -0
- package/dist/textSearch.js +109 -0
- package/dist/textSearch.js.map +1 -0
- package/dist/tracing/cloud-sink.d.ts +4 -0
- package/dist/tracing/cloud-sink.d.ts.map +1 -1
- package/dist/tracing/cloud-sink.js +15 -0
- package/dist/tracing/cloud-sink.js.map +1 -1
- package/dist/tracing/index-schema.d.ts +182 -0
- package/dist/tracing/index-schema.d.ts.map +1 -0
- package/dist/tracing/index-schema.js +150 -0
- package/dist/tracing/index-schema.js.map +1 -0
- package/dist/tracing/indexer.d.ts +17 -0
- package/dist/tracing/indexer.d.ts.map +1 -0
- package/dist/tracing/indexer.js +282 -0
- package/dist/tracing/indexer.js.map +1 -0
- package/dist/tracing/jsonl-sink.d.ts +4 -0
- package/dist/tracing/jsonl-sink.d.ts.map +1 -1
- package/dist/tracing/jsonl-sink.js +15 -0
- package/dist/tracing/jsonl-sink.js.map +1 -1
- package/dist/tracing/tracer-factory.d.ts +11 -5
- package/dist/tracing/tracer-factory.d.ts.map +1 -1
- package/dist/tracing/tracer-factory.js +16 -7
- package/dist/tracing/tracer-factory.js.map +1 -1
- package/dist/types.d.ts +98 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/extension/background.js +222 -52
- package/src/extension/content.js +285 -9
- package/src/extension/injected_api.js +1224 -189
- package/src/extension/manifest.json +10 -4
- package/src/extension/pkg/README.md +163 -2
- package/src/extension/pkg/sentience_core.d.ts +9 -0
- package/src/extension/pkg/sentience_core.js +16 -0
- package/src/extension/pkg/sentience_core_bg.wasm +0 -0
- package/src/extension/pkg/sentience_core_bg.wasm.d.ts +1 -0
- package/src/extension/release.json +115 -0
- package/src/extension/test-content.js +4 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Type definitions for trace index schema using concrete classes.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TraceIndex = exports.StepIndex = exports.StepCounters = exports.ActionInfo = exports.SnapshotInfo = exports.TraceSummary = exports.TraceFileInfo = void 0;
|
|
7
|
+
class TraceFileInfo {
|
|
8
|
+
constructor(path, size_bytes, sha256) {
|
|
9
|
+
this.path = path;
|
|
10
|
+
this.size_bytes = size_bytes;
|
|
11
|
+
this.sha256 = sha256;
|
|
12
|
+
}
|
|
13
|
+
toJSON() {
|
|
14
|
+
return {
|
|
15
|
+
path: this.path,
|
|
16
|
+
size_bytes: this.size_bytes,
|
|
17
|
+
sha256: this.sha256,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.TraceFileInfo = TraceFileInfo;
|
|
22
|
+
class TraceSummary {
|
|
23
|
+
constructor(first_ts, last_ts, event_count, step_count, error_count, final_url) {
|
|
24
|
+
this.first_ts = first_ts;
|
|
25
|
+
this.last_ts = last_ts;
|
|
26
|
+
this.event_count = event_count;
|
|
27
|
+
this.step_count = step_count;
|
|
28
|
+
this.error_count = error_count;
|
|
29
|
+
this.final_url = final_url;
|
|
30
|
+
}
|
|
31
|
+
toJSON() {
|
|
32
|
+
return {
|
|
33
|
+
first_ts: this.first_ts,
|
|
34
|
+
last_ts: this.last_ts,
|
|
35
|
+
event_count: this.event_count,
|
|
36
|
+
step_count: this.step_count,
|
|
37
|
+
error_count: this.error_count,
|
|
38
|
+
final_url: this.final_url,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.TraceSummary = TraceSummary;
|
|
43
|
+
class SnapshotInfo {
|
|
44
|
+
constructor(snapshot_id = null, digest = null, url = null) {
|
|
45
|
+
this.snapshot_id = snapshot_id;
|
|
46
|
+
this.digest = digest;
|
|
47
|
+
this.url = url;
|
|
48
|
+
}
|
|
49
|
+
toJSON() {
|
|
50
|
+
return {
|
|
51
|
+
snapshot_id: this.snapshot_id,
|
|
52
|
+
digest: this.digest,
|
|
53
|
+
url: this.url,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.SnapshotInfo = SnapshotInfo;
|
|
58
|
+
class ActionInfo {
|
|
59
|
+
constructor(type = null, target_element_id = null, args_digest = null, success = null) {
|
|
60
|
+
this.type = type;
|
|
61
|
+
this.target_element_id = target_element_id;
|
|
62
|
+
this.args_digest = args_digest;
|
|
63
|
+
this.success = success;
|
|
64
|
+
}
|
|
65
|
+
toJSON() {
|
|
66
|
+
return {
|
|
67
|
+
type: this.type,
|
|
68
|
+
target_element_id: this.target_element_id,
|
|
69
|
+
args_digest: this.args_digest,
|
|
70
|
+
success: this.success,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.ActionInfo = ActionInfo;
|
|
75
|
+
class StepCounters {
|
|
76
|
+
constructor(events = 0, snapshots = 0, actions = 0, llm_calls = 0) {
|
|
77
|
+
this.events = events;
|
|
78
|
+
this.snapshots = snapshots;
|
|
79
|
+
this.actions = actions;
|
|
80
|
+
this.llm_calls = llm_calls;
|
|
81
|
+
}
|
|
82
|
+
toJSON() {
|
|
83
|
+
return {
|
|
84
|
+
events: this.events,
|
|
85
|
+
snapshots: this.snapshots,
|
|
86
|
+
actions: this.actions,
|
|
87
|
+
llm_calls: this.llm_calls,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.StepCounters = StepCounters;
|
|
92
|
+
class StepIndex {
|
|
93
|
+
constructor(step_index, step_id, goal, status, ts_start, ts_end, offset_start, offset_end, url_before, url_after, snapshot_before, snapshot_after, action, counters) {
|
|
94
|
+
this.step_index = step_index;
|
|
95
|
+
this.step_id = step_id;
|
|
96
|
+
this.goal = goal;
|
|
97
|
+
this.status = status;
|
|
98
|
+
this.ts_start = ts_start;
|
|
99
|
+
this.ts_end = ts_end;
|
|
100
|
+
this.offset_start = offset_start;
|
|
101
|
+
this.offset_end = offset_end;
|
|
102
|
+
this.url_before = url_before;
|
|
103
|
+
this.url_after = url_after;
|
|
104
|
+
this.snapshot_before = snapshot_before;
|
|
105
|
+
this.snapshot_after = snapshot_after;
|
|
106
|
+
this.action = action;
|
|
107
|
+
this.counters = counters;
|
|
108
|
+
}
|
|
109
|
+
toJSON() {
|
|
110
|
+
return {
|
|
111
|
+
step_index: this.step_index,
|
|
112
|
+
step_id: this.step_id,
|
|
113
|
+
goal: this.goal,
|
|
114
|
+
status: this.status,
|
|
115
|
+
ts_start: this.ts_start,
|
|
116
|
+
ts_end: this.ts_end,
|
|
117
|
+
offset_start: this.offset_start,
|
|
118
|
+
offset_end: this.offset_end,
|
|
119
|
+
url_before: this.url_before,
|
|
120
|
+
url_after: this.url_after,
|
|
121
|
+
snapshot_before: this.snapshot_before.toJSON(),
|
|
122
|
+
snapshot_after: this.snapshot_after.toJSON(),
|
|
123
|
+
action: this.action.toJSON(),
|
|
124
|
+
counters: this.counters.toJSON(),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.StepIndex = StepIndex;
|
|
129
|
+
class TraceIndex {
|
|
130
|
+
constructor(version, run_id, created_at, trace_file, summary, steps = []) {
|
|
131
|
+
this.version = version;
|
|
132
|
+
this.run_id = run_id;
|
|
133
|
+
this.created_at = created_at;
|
|
134
|
+
this.trace_file = trace_file;
|
|
135
|
+
this.summary = summary;
|
|
136
|
+
this.steps = steps;
|
|
137
|
+
}
|
|
138
|
+
toJSON() {
|
|
139
|
+
return {
|
|
140
|
+
version: this.version,
|
|
141
|
+
run_id: this.run_id,
|
|
142
|
+
created_at: this.created_at,
|
|
143
|
+
trace_file: this.trace_file.toJSON(),
|
|
144
|
+
summary: this.summary.toJSON(),
|
|
145
|
+
steps: this.steps.map((s) => s.toJSON()),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.TraceIndex = TraceIndex;
|
|
150
|
+
//# sourceMappingURL=index-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-schema.js","sourceRoot":"","sources":["../../src/tracing/index-schema.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,MAAa,aAAa;IACxB,YACS,IAAY,EACZ,UAAkB,EAClB,MAAc;QAFd,SAAI,GAAJ,IAAI,CAAQ;QACZ,eAAU,GAAV,UAAU,CAAQ;QAClB,WAAM,GAAN,MAAM,CAAQ;IACpB,CAAC;IAEJ,MAAM;QACJ,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC;IACJ,CAAC;CACF;AAdD,sCAcC;AAED,MAAa,YAAY;IACvB,YACS,QAAgB,EAChB,OAAe,EACf,WAAmB,EACnB,UAAkB,EAClB,WAAmB,EACnB,SAAwB;QALxB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,YAAO,GAAP,OAAO,CAAQ;QACf,gBAAW,GAAX,WAAW,CAAQ;QACnB,eAAU,GAAV,UAAU,CAAQ;QAClB,gBAAW,GAAX,WAAW,CAAQ;QACnB,cAAS,GAAT,SAAS,CAAe;IAC9B,CAAC;IAEJ,MAAM;QACJ,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,SAAS,EAAE,IAAI,CAAC,SAAS;SAC1B,CAAC;IACJ,CAAC;CACF;AApBD,oCAoBC;AAED,MAAa,YA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AAC,MAAM,EAAE;YAC5B,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;SACjC,CAAC;IACJ,CAAC;CACF;AApCD,8BAoCC;AAED,MAAa,UAAU;IACrB,YACS,OAAe,EACf,MAAc,EACd,UAAkB,EAClB,UAAyB,EACzB,OAAqB,EACrB,QAAqB,EAAE;QALvB,YAAO,GAAP,OAAO,CAAQ;QACf,WAAM,GAAN,MAAM,CAAQ;QACd,eAAU,GAAV,UAAU,CAAQ;QAClB,eAAU,GAAV,UAAU,CAAe;QACzB,YAAO,GAAP,OAAO,CAAc;QACrB,UAAK,GAAL,KAAK,CAAkB;IAC7B,CAAC;IAEJ,MAAM;QACJ,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE;YACpC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YAC9B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;SACzC,CAAC;IACJ,CAAC;CACF;AApBD,gCAoBC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trace indexing for fast timeline rendering and step drill-down.
|
|
3
|
+
*/
|
|
4
|
+
import { TraceIndex } from './index-schema';
|
|
5
|
+
/**
|
|
6
|
+
* Build trace index from JSONL file in single streaming pass
|
|
7
|
+
*/
|
|
8
|
+
export declare function buildTraceIndex(tracePath: string): TraceIndex;
|
|
9
|
+
/**
|
|
10
|
+
* Build index and write to file
|
|
11
|
+
*/
|
|
12
|
+
export declare function writeTraceIndex(tracePath: string, indexPath?: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Read events for a specific step using byte offsets from index
|
|
15
|
+
*/
|
|
16
|
+
export declare function readStepEvents(tracePath: string, offsetStart: number, offsetEnd: number): any[];
|
|
17
|
+
//# sourceMappingURL=indexer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexer.d.ts","sourceRoot":"","sources":["../../src/tracing/indexer.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,EACL,UAAU,EAQX,MAAM,gBAAgB,CAAC;AA6GxB;;GAEG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,UAAU,CA+J7D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAU7E;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GAChB,GAAG,EAAE,CA0BP"}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Trace indexing for fast timeline rendering and step drill-down.
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.buildTraceIndex = buildTraceIndex;
|
|
40
|
+
exports.writeTraceIndex = writeTraceIndex;
|
|
41
|
+
exports.readStepEvents = readStepEvents;
|
|
42
|
+
const fs = __importStar(require("fs"));
|
|
43
|
+
const crypto = __importStar(require("crypto"));
|
|
44
|
+
const path = __importStar(require("path"));
|
|
45
|
+
const index_schema_1 = require("./index-schema");
|
|
46
|
+
/**
|
|
47
|
+
* Normalize text for digest: trim, collapse whitespace, lowercase, cap length
|
|
48
|
+
*/
|
|
49
|
+
function normalizeText(text, maxLen = 80) {
|
|
50
|
+
if (!text)
|
|
51
|
+
return '';
|
|
52
|
+
// Trim and collapse whitespace
|
|
53
|
+
let normalized = text.split(/\s+/).join(' ').trim();
|
|
54
|
+
// Lowercase
|
|
55
|
+
normalized = normalized.toLowerCase();
|
|
56
|
+
// Cap length
|
|
57
|
+
if (normalized.length > maxLen) {
|
|
58
|
+
normalized = normalized.substring(0, maxLen);
|
|
59
|
+
}
|
|
60
|
+
return normalized;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Round bbox coordinates to reduce noise (default: 2px precision)
|
|
64
|
+
*/
|
|
65
|
+
function roundBBox(bbox, precision = 2) {
|
|
66
|
+
return {
|
|
67
|
+
x: Math.round((bbox.x || 0) / precision) * precision,
|
|
68
|
+
y: Math.round((bbox.y || 0) / precision) * precision,
|
|
69
|
+
width: Math.round((bbox.width || 0) / precision) * precision,
|
|
70
|
+
height: Math.round((bbox.height || 0) / precision) * precision,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Compute stable digest of snapshot for diffing
|
|
75
|
+
*/
|
|
76
|
+
function computeSnapshotDigest(snapshotData) {
|
|
77
|
+
const url = snapshotData.url || '';
|
|
78
|
+
const viewport = snapshotData.viewport || {};
|
|
79
|
+
const elements = snapshotData.elements || [];
|
|
80
|
+
// Canonicalize elements
|
|
81
|
+
const canonicalElements = elements.map((elem) => ({
|
|
82
|
+
id: elem.id,
|
|
83
|
+
role: elem.role || '',
|
|
84
|
+
text_norm: normalizeText(elem.text),
|
|
85
|
+
bbox: roundBBox(elem.bbox || { x: 0, y: 0, width: 0, height: 0 }),
|
|
86
|
+
is_primary: elem.is_primary || false,
|
|
87
|
+
is_clickable: elem.is_clickable || false,
|
|
88
|
+
}));
|
|
89
|
+
// Sort by element id for determinism
|
|
90
|
+
canonicalElements.sort((a, b) => (a.id || 0) - (b.id || 0));
|
|
91
|
+
// Build canonical object
|
|
92
|
+
const canonical = {
|
|
93
|
+
url,
|
|
94
|
+
viewport: {
|
|
95
|
+
width: viewport.width || 0,
|
|
96
|
+
height: viewport.height || 0,
|
|
97
|
+
},
|
|
98
|
+
elements: canonicalElements,
|
|
99
|
+
};
|
|
100
|
+
// Hash
|
|
101
|
+
const canonicalJson = JSON.stringify(canonical);
|
|
102
|
+
const hash = crypto.createHash('sha256').update(canonicalJson, 'utf8').digest('hex');
|
|
103
|
+
return `sha256:${hash}`;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Compute digest of action args for privacy + determinism
|
|
107
|
+
*/
|
|
108
|
+
function computeActionDigest(actionData) {
|
|
109
|
+
const actionType = actionData.type || '';
|
|
110
|
+
const targetId = actionData.target_element_id;
|
|
111
|
+
const canonical = {
|
|
112
|
+
type: actionType,
|
|
113
|
+
target_element_id: targetId,
|
|
114
|
+
};
|
|
115
|
+
// Type-specific canonicalization
|
|
116
|
+
if (actionType === 'TYPE') {
|
|
117
|
+
const text = actionData.text || '';
|
|
118
|
+
canonical.text_len = text.length;
|
|
119
|
+
canonical.text_sha256 = crypto.createHash('sha256').update(text, 'utf8').digest('hex');
|
|
120
|
+
}
|
|
121
|
+
else if (actionType === 'PRESS') {
|
|
122
|
+
canonical.key = actionData.key || '';
|
|
123
|
+
}
|
|
124
|
+
// CLICK has no extra args
|
|
125
|
+
// Hash
|
|
126
|
+
const canonicalJson = JSON.stringify(canonical);
|
|
127
|
+
const hash = crypto.createHash('sha256').update(canonicalJson, 'utf8').digest('hex');
|
|
128
|
+
return `sha256:${hash}`;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Compute SHA256 hash of entire file
|
|
132
|
+
*/
|
|
133
|
+
function computeFileSha256(filePath) {
|
|
134
|
+
const hash = crypto.createHash('sha256');
|
|
135
|
+
const data = fs.readFileSync(filePath);
|
|
136
|
+
hash.update(data);
|
|
137
|
+
return hash.digest('hex');
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Build trace index from JSONL file in single streaming pass
|
|
141
|
+
*/
|
|
142
|
+
function buildTraceIndex(tracePath) {
|
|
143
|
+
if (!fs.existsSync(tracePath)) {
|
|
144
|
+
throw new Error(`Trace file not found: ${tracePath}`);
|
|
145
|
+
}
|
|
146
|
+
// Extract run_id from filename
|
|
147
|
+
const runId = path.basename(tracePath, '.jsonl');
|
|
148
|
+
// Initialize summary
|
|
149
|
+
let firstTs = '';
|
|
150
|
+
let lastTs = '';
|
|
151
|
+
let eventCount = 0;
|
|
152
|
+
let errorCount = 0;
|
|
153
|
+
let finalUrl = null;
|
|
154
|
+
const stepsById = new Map();
|
|
155
|
+
const stepOrder = [];
|
|
156
|
+
// Stream through file, tracking byte offsets
|
|
157
|
+
const fileBuffer = fs.readFileSync(tracePath);
|
|
158
|
+
let byteOffset = 0;
|
|
159
|
+
const lines = fileBuffer.toString('utf-8').split('\n');
|
|
160
|
+
for (const line of lines) {
|
|
161
|
+
const lineBytes = Buffer.byteLength(line + '\n', 'utf-8');
|
|
162
|
+
if (!line.trim()) {
|
|
163
|
+
byteOffset += lineBytes;
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
let event;
|
|
167
|
+
try {
|
|
168
|
+
event = JSON.parse(line);
|
|
169
|
+
}
|
|
170
|
+
catch (e) {
|
|
171
|
+
// Skip malformed lines
|
|
172
|
+
byteOffset += lineBytes;
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
// Extract event metadata
|
|
176
|
+
const eventType = event.type || '';
|
|
177
|
+
const ts = event.ts || event.timestamp || '';
|
|
178
|
+
const stepId = event.step_id || 'step-0';
|
|
179
|
+
const data = event.data || {};
|
|
180
|
+
// Update summary
|
|
181
|
+
eventCount++;
|
|
182
|
+
if (!firstTs) {
|
|
183
|
+
firstTs = ts;
|
|
184
|
+
}
|
|
185
|
+
lastTs = ts;
|
|
186
|
+
if (eventType === 'error') {
|
|
187
|
+
errorCount++;
|
|
188
|
+
}
|
|
189
|
+
// Initialize step if first time seeing this step_id
|
|
190
|
+
if (!stepsById.has(stepId)) {
|
|
191
|
+
stepOrder.push(stepId);
|
|
192
|
+
stepsById.set(stepId, new index_schema_1.StepIndex(stepOrder.length, stepId, null, 'partial', ts, ts, byteOffset, byteOffset + lineBytes, null, null, new index_schema_1.SnapshotInfo(), new index_schema_1.SnapshotInfo(), new index_schema_1.ActionInfo(), new index_schema_1.StepCounters()));
|
|
193
|
+
}
|
|
194
|
+
const step = stepsById.get(stepId);
|
|
195
|
+
// Update step metadata
|
|
196
|
+
step.ts_end = ts;
|
|
197
|
+
step.offset_end = byteOffset + lineBytes;
|
|
198
|
+
step.counters.events++;
|
|
199
|
+
// Handle specific event types
|
|
200
|
+
if (eventType === 'step_start') {
|
|
201
|
+
step.goal = data.goal;
|
|
202
|
+
step.url_before = data.pre_url;
|
|
203
|
+
}
|
|
204
|
+
else if (eventType === 'snapshot') {
|
|
205
|
+
const snapshotId = data.snapshot_id;
|
|
206
|
+
const url = data.url;
|
|
207
|
+
const digest = computeSnapshotDigest(data);
|
|
208
|
+
// First snapshot = before, last snapshot = after
|
|
209
|
+
if (!step.snapshot_before.snapshot_id) {
|
|
210
|
+
step.snapshot_before = new index_schema_1.SnapshotInfo(snapshotId, digest, url);
|
|
211
|
+
step.url_before = step.url_before || url;
|
|
212
|
+
}
|
|
213
|
+
step.snapshot_after = new index_schema_1.SnapshotInfo(snapshotId, digest, url);
|
|
214
|
+
step.url_after = url;
|
|
215
|
+
step.counters.snapshots++;
|
|
216
|
+
finalUrl = url;
|
|
217
|
+
}
|
|
218
|
+
else if (eventType === 'action') {
|
|
219
|
+
step.action = new index_schema_1.ActionInfo(data.type, data.target_element_id, computeActionDigest(data), data.success !== false);
|
|
220
|
+
step.counters.actions++;
|
|
221
|
+
}
|
|
222
|
+
else if (eventType === 'llm_response') {
|
|
223
|
+
step.counters.llm_calls++;
|
|
224
|
+
}
|
|
225
|
+
else if (eventType === 'error') {
|
|
226
|
+
step.status = 'error';
|
|
227
|
+
}
|
|
228
|
+
else if (eventType === 'step_end') {
|
|
229
|
+
if (step.status !== 'error') {
|
|
230
|
+
step.status = 'ok';
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
byteOffset += lineBytes;
|
|
234
|
+
}
|
|
235
|
+
// Build summary
|
|
236
|
+
const summary = new index_schema_1.TraceSummary(firstTs, lastTs, eventCount, stepsById.size, errorCount, finalUrl);
|
|
237
|
+
// Build steps list in order
|
|
238
|
+
const stepsList = stepOrder.map((sid) => stepsById.get(sid));
|
|
239
|
+
// Build trace file info
|
|
240
|
+
const traceFile = new index_schema_1.TraceFileInfo(tracePath, fs.statSync(tracePath).size, computeFileSha256(tracePath));
|
|
241
|
+
// Build final index
|
|
242
|
+
const index = new index_schema_1.TraceIndex(1, runId, new Date().toISOString(), traceFile, summary, stepsList);
|
|
243
|
+
return index;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Build index and write to file
|
|
247
|
+
*/
|
|
248
|
+
function writeTraceIndex(tracePath, indexPath) {
|
|
249
|
+
if (!indexPath) {
|
|
250
|
+
indexPath = tracePath.replace(/\.jsonl$/, '.index.json');
|
|
251
|
+
}
|
|
252
|
+
const index = buildTraceIndex(tracePath);
|
|
253
|
+
fs.writeFileSync(indexPath, JSON.stringify(index.toJSON(), null, 2));
|
|
254
|
+
return indexPath;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Read events for a specific step using byte offsets from index
|
|
258
|
+
*/
|
|
259
|
+
function readStepEvents(tracePath, offsetStart, offsetEnd) {
|
|
260
|
+
const events = [];
|
|
261
|
+
const fd = fs.openSync(tracePath, 'r');
|
|
262
|
+
const bytesToRead = offsetEnd - offsetStart;
|
|
263
|
+
const buffer = Buffer.alloc(bytesToRead);
|
|
264
|
+
fs.readSync(fd, buffer, 0, bytesToRead, offsetStart);
|
|
265
|
+
fs.closeSync(fd);
|
|
266
|
+
// Parse lines
|
|
267
|
+
const chunk = buffer.toString('utf-8');
|
|
268
|
+
const lines = chunk.split('\n');
|
|
269
|
+
for (const line of lines) {
|
|
270
|
+
if (!line.trim())
|
|
271
|
+
continue;
|
|
272
|
+
try {
|
|
273
|
+
const event = JSON.parse(line);
|
|
274
|
+
events.push(event);
|
|
275
|
+
}
|
|
276
|
+
catch (e) {
|
|
277
|
+
// Skip malformed lines
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return events;
|
|
281
|
+
}
|
|
282
|
+
//# sourceMappingURL=indexer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version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uB;QACzB,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -25,6 +25,10 @@ export declare class JsonlTraceSink extends TraceSink {
|
|
|
25
25
|
* Close the sink and flush buffered data
|
|
26
26
|
*/
|
|
27
27
|
close(): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Generate trace index file (automatic on close)
|
|
30
|
+
*/
|
|
31
|
+
private generateIndex;
|
|
28
32
|
/**
|
|
29
33
|
* Get sink type identifier
|
|
30
34
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonl-sink.d.ts","sourceRoot":"","sources":["../../src/tracing/jsonl-sink.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnC;;GAEG;AACH,qBAAa,cAAe,SAAQ,SAAS;IAC3C,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,WAAW,CAA+B;IAClD,OAAO,CAAC,MAAM,CAAkB;IAEhC;;;OAGG;gBACS,QAAQ,EAAE,MAAM;IAiC5B;;;OAGG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAoCtC;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"jsonl-sink.d.ts","sourceRoot":"","sources":["../../src/tracing/jsonl-sink.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnC;;GAEG;AACH,qBAAa,cAAe,SAAQ,SAAS;IAC3C,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,WAAW,CAA+B;IAClD,OAAO,CAAC,MAAM,CAAkB;IAEhC;;;OAGG;gBACS,QAAQ,EAAE,MAAM;IAiC5B;;;OAGG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAoCtC;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAkC5B;;OAEG;IACH,OAAO,CAAC,aAAa;IAUrB;;OAEG;IACH,WAAW,IAAI,MAAM;IAIrB;;OAEG;IACH,OAAO,IAAI,MAAM;IAIjB;;OAEG;IACH,QAAQ,IAAI,OAAO;CAGpB"}
|
|
@@ -140,11 +140,26 @@ class JsonlTraceSink extends sink_1.TraceSink {
|
|
|
140
140
|
// Silently ignore close errors in production
|
|
141
141
|
// (they're logged during stream lifetime if needed)
|
|
142
142
|
}
|
|
143
|
+
// Generate index after closing file
|
|
144
|
+
this.generateIndex();
|
|
143
145
|
// Always resolve, don't reject on close errors
|
|
144
146
|
resolve();
|
|
145
147
|
});
|
|
146
148
|
});
|
|
147
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Generate trace index file (automatic on close)
|
|
152
|
+
*/
|
|
153
|
+
generateIndex() {
|
|
154
|
+
try {
|
|
155
|
+
const { writeTraceIndex } = require('./indexer');
|
|
156
|
+
writeTraceIndex(this.path);
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
// Non-fatal: log but don't crash
|
|
160
|
+
console.log(`⚠️ Failed to generate trace index: ${error.message}`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
148
163
|
/**
|
|
149
164
|
* Get sink type identifier
|
|
150
165
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonl-sink.js","sourceRoot":"","sources":["../../src/tracing/jsonl-sink.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,uCAAyB;AACzB,2CAA6B;AAC7B,iCAAmC;AAEnC;;GAEG;AACH,MAAa,cAAe,SAAQ,gBAAS;IAK3C;;;OAGG;IACH,YAAY,QAAgB;QAC1B,KAAK,EAAE,CAAC;QARF,gBAAW,GAA0B,IAAI,CA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,EAAE,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;IAED;;OAEG;IACH,WAAW;QACT,OAAO,kBAAkB,IAAI,CAAC,IAAI,GAAG,CAAC;IACxC,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AAxJD,wCAwJC"}
|
|
@@ -17,22 +17,27 @@ export declare const SENTIENCE_API_URL = "https://api.sentienceapi.com";
|
|
|
17
17
|
* Create tracer with automatic tier detection
|
|
18
18
|
*
|
|
19
19
|
* Tier Detection:
|
|
20
|
-
* - If apiKey is provided: Try to initialize CloudTraceSink (Pro/Enterprise)
|
|
21
|
-
* - If cloud init fails or
|
|
20
|
+
* - If apiKey is provided AND uploadTrace is true: Try to initialize CloudTraceSink (Pro/Enterprise)
|
|
21
|
+
* - If cloud init fails, no apiKey, or uploadTrace is false: Fall back to JsonlTraceSink (Free tier)
|
|
22
22
|
*
|
|
23
23
|
* @param options - Configuration options
|
|
24
24
|
* @param options.apiKey - Sentience API key (e.g., "sk_pro_xxxxx")
|
|
25
25
|
* @param options.runId - Unique identifier for this agent run (generates UUID if not provided)
|
|
26
26
|
* @param options.apiUrl - Sentience API base URL (default: https://api.sentienceapi.com)
|
|
27
27
|
* @param options.logger - Optional logger instance for logging file sizes and errors
|
|
28
|
+
* @param options.uploadTrace - Enable cloud trace upload (default: true for backward compatibility)
|
|
28
29
|
* @returns Tracer configured with appropriate sink
|
|
29
30
|
*
|
|
30
31
|
* @example
|
|
31
32
|
* ```typescript
|
|
32
|
-
* // Pro tier user
|
|
33
|
-
* const tracer = await createTracer({ apiKey: "sk_pro_xyz", runId: "demo" });
|
|
33
|
+
* // Pro tier user with cloud upload
|
|
34
|
+
* const tracer = await createTracer({ apiKey: "sk_pro_xyz", runId: "demo", uploadTrace: true });
|
|
34
35
|
* // Returns: Tracer with CloudTraceSink
|
|
35
36
|
*
|
|
37
|
+
* // Pro tier user with local-only tracing
|
|
38
|
+
* const tracer = await createTracer({ apiKey: "sk_pro_xyz", runId: "demo", uploadTrace: false });
|
|
39
|
+
* // Returns: Tracer with JsonlTraceSink (local-only)
|
|
40
|
+
*
|
|
36
41
|
* // Free tier user
|
|
37
42
|
* const tracer = await createTracer({ runId: "demo" });
|
|
38
43
|
* // Returns: Tracer with JsonlTraceSink (local-only)
|
|
@@ -40,7 +45,7 @@ export declare const SENTIENCE_API_URL = "https://api.sentienceapi.com";
|
|
|
40
45
|
* // Use with agent
|
|
41
46
|
* const agent = new SentienceAgent(browser, llm, 50, true, tracer);
|
|
42
47
|
* await agent.act("Click search");
|
|
43
|
-
* await tracer.close(); // Uploads to cloud if Pro tier
|
|
48
|
+
* await tracer.close(); // Uploads to cloud if uploadTrace: true and Pro tier
|
|
44
49
|
* ```
|
|
45
50
|
*/
|
|
46
51
|
export declare function createTracer(options: {
|
|
@@ -48,6 +53,7 @@ export declare function createTracer(options: {
|
|
|
48
53
|
runId?: string;
|
|
49
54
|
apiUrl?: string;
|
|
50
55
|
logger?: SentienceLogger;
|
|
56
|
+
uploadTrace?: boolean;
|
|
51
57
|
}): Promise<Tracer>;
|
|
52
58
|
/**
|
|
53
59
|
* Synchronous version of createTracer for non-async contexts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracer-factory.d.ts","sourceRoot":"","sources":["../../src/tracing/tracer-factory.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AASH,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAkB,eAAe,EAAE,MAAM,cAAc,CAAC;AAG/D;;GAEG;AACH,eAAO,MAAM,iBAAiB,iCAAiC,CAAC;AA2IhE
|
|
1
|
+
{"version":3,"file":"tracer-factory.d.ts","sourceRoot":"","sources":["../../src/tracing/tracer-factory.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AASH,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAkB,eAAe,EAAE,MAAM,cAAc,CAAC;AAG/D;;GAEG;AACH,eAAO,MAAM,iBAAiB,iCAAiC,CAAC;AA2IhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,GAAG,OAAO,CAAC,MAAM,CAAC,CAoElB;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAYxD"}
|
|
@@ -174,22 +174,27 @@ function httpPost(url, data, headers) {
|
|
|
174
174
|
* Create tracer with automatic tier detection
|
|
175
175
|
*
|
|
176
176
|
* Tier Detection:
|
|
177
|
-
* - If apiKey is provided: Try to initialize CloudTraceSink (Pro/Enterprise)
|
|
178
|
-
* - If cloud init fails or
|
|
177
|
+
* - If apiKey is provided AND uploadTrace is true: Try to initialize CloudTraceSink (Pro/Enterprise)
|
|
178
|
+
* - If cloud init fails, no apiKey, or uploadTrace is false: Fall back to JsonlTraceSink (Free tier)
|
|
179
179
|
*
|
|
180
180
|
* @param options - Configuration options
|
|
181
181
|
* @param options.apiKey - Sentience API key (e.g., "sk_pro_xxxxx")
|
|
182
182
|
* @param options.runId - Unique identifier for this agent run (generates UUID if not provided)
|
|
183
183
|
* @param options.apiUrl - Sentience API base URL (default: https://api.sentienceapi.com)
|
|
184
184
|
* @param options.logger - Optional logger instance for logging file sizes and errors
|
|
185
|
+
* @param options.uploadTrace - Enable cloud trace upload (default: true for backward compatibility)
|
|
185
186
|
* @returns Tracer configured with appropriate sink
|
|
186
187
|
*
|
|
187
188
|
* @example
|
|
188
189
|
* ```typescript
|
|
189
|
-
* // Pro tier user
|
|
190
|
-
* const tracer = await createTracer({ apiKey: "sk_pro_xyz", runId: "demo" });
|
|
190
|
+
* // Pro tier user with cloud upload
|
|
191
|
+
* const tracer = await createTracer({ apiKey: "sk_pro_xyz", runId: "demo", uploadTrace: true });
|
|
191
192
|
* // Returns: Tracer with CloudTraceSink
|
|
192
193
|
*
|
|
194
|
+
* // Pro tier user with local-only tracing
|
|
195
|
+
* const tracer = await createTracer({ apiKey: "sk_pro_xyz", runId: "demo", uploadTrace: false });
|
|
196
|
+
* // Returns: Tracer with JsonlTraceSink (local-only)
|
|
197
|
+
*
|
|
193
198
|
* // Free tier user
|
|
194
199
|
* const tracer = await createTracer({ runId: "demo" });
|
|
195
200
|
* // Returns: Tracer with JsonlTraceSink (local-only)
|
|
@@ -197,23 +202,27 @@ function httpPost(url, data, headers) {
|
|
|
197
202
|
* // Use with agent
|
|
198
203
|
* const agent = new SentienceAgent(browser, llm, 50, true, tracer);
|
|
199
204
|
* await agent.act("Click search");
|
|
200
|
-
* await tracer.close(); // Uploads to cloud if Pro tier
|
|
205
|
+
* await tracer.close(); // Uploads to cloud if uploadTrace: true and Pro tier
|
|
201
206
|
* ```
|
|
202
207
|
*/
|
|
203
208
|
async function createTracer(options) {
|
|
204
209
|
const runId = options.runId || (0, crypto_1.randomUUID)();
|
|
205
210
|
const apiUrl = options.apiUrl || exports.SENTIENCE_API_URL;
|
|
211
|
+
// Default uploadTrace to true for backward compatibility
|
|
212
|
+
const uploadTrace = options.uploadTrace !== false;
|
|
206
213
|
// PRODUCTION FIX: Recover orphaned traces from previous crashes
|
|
207
214
|
// Note: This is skipped in test environments (see recoverOrphanedTraces function)
|
|
208
215
|
// Run in background to avoid blocking tracer creation
|
|
209
|
-
if
|
|
216
|
+
// Only recover if uploadTrace is enabled
|
|
217
|
+
if (options.apiKey && uploadTrace) {
|
|
210
218
|
// Don't await - run in background to avoid blocking
|
|
211
219
|
recoverOrphanedTraces(options.apiKey, apiUrl).catch(() => {
|
|
212
220
|
// Silently fail - orphan recovery should not block tracer creation
|
|
213
221
|
});
|
|
214
222
|
}
|
|
215
223
|
// 1. Try to initialize Cloud Sink (Pro/Enterprise tier)
|
|
216
|
-
if
|
|
224
|
+
// Only attempt cloud init if uploadTrace is enabled
|
|
225
|
+
if (options.apiKey && uploadTrace) {
|
|
217
226
|
try {
|
|
218
227
|
// Request pre-signed upload URL from backend
|
|
219
228
|
const response = await httpPost(`${apiUrl}/v1/traces/init`, { run_id: runId }, { Authorization: `Bearer ${options.apiKey}` });
|