@mcp-b/global 1.3.0 → 1.5.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 +33 -0
- package/dist/index.d.ts +2 -1013
- package/dist/index.d.ts.map +1 -1
- package/dist/index.iife.js +13 -9
- package/dist/index.js +246 -232
- package/dist/index.js.map +1 -1
- package/dist/testing.d.ts +71 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +48 -0
- package/dist/testing.js.map +1 -0
- package/dist/types-DemXxUoc.d.ts +1036 -0
- package/dist/types-DemXxUoc.d.ts.map +1 -0
- package/package.json +10 -4
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { M as ToolInfo, N as ToolListItem, P as ToolResponse, g as ModelContextTesting } from "./types-DemXxUoc.js";
|
|
2
|
+
|
|
3
|
+
//#region src/testing.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Test helper API exposed via @mcp-b/global/testing.
|
|
7
|
+
* Wraps navigator.modelContextTesting and normalizes object-arg tool execution.
|
|
8
|
+
*/
|
|
9
|
+
interface ModelContextTestHelper {
|
|
10
|
+
/**
|
|
11
|
+
* Execute a tool with object arguments.
|
|
12
|
+
* Internally delegates to modelContextTesting.executeTool(name, JSON.stringify(args)).
|
|
13
|
+
*/
|
|
14
|
+
executeTool(toolName: string, args?: Record<string, unknown>): Promise<unknown>;
|
|
15
|
+
/**
|
|
16
|
+
* List tools exposed by modelContextTesting.
|
|
17
|
+
*/
|
|
18
|
+
listTools(): ToolInfo[];
|
|
19
|
+
/**
|
|
20
|
+
* Register for tool list updates.
|
|
21
|
+
*/
|
|
22
|
+
onToolsChanged(callback: () => void): void;
|
|
23
|
+
/**
|
|
24
|
+
* Get recorded tool calls.
|
|
25
|
+
* Only available when using the polyfill extensions.
|
|
26
|
+
*/
|
|
27
|
+
getToolCalls(): Array<{
|
|
28
|
+
toolName: string;
|
|
29
|
+
arguments: Record<string, unknown>;
|
|
30
|
+
timestamp: number;
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* Clear recorded tool calls.
|
|
34
|
+
* Only available when using the polyfill extensions.
|
|
35
|
+
*/
|
|
36
|
+
clearToolCalls(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Set mock response for a tool.
|
|
39
|
+
* Only available when using the polyfill extensions.
|
|
40
|
+
*/
|
|
41
|
+
setMockToolResponse(toolName: string, response: ToolResponse): void;
|
|
42
|
+
/**
|
|
43
|
+
* Clear mock response for a tool.
|
|
44
|
+
* Only available when using the polyfill extensions.
|
|
45
|
+
*/
|
|
46
|
+
clearMockToolResponse(toolName: string): void;
|
|
47
|
+
/**
|
|
48
|
+
* Clear all mock responses.
|
|
49
|
+
* Only available when using the polyfill extensions.
|
|
50
|
+
*/
|
|
51
|
+
clearAllMockToolResponses(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Get registered tools from modelContext internals.
|
|
54
|
+
* Only available when using the polyfill extensions.
|
|
55
|
+
*/
|
|
56
|
+
getRegisteredTools(): ToolListItem[];
|
|
57
|
+
/**
|
|
58
|
+
* Reset polyfill testing state.
|
|
59
|
+
* Only available when using the polyfill extensions.
|
|
60
|
+
*/
|
|
61
|
+
reset(): void;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create a testing helper bound to modelContextTesting.
|
|
65
|
+
*
|
|
66
|
+
* @param testingOverride - Optional explicit testing API instance.
|
|
67
|
+
*/
|
|
68
|
+
declare function createTestHelper(testingOverride?: ModelContextTesting): ModelContextTestHelper;
|
|
69
|
+
//#endregion
|
|
70
|
+
export { ModelContextTestHelper, createTestHelper };
|
|
71
|
+
//# sourceMappingURL=testing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.d.ts","names":[],"sources":["../src/testing.ts"],"sourcesContent":[],"mappings":";;;;;;AAMA;;AAKiE,UALhD,sBAAA,CAKgD;EAKlD;;;;EA6CS,WAAA,CAAA,QAAA,EAAA,MAAA,EAAA,IAAA,CAAA,EAlDe,MAkDf,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA,EAlDyC,OAkDzC,CAAA,OAAA,CAAA;EAAY;AAuEpC;;eApHe;;;;;;;;;kBAWG;;eAEH;;;;;;;;;;;;kDAcmC;;;;;;;;;;;;;;;wBAkB1B;;;;;;;;;;;;iBAuER,gBAAA,mBAAmC,sBAAsB"}
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
//#region src/testing.ts
|
|
2
|
+
function resolveTestingAPI(override) {
|
|
3
|
+
if (override) return override;
|
|
4
|
+
if (typeof window !== "undefined") {
|
|
5
|
+
const bridgeTesting = window.__mcpBridge?.modelContextTesting;
|
|
6
|
+
if (bridgeTesting) return bridgeTesting;
|
|
7
|
+
}
|
|
8
|
+
if (typeof navigator === "undefined" || !navigator.modelContextTesting) throw new Error("navigator.modelContextTesting is not available. Ensure @mcp-b/global is initialized first.");
|
|
9
|
+
return navigator.modelContextTesting;
|
|
10
|
+
}
|
|
11
|
+
function getPolyfillExtensions(testing) {
|
|
12
|
+
const candidate = testing;
|
|
13
|
+
for (const method of [
|
|
14
|
+
"getToolCalls",
|
|
15
|
+
"clearToolCalls",
|
|
16
|
+
"setMockToolResponse",
|
|
17
|
+
"clearMockToolResponse",
|
|
18
|
+
"clearAllMockToolResponses",
|
|
19
|
+
"getRegisteredTools",
|
|
20
|
+
"reset"
|
|
21
|
+
]) if (typeof candidate[method] !== "function") throw new Error(`modelContextTesting.${String(method)} is not available in this runtime. These helpers require the @mcp-b/global polyfill testing extensions.`);
|
|
22
|
+
return candidate;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create a testing helper bound to modelContextTesting.
|
|
26
|
+
*
|
|
27
|
+
* @param testingOverride - Optional explicit testing API instance.
|
|
28
|
+
*/
|
|
29
|
+
function createTestHelper(testingOverride) {
|
|
30
|
+
const testing = resolveTestingAPI(testingOverride);
|
|
31
|
+
const polyfillExtensions = () => getPolyfillExtensions(testing);
|
|
32
|
+
return {
|
|
33
|
+
executeTool: (toolName, args = {}) => testing.executeTool(toolName, JSON.stringify(args)),
|
|
34
|
+
listTools: () => testing.listTools(),
|
|
35
|
+
onToolsChanged: (callback) => testing.registerToolsChangedCallback(callback),
|
|
36
|
+
getToolCalls: () => polyfillExtensions().getToolCalls(),
|
|
37
|
+
clearToolCalls: () => polyfillExtensions().clearToolCalls(),
|
|
38
|
+
setMockToolResponse: (toolName, response) => polyfillExtensions().setMockToolResponse(toolName, response),
|
|
39
|
+
clearMockToolResponse: (toolName) => polyfillExtensions().clearMockToolResponse(toolName),
|
|
40
|
+
clearAllMockToolResponses: () => polyfillExtensions().clearAllMockToolResponses(),
|
|
41
|
+
getRegisteredTools: () => polyfillExtensions().getRegisteredTools(),
|
|
42
|
+
reset: () => polyfillExtensions().reset()
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
export { createTestHelper };
|
|
48
|
+
//# sourceMappingURL=testing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.js","names":[],"sources":["../src/testing.ts"],"sourcesContent":["import type { ModelContextTesting, ToolInfo, ToolListItem, ToolResponse } from './types.js';\n\n/**\n * Test helper API exposed via @mcp-b/global/testing.\n * Wraps navigator.modelContextTesting and normalizes object-arg tool execution.\n */\nexport interface ModelContextTestHelper {\n /**\n * Execute a tool with object arguments.\n * Internally delegates to modelContextTesting.executeTool(name, JSON.stringify(args)).\n */\n executeTool(toolName: string, args?: Record<string, unknown>): Promise<unknown>;\n\n /**\n * List tools exposed by modelContextTesting.\n */\n listTools(): ToolInfo[];\n\n /**\n * Register for tool list updates.\n */\n onToolsChanged(callback: () => void): void;\n\n /**\n * Get recorded tool calls.\n * Only available when using the polyfill extensions.\n */\n getToolCalls(): Array<{\n toolName: string;\n arguments: Record<string, unknown>;\n timestamp: number;\n }>;\n\n /**\n * Clear recorded tool calls.\n * Only available when using the polyfill extensions.\n */\n clearToolCalls(): void;\n\n /**\n * Set mock response for a tool.\n * Only available when using the polyfill extensions.\n */\n setMockToolResponse(toolName: string, response: ToolResponse): void;\n\n /**\n * Clear mock response for a tool.\n * Only available when using the polyfill extensions.\n */\n clearMockToolResponse(toolName: string): void;\n\n /**\n * Clear all mock responses.\n * Only available when using the polyfill extensions.\n */\n clearAllMockToolResponses(): void;\n\n /**\n * Get registered tools from modelContext internals.\n * Only available when using the polyfill extensions.\n */\n getRegisteredTools(): ToolListItem[];\n\n /**\n * Reset polyfill testing state.\n * Only available when using the polyfill extensions.\n */\n reset(): void;\n}\n\ntype PolyfillTestingExtensions = Pick<\n ModelContextTesting,\n | 'getToolCalls'\n | 'clearToolCalls'\n | 'setMockToolResponse'\n | 'clearMockToolResponse'\n | 'clearAllMockToolResponses'\n | 'getRegisteredTools'\n | 'reset'\n>;\n\nfunction resolveTestingAPI(override?: ModelContextTesting): ModelContextTesting {\n if (override) {\n return override;\n }\n\n // Prefer bridge-bound instance to avoid touching deprecated navigator accessor.\n if (typeof window !== 'undefined') {\n const bridgeTesting = window.__mcpBridge?.modelContextTesting;\n if (bridgeTesting) {\n return bridgeTesting;\n }\n }\n\n if (typeof navigator === 'undefined' || !navigator.modelContextTesting) {\n throw new Error(\n 'navigator.modelContextTesting is not available. Ensure @mcp-b/global is initialized first.'\n );\n }\n\n return navigator.modelContextTesting;\n}\n\nfunction getPolyfillExtensions(testing: ModelContextTesting): PolyfillTestingExtensions {\n const candidate = testing as ModelContextTesting & Partial<PolyfillTestingExtensions>;\n const requiredMethods: Array<keyof PolyfillTestingExtensions> = [\n 'getToolCalls',\n 'clearToolCalls',\n 'setMockToolResponse',\n 'clearMockToolResponse',\n 'clearAllMockToolResponses',\n 'getRegisteredTools',\n 'reset',\n ];\n\n for (const method of requiredMethods) {\n if (typeof candidate[method] !== 'function') {\n throw new Error(\n `modelContextTesting.${String(method)} is not available in this runtime. ` +\n 'These helpers require the @mcp-b/global polyfill testing extensions.'\n );\n }\n }\n\n return candidate as PolyfillTestingExtensions;\n}\n\n/**\n * Create a testing helper bound to modelContextTesting.\n *\n * @param testingOverride - Optional explicit testing API instance.\n */\nexport function createTestHelper(testingOverride?: ModelContextTesting): ModelContextTestHelper {\n const testing = resolveTestingAPI(testingOverride);\n const polyfillExtensions = () => getPolyfillExtensions(testing);\n\n return {\n executeTool: (toolName: string, args: Record<string, unknown> = {}) =>\n testing.executeTool(toolName, JSON.stringify(args)),\n listTools: () => testing.listTools(),\n onToolsChanged: (callback: () => void) => testing.registerToolsChangedCallback(callback),\n getToolCalls: () => polyfillExtensions().getToolCalls(),\n clearToolCalls: () => polyfillExtensions().clearToolCalls(),\n setMockToolResponse: (toolName: string, response: ToolResponse) =>\n polyfillExtensions().setMockToolResponse(toolName, response),\n clearMockToolResponse: (toolName: string) =>\n polyfillExtensions().clearMockToolResponse(toolName),\n clearAllMockToolResponses: () => polyfillExtensions().clearAllMockToolResponses(),\n getRegisteredTools: () => polyfillExtensions().getRegisteredTools(),\n reset: () => polyfillExtensions().reset(),\n };\n}\n"],"mappings":";AAiFA,SAAS,kBAAkB,UAAqD;AAC9E,KAAI,SACF,QAAO;AAIT,KAAI,OAAO,WAAW,aAAa;EACjC,MAAM,gBAAgB,OAAO,aAAa;AAC1C,MAAI,cACF,QAAO;;AAIX,KAAI,OAAO,cAAc,eAAe,CAAC,UAAU,oBACjD,OAAM,IAAI,MACR,6FACD;AAGH,QAAO,UAAU;;AAGnB,SAAS,sBAAsB,SAAyD;CACtF,MAAM,YAAY;AAWlB,MAAK,MAAM,UAVqD;EAC9D;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAGC,KAAI,OAAO,UAAU,YAAY,WAC/B,OAAM,IAAI,MACR,uBAAuB,OAAO,OAAO,CAAC,yGAEvC;AAIL,QAAO;;;;;;;AAQT,SAAgB,iBAAiB,iBAA+D;CAC9F,MAAM,UAAU,kBAAkB,gBAAgB;CAClD,MAAM,2BAA2B,sBAAsB,QAAQ;AAE/D,QAAO;EACL,cAAc,UAAkB,OAAgC,EAAE,KAChE,QAAQ,YAAY,UAAU,KAAK,UAAU,KAAK,CAAC;EACrD,iBAAiB,QAAQ,WAAW;EACpC,iBAAiB,aAAyB,QAAQ,6BAA6B,SAAS;EACxF,oBAAoB,oBAAoB,CAAC,cAAc;EACvD,sBAAsB,oBAAoB,CAAC,gBAAgB;EAC3D,sBAAsB,UAAkB,aACtC,oBAAoB,CAAC,oBAAoB,UAAU,SAAS;EAC9D,wBAAwB,aACtB,oBAAoB,CAAC,sBAAsB,SAAS;EACtD,iCAAiC,oBAAoB,CAAC,2BAA2B;EACjF,0BAA0B,oBAAoB,CAAC,oBAAoB;EACnE,aAAa,oBAAoB,CAAC,OAAO;EAC1C"}
|