@posthog/mcp 0.0.9 → 0.1.16
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/LICENSE +307 -3
- package/README.md +182 -90
- package/dist/extensions/capture.d.ts +13 -0
- package/dist/extensions/capture.d.ts.map +1 -0
- package/dist/extensions/capture.js +80 -0
- package/dist/extensions/capture.mjs +46 -0
- package/dist/extensions/compatibility.d.ts +23 -0
- package/dist/extensions/compatibility.d.ts.map +1 -0
- package/dist/extensions/compatibility.js +113 -0
- package/dist/extensions/compatibility.mjs +67 -0
- package/dist/extensions/constants.d.ts +39 -0
- package/dist/extensions/constants.d.ts.map +1 -0
- package/dist/extensions/constants.js +86 -0
- package/dist/extensions/constants.mjs +37 -0
- package/dist/extensions/context-parameters.d.ts +31 -0
- package/dist/extensions/context-parameters.d.ts.map +1 -0
- package/dist/extensions/context-parameters.js +93 -0
- package/dist/extensions/context-parameters.mjs +50 -0
- package/dist/extensions/conversation-id.d.ts +52 -0
- package/dist/extensions/conversation-id.d.ts.map +1 -0
- package/dist/extensions/conversation-id.js +164 -0
- package/dist/extensions/conversation-id.mjs +103 -0
- package/dist/extensions/event-types.d.ts +21 -0
- package/dist/extensions/event-types.d.ts.map +1 -0
- package/dist/extensions/event-types.js +47 -0
- package/dist/extensions/event-types.mjs +13 -0
- package/dist/extensions/exceptions.d.ts +13 -0
- package/dist/extensions/exceptions.d.ts.map +1 -0
- package/dist/extensions/exceptions.js +58 -0
- package/dist/extensions/exceptions.mjs +24 -0
- package/dist/extensions/ids.d.ts +13 -0
- package/dist/extensions/ids.d.ts.map +1 -0
- package/dist/extensions/ids.js +55 -0
- package/dist/extensions/ids.mjs +18 -0
- package/dist/extensions/instrument-highlevel.d.ts +3 -0
- package/dist/extensions/instrument-highlevel.d.ts.map +1 -0
- package/dist/extensions/instrument-highlevel.js +229 -0
- package/dist/extensions/instrument-highlevel.mjs +195 -0
- package/dist/extensions/instrument-lowlevel.d.ts +8 -0
- package/dist/extensions/instrument-lowlevel.d.ts.map +1 -0
- package/dist/extensions/instrument-lowlevel.js +85 -0
- package/dist/extensions/instrument-lowlevel.mjs +51 -0
- package/dist/extensions/instrumentation.d.ts +59 -0
- package/dist/extensions/instrumentation.d.ts.map +1 -0
- package/dist/extensions/instrumentation.js +237 -0
- package/dist/extensions/instrumentation.mjs +194 -0
- package/dist/extensions/intent.d.ts +10 -0
- package/dist/extensions/intent.d.ts.map +1 -0
- package/dist/extensions/intent.js +84 -0
- package/dist/extensions/intent.mjs +44 -0
- package/dist/extensions/internal.d.ts +32 -0
- package/dist/extensions/internal.d.ts.map +1 -0
- package/dist/extensions/internal.js +158 -0
- package/dist/extensions/internal.mjs +106 -0
- package/dist/extensions/logger.d.ts +14 -0
- package/dist/extensions/logger.d.ts.map +1 -0
- package/dist/extensions/logger.js +47 -0
- package/dist/extensions/logger.mjs +10 -0
- package/dist/extensions/mcp-payloads.d.ts +5 -0
- package/dist/extensions/mcp-payloads.d.ts.map +1 -0
- package/dist/extensions/mcp-payloads.js +91 -0
- package/dist/extensions/mcp-payloads.mjs +54 -0
- package/dist/extensions/mcp-sdk-compat.d.ts +33 -0
- package/dist/extensions/mcp-sdk-compat.d.ts.map +1 -0
- package/dist/extensions/mcp-sdk-compat.js +112 -0
- package/dist/extensions/mcp-sdk-compat.mjs +60 -0
- package/dist/extensions/posthog-events.d.ts +14 -0
- package/dist/extensions/posthog-events.d.ts.map +1 -0
- package/dist/extensions/posthog-events.js +143 -0
- package/dist/extensions/posthog-events.mjs +109 -0
- package/dist/extensions/sanitization.d.ts +10 -0
- package/dist/extensions/sanitization.d.ts.map +1 -0
- package/dist/extensions/sanitization.js +96 -0
- package/dist/extensions/sanitization.mjs +62 -0
- package/dist/extensions/session.d.ts +20 -0
- package/dist/extensions/session.d.ts.map +1 -0
- package/dist/extensions/session.js +113 -0
- package/dist/extensions/session.mjs +67 -0
- package/dist/extensions/sink.d.ts +44 -0
- package/dist/extensions/sink.d.ts.map +1 -0
- package/dist/extensions/sink.js +102 -0
- package/dist/extensions/sink.mjs +65 -0
- package/dist/extensions/tools.d.ts +9 -0
- package/dist/extensions/tools.d.ts.map +1 -0
- package/dist/extensions/tools.js +79 -0
- package/dist/extensions/tools.mjs +39 -0
- package/dist/extensions/tracing-helpers.d.ts +29 -0
- package/dist/extensions/tracing-helpers.d.ts.map +1 -0
- package/dist/extensions/tracing-helpers.js +59 -0
- package/dist/extensions/tracing-helpers.mjs +16 -0
- package/dist/extensions/truncation.d.ts +25 -0
- package/dist/extensions/truncation.d.ts.map +1 -0
- package/dist/extensions/truncation.js +277 -0
- package/dist/extensions/truncation.mjs +228 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +132 -0
- package/dist/index.mjs +83 -2929
- package/dist/types.d.ts +220 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +18 -0
- package/dist/types.mjs +0 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +36 -0
- package/dist/version.mjs +2 -0
- package/package.json +55 -87
- package/src/extensions/capture.ts +68 -0
- package/src/extensions/compatibility.ts +138 -0
- package/src/extensions/constants.ts +48 -0
- package/src/extensions/context-parameters.ts +119 -0
- package/src/extensions/conversation-id.ts +177 -0
- package/src/extensions/event-types.ts +21 -0
- package/src/extensions/exceptions.ts +83 -0
- package/src/extensions/ids.ts +32 -0
- package/src/extensions/instrument-highlevel.ts +297 -0
- package/src/extensions/instrument-lowlevel.ts +83 -0
- package/src/extensions/instrumentation.ts +415 -0
- package/src/extensions/intent.ts +78 -0
- package/src/extensions/internal.ts +193 -0
- package/src/extensions/logger.ts +27 -0
- package/src/extensions/mcp-payloads.ts +98 -0
- package/src/extensions/mcp-sdk-compat.ts +160 -0
- package/src/extensions/posthog-events.ts +212 -0
- package/src/extensions/sanitization.ts +121 -0
- package/src/extensions/session.ts +117 -0
- package/src/extensions/sink.ts +130 -0
- package/src/extensions/tools.ts +50 -0
- package/src/extensions/tracing-helpers.ts +51 -0
- package/src/extensions/truncation.ts +453 -0
- package/src/index.ts +174 -0
- package/src/types.ts +244 -0
- package/src/version.ts +1 -0
- package/dist/index.cjs +0 -2937
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -264
- package/dist/index.d.mts +0 -263
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { DEFAULT_CONTEXT_PARAMETER_DESCRIPTION } from "./constants.mjs";
|
|
2
|
+
import { log } from "./logger.mjs";
|
|
3
|
+
function isContextEnabled(context) {
|
|
4
|
+
return false !== context;
|
|
5
|
+
}
|
|
6
|
+
function getContextDescription(context) {
|
|
7
|
+
return 'object' == typeof context ? context.description : void 0;
|
|
8
|
+
}
|
|
9
|
+
function addContextParameterToTool(tool, contextDescriptionOverride) {
|
|
10
|
+
const modifiedTool = {
|
|
11
|
+
...tool
|
|
12
|
+
};
|
|
13
|
+
const toolName = tool.name || 'unknown';
|
|
14
|
+
const schema = modifiedTool.inputSchema;
|
|
15
|
+
if (schema?.properties?.context) {
|
|
16
|
+
log(`WARN: Tool "${toolName}" already has 'context' parameter. Skipping context injection.`);
|
|
17
|
+
return modifiedTool;
|
|
18
|
+
}
|
|
19
|
+
if (schema?.oneOf || schema?.allOf || schema?.anyOf) {
|
|
20
|
+
log(`WARN: Tool "${toolName}" has complex schema (oneOf/allOf/anyOf). Skipping context injection.`);
|
|
21
|
+
return modifiedTool;
|
|
22
|
+
}
|
|
23
|
+
if (!modifiedTool.inputSchema) modifiedTool.inputSchema = {
|
|
24
|
+
type: 'object',
|
|
25
|
+
properties: {},
|
|
26
|
+
required: []
|
|
27
|
+
};
|
|
28
|
+
const contextDescription = contextDescriptionOverride || DEFAULT_CONTEXT_PARAMETER_DESCRIPTION;
|
|
29
|
+
modifiedTool.inputSchema = JSON.parse(JSON.stringify(modifiedTool.inputSchema));
|
|
30
|
+
const inputSchema = modifiedTool.inputSchema;
|
|
31
|
+
if (!inputSchema.properties) inputSchema.properties = {};
|
|
32
|
+
if (false === inputSchema.additionalProperties) inputSchema.additionalProperties = void 0;
|
|
33
|
+
inputSchema.properties.context = {
|
|
34
|
+
type: 'string',
|
|
35
|
+
description: contextDescription
|
|
36
|
+
};
|
|
37
|
+
if (Array.isArray(inputSchema.required)) {
|
|
38
|
+
if (!inputSchema.required.includes('context')) inputSchema.required.push('context');
|
|
39
|
+
} else inputSchema.required = [
|
|
40
|
+
'context'
|
|
41
|
+
];
|
|
42
|
+
return modifiedTool;
|
|
43
|
+
}
|
|
44
|
+
function addContextParameterToTools(tools, contextDescriptionOverride) {
|
|
45
|
+
return tools.map((tool)=>{
|
|
46
|
+
if ('get_more_tools' === tool.name) return tool;
|
|
47
|
+
return addContextParameterToTool(tool, contextDescriptionOverride);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
export { addContextParameterToTool, addContextParameterToTools, getContextDescription, isContextEnabled };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export declare const CONVERSATION_ID_PARAM_NAME = "conversation_id";
|
|
2
|
+
interface JsonSchema {
|
|
3
|
+
additionalProperties?: boolean;
|
|
4
|
+
allOf?: unknown;
|
|
5
|
+
anyOf?: unknown;
|
|
6
|
+
oneOf?: unknown;
|
|
7
|
+
properties?: Record<string, unknown>;
|
|
8
|
+
required?: string[];
|
|
9
|
+
type?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ConversationIdInjectableTool {
|
|
12
|
+
inputSchema?: JsonSchema;
|
|
13
|
+
name?: string;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
export declare function addConversationIdToTool<TTool extends ConversationIdInjectableTool>(tool: TTool): TTool;
|
|
17
|
+
export declare function addConversationIdToTools<TTool extends ConversationIdInjectableTool>(tools: TTool[]): TTool[];
|
|
18
|
+
export type ConversationIdResolution = {
|
|
19
|
+
minted: false;
|
|
20
|
+
conversationId: string | undefined;
|
|
21
|
+
} | {
|
|
22
|
+
minted: true;
|
|
23
|
+
conversationId: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Decides which conversation_id to use for a tool call:
|
|
27
|
+
* - disabled or get_more_tools → none
|
|
28
|
+
* - agent supplied a value → use it
|
|
29
|
+
* - agent omitted → mint a UUID
|
|
30
|
+
*/
|
|
31
|
+
export declare function resolveConversationId(enabled: boolean, args: unknown, toolName: string | undefined): ConversationIdResolution;
|
|
32
|
+
/**
|
|
33
|
+
* Predicate matching the same eligibility checks injectConversationIdPromptBack uses,
|
|
34
|
+
* exposed so callers can pre-decide whether the prompt-back will actually land
|
|
35
|
+
* (and clear event.conversationId if not, to avoid orphan ids in analytics).
|
|
36
|
+
*/
|
|
37
|
+
export declare function canInjectConversationIdPromptBack(result: unknown): boolean;
|
|
38
|
+
export declare function extractConversationId(args: unknown): string | undefined;
|
|
39
|
+
export declare function cloneRequestWithoutConversationId<TRequest extends {
|
|
40
|
+
params?: {
|
|
41
|
+
arguments?: unknown;
|
|
42
|
+
[k: string]: unknown;
|
|
43
|
+
};
|
|
44
|
+
}>(request: TRequest): TRequest;
|
|
45
|
+
export declare function stripConversationId(args: unknown): unknown;
|
|
46
|
+
export declare function buildConversationIdPromptBack(conversationId: string): {
|
|
47
|
+
type: 'text';
|
|
48
|
+
text: string;
|
|
49
|
+
};
|
|
50
|
+
export declare function injectConversationIdPromptBack(result: unknown, conversationId: string): unknown;
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=conversation-id.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversation-id.d.ts","sourceRoot":"","sources":["../../src/extensions/conversation-id.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,0BAA0B,oBAAoB,CAAA;AAE3D,UAAU,UAAU;IAClB,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;IACnB,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,4BAA4B;IAC3C,WAAW,CAAC,EAAE,UAAU,CAAA;IACxB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,wBAAgB,uBAAuB,CAAC,KAAK,SAAS,4BAA4B,EAAE,IAAI,EAAE,KAAK,GAAG,KAAK,CA2CtG;AAED,wBAAgB,wBAAwB,CAAC,KAAK,SAAS,4BAA4B,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,CAO5G;AAED,MAAM,MAAM,wBAAwB,GAChC;IAAE,MAAM,EAAE,KAAK,CAAC;IAAC,cAAc,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GACrD;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,CAAA;AAE5C;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,OAAO,EACb,QAAQ,EAAE,MAAM,GAAG,SAAS,GAC3B,wBAAwB,CAS1B;AAED;;;;GAIG;AACH,wBAAgB,iCAAiC,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAS1E;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAUvE;AAED,wBAAgB,iCAAiC,CAC/C,QAAQ,SAAS;IAAE,MAAM,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAC;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAA;CAAE,EAC3E,OAAO,EAAE,QAAQ,GAAG,QAAQ,CAe7B;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAM1D;AAED,wBAAgB,6BAA6B,CAAC,cAAc,EAAE,MAAM,GAAG;IACrE,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;CACb,CAKA;AAED,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAS/F"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
CONVERSATION_ID_PARAM_NAME: ()=>CONVERSATION_ID_PARAM_NAME,
|
|
28
|
+
resolveConversationId: ()=>resolveConversationId,
|
|
29
|
+
buildConversationIdPromptBack: ()=>buildConversationIdPromptBack,
|
|
30
|
+
addConversationIdToTool: ()=>addConversationIdToTool,
|
|
31
|
+
addConversationIdToTools: ()=>addConversationIdToTools,
|
|
32
|
+
extractConversationId: ()=>extractConversationId,
|
|
33
|
+
injectConversationIdPromptBack: ()=>injectConversationIdPromptBack,
|
|
34
|
+
cloneRequestWithoutConversationId: ()=>cloneRequestWithoutConversationId,
|
|
35
|
+
stripConversationId: ()=>stripConversationId,
|
|
36
|
+
canInjectConversationIdPromptBack: ()=>canInjectConversationIdPromptBack
|
|
37
|
+
});
|
|
38
|
+
const core_namespaceObject = require("@posthog/core");
|
|
39
|
+
const external_constants_js_namespaceObject = require("./constants.js");
|
|
40
|
+
const external_logger_js_namespaceObject = require("./logger.js");
|
|
41
|
+
const external_tools_js_namespaceObject = require("./tools.js");
|
|
42
|
+
const CONVERSATION_ID_PARAM_NAME = 'conversation_id';
|
|
43
|
+
function addConversationIdToTool(tool) {
|
|
44
|
+
const modifiedTool = {
|
|
45
|
+
...tool
|
|
46
|
+
};
|
|
47
|
+
const toolName = tool.name || 'unknown';
|
|
48
|
+
const schema = modifiedTool.inputSchema;
|
|
49
|
+
if (schema?.properties?.[CONVERSATION_ID_PARAM_NAME]) {
|
|
50
|
+
(0, external_logger_js_namespaceObject.log)(`WARN: Tool "${toolName}" already has '${CONVERSATION_ID_PARAM_NAME}' parameter. Skipping conversation_id injection.`);
|
|
51
|
+
return modifiedTool;
|
|
52
|
+
}
|
|
53
|
+
if (schema?.oneOf || schema?.allOf || schema?.anyOf) {
|
|
54
|
+
(0, external_logger_js_namespaceObject.log)(`WARN: Tool "${toolName}" has complex schema (oneOf/allOf/anyOf). Skipping conversation_id injection.`);
|
|
55
|
+
return modifiedTool;
|
|
56
|
+
}
|
|
57
|
+
if (!modifiedTool.inputSchema) modifiedTool.inputSchema = {
|
|
58
|
+
type: 'object',
|
|
59
|
+
properties: {},
|
|
60
|
+
required: []
|
|
61
|
+
};
|
|
62
|
+
modifiedTool.inputSchema = JSON.parse(JSON.stringify(modifiedTool.inputSchema));
|
|
63
|
+
const inputSchema = modifiedTool.inputSchema;
|
|
64
|
+
if (!inputSchema.properties) inputSchema.properties = {};
|
|
65
|
+
if (false === inputSchema.additionalProperties) inputSchema.additionalProperties = void 0;
|
|
66
|
+
inputSchema.properties[CONVERSATION_ID_PARAM_NAME] = {
|
|
67
|
+
type: 'string',
|
|
68
|
+
description: external_constants_js_namespaceObject.DEFAULT_CONVERSATION_ID_DESCRIPTION
|
|
69
|
+
};
|
|
70
|
+
return modifiedTool;
|
|
71
|
+
}
|
|
72
|
+
function addConversationIdToTools(tools) {
|
|
73
|
+
return tools.map((tool)=>{
|
|
74
|
+
if (tool.name === external_tools_js_namespaceObject.GET_MORE_TOOLS_NAME) return tool;
|
|
75
|
+
return addConversationIdToTool(tool);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function resolveConversationId(enabled, args, toolName) {
|
|
79
|
+
if (!enabled || toolName === external_tools_js_namespaceObject.GET_MORE_TOOLS_NAME) return {
|
|
80
|
+
minted: false,
|
|
81
|
+
conversationId: void 0
|
|
82
|
+
};
|
|
83
|
+
const supplied = extractConversationId(args);
|
|
84
|
+
if (supplied) return {
|
|
85
|
+
minted: false,
|
|
86
|
+
conversationId: supplied
|
|
87
|
+
};
|
|
88
|
+
return {
|
|
89
|
+
minted: true,
|
|
90
|
+
conversationId: (0, core_namespaceObject.uuidv7)()
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function canInjectConversationIdPromptBack(result) {
|
|
94
|
+
if (!(result && 'object' == typeof result)) return false;
|
|
95
|
+
const resultObj = result;
|
|
96
|
+
if (true === resultObj.isError) return false;
|
|
97
|
+
return Array.isArray(resultObj.content);
|
|
98
|
+
}
|
|
99
|
+
function extractConversationId(args) {
|
|
100
|
+
if (!(args && 'object' == typeof args)) return;
|
|
101
|
+
const value = args[CONVERSATION_ID_PARAM_NAME];
|
|
102
|
+
if ('string' != typeof value) return;
|
|
103
|
+
const trimmed = value.trim();
|
|
104
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
105
|
+
}
|
|
106
|
+
function cloneRequestWithoutConversationId(request) {
|
|
107
|
+
if (!request.params || 'object' != typeof request.params) return request;
|
|
108
|
+
const args = request.params.arguments;
|
|
109
|
+
if (!(args && 'object' == typeof args)) return request;
|
|
110
|
+
return {
|
|
111
|
+
...request,
|
|
112
|
+
params: {
|
|
113
|
+
...request.params,
|
|
114
|
+
arguments: stripConversationId(args)
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function stripConversationId(args) {
|
|
119
|
+
if (!args || 'object' != typeof args || !(CONVERSATION_ID_PARAM_NAME in args)) return args;
|
|
120
|
+
const { [CONVERSATION_ID_PARAM_NAME]: _omit, ...rest } = args;
|
|
121
|
+
return rest;
|
|
122
|
+
}
|
|
123
|
+
function buildConversationIdPromptBack(conversationId) {
|
|
124
|
+
return {
|
|
125
|
+
type: 'text',
|
|
126
|
+
text: `[SERVER]: Reuse conversation_id=${conversationId} on every subsequent tool call in this conversation. Required for the server to correlate calls and provide context-aware results.`
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function injectConversationIdPromptBack(result, conversationId) {
|
|
130
|
+
if (!canInjectConversationIdPromptBack(result)) return result;
|
|
131
|
+
const resultObj = result;
|
|
132
|
+
return {
|
|
133
|
+
...resultObj,
|
|
134
|
+
content: [
|
|
135
|
+
...resultObj.content,
|
|
136
|
+
buildConversationIdPromptBack(conversationId)
|
|
137
|
+
]
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
exports.CONVERSATION_ID_PARAM_NAME = __webpack_exports__.CONVERSATION_ID_PARAM_NAME;
|
|
141
|
+
exports.addConversationIdToTool = __webpack_exports__.addConversationIdToTool;
|
|
142
|
+
exports.addConversationIdToTools = __webpack_exports__.addConversationIdToTools;
|
|
143
|
+
exports.buildConversationIdPromptBack = __webpack_exports__.buildConversationIdPromptBack;
|
|
144
|
+
exports.canInjectConversationIdPromptBack = __webpack_exports__.canInjectConversationIdPromptBack;
|
|
145
|
+
exports.cloneRequestWithoutConversationId = __webpack_exports__.cloneRequestWithoutConversationId;
|
|
146
|
+
exports.extractConversationId = __webpack_exports__.extractConversationId;
|
|
147
|
+
exports.injectConversationIdPromptBack = __webpack_exports__.injectConversationIdPromptBack;
|
|
148
|
+
exports.resolveConversationId = __webpack_exports__.resolveConversationId;
|
|
149
|
+
exports.stripConversationId = __webpack_exports__.stripConversationId;
|
|
150
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
151
|
+
"CONVERSATION_ID_PARAM_NAME",
|
|
152
|
+
"addConversationIdToTool",
|
|
153
|
+
"addConversationIdToTools",
|
|
154
|
+
"buildConversationIdPromptBack",
|
|
155
|
+
"canInjectConversationIdPromptBack",
|
|
156
|
+
"cloneRequestWithoutConversationId",
|
|
157
|
+
"extractConversationId",
|
|
158
|
+
"injectConversationIdPromptBack",
|
|
159
|
+
"resolveConversationId",
|
|
160
|
+
"stripConversationId"
|
|
161
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
162
|
+
Object.defineProperty(exports, '__esModule', {
|
|
163
|
+
value: true
|
|
164
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { uuidv7 } from "@posthog/core";
|
|
2
|
+
import { DEFAULT_CONVERSATION_ID_DESCRIPTION } from "./constants.mjs";
|
|
3
|
+
import { log } from "./logger.mjs";
|
|
4
|
+
import { GET_MORE_TOOLS_NAME } from "./tools.mjs";
|
|
5
|
+
const CONVERSATION_ID_PARAM_NAME = 'conversation_id';
|
|
6
|
+
function addConversationIdToTool(tool) {
|
|
7
|
+
const modifiedTool = {
|
|
8
|
+
...tool
|
|
9
|
+
};
|
|
10
|
+
const toolName = tool.name || 'unknown';
|
|
11
|
+
const schema = modifiedTool.inputSchema;
|
|
12
|
+
if (schema?.properties?.[CONVERSATION_ID_PARAM_NAME]) {
|
|
13
|
+
log(`WARN: Tool "${toolName}" already has '${CONVERSATION_ID_PARAM_NAME}' parameter. Skipping conversation_id injection.`);
|
|
14
|
+
return modifiedTool;
|
|
15
|
+
}
|
|
16
|
+
if (schema?.oneOf || schema?.allOf || schema?.anyOf) {
|
|
17
|
+
log(`WARN: Tool "${toolName}" has complex schema (oneOf/allOf/anyOf). Skipping conversation_id injection.`);
|
|
18
|
+
return modifiedTool;
|
|
19
|
+
}
|
|
20
|
+
if (!modifiedTool.inputSchema) modifiedTool.inputSchema = {
|
|
21
|
+
type: 'object',
|
|
22
|
+
properties: {},
|
|
23
|
+
required: []
|
|
24
|
+
};
|
|
25
|
+
modifiedTool.inputSchema = JSON.parse(JSON.stringify(modifiedTool.inputSchema));
|
|
26
|
+
const inputSchema = modifiedTool.inputSchema;
|
|
27
|
+
if (!inputSchema.properties) inputSchema.properties = {};
|
|
28
|
+
if (false === inputSchema.additionalProperties) inputSchema.additionalProperties = void 0;
|
|
29
|
+
inputSchema.properties[CONVERSATION_ID_PARAM_NAME] = {
|
|
30
|
+
type: 'string',
|
|
31
|
+
description: DEFAULT_CONVERSATION_ID_DESCRIPTION
|
|
32
|
+
};
|
|
33
|
+
return modifiedTool;
|
|
34
|
+
}
|
|
35
|
+
function addConversationIdToTools(tools) {
|
|
36
|
+
return tools.map((tool)=>{
|
|
37
|
+
if (tool.name === GET_MORE_TOOLS_NAME) return tool;
|
|
38
|
+
return addConversationIdToTool(tool);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function resolveConversationId(enabled, args, toolName) {
|
|
42
|
+
if (!enabled || toolName === GET_MORE_TOOLS_NAME) return {
|
|
43
|
+
minted: false,
|
|
44
|
+
conversationId: void 0
|
|
45
|
+
};
|
|
46
|
+
const supplied = extractConversationId(args);
|
|
47
|
+
if (supplied) return {
|
|
48
|
+
minted: false,
|
|
49
|
+
conversationId: supplied
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
minted: true,
|
|
53
|
+
conversationId: uuidv7()
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function canInjectConversationIdPromptBack(result) {
|
|
57
|
+
if (!(result && 'object' == typeof result)) return false;
|
|
58
|
+
const resultObj = result;
|
|
59
|
+
if (true === resultObj.isError) return false;
|
|
60
|
+
return Array.isArray(resultObj.content);
|
|
61
|
+
}
|
|
62
|
+
function extractConversationId(args) {
|
|
63
|
+
if (!(args && 'object' == typeof args)) return;
|
|
64
|
+
const value = args[CONVERSATION_ID_PARAM_NAME];
|
|
65
|
+
if ('string' != typeof value) return;
|
|
66
|
+
const trimmed = value.trim();
|
|
67
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
68
|
+
}
|
|
69
|
+
function cloneRequestWithoutConversationId(request) {
|
|
70
|
+
if (!request.params || 'object' != typeof request.params) return request;
|
|
71
|
+
const args = request.params.arguments;
|
|
72
|
+
if (!(args && 'object' == typeof args)) return request;
|
|
73
|
+
return {
|
|
74
|
+
...request,
|
|
75
|
+
params: {
|
|
76
|
+
...request.params,
|
|
77
|
+
arguments: stripConversationId(args)
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function stripConversationId(args) {
|
|
82
|
+
if (!args || 'object' != typeof args || !(CONVERSATION_ID_PARAM_NAME in args)) return args;
|
|
83
|
+
const { [CONVERSATION_ID_PARAM_NAME]: _omit, ...rest } = args;
|
|
84
|
+
return rest;
|
|
85
|
+
}
|
|
86
|
+
function buildConversationIdPromptBack(conversationId) {
|
|
87
|
+
return {
|
|
88
|
+
type: 'text',
|
|
89
|
+
text: `[SERVER]: Reuse conversation_id=${conversationId} on every subsequent tool call in this conversation. Required for the server to correlate calls and provide context-aware results.`
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function injectConversationIdPromptBack(result, conversationId) {
|
|
93
|
+
if (!canInjectConversationIdPromptBack(result)) return result;
|
|
94
|
+
const resultObj = result;
|
|
95
|
+
return {
|
|
96
|
+
...resultObj,
|
|
97
|
+
content: [
|
|
98
|
+
...resultObj.content,
|
|
99
|
+
buildConversationIdPromptBack(conversationId)
|
|
100
|
+
]
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
export { CONVERSATION_ID_PARAM_NAME, addConversationIdToTool, addConversationIdToTools, buildConversationIdPromptBack, canInjectConversationIdPromptBack, cloneRequestWithoutConversationId, extractConversationId, injectConversationIdPromptBack, resolveConversationId, stripConversationId };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal SDK event vocabulary.
|
|
3
|
+
*
|
|
4
|
+
* These values are not imported from `@modelcontextprotocol/sdk`; they are the
|
|
5
|
+
* protocol-shaped event types this SDK observes before mapping them to PostHog
|
|
6
|
+
* event names.
|
|
7
|
+
*/
|
|
8
|
+
export declare const MCPAnalyticsEventType: {
|
|
9
|
+
readonly identify: "posthog:identify";
|
|
10
|
+
readonly custom: "posthog:custom";
|
|
11
|
+
readonly mcpMissingCapability: "mcp:missing_capability";
|
|
12
|
+
readonly mcpInitialize: "mcp:initialize";
|
|
13
|
+
readonly mcpPromptsGet: "mcp:prompts/get";
|
|
14
|
+
readonly mcpPromptsList: "mcp:prompts/list";
|
|
15
|
+
readonly mcpResourcesList: "mcp:resources/list";
|
|
16
|
+
readonly mcpResourcesRead: "mcp:resources/read";
|
|
17
|
+
readonly mcpToolsCall: "mcp:tools/call";
|
|
18
|
+
readonly mcpToolsList: "mcp:tools/list";
|
|
19
|
+
};
|
|
20
|
+
export type MCPAnalyticsEventType = (typeof MCPAnalyticsEventType)[keyof typeof MCPAnalyticsEventType];
|
|
21
|
+
//# sourceMappingURL=event-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-types.d.ts","sourceRoot":"","sources":["../../src/extensions/event-types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;CAWxB,CAAA;AAEV,MAAM,MAAM,qBAAqB,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,OAAO,qBAAqB,CAAC,CAAA"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
MCPAnalyticsEventType: ()=>MCPAnalyticsEventType
|
|
28
|
+
});
|
|
29
|
+
const MCPAnalyticsEventType = {
|
|
30
|
+
identify: 'posthog:identify',
|
|
31
|
+
custom: 'posthog:custom',
|
|
32
|
+
mcpMissingCapability: 'mcp:missing_capability',
|
|
33
|
+
mcpInitialize: 'mcp:initialize',
|
|
34
|
+
mcpPromptsGet: 'mcp:prompts/get',
|
|
35
|
+
mcpPromptsList: 'mcp:prompts/list',
|
|
36
|
+
mcpResourcesList: 'mcp:resources/list',
|
|
37
|
+
mcpResourcesRead: 'mcp:resources/read',
|
|
38
|
+
mcpToolsCall: 'mcp:tools/call',
|
|
39
|
+
mcpToolsList: 'mcp:tools/list'
|
|
40
|
+
};
|
|
41
|
+
exports.MCPAnalyticsEventType = __webpack_exports__.MCPAnalyticsEventType;
|
|
42
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
43
|
+
"MCPAnalyticsEventType"
|
|
44
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
45
|
+
Object.defineProperty(exports, '__esModule', {
|
|
46
|
+
value: true
|
|
47
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const MCPAnalyticsEventType = {
|
|
2
|
+
identify: 'posthog:identify',
|
|
3
|
+
custom: 'posthog:custom',
|
|
4
|
+
mcpMissingCapability: 'mcp:missing_capability',
|
|
5
|
+
mcpInitialize: 'mcp:initialize',
|
|
6
|
+
mcpPromptsGet: 'mcp:prompts/get',
|
|
7
|
+
mcpPromptsList: 'mcp:prompts/list',
|
|
8
|
+
mcpResourcesList: 'mcp:resources/list',
|
|
9
|
+
mcpResourcesRead: 'mcp:resources/read',
|
|
10
|
+
mcpToolsCall: 'mcp:tools/call',
|
|
11
|
+
mcpToolsList: 'mcp:tools/list'
|
|
12
|
+
};
|
|
13
|
+
export { MCPAnalyticsEventType };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ErrorTracking as CoreErrorTracking } from '@posthog/core';
|
|
2
|
+
/**
|
|
3
|
+
* Captures structured exception properties from any thrown value.
|
|
4
|
+
*
|
|
5
|
+
* Returns the `$exception_list` shape PostHog error tracking expects, so MCP
|
|
6
|
+
* tool failures group and (with uploaded source maps) symbolicate the same way
|
|
7
|
+
* as exceptions from any other PostHog SDK.
|
|
8
|
+
*
|
|
9
|
+
* @param error - The thrown value (Error, string, object, CallToolResult, or anything).
|
|
10
|
+
* @returns Core `ErrorProperties` ready to spread onto a `$exception` event.
|
|
11
|
+
*/
|
|
12
|
+
export declare function captureException(error: unknown): CoreErrorTracking.ErrorProperties;
|
|
13
|
+
//# sourceMappingURL=exceptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptions.d.ts","sourceRoot":"","sources":["../../src/extensions/exceptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,eAAe,CAAA;AA8BlE;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,iBAAiB,CAAC,eAAe,CAMlF"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
captureException: ()=>captureException
|
|
28
|
+
});
|
|
29
|
+
const core_namespaceObject = require("@posthog/core");
|
|
30
|
+
const errorPropertiesBuilder = new core_namespaceObject.ErrorTracking.ErrorPropertiesBuilder([
|
|
31
|
+
new core_namespaceObject.ErrorTracking.EventCoercer(),
|
|
32
|
+
new core_namespaceObject.ErrorTracking.ErrorCoercer(),
|
|
33
|
+
new core_namespaceObject.ErrorTracking.ObjectCoercer(),
|
|
34
|
+
new core_namespaceObject.ErrorTracking.StringCoercer(),
|
|
35
|
+
new core_namespaceObject.ErrorTracking.PrimitiveCoercer()
|
|
36
|
+
], core_namespaceObject.ErrorTracking.createStackParser("node:javascript", core_namespaceObject.ErrorTracking.nodeStackLineParser));
|
|
37
|
+
function captureException(error) {
|
|
38
|
+
const normalized = isCallToolResult(error) ? extractCallToolResultMessage(error) : error;
|
|
39
|
+
return errorPropertiesBuilder.buildFromUnknown(normalized);
|
|
40
|
+
}
|
|
41
|
+
function isCallToolResult(value) {
|
|
42
|
+
return null !== value && 'object' == typeof value && 'isError' in value && 'content' in value && Array.isArray(value.content);
|
|
43
|
+
}
|
|
44
|
+
function isTextContentPart(value) {
|
|
45
|
+
if (null === value || 'object' != typeof value) return false;
|
|
46
|
+
const contentPart = value;
|
|
47
|
+
return 'text' === contentPart.type && 'string' == typeof contentPart.text;
|
|
48
|
+
}
|
|
49
|
+
function extractCallToolResultMessage(result) {
|
|
50
|
+
return result.content.filter(isTextContentPart).map((contentPart)=>contentPart.text).join(' ').trim() || 'Unknown error';
|
|
51
|
+
}
|
|
52
|
+
exports.captureException = __webpack_exports__.captureException;
|
|
53
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
54
|
+
"captureException"
|
|
55
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
56
|
+
Object.defineProperty(exports, '__esModule', {
|
|
57
|
+
value: true
|
|
58
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ErrorTracking } from "@posthog/core";
|
|
2
|
+
const errorPropertiesBuilder = new ErrorTracking.ErrorPropertiesBuilder([
|
|
3
|
+
new ErrorTracking.EventCoercer(),
|
|
4
|
+
new ErrorTracking.ErrorCoercer(),
|
|
5
|
+
new ErrorTracking.ObjectCoercer(),
|
|
6
|
+
new ErrorTracking.StringCoercer(),
|
|
7
|
+
new ErrorTracking.PrimitiveCoercer()
|
|
8
|
+
], ErrorTracking.createStackParser("node:javascript", ErrorTracking.nodeStackLineParser));
|
|
9
|
+
function captureException(error) {
|
|
10
|
+
const normalized = isCallToolResult(error) ? extractCallToolResultMessage(error) : error;
|
|
11
|
+
return errorPropertiesBuilder.buildFromUnknown(normalized);
|
|
12
|
+
}
|
|
13
|
+
function isCallToolResult(value) {
|
|
14
|
+
return null !== value && 'object' == typeof value && 'isError' in value && 'content' in value && Array.isArray(value.content);
|
|
15
|
+
}
|
|
16
|
+
function isTextContentPart(value) {
|
|
17
|
+
if (null === value || 'object' != typeof value) return false;
|
|
18
|
+
const contentPart = value;
|
|
19
|
+
return 'text' === contentPart.type && 'string' == typeof contentPart.text;
|
|
20
|
+
}
|
|
21
|
+
function extractCallToolResultMessage(result) {
|
|
22
|
+
return result.content.filter(isTextContentPart).map((contentPart)=>contentPart.text).join(' ').trim() || 'Unknown error';
|
|
23
|
+
}
|
|
24
|
+
export { captureException };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type MCPAnalyticsIDPrefix = 'evt' | 'ses';
|
|
2
|
+
export declare function newPrefixedId(prefix: MCPAnalyticsIDPrefix): string;
|
|
3
|
+
/**
|
|
4
|
+
* Deterministic id derived from an arbitrary string. Used to map MCP protocol
|
|
5
|
+
* session ids to SDK session ids so the same MCP session reuses the same
|
|
6
|
+
* `$session_id` across server restarts.
|
|
7
|
+
*
|
|
8
|
+
* Uses the FNV-1a 64-bit hash (mixed twice to fill 32 hex chars), which works
|
|
9
|
+
* everywhere — no `node:crypto`, no Web Crypto async API. Not cryptographic; we
|
|
10
|
+
* only need stable, low-collision input → output mapping.
|
|
11
|
+
*/
|
|
12
|
+
export declare function deterministicPrefixedId(prefix: MCPAnalyticsIDPrefix, input: string): string;
|
|
13
|
+
//# sourceMappingURL=ids.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../../src/extensions/ids.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,oBAAoB,GAAG,KAAK,GAAG,KAAK,CAAA;AAEhD,wBAAgB,aAAa,CAAC,MAAM,EAAE,oBAAoB,GAAG,MAAM,CAElE;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAE3F"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
deterministicPrefixedId: ()=>deterministicPrefixedId,
|
|
28
|
+
newPrefixedId: ()=>newPrefixedId
|
|
29
|
+
});
|
|
30
|
+
const core_namespaceObject = require("@posthog/core");
|
|
31
|
+
function newPrefixedId(prefix) {
|
|
32
|
+
return `${prefix}_${(0, core_namespaceObject.uuidv7)()}`;
|
|
33
|
+
}
|
|
34
|
+
function deterministicPrefixedId(prefix, input) {
|
|
35
|
+
return `${prefix}_${fnv1aHex(input)}${fnv1aHex(`${input}::salt`)}`;
|
|
36
|
+
}
|
|
37
|
+
function fnv1aHex(input) {
|
|
38
|
+
let h1 = 0x84222325;
|
|
39
|
+
let h2 = 0xcbf29ce4;
|
|
40
|
+
for(let i = 0; i < input.length; i++){
|
|
41
|
+
const c = input.charCodeAt(i);
|
|
42
|
+
h1 = Math.imul(h1 ^ c, 0x000001b3);
|
|
43
|
+
h2 = Math.imul(h2 ^ c, 0x00000193);
|
|
44
|
+
}
|
|
45
|
+
return (h1 >>> 0).toString(16).padStart(8, '0') + (h2 >>> 0).toString(16).padStart(8, '0');
|
|
46
|
+
}
|
|
47
|
+
exports.deterministicPrefixedId = __webpack_exports__.deterministicPrefixedId;
|
|
48
|
+
exports.newPrefixedId = __webpack_exports__.newPrefixedId;
|
|
49
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
50
|
+
"deterministicPrefixedId",
|
|
51
|
+
"newPrefixedId"
|
|
52
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
53
|
+
Object.defineProperty(exports, '__esModule', {
|
|
54
|
+
value: true
|
|
55
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { uuidv7 } from "@posthog/core";
|
|
2
|
+
function newPrefixedId(prefix) {
|
|
3
|
+
return `${prefix}_${uuidv7()}`;
|
|
4
|
+
}
|
|
5
|
+
function deterministicPrefixedId(prefix, input) {
|
|
6
|
+
return `${prefix}_${fnv1aHex(input)}${fnv1aHex(`${input}::salt`)}`;
|
|
7
|
+
}
|
|
8
|
+
function fnv1aHex(input) {
|
|
9
|
+
let h1 = 0x84222325;
|
|
10
|
+
let h2 = 0xcbf29ce4;
|
|
11
|
+
for(let i = 0; i < input.length; i++){
|
|
12
|
+
const c = input.charCodeAt(i);
|
|
13
|
+
h1 = Math.imul(h1 ^ c, 0x000001b3);
|
|
14
|
+
h2 = Math.imul(h2 ^ c, 0x00000193);
|
|
15
|
+
}
|
|
16
|
+
return (h1 >>> 0).toString(16).padStart(8, '0') + (h2 >>> 0).toString(16).padStart(8, '0');
|
|
17
|
+
}
|
|
18
|
+
export { deterministicPrefixedId, newPrefixedId };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instrument-highlevel.d.ts","sourceRoot":"","sources":["../../src/extensions/instrument-highlevel.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAiC,sBAAsB,EAAiC,MAAM,UAAU,CAAA;AA2QpH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,sBAAsB,GAAG,IAAI,CAoB9E"}
|