@alpic-ai/insights 0.0.0-dev.g279a914 → 0.0.0-dev.g27cc698
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 -9
- package/dist/index.mjs +34 -45
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
2
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
-
|
|
4
3
|
//#region src/intent-middleware.d.ts
|
|
5
4
|
interface PromptData {
|
|
6
5
|
toolName: string;
|
|
@@ -65,10 +64,6 @@ declare function feedbackMiddleware(options?: FeedbackMiddlewareOptions): McpMid
|
|
|
65
64
|
* or the low-level `Server` and patches the `tools/list` and `tools/call`
|
|
66
65
|
* request handlers to surface captured feedback via `options.handler` (or,
|
|
67
66
|
* when `ALPIC_FEEDBACK_META_KEY` is set, via the response `_meta`).
|
|
68
|
-
*
|
|
69
|
-
* Already-registered handlers are wrapped immediately; future registrations
|
|
70
|
-
* are wrapped via a `Map.set` proxy so order of calls relative to
|
|
71
|
-
* `registerTool` does not matter.
|
|
72
67
|
*/
|
|
73
68
|
declare const captureFeedback: (server: McpServer | Server, options?: FeedbackMiddlewareOptions) => void;
|
|
74
69
|
//#endregion
|
|
@@ -79,10 +74,6 @@ declare const captureFeedback: (server: McpServer | Server, options?: FeedbackMi
|
|
|
79
74
|
* low-level `Server` and patches the `tools/list` and `tools/call` request
|
|
80
75
|
* handlers to surface the captured intent via `options.handler` (or, when
|
|
81
76
|
* `ALPIC_INTENT_META_KEY` is set, via the response `_meta`).
|
|
82
|
-
*
|
|
83
|
-
* Already-registered handlers are wrapped immediately; future registrations
|
|
84
|
-
* (e.g. tools added after this call) are wrapped via a `Map.set` proxy so order
|
|
85
|
-
* of calls relative to `registerTool` does not matter.
|
|
86
77
|
*/
|
|
87
78
|
declare const captureIntents: (server: McpServer | Server, options?: IntentMiddlewareOptions) => void;
|
|
88
79
|
//#endregion
|
package/dist/index.mjs
CHANGED
|
@@ -49,9 +49,9 @@ function feedbackMiddleware(options) {
|
|
|
49
49
|
},
|
|
50
50
|
outputSchema: FEEDBACK_OUTPUT_SCHEMA,
|
|
51
51
|
annotations: {
|
|
52
|
-
readOnlyHint:
|
|
52
|
+
readOnlyHint: true,
|
|
53
53
|
destructiveHint: false,
|
|
54
|
-
openWorldHint:
|
|
54
|
+
openWorldHint: false,
|
|
55
55
|
idempotentHint: true
|
|
56
56
|
}
|
|
57
57
|
});
|
|
@@ -98,30 +98,26 @@ function feedbackMiddleware(options) {
|
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
100
|
//#endregion
|
|
101
|
-
//#region src/capture-
|
|
102
|
-
const INSTALLED_MARKER$1 = "__alpicCaptureFeedbackInstalled";
|
|
101
|
+
//#region src/install-capture-middleware.ts
|
|
103
102
|
/**
|
|
104
|
-
*
|
|
105
|
-
* server
|
|
106
|
-
*
|
|
107
|
-
* request handlers to surface captured feedback via `options.handler` (or,
|
|
108
|
-
* when `ALPIC_FEEDBACK_META_KEY` is set, via the response `_meta`).
|
|
103
|
+
* Patches the `tools/list` and `tools/call` request handlers of a vanilla
|
|
104
|
+
* `@modelcontextprotocol/sdk` server (high-level `McpServer` or low-level
|
|
105
|
+
* `Server`) to run the given middleware.
|
|
109
106
|
*
|
|
110
107
|
* Already-registered handlers are wrapped immediately; future registrations
|
|
111
|
-
* are wrapped via a `Map.set` proxy so order
|
|
112
|
-
* `registerTool` does not matter.
|
|
108
|
+
* (e.g. tools added after this call) are wrapped via a `Map.set` proxy so order
|
|
109
|
+
* of calls relative to `registerTool` does not matter.
|
|
113
110
|
*/
|
|
114
|
-
const
|
|
111
|
+
const installCaptureMiddleware = (server, { middleware, installedMarker, disabledWarning }) => {
|
|
115
112
|
const handlers = ("server" in server ? server.server : server)?._requestHandlers;
|
|
116
113
|
if (!(handlers instanceof Map)) {
|
|
117
|
-
console.warn(
|
|
114
|
+
console.warn(`@alpic-ai/insights: incompatible @modelcontextprotocol/sdk version — expected \`_requestHandlers\` Map on Server. ${disabledWarning}`);
|
|
118
115
|
return;
|
|
119
116
|
}
|
|
120
117
|
const marked = handlers;
|
|
121
|
-
if (marked[
|
|
122
|
-
marked[
|
|
123
|
-
const
|
|
124
|
-
const targets = new Set(["tools/list", "tools/call"]);
|
|
118
|
+
if (marked[installedMarker]) return;
|
|
119
|
+
marked[installedMarker] = true;
|
|
120
|
+
const targets = /* @__PURE__ */ new Set(["tools/list", "tools/call"]);
|
|
125
121
|
const wrap = (method, handler) => {
|
|
126
122
|
if (!targets.has(method)) return handler;
|
|
127
123
|
return async (...args) => {
|
|
@@ -137,6 +133,22 @@ const captureFeedback = (server, options) => {
|
|
|
137
133
|
handlers.set = (method, handler) => originalSet(method, wrap(method, handler));
|
|
138
134
|
};
|
|
139
135
|
//#endregion
|
|
136
|
+
//#region src/capture-feedback.ts
|
|
137
|
+
/**
|
|
138
|
+
* Injects a `send_feedback` tool into a vanilla `@modelcontextprotocol/sdk`
|
|
139
|
+
* server and captures feedback submissions. Accepts the high-level `McpServer`
|
|
140
|
+
* or the low-level `Server` and patches the `tools/list` and `tools/call`
|
|
141
|
+
* request handlers to surface captured feedback via `options.handler` (or,
|
|
142
|
+
* when `ALPIC_FEEDBACK_META_KEY` is set, via the response `_meta`).
|
|
143
|
+
*/
|
|
144
|
+
const captureFeedback = (server, options) => {
|
|
145
|
+
installCaptureMiddleware(server, {
|
|
146
|
+
middleware: feedbackMiddleware(options),
|
|
147
|
+
installedMarker: "__alpicCaptureFeedbackInstalled",
|
|
148
|
+
disabledWarning: "Feedback capture disabled."
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
//#endregion
|
|
140
152
|
//#region src/intent-middleware.ts
|
|
141
153
|
const USER_INTENT_FIELD = "user_intent";
|
|
142
154
|
/**
|
|
@@ -244,42 +256,19 @@ Examples:
|
|
|
244
256
|
}
|
|
245
257
|
//#endregion
|
|
246
258
|
//#region src/capture-intents.ts
|
|
247
|
-
const INSTALLED_MARKER = "__alpicCaptureIntentsInstalled";
|
|
248
259
|
/**
|
|
249
260
|
* Captures the user's natural-language intent behind each tool call on a vanilla
|
|
250
261
|
* `@modelcontextprotocol/sdk` server. Accepts the high-level `McpServer` or the
|
|
251
262
|
* low-level `Server` and patches the `tools/list` and `tools/call` request
|
|
252
263
|
* handlers to surface the captured intent via `options.handler` (or, when
|
|
253
264
|
* `ALPIC_INTENT_META_KEY` is set, via the response `_meta`).
|
|
254
|
-
*
|
|
255
|
-
* Already-registered handlers are wrapped immediately; future registrations
|
|
256
|
-
* (e.g. tools added after this call) are wrapped via a `Map.set` proxy so order
|
|
257
|
-
* of calls relative to `registerTool` does not matter.
|
|
258
265
|
*/
|
|
259
266
|
const captureIntents = (server, options) => {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}
|
|
265
|
-
const marked = handlers;
|
|
266
|
-
if (marked[INSTALLED_MARKER]) return;
|
|
267
|
-
marked[INSTALLED_MARKER] = true;
|
|
268
|
-
const middleware = intentMiddleware(options);
|
|
269
|
-
const targets = new Set(["tools/list", "tools/call"]);
|
|
270
|
-
const wrap = (method, handler) => {
|
|
271
|
-
if (!targets.has(method)) return handler;
|
|
272
|
-
return async (...args) => {
|
|
273
|
-
const [request, extra] = args;
|
|
274
|
-
return middleware({
|
|
275
|
-
method,
|
|
276
|
-
params: request.params ?? {}
|
|
277
|
-
}, extra, () => handler(...args));
|
|
278
|
-
};
|
|
279
|
-
};
|
|
280
|
-
for (const [method, handler] of [...handlers]) handlers.set(method, wrap(method, handler));
|
|
281
|
-
const originalSet = handlers.set.bind(handlers);
|
|
282
|
-
handlers.set = (method, handler) => originalSet(method, wrap(method, handler));
|
|
267
|
+
installCaptureMiddleware(server, {
|
|
268
|
+
middleware: intentMiddleware(options),
|
|
269
|
+
installedMarker: "__alpicCaptureIntentsInstalled",
|
|
270
|
+
disabledWarning: "Prompt capture disabled."
|
|
271
|
+
});
|
|
283
272
|
};
|
|
284
273
|
//#endregion
|
|
285
274
|
export { captureFeedback, captureIntents, feedbackMiddleware, intentMiddleware };
|
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.g27cc698",
|
|
4
4
|
"description": "User insights middlewares for Alpic-hosted MCP servers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.mjs",
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
30
30
|
"@total-typescript/tsconfig": "^1.0.4",
|
|
31
|
-
"@types/node": "^25.9.
|
|
31
|
+
"@types/node": "^25.9.5",
|
|
32
32
|
"shx": "^0.4.0",
|
|
33
|
-
"skybridge": "^1.
|
|
34
|
-
"tsdown": "^0.22.
|
|
33
|
+
"skybridge": "^1.2.7",
|
|
34
|
+
"tsdown": "^0.22.5",
|
|
35
35
|
"typescript": "^6.0.3",
|
|
36
|
-
"vitest": "^4.1.
|
|
36
|
+
"vitest": "^4.1.10",
|
|
37
37
|
"zod": "^4.4.3"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"test": "pnpm run test:unit && pnpm run test:type && pnpm run test:format",
|
|
43
43
|
"test:unit": "vitest run",
|
|
44
44
|
"test:format": "biome check --error-on-warnings .",
|
|
45
|
-
"test:type": "
|
|
45
|
+
"test:type": "tsgo --noEmit",
|
|
46
46
|
"publish:npm": "pnpm publish --tag \"${NPM_TAG}\" --access public --no-git-checks"
|
|
47
47
|
}
|
|
48
48
|
}
|