@armature-tech/mcp-analytics 0.6.18 → 0.6.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +99 -4
  2. package/SKILL.md +29 -4
  3. package/dist/cjs/cli.d.ts +2 -0
  4. package/dist/cjs/cli.js +62 -0
  5. package/dist/cjs/doctor-args.d.ts +2 -0
  6. package/dist/cjs/doctor-args.js +101 -0
  7. package/dist/cjs/doctor.d.ts +63 -0
  8. package/dist/cjs/doctor.js +325 -0
  9. package/dist/cjs/emit.d.ts +3 -0
  10. package/dist/cjs/emit.js +18 -3
  11. package/dist/cjs/events.d.ts +18 -5
  12. package/dist/cjs/events.js +127 -41
  13. package/dist/cjs/index.d.ts +6 -4
  14. package/dist/cjs/index.js +15 -1
  15. package/dist/cjs/mastra.js +42 -0
  16. package/dist/cjs/queue.d.ts +9 -0
  17. package/dist/cjs/queue.js +116 -0
  18. package/dist/cjs/recorder.js +157 -70
  19. package/dist/cjs/redact-secrets.d.ts +10 -0
  20. package/dist/cjs/redact-secrets.js +121 -0
  21. package/dist/cjs/request-capability.d.ts +12 -0
  22. package/dist/cjs/request-capability.js +50 -0
  23. package/dist/cjs/sanitize.d.ts +5 -1
  24. package/dist/cjs/sanitize.js +51 -37
  25. package/dist/cjs/server.js +20 -0
  26. package/dist/cjs/types.d.ts +25 -1
  27. package/dist/esm/cli.d.ts +2 -0
  28. package/dist/esm/cli.js +60 -0
  29. package/dist/esm/doctor-args.d.ts +2 -0
  30. package/dist/esm/doctor-args.js +97 -0
  31. package/dist/esm/doctor.d.ts +63 -0
  32. package/dist/esm/doctor.js +315 -0
  33. package/dist/esm/emit.d.ts +3 -0
  34. package/dist/esm/emit.js +14 -1
  35. package/dist/esm/events.d.ts +18 -5
  36. package/dist/esm/events.js +124 -40
  37. package/dist/esm/index.d.ts +6 -4
  38. package/dist/esm/index.js +5 -3
  39. package/dist/esm/mastra.js +42 -0
  40. package/dist/esm/queue.d.ts +9 -0
  41. package/dist/esm/queue.js +112 -0
  42. package/dist/esm/recorder.js +159 -72
  43. package/dist/esm/redact-secrets.d.ts +10 -0
  44. package/dist/esm/redact-secrets.js +115 -0
  45. package/dist/esm/request-capability.d.ts +12 -0
  46. package/dist/esm/request-capability.js +45 -0
  47. package/dist/esm/sanitize.d.ts +5 -1
  48. package/dist/esm/sanitize.js +50 -36
  49. package/dist/esm/server.js +20 -0
  50. package/dist/esm/types.d.ts +25 -1
  51. package/package.json +6 -1
@@ -0,0 +1,325 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultDoctorOptions = exports.runDoctor = exports.verifyIngest = exports.detectLocalSdks = exports.inspectToolCoverage = exports.classifyToolInstrumentation = exports.inspectMcp = void 0;
4
+ const promises_1 = require("node:fs/promises");
5
+ const node_path_1 = require("node:path");
6
+ const index_js_1 = require("@modelcontextprotocol/sdk/client/index.js");
7
+ const stdio_js_1 = require("@modelcontextprotocol/sdk/client/stdio.js");
8
+ const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
9
+ const DEFAULT_INGEST_URL = "https://app.armature.tech/api/mcp-analytics/ingest";
10
+ const DEFAULT_TIMEOUT_MS = 10_000;
11
+ const CURRENT_TELEMETRY_MARKER = "Conversation telemetry.";
12
+ const LEGACY_TELEMETRY_MARKERS = [
13
+ "Pass telemetry.user_intent",
14
+ "Pass telemetry.intent",
15
+ ];
16
+ const isRecord = (value) => (typeof value === "object" && value !== null && !Array.isArray(value));
17
+ const errorMessage = (error) => {
18
+ if (error instanceof Error && error.message)
19
+ return error.message;
20
+ return String(error || "unknown error");
21
+ };
22
+ const withTimeout = async (promise, timeoutMs, label) => {
23
+ let timer;
24
+ try {
25
+ return await Promise.race([
26
+ promise,
27
+ new Promise((_resolve, reject) => {
28
+ timer = setTimeout(() => reject(new Error(`${label} timed out after ${timeoutMs}ms`)), timeoutMs);
29
+ }),
30
+ ]);
31
+ }
32
+ finally {
33
+ if (timer)
34
+ clearTimeout(timer);
35
+ }
36
+ };
37
+ const currentProcessEnvironment = () => {
38
+ const out = {};
39
+ for (const [key, value] of Object.entries(process.env)) {
40
+ if (typeof value === "string")
41
+ out[key] = value;
42
+ }
43
+ return out;
44
+ };
45
+ const inspectMcp = async (options) => {
46
+ const client = new index_js_1.Client({ name: "armature-mcp-doctor", version: "1" });
47
+ const transport = options.target.kind === "http"
48
+ ? new streamableHttp_js_1.StreamableHTTPClientTransport(new URL(options.target.url), {
49
+ requestInit: { headers: options.target.headers },
50
+ })
51
+ : new stdio_js_1.StdioClientTransport({
52
+ command: options.target.command,
53
+ args: options.target.args,
54
+ cwd: options.target.cwd,
55
+ env: currentProcessEnvironment(),
56
+ stderr: "pipe",
57
+ });
58
+ if (transport instanceof stdio_js_1.StdioClientTransport) {
59
+ // The SDK exposes the PassThrough before spawning the child, so start
60
+ // draining immediately. Otherwise a chatty server can fill the bounded
61
+ // stderr pipe and block before it answers the MCP handshake.
62
+ transport.stderr?.on("data", () => undefined);
63
+ }
64
+ try {
65
+ await withTimeout(client.connect(transport), options.timeoutMs, "MCP initialize");
66
+ const listed = await withTimeout(client.listTools(), options.timeoutMs, "MCP tools/list");
67
+ const server = client.getServerVersion();
68
+ return {
69
+ serverName: server?.name,
70
+ serverVersion: server?.version,
71
+ tools: listed.tools.map((tool) => ({
72
+ name: tool.name,
73
+ description: tool.description,
74
+ inputSchema: tool.inputSchema,
75
+ })),
76
+ };
77
+ }
78
+ finally {
79
+ // Some stdio servers do not exit promptly after stdin closes. Diagnostics
80
+ // must still return a result instead of hanging on cleanup.
81
+ await withTimeout(client.close(), Math.min(options.timeoutMs, 1_000), "MCP close")
82
+ .catch(() => {
83
+ if (transport instanceof stdio_js_1.StdioClientTransport && transport.pid) {
84
+ try {
85
+ process.kill(transport.pid, "SIGTERM");
86
+ }
87
+ catch {
88
+ // The child may already have exited between the pid read and kill.
89
+ }
90
+ }
91
+ });
92
+ }
93
+ };
94
+ exports.inspectMcp = inspectMcp;
95
+ const telemetryShape = (tool) => {
96
+ if (!isRecord(tool.inputSchema))
97
+ return null;
98
+ const properties = tool.inputSchema.properties;
99
+ if (!isRecord(properties))
100
+ return null;
101
+ return isRecord(properties.telemetry) ? properties.telemetry : null;
102
+ };
103
+ const classifyToolInstrumentation = (tool) => {
104
+ const inputProperties = isRecord(tool.inputSchema)
105
+ && isRecord(tool.inputSchema.properties)
106
+ ? tool.inputSchema.properties
107
+ : null;
108
+ const ownsTelemetryField = Boolean(inputProperties && "telemetry" in inputProperties);
109
+ const telemetry = telemetryShape(tool);
110
+ if (!telemetry)
111
+ return ownsTelemetryField ? "owned" : "missing";
112
+ const properties = isRecord(telemetry.properties) ? telemetry.properties : {};
113
+ const telemetryDescription = typeof telemetry.description === "string"
114
+ ? telemetry.description
115
+ : "";
116
+ const toolDescription = tool.description || "";
117
+ if ("agent_thinking" in properties
118
+ && "user_intent" in properties
119
+ && telemetryDescription.includes(CURRENT_TELEMETRY_MARKER)) {
120
+ return "current";
121
+ }
122
+ if ("intent" in properties
123
+ || "context" in properties
124
+ || LEGACY_TELEMETRY_MARKERS.some((marker) => toolDescription.includes(marker))) {
125
+ return "legacy";
126
+ }
127
+ return ownsTelemetryField ? "owned" : "missing";
128
+ };
129
+ exports.classifyToolInstrumentation = classifyToolInstrumentation;
130
+ const inspectToolCoverage = (tools) => {
131
+ const current = [];
132
+ const legacy = [];
133
+ const owned = [];
134
+ const missing = [];
135
+ for (const tool of tools) {
136
+ const classification = (0, exports.classifyToolInstrumentation)(tool);
137
+ if (classification === "current")
138
+ current.push(tool.name);
139
+ else if (classification === "legacy")
140
+ legacy.push(tool.name);
141
+ else if (classification === "owned")
142
+ owned.push(tool.name);
143
+ else
144
+ missing.push(tool.name);
145
+ }
146
+ return { current, legacy, owned, missing, total: tools.length };
147
+ };
148
+ exports.inspectToolCoverage = inspectToolCoverage;
149
+ const readIfPresent = async (path) => {
150
+ try {
151
+ return await (0, promises_1.readFile)(path, "utf8");
152
+ }
153
+ catch (error) {
154
+ const code = isRecord(error) ? error.code : undefined;
155
+ if (code === "ENOENT")
156
+ return null;
157
+ throw error;
158
+ }
159
+ };
160
+ const detectLocalSdks = async (cwd) => {
161
+ const found = [];
162
+ const packageJson = await readIfPresent((0, node_path_1.resolve)(cwd, "package.json"));
163
+ if (packageJson) {
164
+ try {
165
+ const parsed = JSON.parse(packageJson);
166
+ const sections = [parsed.dependencies, parsed.devDependencies, parsed.peerDependencies];
167
+ for (const section of sections) {
168
+ if (isRecord(section) && typeof section["@armature-tech/mcp-analytics"] === "string") {
169
+ found.push({
170
+ language: "typescript",
171
+ declaration: `@armature-tech/mcp-analytics ${section["@armature-tech/mcp-analytics"]}`,
172
+ });
173
+ break;
174
+ }
175
+ }
176
+ }
177
+ catch {
178
+ // A malformed package.json will be reported by the customer's package manager.
179
+ }
180
+ }
181
+ const pyproject = await readIfPresent((0, node_path_1.resolve)(cwd, "pyproject.toml"));
182
+ const requirements = await readIfPresent((0, node_path_1.resolve)(cwd, "requirements.txt"));
183
+ const pythonDeclaration = [pyproject, requirements]
184
+ .filter((value) => Boolean(value))
185
+ .join("\n")
186
+ .match(/armature-mcp-analytics(?:\[[^\]]+\])?(?:\s*[<>=~!]+\s*[^\s"',\]]+)?/i)?.[0];
187
+ if (pythonDeclaration) {
188
+ found.push({ language: "python", declaration: pythonDeclaration.replace(/["',]/g, "") });
189
+ }
190
+ const goMod = await readIfPresent((0, node_path_1.resolve)(cwd, "go.mod"));
191
+ const goDeclaration = goMod
192
+ ?.match(/github\.com\/armature-tech\/mcp-analytics-go(?:\/[^\s]+)?\s+v[^\s)]+/)?.[0];
193
+ if (goDeclaration)
194
+ found.push({ language: "go", declaration: goDeclaration });
195
+ return found;
196
+ };
197
+ exports.detectLocalSdks = detectLocalSdks;
198
+ const verifyIngest = async (endpoint, apiKey, timeoutMs) => {
199
+ const url = new URL(endpoint);
200
+ if (!["http:", "https:"].includes(url.protocol)) {
201
+ throw new Error("ingest URL must use http or https");
202
+ }
203
+ const controller = new AbortController();
204
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
205
+ try {
206
+ // The ingest route resolves bearer auth before accepting an empty batch,
207
+ // so this validates reachability and the key without creating a session or
208
+ // sending tool, user, or response content. Keep that server contract covered
209
+ // by test/api-mcp-analytics-ingest-doctor.test.js.
210
+ const response = await fetch(url, {
211
+ method: "POST",
212
+ headers: {
213
+ "content-type": "application/json",
214
+ authorization: `Bearer ${apiKey}`,
215
+ },
216
+ body: JSON.stringify({ schema_version: 1, events: [] }),
217
+ signal: controller.signal,
218
+ });
219
+ // Drain the body so undici can release its pooled connection promptly and
220
+ // the one-shot CLI does not appear to hang after printing the report.
221
+ await response.arrayBuffer();
222
+ if (!response.ok) {
223
+ throw new Error(`Armature ingest returned HTTP ${response.status}`);
224
+ }
225
+ }
226
+ finally {
227
+ clearTimeout(timer);
228
+ }
229
+ };
230
+ exports.verifyIngest = verifyIngest;
231
+ const pass = (id, label, detail) => ({
232
+ id, label, detail, status: "pass",
233
+ });
234
+ const warn = (id, label, detail, remediation) => ({
235
+ id, label, detail, status: "warn", ...(remediation ? { remediation } : {}),
236
+ });
237
+ const fail = (id, label, detail, remediation) => ({
238
+ id, label, detail, status: "fail", ...(remediation ? { remediation } : {}),
239
+ });
240
+ const runDoctor = async (options, dependencies = { inspectMcp: exports.inspectMcp, detectLocalSdks: exports.detectLocalSdks, verifyIngest: exports.verifyIngest }, environment = process.env) => {
241
+ const checks = [];
242
+ try {
243
+ const sdks = await dependencies.detectLocalSdks(options.cwd);
244
+ if (sdks.length === 0) {
245
+ checks.push(warn("sdk-declaration", "SDK dependency", "No Armature SDK declaration was found in this directory.", "Run the doctor from the MCP project root, or confirm the SDK is installed in the deployed project."));
246
+ }
247
+ else {
248
+ checks.push(pass("sdk-declaration", "SDK dependency", sdks.map((sdk) => `${sdk.language}: ${sdk.declaration}`).join("; ")));
249
+ }
250
+ }
251
+ catch (error) {
252
+ checks.push(warn("sdk-declaration", "SDK dependency", errorMessage(error)));
253
+ }
254
+ try {
255
+ const inspection = await dependencies.inspectMcp(options);
256
+ const identity = [inspection.serverName, inspection.serverVersion].filter(Boolean).join(" ");
257
+ checks.push(pass("mcp-initialize", "MCP initialize", identity ? `Connected to ${identity}.` : "The server completed the MCP handshake."));
258
+ if (inspection.tools.length === 0) {
259
+ checks.push(fail("tools-list", "Tool discovery", "The server returned zero tools, so wrapping cannot be verified.", "Register at least one tool and run the doctor again."));
260
+ }
261
+ else {
262
+ checks.push(pass("tools-list", "Tool discovery", `The server returned ${inspection.tools.length} tool${inspection.tools.length === 1 ? "" : "s"}.`));
263
+ const coverage = (0, exports.inspectToolCoverage)(inspection.tools);
264
+ if (!options.expectCapture) {
265
+ const exposed = coverage.current.length + coverage.legacy.length;
266
+ checks.push(exposed === 0
267
+ ? pass("tool-wrapping", "Telemetry capture", "No Armature telemetry fields are advertised, as requested.")
268
+ : warn("tool-wrapping", "Telemetry capture", `${exposed}/${coverage.total} tools still advertise Armature telemetry fields.`, "Confirm captureTelemetry=false is applied before tools are registered."));
269
+ }
270
+ else if (coverage.missing.length > 0) {
271
+ const sample = coverage.missing.slice(0, 5).join(", ");
272
+ checks.push(fail("tool-wrapping", "Tool wrapping", `${coverage.missing.length}/${coverage.total} tools do not expose the Armature telemetry contract${sample ? `: ${sample}` : ""}.`, "Wrap the same server instance that is started, and register tools inside withMcpAnalytics or through an Armature recorder."));
273
+ }
274
+ else if (coverage.legacy.length > 0) {
275
+ checks.push(warn("tool-wrapping", "Tool wrapping", `All ${coverage.total} tools are wrapped, but ${coverage.legacy.length} use the legacy telemetry contract.`, "Upgrade the Armature SDK and restart the MCP server."));
276
+ }
277
+ else if (coverage.owned.length > 0) {
278
+ const sample = coverage.owned.slice(0, 5).join(", ");
279
+ checks.push(warn("tool-wrapping", "Tool wrapping", `${coverage.current.length}/${coverage.total} tools expose the current Armature telemetry contract; ${coverage.owned.length} own a top-level telemetry field and are intentionally untouched${sample ? `: ${sample}` : ""}.`, "Rename the tool-owned telemetry input if you want Armature analytics for that tool, then restart the MCP server."));
280
+ }
281
+ else {
282
+ checks.push(pass("tool-wrapping", "Tool wrapping", `All ${coverage.total} tools expose the current Armature telemetry contract.`));
283
+ }
284
+ }
285
+ }
286
+ catch (error) {
287
+ checks.push(fail("mcp-initialize", "MCP initialize", errorMessage(error), options.target.kind === "http"
288
+ ? "Start the MCP server, verify the URL/auth headers, and run the doctor again."
289
+ : "Run the server command directly once, fix startup errors, then run the doctor again."));
290
+ }
291
+ if (options.skipIngest) {
292
+ checks.push(warn("ingest-auth", "Armature ingest", "Skipped by --skip-ingest; no network request was made."));
293
+ }
294
+ else {
295
+ const apiKey = environment.ANALYTICS_INGEST_API_KEY;
296
+ const endpoint = environment.ANALYTICS_INGEST_URL || DEFAULT_INGEST_URL;
297
+ if (!apiKey) {
298
+ checks.push(fail("ingest-auth", "Armature ingest", "ANALYTICS_INGEST_API_KEY is not set in the doctor environment.", "Export the same ingest key used by the MCP server, then run the doctor again."));
299
+ }
300
+ else {
301
+ try {
302
+ await dependencies.verifyIngest(endpoint, apiKey, options.timeoutMs);
303
+ checks.push(pass("ingest-auth", "Armature ingest", "The endpoint accepted an empty authenticated health probe; no session or customer content was sent."));
304
+ }
305
+ catch (error) {
306
+ checks.push(fail("ingest-auth", "Armature ingest", errorMessage(error), "Check ANALYTICS_INGEST_API_KEY and ANALYTICS_INGEST_URL, then run the doctor again."));
307
+ }
308
+ }
309
+ }
310
+ return {
311
+ healthy: !checks.some((check) => check.status === "fail"),
312
+ target: options.target.kind,
313
+ checks,
314
+ };
315
+ };
316
+ exports.runDoctor = runDoctor;
317
+ const defaultDoctorOptions = (target) => ({
318
+ target,
319
+ cwd: process.cwd(),
320
+ timeoutMs: DEFAULT_TIMEOUT_MS,
321
+ expectCapture: true,
322
+ skipIngest: false,
323
+ json: false,
324
+ });
325
+ exports.defaultDoctorOptions = defaultDoctorOptions;
@@ -9,6 +9,8 @@ export declare const defaultMcpAnalyticsConfig: {
9
9
  export declare const resolveEndpointUrl: (config: McpAnalyticsConfig) => string;
10
10
  export declare const resolveApiKey: (config: McpAnalyticsConfig) => string | undefined;
11
11
  export declare const resolveActorSeed: (config: McpAnalyticsConfig, input: ActorIdResolverInput) => Promise<string>;
12
+ /** Resolve the optional caller-provided identifier without interpreting it. */
13
+ export declare const resolveActorIdentifier: (config: McpAnalyticsConfig, input: ActorIdResolverInput) => Promise<string | undefined>;
12
14
  export declare const postTelemetryEvent: (batch: AnalyticsIngestBatch, config?: McpAnalyticsConfig) => Promise<{
13
15
  skipped: boolean;
14
16
  reason: string;
@@ -20,6 +22,7 @@ export declare const postTelemetryEvent: (batch: AnalyticsIngestBatch, config?:
20
22
  status: number;
21
23
  reason?: undefined;
22
24
  }>;
25
+ export declare const reportEmitError: (error: unknown, batch: AnalyticsIngestBatch, config: McpAnalyticsConfig) => void;
23
26
  export declare const emitTelemetryEvent: (batch: AnalyticsIngestBatch, config?: McpAnalyticsConfig) => Promise<void>;
24
27
  export declare const createFlushableEmitter: (config: McpAnalyticsConfig) => {
25
28
  emitBatch: (batch: AnalyticsIngestBatch) => Promise<void>;
package/dist/cjs/emit.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createFlushableEmitter = exports.emitTelemetryEvent = exports.postTelemetryEvent = exports.resolveActorSeed = exports.resolveApiKey = exports.resolveEndpointUrl = exports.defaultMcpAnalyticsConfig = void 0;
3
+ exports.createFlushableEmitter = exports.emitTelemetryEvent = exports.reportEmitError = exports.postTelemetryEvent = exports.resolveActorIdentifier = exports.resolveActorSeed = exports.resolveApiKey = exports.resolveEndpointUrl = exports.defaultMcpAnalyticsConfig = void 0;
4
4
  const utils_js_1 = require("./utils.js");
5
5
  exports.defaultMcpAnalyticsConfig = {
6
6
  armature: {
@@ -40,6 +40,20 @@ const resolveActorSeed = async (config, input) => {
40
40
  return "anonymous";
41
41
  };
42
42
  exports.resolveActorSeed = resolveActorSeed;
43
+ const MAX_ACTOR_IDENTIFIER_BYTES = 8 * 1024;
44
+ /** Resolve the optional caller-provided identifier without interpreting it. */
45
+ const resolveActorIdentifier = async (config, input) => {
46
+ const configured = config.armature?.actorIdentifier;
47
+ if (configured === undefined)
48
+ return undefined;
49
+ const value = typeof configured === "function" ? await configured(input) : configured;
50
+ if (typeof value !== "string" || value.length === 0)
51
+ return undefined;
52
+ return new TextEncoder().encode(value).byteLength <= MAX_ACTOR_IDENTIFIER_BYTES
53
+ ? value
54
+ : undefined;
55
+ };
56
+ exports.resolveActorIdentifier = resolveActorIdentifier;
43
57
  const postTelemetryEvent = async (batch, config = exports.defaultMcpAnalyticsConfig) => {
44
58
  const endpointUrl = (0, exports.resolveEndpointUrl)(config);
45
59
  const apiKey = (0, exports.resolveApiKey)(config);
@@ -78,6 +92,7 @@ const reportEmitError = (error, batch, config) => {
78
92
  // eslint-disable-next-line no-console
79
93
  console.warn("[mcp-analytics] telemetry emit failed:", error);
80
94
  };
95
+ exports.reportEmitError = reportEmitError;
81
96
  const emitTelemetryEvent = (batch, config = exports.defaultMcpAnalyticsConfig) => {
82
97
  if (config.armature?.enabled === false) {
83
98
  return Promise.resolve();
@@ -91,7 +106,7 @@ const emitTelemetryEvent = (batch, config = exports.defaultMcpAnalyticsConfig) =
91
106
  await emit(batch);
92
107
  }
93
108
  catch (error) {
94
- reportEmitError(error, batch, config);
109
+ (0, exports.reportEmitError)(error, batch, config);
95
110
  }
96
111
  };
97
112
  if (config.armature?.delivery === "await") {
@@ -118,7 +133,7 @@ const createFlushableEmitter = (config) => {
118
133
  await emit(batch);
119
134
  }
120
135
  catch (error) {
121
- reportEmitError(error, batch, config);
136
+ (0, exports.reportEmitError)(error, batch, config);
122
137
  }
123
138
  };
124
139
  if (config.armature?.delivery === "await") {
@@ -1,4 +1,4 @@
1
- import type { AnalyticsEventKind, AnalyticsIngestBatch, AnalyticsIngestEvent, McpClientInfo, RedactFunction, RequestExtra, TelemetryArgs } from "./types.js";
1
+ import type { AnalyticsEventKind, AnalyticsIngestBatch, AnalyticsIngestEvent, McpClientInfo, RedactEventHook, RedactFunction, RequestExtra, TelemetryArgs } from "./types.js";
2
2
  import { type BoundedKeySet } from "./utils.js";
3
3
  export declare const buildActorId: ({ actorSeed, }: {
4
4
  actorSeed: string;
@@ -8,7 +8,12 @@ export declare const buildEventId: ({ actorId, requestId, kind, }: {
8
8
  requestId: string;
9
9
  kind: AnalyticsEventKind;
10
10
  }) => string;
11
- export declare const buildToolCallEvent: ({ toolName, telemetry, input, output, status, durationMs, errorMessage, actorId, sessionId, requestId, startedAt, finishedAt, workflowRunId, redact, }: {
11
+ export declare const buildActorIdentityEvent: ({ actorId, identifier, startedAt, }: {
12
+ actorId: string;
13
+ identifier: string;
14
+ startedAt: string;
15
+ }) => AnalyticsIngestEvent;
16
+ export type BuildToolCallEventInput = {
12
17
  toolName: string;
13
18
  telemetry?: TelemetryArgs;
14
19
  input: unknown;
@@ -22,8 +27,14 @@ export declare const buildToolCallEvent: ({ toolName, telemetry, input, output,
22
27
  startedAt: string;
23
28
  finishedAt: string;
24
29
  workflowRunId?: string;
30
+ capabilityRequest?: boolean;
25
31
  redact?: RedactFunction;
26
- }) => AnalyticsIngestEvent;
32
+ redactSecrets?: boolean;
33
+ };
34
+ export declare const buildToolCallEvent: (input: BuildToolCallEventInput) => AnalyticsIngestEvent;
35
+ export declare const finalizeToolCallEvent: (input: BuildToolCallEventInput & {
36
+ redactEvent?: RedactEventHook;
37
+ }) => Promise<AnalyticsIngestEvent | null>;
27
38
  export declare const buildSessionInitEvent: ({ actorId, sessionId, startedAt, extra, clientInfo, workflowRunId, }: {
28
39
  actorId: string;
29
40
  sessionId: string;
@@ -32,8 +43,9 @@ export declare const buildSessionInitEvent: ({ actorId, sessionId, startedAt, ex
32
43
  clientInfo?: McpClientInfo;
33
44
  workflowRunId?: string;
34
45
  }) => AnalyticsIngestEvent;
35
- export declare const buildBatch: ({ event, extra, actorId, startedAt, sessionInitKeys, clientInfo, workflowRunId, }: {
46
+ export declare const buildBatch: ({ event, identityEvent, extra, actorId, startedAt, sessionInitKeys, clientInfo, workflowRunId, }: {
36
47
  event: AnalyticsIngestEvent;
48
+ identityEvent?: AnalyticsIngestEvent;
37
49
  extra?: RequestExtra;
38
50
  actorId: string;
39
51
  startedAt: string;
@@ -41,7 +53,7 @@ export declare const buildBatch: ({ event, extra, actorId, startedAt, sessionIni
41
53
  clientInfo?: McpClientInfo;
42
54
  workflowRunId?: string;
43
55
  }) => AnalyticsIngestBatch;
44
- export declare const buildSessionInitBatch: ({ actorId, sessionId, startedAt, extra, sessionInitKeys, clientInfo, workflowRunId, }: {
56
+ export declare const buildSessionInitBatch: ({ actorId, sessionId, startedAt, extra, sessionInitKeys, clientInfo, workflowRunId, identityEvent, }: {
45
57
  actorId: string;
46
58
  sessionId: string;
47
59
  startedAt: string;
@@ -49,6 +61,7 @@ export declare const buildSessionInitBatch: ({ actorId, sessionId, startedAt, ex
49
61
  sessionInitKeys: BoundedKeySet;
50
62
  clientInfo?: McpClientInfo;
51
63
  workflowRunId?: string;
64
+ identityEvent?: AnalyticsIngestEvent;
52
65
  }) => AnalyticsIngestBatch | null;
53
66
  export declare const normalizeSessionId: (eventSessionId: string | undefined, extra: RequestExtra | undefined) => string | undefined;
54
67
  export declare const normalizeRequestId: (eventRequestId: string | undefined) => string;