@posthog/mcp 0.16.4 → 0.18.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 +68 -25
- package/dist/extensions/constants.d.ts +45 -45
- package/dist/extensions/constants.d.ts.map +1 -1
- package/dist/extensions/event-types.d.ts +11 -11
- package/dist/extensions/event-types.d.ts.map +1 -1
- package/dist/extensions/feedback.d.ts +1 -1
- package/dist/extensions/instrumentation.d.ts.map +1 -1
- package/dist/extensions/instrumentation.js +33 -9
- package/dist/extensions/instrumentation.mjs +34 -10
- package/dist/extensions/internal.d.ts.map +1 -1
- package/dist/extensions/model-parameters.d.ts +1 -1
- package/dist/extensions/model-parameters.d.ts.map +1 -1
- package/dist/extensions/model-parameters.js +1 -1
- package/dist/extensions/model-parameters.mjs +1 -1
- package/dist/extensions/posthog-mcp.d.ts +53 -18
- package/dist/extensions/posthog-mcp.d.ts.map +1 -1
- package/dist/extensions/posthog-mcp.js +107 -25
- package/dist/extensions/posthog-mcp.mjs +108 -26
- package/dist/extensions/sink.d.ts.map +1 -1
- package/dist/extensions/tools.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.mjs +3 -2
- package/dist/types.d.ts +34 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.mjs +1 -1
- package/package.json +6 -5
- package/src/extensions/instrumentation.ts +55 -22
- package/src/extensions/model-parameters.ts +4 -2
- package/src/extensions/posthog-mcp.ts +185 -47
- package/src/index.ts +7 -2
- package/src/types.ts +35 -5
- package/src/version.ts +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PostHog, type PostHogOptions } from 'posthog-node';
|
|
2
|
-
import type { FeedbackCaptureData, CollectFeedbackConfig, InitializeCaptureData, MCPAnalyticsOptions, MissingCapabilityCaptureData, PreparedToolCall, PrepareToolCallOptions, PrepareToolListOptions, ToolCallCaptureData, ToolsListCaptureData } from '../types';
|
|
2
|
+
import type { FeedbackCaptureData, CollectFeedbackConfig, InitializeCaptureData, MCPAnalyticsOptions, MissingCapabilityCaptureData, PreparedToolCall, PreparedToolResult, PrepareToolCallOptions, PrepareToolListOptions, ToolCallCaptureData, ToolsListCaptureData } from '../types';
|
|
3
3
|
import { type ContextInjectableTool } from './context-parameters';
|
|
4
4
|
/**
|
|
5
5
|
* Options for {@link PostHogMCP}. A superset of `posthog-node`'s options, plus
|
|
@@ -26,9 +26,15 @@ export interface PostHogMCPOptions extends PostHogOptions {
|
|
|
26
26
|
collectFeedback?: CollectFeedbackConfig;
|
|
27
27
|
/**
|
|
28
28
|
* Capture the calling model from recognized client metadata, with an injected
|
|
29
|
-
* `llm_model` argument as fallback.
|
|
29
|
+
* `llm_model` argument as fallback. On by default; `false` disables it.
|
|
30
30
|
*/
|
|
31
31
|
captureModel?: MCPAnalyticsOptions['captureModel'];
|
|
32
|
+
/**
|
|
33
|
+
* Correlate calls with an agent-carried `conversation_id` and a derived
|
|
34
|
+
* PostHog session id. On by default; `false` leaves schemas, arguments, tool
|
|
35
|
+
* results, and capture data unchanged.
|
|
36
|
+
*/
|
|
37
|
+
enableConversationId?: boolean;
|
|
32
38
|
}
|
|
33
39
|
/**
|
|
34
40
|
* A `posthog-node` client with first-class MCP analytics. Use this when there is
|
|
@@ -84,9 +90,10 @@ export declare class PostHogMCP extends PostHog {
|
|
|
84
90
|
* Decorate your `tools/list` response with PostHog's analytics affordances:
|
|
85
91
|
* injects the `context` argument into every tool (so agents state their intent,
|
|
86
92
|
* captured as `$mcp_intent`), injects `llm_model` when the constructor's
|
|
87
|
-
* `captureModel` option is enabled,
|
|
88
|
-
*
|
|
89
|
-
* on. Returns a new array; your tools
|
|
93
|
+
* `captureModel` option is enabled, and injects the optional `conversation_id`
|
|
94
|
+
* handle by default. It appends `get_more_tools` when `reportMissing` is on and
|
|
95
|
+
* `send_feedback` when `collectFeedback` is on. Returns a new array; your tools
|
|
96
|
+
* are untouched.
|
|
90
97
|
*
|
|
91
98
|
* The appended `get_more_tools` descriptor carries only the base MCP tool fields
|
|
92
99
|
* (name, description, input schema) — not any framework-specific fields your
|
|
@@ -94,8 +101,9 @@ export declare class PostHogMCP extends PostHog {
|
|
|
94
101
|
* {@link prepareToolCall}'s `isMissingCapability`, not dispatched through a handler.
|
|
95
102
|
*
|
|
96
103
|
* Call this when there is no `Server` to wrap — it does for a custom dispatcher
|
|
97
|
-
* what `instrument()` does for a `Server`. Pair it with
|
|
98
|
-
* on the inbound side
|
|
104
|
+
* what `instrument()` does for a `Server`. Pair it with
|
|
105
|
+
* {@link prepareToolCall} on the inbound side and {@link prepareToolResult} on
|
|
106
|
+
* the outbound side.
|
|
99
107
|
*
|
|
100
108
|
* @example
|
|
101
109
|
* ```ts
|
|
@@ -109,8 +117,10 @@ export declare class PostHogMCP extends PostHog {
|
|
|
109
117
|
* from SDK-owned arguments, strips those arguments before validation, and flags
|
|
110
118
|
* whether the call targeted the `get_more_tools` virtual tool.
|
|
111
119
|
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
120
|
+
* Dispatch the returned `args` to your tool. Then pass the tool result and
|
|
121
|
+
* this prepared call to {@link prepareToolResult}. Use its result as the MCP
|
|
122
|
+
* response and its session and conversation values with
|
|
123
|
+
* {@link captureToolCall}.
|
|
114
124
|
*
|
|
115
125
|
* On stateless or multi-replica servers, pass the original tool descriptor
|
|
116
126
|
* so ownership does not depend on which process served `tools/list`.
|
|
@@ -124,24 +134,49 @@ export declare class PostHogMCP extends PostHog {
|
|
|
124
134
|
* @example
|
|
125
135
|
* ```ts
|
|
126
136
|
* const originalTool = myTools.find((tool) => tool.name === name)
|
|
127
|
-
* const
|
|
128
|
-
* posthog.prepareToolCall(name, rawArgs, {
|
|
137
|
+
* const preparedCall = posthog.prepareToolCall(name, rawArgs, {
|
|
129
138
|
* originalTool,
|
|
130
139
|
* requestMeta: request.params?._meta,
|
|
131
140
|
* })
|
|
132
|
-
* if (isMissingCapability) {
|
|
133
|
-
* posthog.
|
|
134
|
-
*
|
|
141
|
+
* if (preparedCall.isMissingCapability) {
|
|
142
|
+
* const preparedResult = posthog.prepareToolResult(getMoreToolsResult(), preparedCall)
|
|
143
|
+
* posthog.captureMissingCapability({
|
|
144
|
+
* context: preparedCall.intent,
|
|
145
|
+
* sessionId: preparedResult.sessionId,
|
|
146
|
+
* conversationId: preparedResult.conversationId,
|
|
147
|
+
* ...identity,
|
|
148
|
+
* })
|
|
149
|
+
* return preparedResult.result
|
|
135
150
|
* }
|
|
136
|
-
* const
|
|
137
|
-
* posthog.
|
|
151
|
+
* const toolResult = await runTool(name, preparedCall.args)
|
|
152
|
+
* const preparedResult = posthog.prepareToolResult(toolResult, preparedCall)
|
|
153
|
+
* posthog.captureToolCall({
|
|
154
|
+
* toolName: name,
|
|
155
|
+
* intent: preparedCall.intent,
|
|
156
|
+
* sessionId: preparedResult.sessionId,
|
|
157
|
+
* conversationId: preparedResult.conversationId,
|
|
158
|
+
* ...identity,
|
|
159
|
+
* })
|
|
160
|
+
* return preparedResult.result
|
|
138
161
|
* ```
|
|
139
162
|
*/
|
|
140
163
|
prepareToolCall(name: string, args?: Record<string, unknown>, options?: PrepareToolCallOptions): PreparedToolCall;
|
|
164
|
+
/**
|
|
165
|
+
* Add the conversation handle to a tool result without changing the original
|
|
166
|
+
* value. A new handle is appended to text content once. When the advertised
|
|
167
|
+
* output schema supports it, the handle is also mirrored into
|
|
168
|
+
* `structuredContent`.
|
|
169
|
+
*
|
|
170
|
+
* Use the returned session and conversation values for capture. If a new
|
|
171
|
+
* handle could not reach the client, the conversation value is omitted while
|
|
172
|
+
* the derived session value is kept.
|
|
173
|
+
*/
|
|
174
|
+
prepareToolResult<TResult>(result: TResult, preparedCall: PreparedToolCall): PreparedToolResult<TResult>;
|
|
141
175
|
/**
|
|
142
176
|
* Capture a `get_more_tools` call as a missing-capability report. Emits
|
|
143
177
|
* `$mcp_missing_capability` with the agent's description as `$mcp_intent`. Reply
|
|
144
|
-
* to the agent with `getMoreToolsResult()
|
|
178
|
+
* to the agent with `getMoreToolsResult()` after passing it through
|
|
179
|
+
* {@link prepareToolResult}.
|
|
145
180
|
*/
|
|
146
181
|
captureMissingCapability(data: MissingCapabilityCaptureData): void;
|
|
147
182
|
/**
|
|
@@ -149,7 +184,7 @@ export declare class PostHogMCP extends PostHog {
|
|
|
149
184
|
* `$mcp_feedback` with the report's `$mcp_feedback_*` properties and its
|
|
150
185
|
* summary/details as `$mcp_intent`. Reply to the agent with
|
|
151
186
|
* `sendFeedbackResult()` (or a custom text) after routing the report to your
|
|
152
|
-
* own feedback backend.
|
|
187
|
+
* own feedback backend and passing the reply through {@link prepareToolResult}.
|
|
153
188
|
*/
|
|
154
189
|
captureFeedback(data: FeedbackCaptureData): void;
|
|
155
190
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"posthog-mcp.d.ts","sourceRoot":"","sources":["../../src/extensions/posthog-mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAA;AAE3D,OAAO,KAAK,EACV,mBAAmB,
|
|
1
|
+
{"version":3,"file":"posthog-mcp.d.ts","sourceRoot":"","sources":["../../src/extensions/posthog-mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAA;AAE3D,OAAO,KAAK,EACV,mBAAmB,EAGnB,qBAAqB,EACrB,qBAAqB,EAErB,mBAAmB,EAGnB,4BAA4B,EAC5B,gBAAgB,EAChB,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,UAAU,CAAA;AAgBjB,OAAO,EAIL,KAAK,qBAAqB,EAC3B,MAAM,sBAAsB,CAAA;AAkB7B;;;GAGG;AACH,MAAM,WAAW,iBAAkB,SAAQ,cAAc;IACvD;;;;;OAKG;IACH,yBAAyB,CAAC,EAAE,MAAM,CAAA;IAClC;;;;;;;;;OASG;IACH,eAAe,CAAC,EAAE,qBAAqB,CAAA;IACvC;;;OAGG;IACH,YAAY,CAAC,EAAE,mBAAmB,CAAC,cAAc,CAAC,CAAA;IAClD;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAaD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,qBAAa,UAAW,SAAQ,OAAO;;IAcrC,YAAY,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,EAe1D;IAMD,8FAA8F;IAC9F,eAAe,CAAC,IAAI,EAAE,mBAAmB,GAAG,IAAI,CAgB/C;IAED,iEAAiE;IACjE,iBAAiB,CAAC,IAAI,EAAE,qBAAqB,GAAG,IAAI,CAQnD;IAED;;;;;OAKG;IACH,gBAAgB,CAAC,IAAI,EAAE,oBAAoB,GAAG,IAAI,CAYjD;IAED;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,eAAe,CAAC,KAAK,SAAS,qBAAqB,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,OAAO,GAAE,sBAA2B,GAAG,KAAK,EAAE,CAmDlH;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+CG;IACH,eAAe,CACb,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,GAAE,sBAA2B,GACnC,gBAAgB,CAiDlB;IAED;;;;;;;;;OASG;IACH,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,gBAAgB,GAAG,kBAAkB,CAAC,OAAO,CAAC,CA2BvG;IAED;;;;;OAKG;IACH,wBAAwB,CAAC,IAAI,EAAE,4BAA4B,GAAG,IAAI,CAOjE;IAED;;;;;;OAMG;IACH,eAAe,CAAC,IAAI,EAAE,mBAAmB,GAAG,IAAI,CAW/C;CAYF"}
|
|
@@ -33,6 +33,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
33
33
|
const external_posthog_node_namespaceObject = require("posthog-node");
|
|
34
34
|
const external_feedback_js_namespaceObject = require("./feedback.js");
|
|
35
35
|
const external_analytics_parameters_js_namespaceObject = require("./analytics-parameters.js");
|
|
36
|
+
const external_conversation_id_js_namespaceObject = require("./conversation-id.js");
|
|
36
37
|
const external_context_parameters_js_namespaceObject = require("./context-parameters.js");
|
|
37
38
|
const external_event_types_js_namespaceObject = require("./event-types.js");
|
|
38
39
|
const external_exceptions_js_namespaceObject = require("./exceptions.js");
|
|
@@ -41,20 +42,25 @@ const external_lib_identity_js_namespaceObject = require("./lib-identity.js");
|
|
|
41
42
|
const external_logger_js_namespaceObject = require("./logger.js");
|
|
42
43
|
const external_model_parameters_js_namespaceObject = require("./model-parameters.js");
|
|
43
44
|
const external_sink_js_namespaceObject = require("./sink.js");
|
|
45
|
+
const external_output_instructions_js_namespaceObject = require("./output-instructions.js");
|
|
46
|
+
const external_session_js_namespaceObject = require("./session.js");
|
|
44
47
|
const external_tools_js_namespaceObject = require("./tools.js");
|
|
48
|
+
const PREPARED_CONVERSATION_STATE_KEY = '__posthogMcpConversationState';
|
|
45
49
|
class PostHogMCP extends external_posthog_node_namespaceObject.PostHog {
|
|
46
50
|
#sink;
|
|
47
51
|
#missingCapabilityToolName;
|
|
48
52
|
#feedbackOptions;
|
|
49
53
|
#captureModel;
|
|
50
|
-
#
|
|
54
|
+
#enableConversationId;
|
|
55
|
+
#analyticsParameterOwnership;
|
|
51
56
|
constructor(apiKey, options = {}){
|
|
52
|
-
super(apiKey, options), this.#sink = new external_sink_js_namespaceObject.McpEventSink(this), this.#
|
|
57
|
+
super(apiKey, options), this.#sink = new external_sink_js_namespaceObject.McpEventSink(this), this.#analyticsParameterOwnership = new Map();
|
|
53
58
|
this.#missingCapabilityToolName = options.missingCapabilityToolName ?? external_tools_js_namespaceObject.GET_MORE_TOOLS_NAME;
|
|
54
59
|
this.#feedbackOptions = (0, external_feedback_js_namespaceObject.resolveCollectFeedbackOptions)(options.collectFeedback);
|
|
55
60
|
(0, external_feedback_js_namespaceObject.getFeedbackToolDescriptor)(this.#feedbackOptions);
|
|
56
61
|
if (this.#feedbackOptions?.onFeedback) (0, external_logger_js_namespaceObject.log)('Warning: collectFeedback.onFeedback is ignored on the PostHogMCP path - route reports from your dispatcher via prepareToolCall().feedbackReport instead.');
|
|
57
62
|
this.#captureModel = options.captureModel;
|
|
63
|
+
this.#enableConversationId = options.enableConversationId ?? true;
|
|
58
64
|
(0, external_lib_identity_js_namespaceObject.applyMcpLibIdentity)(this);
|
|
59
65
|
}
|
|
60
66
|
get #feedbackToolName() {
|
|
@@ -100,32 +106,47 @@ class PostHogMCP extends external_posthog_node_namespaceObject.PostHog {
|
|
|
100
106
|
let prepared = (0, external_context_parameters_js_namespaceObject.isContextEnabled)(contextOption) ? (0, external_context_parameters_js_namespaceObject.addContextParameterToTools)(tools, (0, external_context_parameters_js_namespaceObject.getContextDescription)(contextOption)) : [
|
|
101
107
|
...tools
|
|
102
108
|
];
|
|
103
|
-
|
|
104
|
-
...
|
|
105
|
-
(0, external_tools_js_namespaceObject.getReportMissingToolDescriptor)(this.#missingCapabilityToolName)
|
|
106
|
-
];
|
|
107
|
-
if (options.collectFeedback && void 0 !== this.#feedbackOptions && !prepared.some((tool)=>tool?.name === this.#feedbackToolName)) prepared = [
|
|
108
|
-
...prepared,
|
|
109
|
-
(0, external_feedback_js_namespaceObject.getFeedbackToolDescriptor)(this.#feedbackOptions)
|
|
109
|
+
const ownershipSources = [
|
|
110
|
+
...tools
|
|
110
111
|
];
|
|
112
|
+
if (options.reportMissing && !prepared.some((tool)=>tool?.name === this.#missingCapabilityToolName)) {
|
|
113
|
+
const virtualTool = (0, external_tools_js_namespaceObject.getReportMissingToolDescriptor)(this.#missingCapabilityToolName);
|
|
114
|
+
prepared = [
|
|
115
|
+
...prepared,
|
|
116
|
+
virtualTool
|
|
117
|
+
];
|
|
118
|
+
ownershipSources.push(virtualTool);
|
|
119
|
+
}
|
|
120
|
+
if (options.collectFeedback && void 0 !== this.#feedbackOptions && !prepared.some((tool)=>tool?.name === this.#feedbackToolName)) {
|
|
121
|
+
const virtualTool = (0, external_feedback_js_namespaceObject.getFeedbackToolDescriptor)(this.#feedbackOptions);
|
|
122
|
+
prepared = [
|
|
123
|
+
...prepared,
|
|
124
|
+
virtualTool
|
|
125
|
+
];
|
|
126
|
+
ownershipSources.push(virtualTool);
|
|
127
|
+
}
|
|
128
|
+
this.#analyticsParameterOwnership.clear();
|
|
129
|
+
const ownershipByName = collectAnalyticsParameterOwnership(ownershipSources);
|
|
130
|
+
for (const [toolName, ownership] of ownershipByName)this.#analyticsParameterOwnership.set(toolName, ownership);
|
|
111
131
|
if ((0, external_model_parameters_js_namespaceObject.isCaptureModelEnabled)(this.#captureModel)) {
|
|
112
|
-
this.#modelParameterOwnership.clear();
|
|
113
|
-
const ownershipByName = new Map();
|
|
114
|
-
for (const tool of prepared){
|
|
115
|
-
if ('string' != typeof tool.name) continue;
|
|
116
|
-
const ownsModel = (0, external_analytics_parameters_js_namespaceObject.analyticsOwnsParameter)(tool.inputSchema, 'llm_model');
|
|
117
|
-
ownershipByName.set(tool.name, (ownershipByName.get(tool.name) ?? true) && ownsModel);
|
|
118
|
-
}
|
|
119
|
-
for (const [toolName, ownsModel] of ownershipByName)this.#modelParameterOwnership.set(toolName, ownsModel);
|
|
120
132
|
const modelDescription = (0, external_model_parameters_js_namespaceObject.getModelDescription)(this.#captureModel);
|
|
121
|
-
prepared = prepared.map((tool)=>'string' == typeof tool.name &&
|
|
133
|
+
prepared = prepared.map((tool)=>'string' == typeof tool.name && ownershipByName.get(tool.name)?.llmModel === false ? tool : (0, external_model_parameters_js_namespaceObject.addModelParameterToTool)(tool, modelDescription));
|
|
134
|
+
}
|
|
135
|
+
if (this.#enableConversationId) {
|
|
136
|
+
prepared = prepared.map((tool)=>'string' == typeof tool.name && ownershipByName.get(tool.name)?.conversationId === false ? tool : (0, external_conversation_id_js_namespaceObject.addConversationIdToTools)([
|
|
137
|
+
tool
|
|
138
|
+
])[0]);
|
|
139
|
+
prepared = prepared.map((tool)=>'string' == typeof tool.name && ownershipByName.get(tool.name)?.outputInstructions === false ? tool : (0, external_output_instructions_js_namespaceObject.addInstructionsToOutputSchemas)([
|
|
140
|
+
tool
|
|
141
|
+
])[0]);
|
|
122
142
|
}
|
|
123
143
|
return prepared;
|
|
124
144
|
}
|
|
125
145
|
prepareToolCall(name, args, options = {}) {
|
|
126
146
|
const rawContext = args?.context;
|
|
127
147
|
const intent = 'string' == typeof rawContext && rawContext.trim() ? rawContext.trim() : void 0;
|
|
128
|
-
const
|
|
148
|
+
const ownership = options.originalTool ? (0, external_analytics_parameters_js_namespaceObject.getAnalyticsParameterOwnership)(options.originalTool.inputSchema, options.originalTool.outputSchema) : this.#analyticsParameterOwnership.get(name);
|
|
149
|
+
const ownsModel = (0, external_model_parameters_js_namespaceObject.isCaptureModelEnabled)(this.#captureModel) && ownership?.llmModel === true;
|
|
129
150
|
const resolvedModel = (0, external_model_parameters_js_namespaceObject.isCaptureModelEnabled)(this.#captureModel) ? (0, external_model_parameters_js_namespaceObject.resolveModel)({
|
|
130
151
|
params: {
|
|
131
152
|
arguments: args,
|
|
@@ -133,20 +154,65 @@ class PostHogMCP extends external_posthog_node_namespaceObject.PostHog {
|
|
|
133
154
|
}
|
|
134
155
|
}, ownsModel) : void 0;
|
|
135
156
|
const strippedArgs = stripContext(args);
|
|
157
|
+
const canReadConversationId = this.#enableConversationId && (ownership?.conversationId ?? true);
|
|
158
|
+
const resolvedConversation = (0, external_conversation_id_js_namespaceObject.resolveConversationId)(canReadConversationId, args);
|
|
159
|
+
const conversation = resolvedConversation.minted && options.sessionId ? {
|
|
160
|
+
minted: false,
|
|
161
|
+
conversationId: void 0
|
|
162
|
+
} : resolvedConversation;
|
|
163
|
+
const conversationId = conversation.conversationId;
|
|
164
|
+
const sessionId = conversationId ? (0, external_session_js_namespaceObject.deriveSessionIdFromConversation)(conversationId) : options.sessionId;
|
|
136
165
|
const isFeedback = void 0 !== this.#feedbackOptions && name === this.#feedbackToolName && null == options.originalTool;
|
|
137
|
-
|
|
166
|
+
const preparedCall = {
|
|
138
167
|
intent,
|
|
139
168
|
intentSource: intent ? 'context_parameter' : void 0,
|
|
140
169
|
llmModel: resolvedModel?.model,
|
|
141
170
|
llmModelSource: resolvedModel?.source,
|
|
142
|
-
args:
|
|
171
|
+
args: (0, external_analytics_parameters_js_namespaceObject.stripOwnedAnalyticsArguments)(strippedArgs, {
|
|
143
172
|
context: false,
|
|
144
|
-
conversationId:
|
|
145
|
-
llmModel:
|
|
146
|
-
})
|
|
173
|
+
conversationId: this.#enableConversationId && ownership?.conversationId === true,
|
|
174
|
+
llmModel: ownsModel
|
|
175
|
+
}),
|
|
176
|
+
sessionId,
|
|
177
|
+
conversationId,
|
|
147
178
|
isMissingCapability: name === this.#missingCapabilityToolName,
|
|
148
179
|
isFeedback,
|
|
149
|
-
feedbackReport: isFeedback ? (0, external_feedback_js_namespaceObject.parseFeedbackReport)(args, this.#feedbackOptions) : void 0
|
|
180
|
+
feedbackReport: isFeedback ? (0, external_feedback_js_namespaceObject.parseFeedbackReport)(args, this.#feedbackOptions) : void 0,
|
|
181
|
+
[PREPARED_CONVERSATION_STATE_KEY]: {
|
|
182
|
+
minted: conversation.minted,
|
|
183
|
+
outputInstructions: this.#enableConversationId && ownership?.outputInstructions === true
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
return preparedCall;
|
|
187
|
+
}
|
|
188
|
+
prepareToolResult(result, preparedCall) {
|
|
189
|
+
const state = preparedCall[PREPARED_CONVERSATION_STATE_KEY];
|
|
190
|
+
const conversationId = preparedCall.conversationId;
|
|
191
|
+
if (!conversationId) return {
|
|
192
|
+
result,
|
|
193
|
+
sessionId: preparedCall.sessionId,
|
|
194
|
+
conversationId
|
|
195
|
+
};
|
|
196
|
+
if (!state) return {
|
|
197
|
+
result,
|
|
198
|
+
sessionId: preparedCall.sessionId,
|
|
199
|
+
conversationId: void 0
|
|
200
|
+
};
|
|
201
|
+
let preparedResult = result;
|
|
202
|
+
let delivered = false;
|
|
203
|
+
if (state.outputInstructions) {
|
|
204
|
+
const mirrored = (0, external_output_instructions_js_namespaceObject.mirrorInstructionsIntoStructuredContent)(preparedResult, conversationId);
|
|
205
|
+
delivered = mirrored !== preparedResult;
|
|
206
|
+
preparedResult = mirrored;
|
|
207
|
+
}
|
|
208
|
+
if (state.minted && (0, external_conversation_id_js_namespaceObject.canInjectConversationIdPromptBack)(preparedResult)) {
|
|
209
|
+
preparedResult = (0, external_conversation_id_js_namespaceObject.injectConversationIdPromptBack)(preparedResult, conversationId);
|
|
210
|
+
delivered = true;
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
result: preparedResult,
|
|
214
|
+
sessionId: preparedCall.sessionId,
|
|
215
|
+
conversationId: state.minted && !delivered ? void 0 : conversationId
|
|
150
216
|
};
|
|
151
217
|
}
|
|
152
218
|
captureMissingCapability(data) {
|
|
@@ -178,6 +244,7 @@ function baseEvent(eventType, common) {
|
|
|
178
244
|
const event = {
|
|
179
245
|
eventType,
|
|
180
246
|
sessionId: common.sessionId,
|
|
247
|
+
conversationId: common.conversationId,
|
|
181
248
|
protocolVersion: common.protocolVersion,
|
|
182
249
|
clientUserAgent: (0, external_headers_js_namespaceObject.normalizeHeaderString)(common.clientUserAgent),
|
|
183
250
|
vendorClient: (0, external_headers_js_namespaceObject.normalizeHeaderString)(common.vendorClient),
|
|
@@ -189,6 +256,21 @@ function baseEvent(eventType, common) {
|
|
|
189
256
|
if (common.setProperties && Object.keys(common.setProperties).length > 0) event.identifyActorData = common.setProperties;
|
|
190
257
|
return event;
|
|
191
258
|
}
|
|
259
|
+
function collectAnalyticsParameterOwnership(tools) {
|
|
260
|
+
const ownershipByName = new Map();
|
|
261
|
+
for (const tool of tools){
|
|
262
|
+
if ('string' != typeof tool.name) continue;
|
|
263
|
+
const next = (0, external_analytics_parameters_js_namespaceObject.getAnalyticsParameterOwnership)(tool.inputSchema, tool.outputSchema);
|
|
264
|
+
const current = ownershipByName.get(tool.name);
|
|
265
|
+
ownershipByName.set(tool.name, current ? {
|
|
266
|
+
context: current.context && next.context,
|
|
267
|
+
conversationId: current.conversationId && next.conversationId,
|
|
268
|
+
llmModel: current.llmModel && next.llmModel,
|
|
269
|
+
outputInstructions: current.outputInstructions && next.outputInstructions
|
|
270
|
+
} : next);
|
|
271
|
+
}
|
|
272
|
+
return ownershipByName;
|
|
273
|
+
}
|
|
192
274
|
function applyIntent(event, intent, source) {
|
|
193
275
|
const trimmed = 'string' == typeof intent ? intent.trim() : '';
|
|
194
276
|
if (!trimmed) return;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PostHog } from "posthog-node";
|
|
2
2
|
import { SEND_FEEDBACK_TOOL_NAME, buildFeedbackEventProperties, buildFeedbackIntent, getFeedbackToolDescriptor, parseFeedbackReport, resolveCollectFeedbackOptions } from "./feedback.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { getAnalyticsParameterOwnership, stripOwnedAnalyticsArguments } from "./analytics-parameters.mjs";
|
|
4
|
+
import { addConversationIdToTools, canInjectConversationIdPromptBack, injectConversationIdPromptBack, resolveConversationId } from "./conversation-id.mjs";
|
|
4
5
|
import { addContextParameterToTools, getContextDescription, isContextEnabled } from "./context-parameters.mjs";
|
|
5
6
|
import { MCPAnalyticsEventType } from "./event-types.mjs";
|
|
6
7
|
import { captureException } from "./exceptions.mjs";
|
|
@@ -9,20 +10,25 @@ import { applyMcpLibIdentity } from "./lib-identity.mjs";
|
|
|
9
10
|
import { log } from "./logger.mjs";
|
|
10
11
|
import { addModelParameterToTool, getModelDescription, isCaptureModelEnabled, resolveModel, setEventModel } from "./model-parameters.mjs";
|
|
11
12
|
import { McpEventSink } from "./sink.mjs";
|
|
13
|
+
import { addInstructionsToOutputSchemas, mirrorInstructionsIntoStructuredContent } from "./output-instructions.mjs";
|
|
14
|
+
import { deriveSessionIdFromConversation } from "./session.mjs";
|
|
12
15
|
import { GET_MORE_TOOLS_NAME, getReportMissingToolDescriptor } from "./tools.mjs";
|
|
16
|
+
const PREPARED_CONVERSATION_STATE_KEY = '__posthogMcpConversationState';
|
|
13
17
|
class PostHogMCP extends PostHog {
|
|
14
18
|
#sink;
|
|
15
19
|
#missingCapabilityToolName;
|
|
16
20
|
#feedbackOptions;
|
|
17
21
|
#captureModel;
|
|
18
|
-
#
|
|
22
|
+
#enableConversationId;
|
|
23
|
+
#analyticsParameterOwnership;
|
|
19
24
|
constructor(apiKey, options = {}){
|
|
20
|
-
super(apiKey, options), this.#sink = new McpEventSink(this), this.#
|
|
25
|
+
super(apiKey, options), this.#sink = new McpEventSink(this), this.#analyticsParameterOwnership = new Map();
|
|
21
26
|
this.#missingCapabilityToolName = options.missingCapabilityToolName ?? GET_MORE_TOOLS_NAME;
|
|
22
27
|
this.#feedbackOptions = resolveCollectFeedbackOptions(options.collectFeedback);
|
|
23
28
|
getFeedbackToolDescriptor(this.#feedbackOptions);
|
|
24
29
|
if (this.#feedbackOptions?.onFeedback) log('Warning: collectFeedback.onFeedback is ignored on the PostHogMCP path - route reports from your dispatcher via prepareToolCall().feedbackReport instead.');
|
|
25
30
|
this.#captureModel = options.captureModel;
|
|
31
|
+
this.#enableConversationId = options.enableConversationId ?? true;
|
|
26
32
|
applyMcpLibIdentity(this);
|
|
27
33
|
}
|
|
28
34
|
get #feedbackToolName() {
|
|
@@ -68,32 +74,47 @@ class PostHogMCP extends PostHog {
|
|
|
68
74
|
let prepared = isContextEnabled(contextOption) ? addContextParameterToTools(tools, getContextDescription(contextOption)) : [
|
|
69
75
|
...tools
|
|
70
76
|
];
|
|
71
|
-
|
|
72
|
-
...
|
|
73
|
-
getReportMissingToolDescriptor(this.#missingCapabilityToolName)
|
|
74
|
-
];
|
|
75
|
-
if (options.collectFeedback && void 0 !== this.#feedbackOptions && !prepared.some((tool)=>tool?.name === this.#feedbackToolName)) prepared = [
|
|
76
|
-
...prepared,
|
|
77
|
-
getFeedbackToolDescriptor(this.#feedbackOptions)
|
|
77
|
+
const ownershipSources = [
|
|
78
|
+
...tools
|
|
78
79
|
];
|
|
80
|
+
if (options.reportMissing && !prepared.some((tool)=>tool?.name === this.#missingCapabilityToolName)) {
|
|
81
|
+
const virtualTool = getReportMissingToolDescriptor(this.#missingCapabilityToolName);
|
|
82
|
+
prepared = [
|
|
83
|
+
...prepared,
|
|
84
|
+
virtualTool
|
|
85
|
+
];
|
|
86
|
+
ownershipSources.push(virtualTool);
|
|
87
|
+
}
|
|
88
|
+
if (options.collectFeedback && void 0 !== this.#feedbackOptions && !prepared.some((tool)=>tool?.name === this.#feedbackToolName)) {
|
|
89
|
+
const virtualTool = getFeedbackToolDescriptor(this.#feedbackOptions);
|
|
90
|
+
prepared = [
|
|
91
|
+
...prepared,
|
|
92
|
+
virtualTool
|
|
93
|
+
];
|
|
94
|
+
ownershipSources.push(virtualTool);
|
|
95
|
+
}
|
|
96
|
+
this.#analyticsParameterOwnership.clear();
|
|
97
|
+
const ownershipByName = collectAnalyticsParameterOwnership(ownershipSources);
|
|
98
|
+
for (const [toolName, ownership] of ownershipByName)this.#analyticsParameterOwnership.set(toolName, ownership);
|
|
79
99
|
if (isCaptureModelEnabled(this.#captureModel)) {
|
|
80
|
-
this.#modelParameterOwnership.clear();
|
|
81
|
-
const ownershipByName = new Map();
|
|
82
|
-
for (const tool of prepared){
|
|
83
|
-
if ('string' != typeof tool.name) continue;
|
|
84
|
-
const ownsModel = analyticsOwnsParameter(tool.inputSchema, 'llm_model');
|
|
85
|
-
ownershipByName.set(tool.name, (ownershipByName.get(tool.name) ?? true) && ownsModel);
|
|
86
|
-
}
|
|
87
|
-
for (const [toolName, ownsModel] of ownershipByName)this.#modelParameterOwnership.set(toolName, ownsModel);
|
|
88
100
|
const modelDescription = getModelDescription(this.#captureModel);
|
|
89
|
-
prepared = prepared.map((tool)=>'string' == typeof tool.name &&
|
|
101
|
+
prepared = prepared.map((tool)=>'string' == typeof tool.name && ownershipByName.get(tool.name)?.llmModel === false ? tool : addModelParameterToTool(tool, modelDescription));
|
|
102
|
+
}
|
|
103
|
+
if (this.#enableConversationId) {
|
|
104
|
+
prepared = prepared.map((tool)=>'string' == typeof tool.name && ownershipByName.get(tool.name)?.conversationId === false ? tool : addConversationIdToTools([
|
|
105
|
+
tool
|
|
106
|
+
])[0]);
|
|
107
|
+
prepared = prepared.map((tool)=>'string' == typeof tool.name && ownershipByName.get(tool.name)?.outputInstructions === false ? tool : addInstructionsToOutputSchemas([
|
|
108
|
+
tool
|
|
109
|
+
])[0]);
|
|
90
110
|
}
|
|
91
111
|
return prepared;
|
|
92
112
|
}
|
|
93
113
|
prepareToolCall(name, args, options = {}) {
|
|
94
114
|
const rawContext = args?.context;
|
|
95
115
|
const intent = 'string' == typeof rawContext && rawContext.trim() ? rawContext.trim() : void 0;
|
|
96
|
-
const
|
|
116
|
+
const ownership = options.originalTool ? getAnalyticsParameterOwnership(options.originalTool.inputSchema, options.originalTool.outputSchema) : this.#analyticsParameterOwnership.get(name);
|
|
117
|
+
const ownsModel = isCaptureModelEnabled(this.#captureModel) && ownership?.llmModel === true;
|
|
97
118
|
const resolvedModel = isCaptureModelEnabled(this.#captureModel) ? resolveModel({
|
|
98
119
|
params: {
|
|
99
120
|
arguments: args,
|
|
@@ -101,20 +122,65 @@ class PostHogMCP extends PostHog {
|
|
|
101
122
|
}
|
|
102
123
|
}, ownsModel) : void 0;
|
|
103
124
|
const strippedArgs = stripContext(args);
|
|
125
|
+
const canReadConversationId = this.#enableConversationId && (ownership?.conversationId ?? true);
|
|
126
|
+
const resolvedConversation = resolveConversationId(canReadConversationId, args);
|
|
127
|
+
const conversation = resolvedConversation.minted && options.sessionId ? {
|
|
128
|
+
minted: false,
|
|
129
|
+
conversationId: void 0
|
|
130
|
+
} : resolvedConversation;
|
|
131
|
+
const conversationId = conversation.conversationId;
|
|
132
|
+
const sessionId = conversationId ? deriveSessionIdFromConversation(conversationId) : options.sessionId;
|
|
104
133
|
const isFeedback = void 0 !== this.#feedbackOptions && name === this.#feedbackToolName && null == options.originalTool;
|
|
105
|
-
|
|
134
|
+
const preparedCall = {
|
|
106
135
|
intent,
|
|
107
136
|
intentSource: intent ? 'context_parameter' : void 0,
|
|
108
137
|
llmModel: resolvedModel?.model,
|
|
109
138
|
llmModelSource: resolvedModel?.source,
|
|
110
|
-
args:
|
|
139
|
+
args: stripOwnedAnalyticsArguments(strippedArgs, {
|
|
111
140
|
context: false,
|
|
112
|
-
conversationId:
|
|
113
|
-
llmModel:
|
|
114
|
-
})
|
|
141
|
+
conversationId: this.#enableConversationId && ownership?.conversationId === true,
|
|
142
|
+
llmModel: ownsModel
|
|
143
|
+
}),
|
|
144
|
+
sessionId,
|
|
145
|
+
conversationId,
|
|
115
146
|
isMissingCapability: name === this.#missingCapabilityToolName,
|
|
116
147
|
isFeedback,
|
|
117
|
-
feedbackReport: isFeedback ? parseFeedbackReport(args, this.#feedbackOptions) : void 0
|
|
148
|
+
feedbackReport: isFeedback ? parseFeedbackReport(args, this.#feedbackOptions) : void 0,
|
|
149
|
+
[PREPARED_CONVERSATION_STATE_KEY]: {
|
|
150
|
+
minted: conversation.minted,
|
|
151
|
+
outputInstructions: this.#enableConversationId && ownership?.outputInstructions === true
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
return preparedCall;
|
|
155
|
+
}
|
|
156
|
+
prepareToolResult(result, preparedCall) {
|
|
157
|
+
const state = preparedCall[PREPARED_CONVERSATION_STATE_KEY];
|
|
158
|
+
const conversationId = preparedCall.conversationId;
|
|
159
|
+
if (!conversationId) return {
|
|
160
|
+
result,
|
|
161
|
+
sessionId: preparedCall.sessionId,
|
|
162
|
+
conversationId
|
|
163
|
+
};
|
|
164
|
+
if (!state) return {
|
|
165
|
+
result,
|
|
166
|
+
sessionId: preparedCall.sessionId,
|
|
167
|
+
conversationId: void 0
|
|
168
|
+
};
|
|
169
|
+
let preparedResult = result;
|
|
170
|
+
let delivered = false;
|
|
171
|
+
if (state.outputInstructions) {
|
|
172
|
+
const mirrored = mirrorInstructionsIntoStructuredContent(preparedResult, conversationId);
|
|
173
|
+
delivered = mirrored !== preparedResult;
|
|
174
|
+
preparedResult = mirrored;
|
|
175
|
+
}
|
|
176
|
+
if (state.minted && canInjectConversationIdPromptBack(preparedResult)) {
|
|
177
|
+
preparedResult = injectConversationIdPromptBack(preparedResult, conversationId);
|
|
178
|
+
delivered = true;
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
result: preparedResult,
|
|
182
|
+
sessionId: preparedCall.sessionId,
|
|
183
|
+
conversationId: state.minted && !delivered ? void 0 : conversationId
|
|
118
184
|
};
|
|
119
185
|
}
|
|
120
186
|
captureMissingCapability(data) {
|
|
@@ -146,6 +212,7 @@ function baseEvent(eventType, common) {
|
|
|
146
212
|
const event = {
|
|
147
213
|
eventType,
|
|
148
214
|
sessionId: common.sessionId,
|
|
215
|
+
conversationId: common.conversationId,
|
|
149
216
|
protocolVersion: common.protocolVersion,
|
|
150
217
|
clientUserAgent: normalizeHeaderString(common.clientUserAgent),
|
|
151
218
|
vendorClient: normalizeHeaderString(common.vendorClient),
|
|
@@ -157,6 +224,21 @@ function baseEvent(eventType, common) {
|
|
|
157
224
|
if (common.setProperties && Object.keys(common.setProperties).length > 0) event.identifyActorData = common.setProperties;
|
|
158
225
|
return event;
|
|
159
226
|
}
|
|
227
|
+
function collectAnalyticsParameterOwnership(tools) {
|
|
228
|
+
const ownershipByName = new Map();
|
|
229
|
+
for (const tool of tools){
|
|
230
|
+
if ('string' != typeof tool.name) continue;
|
|
231
|
+
const next = getAnalyticsParameterOwnership(tool.inputSchema, tool.outputSchema);
|
|
232
|
+
const current = ownershipByName.get(tool.name);
|
|
233
|
+
ownershipByName.set(tool.name, current ? {
|
|
234
|
+
context: current.context && next.context,
|
|
235
|
+
conversationId: current.conversationId && next.conversationId,
|
|
236
|
+
llmModel: current.llmModel && next.llmModel,
|
|
237
|
+
outputInstructions: current.outputInstructions && next.outputInstructions
|
|
238
|
+
} : next);
|
|
239
|
+
}
|
|
240
|
+
return ownershipByName;
|
|
241
|
+
}
|
|
160
242
|
function applyIntent(event, intent, source) {
|
|
161
243
|
const trimmed = 'string' == typeof intent ? intent.trim() : '';
|
|
162
244
|
if (!trimmed) return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sink.d.ts","sourceRoot":"","sources":["../../src/extensions/sink.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAG3C,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAC7D,OAAO,EAAO,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,EAAE,KAAK,mBAAmB,EAA6B,MAAM,kBAAkB,CAAA;AAKtF,yEAAyE;AACzE,MAAM,WAAW,iBAAiB;IAChC,0BAA0B,EAAE,OAAO,CAAA;IACnC,kFAAkF;IAClF,UAAU,CAAC,EAAE,YAAY,CAAA;CAC1B;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,iBAAiB,EAC1B,MAAM,GAAE,QAAc,GACrB,OAAO,CAAC;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,mBAAmB,EAAE,CAAA;CAAE,GAAG,IAAI,CAAC,CA2BnE;AA6BD;;;;;;;GAOG;AACH,qBAAa,YAAY;IAErB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;
|
|
1
|
+
{"version":3,"file":"sink.d.ts","sourceRoot":"","sources":["../../src/extensions/sink.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAG3C,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAC7D,OAAO,EAAO,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,EAAE,KAAK,mBAAmB,EAA6B,MAAM,kBAAkB,CAAA;AAKtF,yEAAyE;AACzE,MAAM,WAAW,iBAAiB;IAChC,0BAA0B,EAAE,OAAO,CAAA;IACnC,kFAAkF;IAClF,UAAU,CAAC,EAAE,YAAY,CAAA;CAC1B;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,iBAAiB,EAC1B,MAAM,GAAE,QAAc,GACrB,OAAO,CAAC;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,mBAAmB,EAAE,CAAA;CAAE,GAAG,IAAI,CAAC,CA2BnE;AA6BD;;;;;;;GAOG;AACH,qBAAa,YAAY;IAErB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAFzB,YACmB,OAAO,EAAE,OAAO,EAChB,MAAM,GAAE,QAAc,EACrC;IAEJ;;;OAGG;IACG,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAkCxE;CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CompatibleTextToolResult, CompatibleToolsListLike } from '../types';
|
|
2
2
|
import { type LoggerFn } from './logger';
|
|
3
|
-
export declare const GET_MORE_TOOLS_NAME:
|
|
3
|
+
export declare const GET_MORE_TOOLS_NAME: 'get_more_tools';
|
|
4
4
|
/**
|
|
5
5
|
* The configured name of the `get_more_tools` virtual tool, falling back to the
|
|
6
6
|
* default. Resolve through here everywhere (inject + detect) so a custom name
|
package/dist/index.d.ts
CHANGED
|
@@ -56,7 +56,7 @@ export { getMoreToolsResult } from './extensions/tools';
|
|
|
56
56
|
export { sendFeedbackResult, SEND_FEEDBACK_TOOL_NAME } from './extensions/feedback';
|
|
57
57
|
export { setLogger } from './extensions/logger';
|
|
58
58
|
export { PostHog, type PostHogOptions } from 'posthog-node';
|
|
59
|
-
export type { FeedbackCaptureData, FeedbackExtraPropertySchema, CollectFeedbackOptions, FeedbackReport, FeedbackSentiment, FeedbackType, BeforeSendFn, CaptureEventData, CollectFeedbackConfig, InitializeCaptureData, McpAnalytics, McpCaptureCommon, MCPAnalyticsContextOptions, MCPAnalyticsIntentSource, MCPAnalyticsModelOptions, MCPAnalyticsModelSource, MCPAnalyticsOptions, MissingCapabilityCaptureData, PreparedToolCall, PrepareToolCallOptions, PrepareToolListOptions, RequestHeaderBag, ToolCallCaptureData, ToolsListCaptureData, UserIdentity, } from './types';
|
|
59
|
+
export type { FeedbackCaptureData, FeedbackExtraPropertySchema, CollectFeedbackOptions, FeedbackReport, FeedbackSentiment, FeedbackType, BeforeSendFn, CaptureEventData, CollectFeedbackConfig, InitializeCaptureData, McpAnalytics, McpCaptureCommon, MCPAnalyticsContextOptions, MCPAnalyticsIntentSource, MCPAnalyticsModelOptions, MCPAnalyticsModelSource, MCPAnalyticsOptions, MissingCapabilityCaptureData, PreparedToolCall, PreparedToolResult, PrepareToolCallOptions, PrepareToolListOptions, RequestHeaderBag, ToolCallCaptureData, ToolsListCaptureData, UserIdentity, } from './types';
|
|
60
60
|
export type IdentifyFunction = MCPAnalyticsOptions['identify'];
|
|
61
61
|
export { instrument, instrumentMutator };
|
|
62
62
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAQ3C,OAAO,EAAE,6BAA6B,EAAkB,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAIlG,OAAO,KAAK,EAGV,YAAY,EAEZ,mBAAmB,EAGpB,MAAM,SAAS,CAAA;AAEhB;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,iBAAS,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAE,mBAAwB,GAAG,YAAY,CA4CtG;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,iBAAS,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAKjH;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAQ3C,OAAO,EAAE,6BAA6B,EAAkB,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAIlG,OAAO,KAAK,EAGV,YAAY,EAEZ,mBAAmB,EAGpB,MAAM,SAAS,CAAA;AAEhB;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,iBAAS,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAE,mBAAwB,GAAG,YAAY,CA4CtG;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,iBAAS,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAKjH;AA4FD,OAAO,EAAE,6BAA6B,EAAE,YAAY,EAAE,CAAA;AAItD,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,KAAK,mBAAmB,GACzB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EACL,4BAA4B,EAC5B,wBAAwB,EACxB,2BAA2B,GAC5B,MAAM,wBAAwB,CAAA;AAG/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAChE,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AACnF,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAI/C,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAA;AAC3D,YAAY,EACV,mBAAmB,EACnB,2BAA2B,EAC3B,sBAAsB,EACtB,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,EACrB,YAAY,EACZ,gBAAgB,EAChB,0BAA0B,EAC1B,wBAAwB,EACxB,wBAAwB,EACxB,uBAAuB,EACvB,mBAAmB,EACnB,4BAA4B,EAC5B,gBAAgB,EAChB,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,GACb,MAAM,SAAS,CAAA;AAChB,MAAM,MAAM,gBAAgB,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAA;AAC9D,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -106,7 +106,8 @@ function getLowLevelServer(server) {
|
|
|
106
106
|
const DEFAULT_OPTIONS = {
|
|
107
107
|
reportMissing: false,
|
|
108
108
|
collectFeedback: false,
|
|
109
|
-
enableConversationId:
|
|
109
|
+
enableConversationId: true,
|
|
110
|
+
captureModel: true
|
|
110
111
|
};
|
|
111
112
|
function buildTrackingData(lowLevelServer, options, sink, logger) {
|
|
112
113
|
return {
|
|
@@ -121,7 +122,7 @@ function buildTrackingData(lowLevelServer, options, sink, logger) {
|
|
|
121
122
|
sessionInfo: (0, session_js_namespaceObject.getSessionInfo)(lowLevelServer, void 0),
|
|
122
123
|
options: {
|
|
123
124
|
...DEFAULT_OPTIONS,
|
|
124
|
-
...options
|
|
125
|
+
...Object.fromEntries(Object.entries(options).filter(([, value])=>void 0 !== value))
|
|
125
126
|
},
|
|
126
127
|
sessionSource: 'generated'
|
|
127
128
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -52,7 +52,8 @@ function getLowLevelServer(server) {
|
|
|
52
52
|
const DEFAULT_OPTIONS = {
|
|
53
53
|
reportMissing: false,
|
|
54
54
|
collectFeedback: false,
|
|
55
|
-
enableConversationId:
|
|
55
|
+
enableConversationId: true,
|
|
56
|
+
captureModel: true
|
|
56
57
|
};
|
|
57
58
|
function buildTrackingData(lowLevelServer, options, sink, logger) {
|
|
58
59
|
return {
|
|
@@ -67,7 +68,7 @@ function buildTrackingData(lowLevelServer, options, sink, logger) {
|
|
|
67
68
|
sessionInfo: getSessionInfo(lowLevelServer, void 0),
|
|
68
69
|
options: {
|
|
69
70
|
...DEFAULT_OPTIONS,
|
|
70
|
-
...options
|
|
71
|
+
...Object.fromEntries(Object.entries(options).filter(([, value])=>void 0 !== value))
|
|
71
72
|
},
|
|
72
73
|
sessionSource: 'generated'
|
|
73
74
|
};
|