@alpic-ai/insights 1.129.7 → 1.130.1
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 +29 -15
- package/dist/index.mjs +40 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -37,20 +37,6 @@ type McpMiddlewareFn = (request: {
|
|
|
37
37
|
*/
|
|
38
38
|
declare function intentMiddleware(options?: IntentMiddlewareOptions): McpMiddlewareFn;
|
|
39
39
|
//#endregion
|
|
40
|
-
//#region src/capture-intents.d.ts
|
|
41
|
-
/**
|
|
42
|
-
* Captures the user's natural-language intent behind each tool call on a vanilla
|
|
43
|
-
* `@modelcontextprotocol/sdk` server. Accepts the high-level `McpServer` or the
|
|
44
|
-
* low-level `Server` and patches the `tools/list` and `tools/call` request
|
|
45
|
-
* handlers to surface the captured intent via `options.handler` (or, when
|
|
46
|
-
* `ALPIC_INTENT_META_KEY` is set, via the response `_meta`).
|
|
47
|
-
*
|
|
48
|
-
* Already-registered handlers are wrapped immediately; future registrations
|
|
49
|
-
* (e.g. tools added after this call) are wrapped via a `Map.set` proxy so order
|
|
50
|
-
* of calls relative to `registerTool` does not matter.
|
|
51
|
-
*/
|
|
52
|
-
declare const captureIntents: (server: McpServer | Server, options?: IntentMiddlewareOptions) => void;
|
|
53
|
-
//#endregion
|
|
54
40
|
//#region src/feedback-middleware.d.ts
|
|
55
41
|
interface FeedbackData {
|
|
56
42
|
content: string;
|
|
@@ -72,4 +58,32 @@ interface FeedbackMiddlewareOptions {
|
|
|
72
58
|
*/
|
|
73
59
|
declare function feedbackMiddleware(options?: FeedbackMiddlewareOptions): McpMiddlewareFn;
|
|
74
60
|
//#endregion
|
|
75
|
-
|
|
61
|
+
//#region src/capture-feedback.d.ts
|
|
62
|
+
/**
|
|
63
|
+
* Injects a `send_feedback` tool into a vanilla `@modelcontextprotocol/sdk`
|
|
64
|
+
* server and captures feedback submissions. Accepts the high-level `McpServer`
|
|
65
|
+
* or the low-level `Server` and patches the `tools/list` and `tools/call`
|
|
66
|
+
* request handlers to surface captured feedback via `options.handler` (or,
|
|
67
|
+
* 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
|
+
*/
|
|
73
|
+
declare const captureFeedback: (server: McpServer | Server, options?: FeedbackMiddlewareOptions) => void;
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/capture-intents.d.ts
|
|
76
|
+
/**
|
|
77
|
+
* Captures the user's natural-language intent behind each tool call on a vanilla
|
|
78
|
+
* `@modelcontextprotocol/sdk` server. Accepts the high-level `McpServer` or the
|
|
79
|
+
* low-level `Server` and patches the `tools/list` and `tools/call` request
|
|
80
|
+
* handlers to surface the captured intent via `options.handler` (or, when
|
|
81
|
+
* `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
|
+
*/
|
|
87
|
+
declare const captureIntents: (server: McpServer | Server, options?: IntentMiddlewareOptions) => void;
|
|
88
|
+
//#endregion
|
|
89
|
+
export { type FeedbackData, type FeedbackMiddlewareOptions, type IntentMiddlewareOptions, type McpMiddlewareFn, type PromptData, captureFeedback, captureIntents, feedbackMiddleware, intentMiddleware };
|
package/dist/index.mjs
CHANGED
|
@@ -82,6 +82,45 @@ function feedbackMiddleware(options) {
|
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
84
|
//#endregion
|
|
85
|
+
//#region src/capture-feedback.ts
|
|
86
|
+
const INSTALLED_MARKER$1 = "__alpicCaptureFeedbackInstalled";
|
|
87
|
+
/**
|
|
88
|
+
* Injects a `send_feedback` tool into a vanilla `@modelcontextprotocol/sdk`
|
|
89
|
+
* server and captures feedback submissions. Accepts the high-level `McpServer`
|
|
90
|
+
* or the low-level `Server` and patches the `tools/list` and `tools/call`
|
|
91
|
+
* request handlers to surface captured feedback via `options.handler` (or,
|
|
92
|
+
* when `ALPIC_FEEDBACK_META_KEY` is set, via the response `_meta`).
|
|
93
|
+
*
|
|
94
|
+
* Already-registered handlers are wrapped immediately; future registrations
|
|
95
|
+
* are wrapped via a `Map.set` proxy so order of calls relative to
|
|
96
|
+
* `registerTool` does not matter.
|
|
97
|
+
*/
|
|
98
|
+
const captureFeedback = (server, options) => {
|
|
99
|
+
const handlers = ("server" in server ? server.server : server)?._requestHandlers;
|
|
100
|
+
if (!(handlers instanceof Map)) {
|
|
101
|
+
console.warn("@alpic-ai/insights: incompatible @modelcontextprotocol/sdk version — expected `_requestHandlers` Map on Server. Feedback capture disabled.");
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const marked = handlers;
|
|
105
|
+
if (marked[INSTALLED_MARKER$1]) return;
|
|
106
|
+
marked[INSTALLED_MARKER$1] = true;
|
|
107
|
+
const middleware = feedbackMiddleware(options);
|
|
108
|
+
const targets = new Set(["tools/list", "tools/call"]);
|
|
109
|
+
const wrap = (method, handler) => {
|
|
110
|
+
if (!targets.has(method)) return handler;
|
|
111
|
+
return async (...args) => {
|
|
112
|
+
const [request, extra] = args;
|
|
113
|
+
return middleware({
|
|
114
|
+
method,
|
|
115
|
+
params: request.params ?? {}
|
|
116
|
+
}, extra, () => handler(...args));
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
for (const [method, handler] of [...handlers]) handlers.set(method, wrap(method, handler));
|
|
120
|
+
const originalSet = handlers.set.bind(handlers);
|
|
121
|
+
handlers.set = (method, handler) => originalSet(method, wrap(method, handler));
|
|
122
|
+
};
|
|
123
|
+
//#endregion
|
|
85
124
|
//#region src/intent-middleware.ts
|
|
86
125
|
const USER_INTENT_FIELD = "user_intent";
|
|
87
126
|
/**
|
|
@@ -227,4 +266,4 @@ const captureIntents = (server, options) => {
|
|
|
227
266
|
handlers.set = (method, handler) => originalSet(method, wrap(method, handler));
|
|
228
267
|
};
|
|
229
268
|
//#endregion
|
|
230
|
-
export { captureIntents, feedbackMiddleware, intentMiddleware };
|
|
269
|
+
export { captureFeedback, captureIntents, feedbackMiddleware, intentMiddleware };
|