@armature-tech/mcp-analytics 0.6.4 → 0.6.5
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/dist/cjs/events.d.ts +8 -4
- package/dist/cjs/events.js +16 -4
- package/dist/cjs/recorder.js +12 -0
- package/dist/cjs/types.d.ts +6 -0
- package/dist/cjs/utils.d.ts +2 -0
- package/dist/cjs/utils.js +15 -1
- package/dist/esm/events.d.ts +8 -4
- package/dist/esm/events.js +16 -4
- package/dist/esm/recorder.js +13 -1
- package/dist/esm/types.d.ts +6 -0
- package/dist/esm/utils.d.ts +2 -0
- package/dist/esm/utils.js +13 -0
- package/package.json +1 -1
package/dist/cjs/events.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ 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, }: {
|
|
11
|
+
export declare const buildToolCallEvent: ({ toolName, telemetry, input, output, status, durationMs, errorMessage, actorId, sessionId, requestId, startedAt, finishedAt, workflowRunId, }: {
|
|
12
12
|
toolName: string;
|
|
13
13
|
telemetry?: TelemetryArgs;
|
|
14
14
|
input: unknown;
|
|
@@ -21,29 +21,33 @@ export declare const buildToolCallEvent: ({ toolName, telemetry, input, output,
|
|
|
21
21
|
requestId: string;
|
|
22
22
|
startedAt: string;
|
|
23
23
|
finishedAt: string;
|
|
24
|
+
workflowRunId?: string;
|
|
24
25
|
}) => AnalyticsIngestEvent;
|
|
25
|
-
export declare const buildSessionInitEvent: ({ actorId, sessionId, startedAt, extra, clientInfo, }: {
|
|
26
|
+
export declare const buildSessionInitEvent: ({ actorId, sessionId, startedAt, extra, clientInfo, workflowRunId, }: {
|
|
26
27
|
actorId: string;
|
|
27
28
|
sessionId: string;
|
|
28
29
|
startedAt: string;
|
|
29
30
|
extra?: RequestExtra;
|
|
30
31
|
clientInfo?: McpClientInfo;
|
|
32
|
+
workflowRunId?: string;
|
|
31
33
|
}) => AnalyticsIngestEvent;
|
|
32
|
-
export declare const buildBatch: ({ event, extra, actorId, startedAt, sessionInitKeys, clientInfo, }: {
|
|
34
|
+
export declare const buildBatch: ({ event, extra, actorId, startedAt, sessionInitKeys, clientInfo, workflowRunId, }: {
|
|
33
35
|
event: AnalyticsIngestEvent;
|
|
34
36
|
extra?: RequestExtra;
|
|
35
37
|
actorId: string;
|
|
36
38
|
startedAt: string;
|
|
37
39
|
sessionInitKeys: BoundedKeySet;
|
|
38
40
|
clientInfo?: McpClientInfo;
|
|
41
|
+
workflowRunId?: string;
|
|
39
42
|
}) => AnalyticsIngestBatch;
|
|
40
|
-
export declare const buildSessionInitBatch: ({ actorId, sessionId, startedAt, extra, sessionInitKeys, clientInfo, }: {
|
|
43
|
+
export declare const buildSessionInitBatch: ({ actorId, sessionId, startedAt, extra, sessionInitKeys, clientInfo, workflowRunId, }: {
|
|
41
44
|
actorId: string;
|
|
42
45
|
sessionId: string;
|
|
43
46
|
startedAt: string;
|
|
44
47
|
extra?: RequestExtra;
|
|
45
48
|
sessionInitKeys: BoundedKeySet;
|
|
46
49
|
clientInfo?: McpClientInfo;
|
|
50
|
+
workflowRunId?: string;
|
|
47
51
|
}) => AnalyticsIngestBatch | null;
|
|
48
52
|
export declare const normalizeSessionId: (eventSessionId: string | undefined, extra: RequestExtra | undefined) => string | undefined;
|
|
49
53
|
export declare const normalizeRequestId: (eventRequestId: string | undefined) => string;
|
package/dist/cjs/events.js
CHANGED
|
@@ -32,13 +32,22 @@ exports.buildEventId = buildEventId;
|
|
|
32
32
|
const buildToolCallSource = (toolName, input) => {
|
|
33
33
|
return `MCP tool call: ${toolName}\n\nInput:\n${(0, utils_js_1.stringifyPreview)(input)}`;
|
|
34
34
|
};
|
|
35
|
-
|
|
35
|
+
// Marks an event as synthetic traffic from an Armature workflow run so
|
|
36
|
+
// Session Analytics can exclude it. Spread first in the event literal —
|
|
37
|
+
// absent when the call did not originate from a workflow run.
|
|
38
|
+
const workflowStamp = (workflowRunId) => {
|
|
39
|
+
if (!workflowRunId)
|
|
40
|
+
return {};
|
|
41
|
+
return { is_workflow: true, workflow_run_id: workflowRunId };
|
|
42
|
+
};
|
|
43
|
+
const buildToolCallEvent = ({ toolName, telemetry, input, output, status, durationMs, errorMessage, actorId, sessionId, requestId, startedAt, finishedAt, workflowRunId, }) => {
|
|
36
44
|
const inputPreview = (0, utils_js_1.truncateUtf8)((0, utils_js_1.stringifyPreview)(input), utils_js_1.MAX_PREVIEW_BYTES);
|
|
37
45
|
const source = (0, utils_js_1.truncateUtf8)(buildToolCallSource(toolName, input), utils_js_1.MAX_SOURCE_BYTES);
|
|
38
46
|
const resultPreview = output === undefined
|
|
39
47
|
? null
|
|
40
48
|
: (0, utils_js_1.truncateUtf8)((0, utils_js_1.stringifyPreview)(output), utils_js_1.MAX_PREVIEW_BYTES);
|
|
41
49
|
return {
|
|
50
|
+
...workflowStamp(workflowRunId),
|
|
42
51
|
event_id: (0, exports.buildEventId)({ actorId, requestId, kind: "tool_call" }),
|
|
43
52
|
kind: "tool_call",
|
|
44
53
|
actor_id: actorId,
|
|
@@ -65,8 +74,9 @@ const buildToolCallEvent = ({ toolName, telemetry, input, output, status, durati
|
|
|
65
74
|
};
|
|
66
75
|
};
|
|
67
76
|
exports.buildToolCallEvent = buildToolCallEvent;
|
|
68
|
-
const buildSessionInitEvent = ({ actorId, sessionId, startedAt, extra, clientInfo, }) => {
|
|
77
|
+
const buildSessionInitEvent = ({ actorId, sessionId, startedAt, extra, clientInfo, workflowRunId, }) => {
|
|
69
78
|
return {
|
|
79
|
+
...workflowStamp(workflowRunId),
|
|
70
80
|
// Stable per (actorId, sessionId): a session has exactly one session_init,
|
|
71
81
|
// so seeding the id with the sessionId lets ingest de-dup it on its own —
|
|
72
82
|
// independent of the in-memory `sessionInitKeys` set (which is now bounded
|
|
@@ -102,7 +112,7 @@ const buildSessionInitEvent = ({ actorId, sessionId, startedAt, extra, clientInf
|
|
|
102
112
|
};
|
|
103
113
|
};
|
|
104
114
|
exports.buildSessionInitEvent = buildSessionInitEvent;
|
|
105
|
-
const buildBatch = ({ event, extra, actorId, startedAt, sessionInitKeys, clientInfo, }) => {
|
|
115
|
+
const buildBatch = ({ event, extra, actorId, startedAt, sessionInitKeys, clientInfo, workflowRunId, }) => {
|
|
106
116
|
const events = [];
|
|
107
117
|
if (extra?.sessionId) {
|
|
108
118
|
const key = `${actorId}:${extra.sessionId}`;
|
|
@@ -114,6 +124,7 @@ const buildBatch = ({ event, extra, actorId, startedAt, sessionInitKeys, clientI
|
|
|
114
124
|
startedAt,
|
|
115
125
|
extra,
|
|
116
126
|
clientInfo,
|
|
127
|
+
workflowRunId,
|
|
117
128
|
}));
|
|
118
129
|
}
|
|
119
130
|
}
|
|
@@ -121,7 +132,7 @@ const buildBatch = ({ event, extra, actorId, startedAt, sessionInitKeys, clientI
|
|
|
121
132
|
return { schema_version: utils_js_1.SCHEMA_VERSION, events };
|
|
122
133
|
};
|
|
123
134
|
exports.buildBatch = buildBatch;
|
|
124
|
-
const buildSessionInitBatch = ({ actorId, sessionId, startedAt, extra, sessionInitKeys, clientInfo, }) => {
|
|
135
|
+
const buildSessionInitBatch = ({ actorId, sessionId, startedAt, extra, sessionInitKeys, clientInfo, workflowRunId, }) => {
|
|
125
136
|
const key = `${actorId}:${sessionId}`;
|
|
126
137
|
if (sessionInitKeys.has(key))
|
|
127
138
|
return null;
|
|
@@ -135,6 +146,7 @@ const buildSessionInitBatch = ({ actorId, sessionId, startedAt, extra, sessionIn
|
|
|
135
146
|
startedAt,
|
|
136
147
|
extra,
|
|
137
148
|
clientInfo,
|
|
149
|
+
workflowRunId,
|
|
138
150
|
}),
|
|
139
151
|
],
|
|
140
152
|
};
|
package/dist/cjs/recorder.js
CHANGED
|
@@ -76,6 +76,14 @@ const createAnalyticsRecorder = (config = emit_js_1.defaultMcpAnalyticsConfig) =
|
|
|
76
76
|
};
|
|
77
77
|
});
|
|
78
78
|
};
|
|
79
|
+
// Explicit caller-supplied workflowRunId wins; otherwise derive it from
|
|
80
|
+
// the x-armature-workflow-run-id header the Armature run dispatcher adds
|
|
81
|
+
// to MCP connections opened by workflow runs. Either way the resulting
|
|
82
|
+
// events are stamped is_workflow so Session Analytics excludes them.
|
|
83
|
+
const resolveWorkflowRunId = (event) => {
|
|
84
|
+
return event.workflowRunId
|
|
85
|
+
?? (0, utils_js_1.workflowRunIdFromHeaders)(event.headers ?? event.extra?.requestInfo?.headers);
|
|
86
|
+
};
|
|
79
87
|
const recordSessionInit = async (event) => {
|
|
80
88
|
const sessionId = (0, events_js_1.normalizeSessionId)(event.sessionId, event.extra);
|
|
81
89
|
if (!sessionId)
|
|
@@ -98,6 +106,7 @@ const createAnalyticsRecorder = (config = emit_js_1.defaultMcpAnalyticsConfig) =
|
|
|
98
106
|
extra: event.extra,
|
|
99
107
|
sessionInitKeys,
|
|
100
108
|
clientInfo: event.clientInfo ?? (0, client_info_cache_js_1.getClientInfoForSessionId)(sessionId),
|
|
109
|
+
workflowRunId: resolveWorkflowRunId(event),
|
|
101
110
|
});
|
|
102
111
|
if (batch)
|
|
103
112
|
await emitBatch(batch);
|
|
@@ -126,6 +135,7 @@ const createAnalyticsRecorder = (config = emit_js_1.defaultMcpAnalyticsConfig) =
|
|
|
126
135
|
: event.error instanceof Error
|
|
127
136
|
? event.error.message
|
|
128
137
|
: String(event.error);
|
|
138
|
+
const workflowRunId = resolveWorkflowRunId(event);
|
|
129
139
|
const toolCallEvent = (0, events_js_1.buildToolCallEvent)({
|
|
130
140
|
toolName: event.name,
|
|
131
141
|
telemetry: event.telemetry,
|
|
@@ -139,6 +149,7 @@ const createAnalyticsRecorder = (config = emit_js_1.defaultMcpAnalyticsConfig) =
|
|
|
139
149
|
requestId,
|
|
140
150
|
startedAt,
|
|
141
151
|
finishedAt,
|
|
152
|
+
workflowRunId,
|
|
142
153
|
});
|
|
143
154
|
// An explicit clientInfo on the event always wins; otherwise look up
|
|
144
155
|
// whatever the initialize-handshake patch captured for this sessionId.
|
|
@@ -153,6 +164,7 @@ const createAnalyticsRecorder = (config = emit_js_1.defaultMcpAnalyticsConfig) =
|
|
|
153
164
|
startedAt,
|
|
154
165
|
sessionInitKeys,
|
|
155
166
|
clientInfo: effectiveClientInfo,
|
|
167
|
+
workflowRunId,
|
|
156
168
|
}));
|
|
157
169
|
};
|
|
158
170
|
const registeredTools = new Map();
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -85,6 +85,7 @@ export type RecordSessionInitEvent = {
|
|
|
85
85
|
requestId?: string;
|
|
86
86
|
startedAt?: string | Date | number;
|
|
87
87
|
clientInfo?: McpClientInfo;
|
|
88
|
+
workflowRunId?: string;
|
|
88
89
|
};
|
|
89
90
|
export type RecordToolCallEvent = {
|
|
90
91
|
name: string;
|
|
@@ -102,6 +103,7 @@ export type RecordToolCallEvent = {
|
|
|
102
103
|
result?: unknown;
|
|
103
104
|
error?: unknown;
|
|
104
105
|
clientInfo?: McpClientInfo;
|
|
106
|
+
workflowRunId?: string;
|
|
105
107
|
};
|
|
106
108
|
export type InstrumentToolCallEvent = {
|
|
107
109
|
name: string;
|
|
@@ -113,6 +115,7 @@ export type InstrumentToolCallEvent = {
|
|
|
113
115
|
sessionId?: string;
|
|
114
116
|
requestId?: string;
|
|
115
117
|
clientInfo?: McpClientInfo;
|
|
118
|
+
workflowRunId?: string;
|
|
116
119
|
};
|
|
117
120
|
export type ToolCallHandler<T> = (args: unknown) => T | Promise<T>;
|
|
118
121
|
export type ToolHandlerContext = {
|
|
@@ -123,6 +126,7 @@ export type ToolHandlerContext = {
|
|
|
123
126
|
sessionId?: string;
|
|
124
127
|
requestId?: string;
|
|
125
128
|
clientInfo?: McpClientInfo;
|
|
129
|
+
workflowRunId?: string;
|
|
126
130
|
};
|
|
127
131
|
export type RegisteredToolHandler<TArgs, TResult> = (args: TArgs, context: ToolHandlerContext) => TResult | Promise<TResult>;
|
|
128
132
|
export type ToolRegistration = {
|
|
@@ -169,6 +173,8 @@ export type AnalyticsIngestEvent = {
|
|
|
169
173
|
calls: unknown[];
|
|
170
174
|
logs: unknown[];
|
|
171
175
|
search_calls: unknown[];
|
|
176
|
+
is_workflow?: boolean;
|
|
177
|
+
workflow_run_id?: string;
|
|
172
178
|
};
|
|
173
179
|
export type AnalyticsIngestBatch = {
|
|
174
180
|
schema_version: 1;
|
package/dist/cjs/utils.d.ts
CHANGED
|
@@ -18,4 +18,6 @@ export declare const truncateUtf8: (value: string, maxBytes: number) => {
|
|
|
18
18
|
value: string;
|
|
19
19
|
truncated: boolean;
|
|
20
20
|
};
|
|
21
|
+
export declare const WORKFLOW_RUN_ID_HEADER = "x-armature-workflow-run-id";
|
|
22
|
+
export declare const workflowRunIdFromHeaders: (headers: HeaderBag | undefined) => string | undefined;
|
|
21
23
|
export declare const headerValue: (headers: HeaderBag | undefined, name: string) => string | null;
|
package/dist/cjs/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.headerValue = exports.truncateUtf8 = exports.stringifyPreview = exports.createBoundedKeySet = exports.sha256Hex = exports.readEnv = exports.isRawShape = exports.isJsonObjectSchema = exports.isRecord = exports.MAX_CAPABILITIES_BYTES = exports.MAX_PREVIEW_BYTES = exports.MAX_SOURCE_BYTES = exports.SCHEMA_VERSION = void 0;
|
|
3
|
+
exports.headerValue = exports.workflowRunIdFromHeaders = exports.WORKFLOW_RUN_ID_HEADER = exports.truncateUtf8 = exports.stringifyPreview = exports.createBoundedKeySet = exports.sha256Hex = exports.readEnv = exports.isRawShape = exports.isJsonObjectSchema = exports.isRecord = exports.MAX_CAPABILITIES_BYTES = exports.MAX_PREVIEW_BYTES = exports.MAX_SOURCE_BYTES = exports.SCHEMA_VERSION = void 0;
|
|
4
4
|
const node_crypto_1 = require("node:crypto");
|
|
5
5
|
exports.SCHEMA_VERSION = 1;
|
|
6
6
|
exports.MAX_SOURCE_BYTES = 32 * 1024;
|
|
@@ -75,6 +75,20 @@ const truncateUtf8 = (value, maxBytes) => {
|
|
|
75
75
|
};
|
|
76
76
|
};
|
|
77
77
|
exports.truncateUtf8 = truncateUtf8;
|
|
78
|
+
// The Armature run dispatcher stamps this header on MCP connections opened
|
|
79
|
+
// by workflow runs. Telemetry produced under it is synthetic harness traffic:
|
|
80
|
+
// events carry `is_workflow` / `workflow_run_id` so Session Analytics can
|
|
81
|
+
// exclude them from every user-facing surface and processing pipeline.
|
|
82
|
+
exports.WORKFLOW_RUN_ID_HEADER = "x-armature-workflow-run-id";
|
|
83
|
+
// Version nibble allows 1-8 so time-ordered v7 ids keep working if the run
|
|
84
|
+
// dispatcher ever stops minting v4.
|
|
85
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
86
|
+
const workflowRunIdFromHeaders = (headers) => {
|
|
87
|
+
const raw = (0, exports.headerValue)(headers, exports.WORKFLOW_RUN_ID_HEADER);
|
|
88
|
+
const value = typeof raw === "string" ? raw.trim() : "";
|
|
89
|
+
return UUID_RE.test(value) ? value : undefined;
|
|
90
|
+
};
|
|
91
|
+
exports.workflowRunIdFromHeaders = workflowRunIdFromHeaders;
|
|
78
92
|
const headerValue = (headers, name) => {
|
|
79
93
|
if (!headers)
|
|
80
94
|
return null;
|
package/dist/esm/events.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ 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, }: {
|
|
11
|
+
export declare const buildToolCallEvent: ({ toolName, telemetry, input, output, status, durationMs, errorMessage, actorId, sessionId, requestId, startedAt, finishedAt, workflowRunId, }: {
|
|
12
12
|
toolName: string;
|
|
13
13
|
telemetry?: TelemetryArgs;
|
|
14
14
|
input: unknown;
|
|
@@ -21,29 +21,33 @@ export declare const buildToolCallEvent: ({ toolName, telemetry, input, output,
|
|
|
21
21
|
requestId: string;
|
|
22
22
|
startedAt: string;
|
|
23
23
|
finishedAt: string;
|
|
24
|
+
workflowRunId?: string;
|
|
24
25
|
}) => AnalyticsIngestEvent;
|
|
25
|
-
export declare const buildSessionInitEvent: ({ actorId, sessionId, startedAt, extra, clientInfo, }: {
|
|
26
|
+
export declare const buildSessionInitEvent: ({ actorId, sessionId, startedAt, extra, clientInfo, workflowRunId, }: {
|
|
26
27
|
actorId: string;
|
|
27
28
|
sessionId: string;
|
|
28
29
|
startedAt: string;
|
|
29
30
|
extra?: RequestExtra;
|
|
30
31
|
clientInfo?: McpClientInfo;
|
|
32
|
+
workflowRunId?: string;
|
|
31
33
|
}) => AnalyticsIngestEvent;
|
|
32
|
-
export declare const buildBatch: ({ event, extra, actorId, startedAt, sessionInitKeys, clientInfo, }: {
|
|
34
|
+
export declare const buildBatch: ({ event, extra, actorId, startedAt, sessionInitKeys, clientInfo, workflowRunId, }: {
|
|
33
35
|
event: AnalyticsIngestEvent;
|
|
34
36
|
extra?: RequestExtra;
|
|
35
37
|
actorId: string;
|
|
36
38
|
startedAt: string;
|
|
37
39
|
sessionInitKeys: BoundedKeySet;
|
|
38
40
|
clientInfo?: McpClientInfo;
|
|
41
|
+
workflowRunId?: string;
|
|
39
42
|
}) => AnalyticsIngestBatch;
|
|
40
|
-
export declare const buildSessionInitBatch: ({ actorId, sessionId, startedAt, extra, sessionInitKeys, clientInfo, }: {
|
|
43
|
+
export declare const buildSessionInitBatch: ({ actorId, sessionId, startedAt, extra, sessionInitKeys, clientInfo, workflowRunId, }: {
|
|
41
44
|
actorId: string;
|
|
42
45
|
sessionId: string;
|
|
43
46
|
startedAt: string;
|
|
44
47
|
extra?: RequestExtra;
|
|
45
48
|
sessionInitKeys: BoundedKeySet;
|
|
46
49
|
clientInfo?: McpClientInfo;
|
|
50
|
+
workflowRunId?: string;
|
|
47
51
|
}) => AnalyticsIngestBatch | null;
|
|
48
52
|
export declare const normalizeSessionId: (eventSessionId: string | undefined, extra: RequestExtra | undefined) => string | undefined;
|
|
49
53
|
export declare const normalizeRequestId: (eventRequestId: string | undefined) => string;
|
package/dist/esm/events.js
CHANGED
|
@@ -27,13 +27,22 @@ export const buildEventId = ({ actorId, requestId, kind, }) => {
|
|
|
27
27
|
const buildToolCallSource = (toolName, input) => {
|
|
28
28
|
return `MCP tool call: ${toolName}\n\nInput:\n${stringifyPreview(input)}`;
|
|
29
29
|
};
|
|
30
|
-
|
|
30
|
+
// Marks an event as synthetic traffic from an Armature workflow run so
|
|
31
|
+
// Session Analytics can exclude it. Spread first in the event literal —
|
|
32
|
+
// absent when the call did not originate from a workflow run.
|
|
33
|
+
const workflowStamp = (workflowRunId) => {
|
|
34
|
+
if (!workflowRunId)
|
|
35
|
+
return {};
|
|
36
|
+
return { is_workflow: true, workflow_run_id: workflowRunId };
|
|
37
|
+
};
|
|
38
|
+
export const buildToolCallEvent = ({ toolName, telemetry, input, output, status, durationMs, errorMessage, actorId, sessionId, requestId, startedAt, finishedAt, workflowRunId, }) => {
|
|
31
39
|
const inputPreview = truncateUtf8(stringifyPreview(input), MAX_PREVIEW_BYTES);
|
|
32
40
|
const source = truncateUtf8(buildToolCallSource(toolName, input), MAX_SOURCE_BYTES);
|
|
33
41
|
const resultPreview = output === undefined
|
|
34
42
|
? null
|
|
35
43
|
: truncateUtf8(stringifyPreview(output), MAX_PREVIEW_BYTES);
|
|
36
44
|
return {
|
|
45
|
+
...workflowStamp(workflowRunId),
|
|
37
46
|
event_id: buildEventId({ actorId, requestId, kind: "tool_call" }),
|
|
38
47
|
kind: "tool_call",
|
|
39
48
|
actor_id: actorId,
|
|
@@ -59,8 +68,9 @@ export const buildToolCallEvent = ({ toolName, telemetry, input, output, status,
|
|
|
59
68
|
search_calls: [],
|
|
60
69
|
};
|
|
61
70
|
};
|
|
62
|
-
export const buildSessionInitEvent = ({ actorId, sessionId, startedAt, extra, clientInfo, }) => {
|
|
71
|
+
export const buildSessionInitEvent = ({ actorId, sessionId, startedAt, extra, clientInfo, workflowRunId, }) => {
|
|
63
72
|
return {
|
|
73
|
+
...workflowStamp(workflowRunId),
|
|
64
74
|
// Stable per (actorId, sessionId): a session has exactly one session_init,
|
|
65
75
|
// so seeding the id with the sessionId lets ingest de-dup it on its own —
|
|
66
76
|
// independent of the in-memory `sessionInitKeys` set (which is now bounded
|
|
@@ -95,7 +105,7 @@ export const buildSessionInitEvent = ({ actorId, sessionId, startedAt, extra, cl
|
|
|
95
105
|
search_calls: [],
|
|
96
106
|
};
|
|
97
107
|
};
|
|
98
|
-
export const buildBatch = ({ event, extra, actorId, startedAt, sessionInitKeys, clientInfo, }) => {
|
|
108
|
+
export const buildBatch = ({ event, extra, actorId, startedAt, sessionInitKeys, clientInfo, workflowRunId, }) => {
|
|
99
109
|
const events = [];
|
|
100
110
|
if (extra?.sessionId) {
|
|
101
111
|
const key = `${actorId}:${extra.sessionId}`;
|
|
@@ -107,13 +117,14 @@ export const buildBatch = ({ event, extra, actorId, startedAt, sessionInitKeys,
|
|
|
107
117
|
startedAt,
|
|
108
118
|
extra,
|
|
109
119
|
clientInfo,
|
|
120
|
+
workflowRunId,
|
|
110
121
|
}));
|
|
111
122
|
}
|
|
112
123
|
}
|
|
113
124
|
events.push(event);
|
|
114
125
|
return { schema_version: SCHEMA_VERSION, events };
|
|
115
126
|
};
|
|
116
|
-
export const buildSessionInitBatch = ({ actorId, sessionId, startedAt, extra, sessionInitKeys, clientInfo, }) => {
|
|
127
|
+
export const buildSessionInitBatch = ({ actorId, sessionId, startedAt, extra, sessionInitKeys, clientInfo, workflowRunId, }) => {
|
|
117
128
|
const key = `${actorId}:${sessionId}`;
|
|
118
129
|
if (sessionInitKeys.has(key))
|
|
119
130
|
return null;
|
|
@@ -127,6 +138,7 @@ export const buildSessionInitBatch = ({ actorId, sessionId, startedAt, extra, se
|
|
|
127
138
|
startedAt,
|
|
128
139
|
extra,
|
|
129
140
|
clientInfo,
|
|
141
|
+
workflowRunId,
|
|
130
142
|
}),
|
|
131
143
|
],
|
|
132
144
|
};
|
package/dist/esm/recorder.js
CHANGED
|
@@ -2,7 +2,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
2
2
|
import { buildActorId, buildBatch, buildSessionInitBatch, buildToolCallEvent, normalizeRequestId, normalizeSessionId, normalizeStartedAt, } from "./events.js";
|
|
3
3
|
import { createFlushableEmitter, defaultMcpAnalyticsConfig, resolveActorSeed, } from "./emit.js";
|
|
4
4
|
import { decorateInputSchemaWithTelemetry, extractTelemetryArguments, INTENT_DESCRIPTION, TELEMETRY_PROPERTY_DESCRIPTION, } from "./schema.js";
|
|
5
|
-
import { createBoundedKeySet, isJsonObjectSchema, isRecord } from "./utils.js";
|
|
5
|
+
import { createBoundedKeySet, isJsonObjectSchema, isRecord, workflowRunIdFromHeaders } from "./utils.js";
|
|
6
6
|
import { getClientInfoForSessionId, installClientInfoCapture, } from "./client-info-cache.js";
|
|
7
7
|
const TELEMETRY_DESCRIPTION_HINT = "\n\nPass telemetry.intent with a one-line user intent for analytics.";
|
|
8
8
|
const TELEMETRY_DESCRIPTION_HINT_MARKER = TELEMETRY_DESCRIPTION_HINT.trim();
|
|
@@ -73,6 +73,14 @@ export const createAnalyticsRecorder = (config = defaultMcpAnalyticsConfig) => {
|
|
|
73
73
|
};
|
|
74
74
|
});
|
|
75
75
|
};
|
|
76
|
+
// Explicit caller-supplied workflowRunId wins; otherwise derive it from
|
|
77
|
+
// the x-armature-workflow-run-id header the Armature run dispatcher adds
|
|
78
|
+
// to MCP connections opened by workflow runs. Either way the resulting
|
|
79
|
+
// events are stamped is_workflow so Session Analytics excludes them.
|
|
80
|
+
const resolveWorkflowRunId = (event) => {
|
|
81
|
+
return event.workflowRunId
|
|
82
|
+
?? workflowRunIdFromHeaders(event.headers ?? event.extra?.requestInfo?.headers);
|
|
83
|
+
};
|
|
76
84
|
const recordSessionInit = async (event) => {
|
|
77
85
|
const sessionId = normalizeSessionId(event.sessionId, event.extra);
|
|
78
86
|
if (!sessionId)
|
|
@@ -95,6 +103,7 @@ export const createAnalyticsRecorder = (config = defaultMcpAnalyticsConfig) => {
|
|
|
95
103
|
extra: event.extra,
|
|
96
104
|
sessionInitKeys,
|
|
97
105
|
clientInfo: event.clientInfo ?? getClientInfoForSessionId(sessionId),
|
|
106
|
+
workflowRunId: resolveWorkflowRunId(event),
|
|
98
107
|
});
|
|
99
108
|
if (batch)
|
|
100
109
|
await emitBatch(batch);
|
|
@@ -123,6 +132,7 @@ export const createAnalyticsRecorder = (config = defaultMcpAnalyticsConfig) => {
|
|
|
123
132
|
: event.error instanceof Error
|
|
124
133
|
? event.error.message
|
|
125
134
|
: String(event.error);
|
|
135
|
+
const workflowRunId = resolveWorkflowRunId(event);
|
|
126
136
|
const toolCallEvent = buildToolCallEvent({
|
|
127
137
|
toolName: event.name,
|
|
128
138
|
telemetry: event.telemetry,
|
|
@@ -136,6 +146,7 @@ export const createAnalyticsRecorder = (config = defaultMcpAnalyticsConfig) => {
|
|
|
136
146
|
requestId,
|
|
137
147
|
startedAt,
|
|
138
148
|
finishedAt,
|
|
149
|
+
workflowRunId,
|
|
139
150
|
});
|
|
140
151
|
// An explicit clientInfo on the event always wins; otherwise look up
|
|
141
152
|
// whatever the initialize-handshake patch captured for this sessionId.
|
|
@@ -150,6 +161,7 @@ export const createAnalyticsRecorder = (config = defaultMcpAnalyticsConfig) => {
|
|
|
150
161
|
startedAt,
|
|
151
162
|
sessionInitKeys,
|
|
152
163
|
clientInfo: effectiveClientInfo,
|
|
164
|
+
workflowRunId,
|
|
153
165
|
}));
|
|
154
166
|
};
|
|
155
167
|
const registeredTools = new Map();
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -85,6 +85,7 @@ export type RecordSessionInitEvent = {
|
|
|
85
85
|
requestId?: string;
|
|
86
86
|
startedAt?: string | Date | number;
|
|
87
87
|
clientInfo?: McpClientInfo;
|
|
88
|
+
workflowRunId?: string;
|
|
88
89
|
};
|
|
89
90
|
export type RecordToolCallEvent = {
|
|
90
91
|
name: string;
|
|
@@ -102,6 +103,7 @@ export type RecordToolCallEvent = {
|
|
|
102
103
|
result?: unknown;
|
|
103
104
|
error?: unknown;
|
|
104
105
|
clientInfo?: McpClientInfo;
|
|
106
|
+
workflowRunId?: string;
|
|
105
107
|
};
|
|
106
108
|
export type InstrumentToolCallEvent = {
|
|
107
109
|
name: string;
|
|
@@ -113,6 +115,7 @@ export type InstrumentToolCallEvent = {
|
|
|
113
115
|
sessionId?: string;
|
|
114
116
|
requestId?: string;
|
|
115
117
|
clientInfo?: McpClientInfo;
|
|
118
|
+
workflowRunId?: string;
|
|
116
119
|
};
|
|
117
120
|
export type ToolCallHandler<T> = (args: unknown) => T | Promise<T>;
|
|
118
121
|
export type ToolHandlerContext = {
|
|
@@ -123,6 +126,7 @@ export type ToolHandlerContext = {
|
|
|
123
126
|
sessionId?: string;
|
|
124
127
|
requestId?: string;
|
|
125
128
|
clientInfo?: McpClientInfo;
|
|
129
|
+
workflowRunId?: string;
|
|
126
130
|
};
|
|
127
131
|
export type RegisteredToolHandler<TArgs, TResult> = (args: TArgs, context: ToolHandlerContext) => TResult | Promise<TResult>;
|
|
128
132
|
export type ToolRegistration = {
|
|
@@ -169,6 +173,8 @@ export type AnalyticsIngestEvent = {
|
|
|
169
173
|
calls: unknown[];
|
|
170
174
|
logs: unknown[];
|
|
171
175
|
search_calls: unknown[];
|
|
176
|
+
is_workflow?: boolean;
|
|
177
|
+
workflow_run_id?: string;
|
|
172
178
|
};
|
|
173
179
|
export type AnalyticsIngestBatch = {
|
|
174
180
|
schema_version: 1;
|
package/dist/esm/utils.d.ts
CHANGED
|
@@ -18,4 +18,6 @@ export declare const truncateUtf8: (value: string, maxBytes: number) => {
|
|
|
18
18
|
value: string;
|
|
19
19
|
truncated: boolean;
|
|
20
20
|
};
|
|
21
|
+
export declare const WORKFLOW_RUN_ID_HEADER = "x-armature-workflow-run-id";
|
|
22
|
+
export declare const workflowRunIdFromHeaders: (headers: HeaderBag | undefined) => string | undefined;
|
|
21
23
|
export declare const headerValue: (headers: HeaderBag | undefined, name: string) => string | null;
|
package/dist/esm/utils.js
CHANGED
|
@@ -64,6 +64,19 @@ export const truncateUtf8 = (value, maxBytes) => {
|
|
|
64
64
|
truncated: true,
|
|
65
65
|
};
|
|
66
66
|
};
|
|
67
|
+
// The Armature run dispatcher stamps this header on MCP connections opened
|
|
68
|
+
// by workflow runs. Telemetry produced under it is synthetic harness traffic:
|
|
69
|
+
// events carry `is_workflow` / `workflow_run_id` so Session Analytics can
|
|
70
|
+
// exclude them from every user-facing surface and processing pipeline.
|
|
71
|
+
export const WORKFLOW_RUN_ID_HEADER = "x-armature-workflow-run-id";
|
|
72
|
+
// Version nibble allows 1-8 so time-ordered v7 ids keep working if the run
|
|
73
|
+
// dispatcher ever stops minting v4.
|
|
74
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
75
|
+
export const workflowRunIdFromHeaders = (headers) => {
|
|
76
|
+
const raw = headerValue(headers, WORKFLOW_RUN_ID_HEADER);
|
|
77
|
+
const value = typeof raw === "string" ? raw.trim() : "";
|
|
78
|
+
return UUID_RE.test(value) ? value : undefined;
|
|
79
|
+
};
|
|
67
80
|
export const headerValue = (headers, name) => {
|
|
68
81
|
if (!headers)
|
|
69
82
|
return null;
|