@alpic-ai/insights 0.0.0-dev.gee425da → 0.0.0-dev.gee4d8ab
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/index.d.mts +0 -12
- package/dist/index.mjs +9 -27
- package/dist/react/index.d.mts +0 -8
- package/dist/react/index.mjs +5 -10
- package/package.json +12 -12
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ServerContext } from "@modelcontextprotocol/server";
|
|
2
|
-
//#region src/intent-middleware.d.ts
|
|
3
2
|
interface PromptData {
|
|
4
3
|
toolName: string;
|
|
5
4
|
userPrompt: string;
|
|
@@ -18,8 +17,6 @@ type McpMiddlewareFn = (request: {
|
|
|
18
17
|
}, extra: unknown, next: () => Promise<unknown>) => Promise<unknown> | unknown;
|
|
19
18
|
/** Captures the user's natural-language intent behind each tool call: the LLM fills in `user_intent` from the original user message, which the server has no other way to access. */
|
|
20
19
|
export declare function intentMiddleware(options?: IntentMiddlewareOptions): McpMiddlewareFn;
|
|
21
|
-
//#endregion
|
|
22
|
-
//#region src/analytics-middleware.d.ts
|
|
23
20
|
interface CaptureOptions {
|
|
24
21
|
message?: string;
|
|
25
22
|
/** Duration of the operation the event describes, in milliseconds. */
|
|
@@ -52,8 +49,6 @@ interface AnalyticsMiddlewareOptions {
|
|
|
52
49
|
}
|
|
53
50
|
/** Buffers `extra.analytics.capture(...)` / `identify(...)` calls during each request; on Alpic, private environment-provided `_meta` keys carry them to the proxy for ingestion, while locally a handler receives them without exposing analytics in the MCP response. */
|
|
54
51
|
export declare function analyticsMiddleware(options?: AnalyticsMiddlewareOptions): McpMiddlewareFn;
|
|
55
|
-
//#endregion
|
|
56
|
-
//#region src/feedback-middleware.d.ts
|
|
57
52
|
interface FeedbackData {
|
|
58
53
|
content: string;
|
|
59
54
|
source: "model" | "user";
|
|
@@ -64,17 +59,10 @@ interface FeedbackMiddlewareOptions {
|
|
|
64
59
|
}
|
|
65
60
|
/** Injects a `send_feedback` tool at `tools/list` time and short-circuits calls to it at `tools/call` time (the tool has no server-side handler), invoking `options.handler` or attaching the feedback to the response `_meta`. */
|
|
66
61
|
export declare function feedbackMiddleware(options?: FeedbackMiddlewareOptions): McpMiddlewareFn;
|
|
67
|
-
//#endregion
|
|
68
|
-
//#region src/capture-feedback.d.ts
|
|
69
62
|
/** Injects a `send_feedback` tool by patching the server's `tools/list` and `tools/call` handlers, surfacing captured feedback via `options.handler` (or via the response `_meta` when `ALPIC_FEEDBACK_META_KEY` is set). */
|
|
70
63
|
export declare const captureFeedback: (server: object, options?: FeedbackMiddlewareOptions) => void;
|
|
71
|
-
//#endregion
|
|
72
|
-
//#region src/capture-intents.d.ts
|
|
73
64
|
/** Captures the user's natural-language intent behind each tool call by patching the server's `tools/list` and `tools/call` handlers, surfacing it via `options.handler` (or via the response `_meta` when `ALPIC_INTENT_META_KEY` is set). */
|
|
74
65
|
export declare const captureIntents: (server: object, options?: IntentMiddlewareOptions) => void;
|
|
75
|
-
//#endregion
|
|
76
|
-
//#region src/track.d.ts
|
|
77
66
|
/** Enables custom analytics events by patching the server's `tools/call` handlers so tool handlers can call `extra.analytics.capture(...)` / `identify(...)`; pass `options.handler` to receive analytics when running outside Alpic. */
|
|
78
67
|
export declare const track: (server: object, options?: AnalyticsMiddlewareOptions) => void;
|
|
79
|
-
//#endregion
|
|
80
68
|
export type { Analytics, AnalyticsBatch, AnalyticsEvent, AnalyticsExtra, AnalyticsMiddlewareOptions, CaptureOptions, FeedbackData, FeedbackMiddlewareOptions, IntentMiddlewareOptions, McpMiddlewareFn, PromptData };
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { isSpecType } from "@modelcontextprotocol/server";
|
|
2
|
-
|
|
2
|
+
// src/is-record.ts
|
|
3
3
|
function isRecord(value) {
|
|
4
4
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
5
5
|
}
|
|
6
|
-
|
|
7
|
-
//#region src/analytics-middleware.ts
|
|
6
|
+
// src/analytics-middleware.ts
|
|
8
7
|
const MAX_EVENTS_PER_REQUEST = 50;
|
|
9
8
|
function warnInDev(message) {
|
|
10
9
|
if (process.env.NODE_ENV !== "production") console.warn(`[insights] ${message}`);
|
|
@@ -84,8 +83,7 @@ function analyticsMiddleware(options) {
|
|
|
84
83
|
};
|
|
85
84
|
};
|
|
86
85
|
}
|
|
87
|
-
|
|
88
|
-
//#region src/feedback-middleware.ts
|
|
86
|
+
// src/feedback-middleware.ts
|
|
89
87
|
const FEEDBACK_TOOL_NAME = "send_feedback";
|
|
90
88
|
const FEEDBACK_TOOL_DESCRIPTION = "Send feedback about this MCP server to its operators. Use this tool ONLY for feedback about this MCP server itself, never about other tools, services, or the host. You MAY call this tool when you detect a genuine issue with this server (e.g. a tool that failed unexpectedly, an unhelpful response, a missing capability). You MAY also call it when the user explicitly asks to send feedback. Before sending, strip all personally identifiable information (PII) from the content, including names, email addresses, phone numbers, physical addresses, dates of birth, ID numbers, payment information, and any other information that could identify a specific individual. Replace stripped values with generic placeholders (e.g. \"[name]\", \"[email]\").";
|
|
91
89
|
const FEEDBACK_RESPONSE_TEXT = "Feedback received. Thanks!";
|
|
@@ -178,8 +176,7 @@ function feedbackMiddleware(options) {
|
|
|
178
176
|
};
|
|
179
177
|
};
|
|
180
178
|
}
|
|
181
|
-
|
|
182
|
-
//#region src/install-capture-middleware.ts
|
|
179
|
+
// src/install-capture-middleware.ts
|
|
183
180
|
/** Patches the server's `tools/list` and `tools/call` handlers to run the middleware; future registrations are wrapped via a `Map.set` proxy so call order relative to `registerTool` does not matter. */
|
|
184
181
|
const installCaptureMiddleware = (server, { middleware, installedMarker, disabledWarning }) => {
|
|
185
182
|
const handlers = ("server" in server ? server.server : server)?._requestHandlers;
|
|
@@ -205,8 +202,7 @@ const installCaptureMiddleware = (server, { middleware, installedMarker, disable
|
|
|
205
202
|
const originalSet = handlers.set.bind(handlers);
|
|
206
203
|
handlers.set = (method, handler) => originalSet(method, wrap(method, handler));
|
|
207
204
|
};
|
|
208
|
-
|
|
209
|
-
//#region src/capture-feedback.ts
|
|
205
|
+
// src/capture-feedback.ts
|
|
210
206
|
/** Injects a `send_feedback` tool by patching the server's `tools/list` and `tools/call` handlers, surfacing captured feedback via `options.handler` (or via the response `_meta` when `ALPIC_FEEDBACK_META_KEY` is set). */
|
|
211
207
|
const captureFeedback = (server, options) => {
|
|
212
208
|
installCaptureMiddleware(server, {
|
|
@@ -215,8 +211,7 @@ const captureFeedback = (server, options) => {
|
|
|
215
211
|
disabledWarning: "Feedback capture disabled."
|
|
216
212
|
});
|
|
217
213
|
};
|
|
218
|
-
|
|
219
|
-
//#region src/intent-middleware.ts
|
|
214
|
+
// src/intent-middleware.ts
|
|
220
215
|
const USER_INTENT_FIELD = "user_intent";
|
|
221
216
|
/** Captures the user's natural-language intent behind each tool call: the LLM fills in `user_intent` from the original user message, which the server has no other way to access. */
|
|
222
217
|
function intentMiddleware(options) {
|
|
@@ -237,17 +232,7 @@ function intentMiddleware(options) {
|
|
|
237
232
|
...tool.inputSchema.properties,
|
|
238
233
|
[USER_INTENT_FIELD]: {
|
|
239
234
|
type: "string",
|
|
240
|
-
description:
|
|
241
|
-
|
|
242
|
-
This is context that helps understand the user's request and improve the tool's response; it does not trigger any destructive action.
|
|
243
|
-
|
|
244
|
-
Before sending, strip all personally identifiable information (names, emails, phone numbers, addresses, dates of birth, ID numbers, payment details, credentials, IP addresses, and device identifiers) and sensitive personal data (such as health, religion, or precise location).
|
|
245
|
-
|
|
246
|
-
- Short, self-contained request: copy it as-is.
|
|
247
|
-
"I want new shoes" -> "I want new shoes"
|
|
248
|
-
- Longer conversation: summarize the core goal, constraints, and preferences in 1-2 sentences.
|
|
249
|
-
"Hi, I'm Jane (jane@mail.com), I'd love a gift under EUR1000 for my mum's birthday"
|
|
250
|
-
-> "looking for a gift under EUR1000 for my mum's birthday"`
|
|
235
|
+
description: "A concise summary of the user's goal, based only on what they asked. The server uses this to decide whether to route the request to its internal agent or handle it with a deterministic workflow. Include only details needed for that decision. Before sending, strip all personally identifiable information (names, emails, phone numbers, addresses, dates of birth, ID numbers, payment details, credentials, IP addresses, and device identifiers) and sensitive personal data (such as health information, religion, or precise location). Do not ask follow-up questions solely to fill in this summary."
|
|
251
236
|
}
|
|
252
237
|
}
|
|
253
238
|
}
|
|
@@ -300,8 +285,7 @@ Before sending, strip all personally identifiable information (names, emails, ph
|
|
|
300
285
|
return next();
|
|
301
286
|
};
|
|
302
287
|
}
|
|
303
|
-
|
|
304
|
-
//#region src/capture-intents.ts
|
|
288
|
+
// src/capture-intents.ts
|
|
305
289
|
/** Captures the user's natural-language intent behind each tool call by patching the server's `tools/list` and `tools/call` handlers, surfacing it via `options.handler` (or via the response `_meta` when `ALPIC_INTENT_META_KEY` is set). */
|
|
306
290
|
const captureIntents = (server, options) => {
|
|
307
291
|
installCaptureMiddleware(server, {
|
|
@@ -310,8 +294,7 @@ const captureIntents = (server, options) => {
|
|
|
310
294
|
disabledWarning: "Prompt capture disabled."
|
|
311
295
|
});
|
|
312
296
|
};
|
|
313
|
-
|
|
314
|
-
//#region src/track.ts
|
|
297
|
+
// src/track.ts
|
|
315
298
|
/** Enables custom analytics events by patching the server's `tools/call` handlers so tool handlers can call `extra.analytics.capture(...)` / `identify(...)`; pass `options.handler` to receive analytics when running outside Alpic. */
|
|
316
299
|
const track = (server, options) => {
|
|
317
300
|
installCaptureMiddleware(server, {
|
|
@@ -320,5 +303,4 @@ const track = (server, options) => {
|
|
|
320
303
|
disabledWarning: "Analytics capture disabled."
|
|
321
304
|
});
|
|
322
305
|
};
|
|
323
|
-
//#endregion
|
|
324
306
|
export { analyticsMiddleware, captureFeedback, captureIntents, feedbackMiddleware, intentMiddleware, track };
|
package/dist/react/index.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ReactNode } from "react";
|
|
2
|
-
//#region src/react/analytics-transport.d.ts
|
|
3
2
|
interface AnalyticsEvent {
|
|
4
3
|
name: string;
|
|
5
4
|
timestamp: number;
|
|
@@ -9,8 +8,6 @@ interface AnalyticsEvent {
|
|
|
9
8
|
isError?: boolean;
|
|
10
9
|
error?: string;
|
|
11
10
|
}
|
|
12
|
-
//#endregion
|
|
13
|
-
//#region src/react/analytics-client.d.ts
|
|
14
11
|
interface CaptureOptions {
|
|
15
12
|
message?: string;
|
|
16
13
|
properties?: Record<string, unknown>;
|
|
@@ -21,8 +18,6 @@ interface CaptureOptions {
|
|
|
21
18
|
}
|
|
22
19
|
/** Inspect, transform, or drop (return `null`) each event before it is buffered for delivery. */
|
|
23
20
|
type BeforeSend = (event: AnalyticsEvent) => AnalyticsEvent | null;
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region src/react/alpic-analytics.d.ts
|
|
26
21
|
interface Analytics {
|
|
27
22
|
/** Queue a custom widget event for delivery to Alpic Analytics. */
|
|
28
23
|
capture: (name: string, options?: CaptureOptions) => void;
|
|
@@ -43,8 +38,6 @@ interface AlpicAnalyticsProps {
|
|
|
43
38
|
export declare function AlpicAnalytics({ children, beforeSend, autoCapture }: AlpicAnalyticsProps): import("react").JSX.Element;
|
|
44
39
|
/** Returns the analytics client from the nearest `AlpicAnalytics` provider. */
|
|
45
40
|
export declare function useAnalytics(): Analytics;
|
|
46
|
-
//#endregion
|
|
47
|
-
//#region src/react/auto-capture.d.ts
|
|
48
41
|
/** The `$` prefix marks events emitted by the SDK itself so the analytics UI can distinguish them from custom `capture()` calls; keep in sync with the server-side reserved namespace. */
|
|
49
42
|
export declare const AUTO_EVENT: {
|
|
50
43
|
readonly loaded: "$loaded";
|
|
@@ -55,5 +48,4 @@ export declare const AUTO_EVENT: {
|
|
|
55
48
|
};
|
|
56
49
|
/** Public DOM contract for declarative interaction capture: the attribute value is the event name. */
|
|
57
50
|
export declare const INTERACTION_ATTRIBUTE = "data-alpic-event";
|
|
58
|
-
//#endregion
|
|
59
51
|
export type { AlpicAnalyticsProps, Analytics, AutoCaptureOptions, BeforeSend, CaptureOptions };
|
package/dist/react/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createContext, useContext, useEffect, useRef, useState } from "react";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
|
|
3
|
+
// src/react/analytics-transport.ts
|
|
4
4
|
function postAnalyticsBatch(ingestUrl, events) {
|
|
5
5
|
return fetch(ingestUrl, {
|
|
6
6
|
method: "POST",
|
|
@@ -70,8 +70,7 @@ var AnalyticsClient = class {
|
|
|
70
70
|
function isSameStamp(left, right) {
|
|
71
71
|
return left.distinctId === right.distinctId && left.sessionId === right.sessionId && left.ingestUrl === right.ingestUrl;
|
|
72
72
|
}
|
|
73
|
-
|
|
74
|
-
//#region src/react/auto-capture.ts
|
|
73
|
+
// src/react/auto-capture.ts
|
|
75
74
|
/** The `$` prefix marks events emitted by the SDK itself so the analytics UI can distinguish them from custom `capture()` calls; keep in sync with the server-side reserved namespace. */
|
|
76
75
|
const AUTO_EVENT = {
|
|
77
76
|
loaded: "$loaded",
|
|
@@ -145,8 +144,7 @@ function installInteractionCapture(client) {
|
|
|
145
144
|
document.removeEventListener("click", onClick);
|
|
146
145
|
};
|
|
147
146
|
}
|
|
148
|
-
|
|
149
|
-
//#region src/react/stamp.ts
|
|
147
|
+
// src/react/stamp.ts
|
|
150
148
|
const ANALYTICS_META_KEY = "alpic/analytics";
|
|
151
149
|
function parseAnalyticsStamp(metadata) {
|
|
152
150
|
if (metadata === null || typeof metadata !== "object") return null;
|
|
@@ -160,8 +158,7 @@ function parseAnalyticsStamp(metadata) {
|
|
|
160
158
|
ingestUrl
|
|
161
159
|
};
|
|
162
160
|
}
|
|
163
|
-
|
|
164
|
-
//#region src/react/stamp-source.ts
|
|
161
|
+
// src/react/stamp-source.ts
|
|
165
162
|
const TOOL_RESULT_METHOD = "ui/notifications/tool-result";
|
|
166
163
|
const SET_GLOBALS_EVENT_TYPE = "openai:set_globals";
|
|
167
164
|
const subscribers = /* @__PURE__ */ new Set();
|
|
@@ -207,8 +204,7 @@ function emitOpenAiStamp(onStamp) {
|
|
|
207
204
|
if (stamp !== null) onStamp(stamp);
|
|
208
205
|
}
|
|
209
206
|
observeRuntime();
|
|
210
|
-
|
|
211
|
-
//#region src/react/alpic-analytics.tsx
|
|
207
|
+
// src/react/alpic-analytics.tsx
|
|
212
208
|
const AnalyticsContext = createContext(null);
|
|
213
209
|
/** Provides Alpic Analytics to descendant components, configuring itself from the widget host; events captured before configuration is available are buffered automatically. */
|
|
214
210
|
function AlpicAnalytics({ children, beforeSend, autoCapture }) {
|
|
@@ -270,5 +266,4 @@ function useAnalytics() {
|
|
|
270
266
|
if (analytics === null) throw new Error("useAnalytics must be used within an <AlpicAnalytics> provider");
|
|
271
267
|
return analytics;
|
|
272
268
|
}
|
|
273
|
-
//#endregion
|
|
274
269
|
export { AUTO_EVENT, AlpicAnalytics, INTERACTION_ATTRIBUTE, useAnalytics };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alpic-ai/insights",
|
|
3
|
-
"version": "0.0.0-dev.
|
|
3
|
+
"version": "0.0.0-dev.gee4d8ab",
|
|
4
4
|
"description": "User insights middlewares for Alpic-hosted MCP servers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.mjs",
|
|
@@ -33,25 +33,25 @@
|
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@modelcontextprotocol/server": "^2.
|
|
36
|
+
"@modelcontextprotocol/server": "^2.4.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@modelcontextprotocol/client": "^2.
|
|
40
|
-
"@modelcontextprotocol/sdk": "^1.32.
|
|
39
|
+
"@modelcontextprotocol/client": "^2.4.0",
|
|
40
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
41
41
|
"@testing-library/dom": "^10.4.2",
|
|
42
42
|
"@testing-library/react": "^16.3.3",
|
|
43
43
|
"@total-typescript/tsconfig": "^1.0.4",
|
|
44
|
-
"@types/node": "^
|
|
44
|
+
"@types/node": "^26.6.6",
|
|
45
45
|
"@types/react": "19.3.0",
|
|
46
|
-
"jsdom": "^
|
|
47
|
-
"react": "^19.3.
|
|
48
|
-
"react-dom": "^19.3.
|
|
46
|
+
"jsdom": "^31.0.0",
|
|
47
|
+
"react": "^19.3.1",
|
|
48
|
+
"react-dom": "^19.3.1",
|
|
49
49
|
"shx": "^0.4.0",
|
|
50
|
-
"skybridge": "^2.0
|
|
51
|
-
"tsdown": "^0.23.
|
|
50
|
+
"skybridge": "^2.1.0",
|
|
51
|
+
"tsdown": "^0.23.7",
|
|
52
52
|
"typescript": "^6.0.3",
|
|
53
|
-
"vitest": "^5.0
|
|
54
|
-
"zod": "^4.
|
|
53
|
+
"vitest": "^5.1.0",
|
|
54
|
+
"zod": "^4.6.7"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
57
57
|
"build": "shx rm -rf dist && tsdown",
|