@webmcp-auto-ui/agent 2.5.23 → 2.5.25
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/package.json +1 -1
- package/src/discovery-cache.ts +9 -0
- package/src/index.ts +1 -1
- package/src/loop.ts +4 -1
- package/src/providers/wasm.ts +19 -5
- package/src/tool-layers.ts +2 -0
- package/src/types.ts +1 -1
package/package.json
CHANGED
package/src/discovery-cache.ts
CHANGED
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
|
|
7
7
|
import type { ProviderTool } from './types.js';
|
|
8
8
|
|
|
9
|
+
/** Tool names that are resolved locally from cache — hidden from user-facing browsers. */
|
|
10
|
+
export const DISCOVERY_TOOL_NAMES = new Set(['list_recipes', 'search_recipes', 'get_recipe', 'list_tools', 'search_tools']);
|
|
11
|
+
|
|
9
12
|
export interface CachedRecipe {
|
|
10
13
|
name: string;
|
|
11
14
|
description?: string;
|
|
@@ -79,6 +82,12 @@ export class DiscoveryCache {
|
|
|
79
82
|
return this.servers.get(serverPrefix)?.tools.length ?? 0;
|
|
80
83
|
}
|
|
81
84
|
|
|
85
|
+
/** Tool count excluding discovery tools (hidden from user-facing browsers) */
|
|
86
|
+
browsableToolCount(serverPrefix: string): number {
|
|
87
|
+
const tools = this.servers.get(serverPrefix)?.tools ?? [];
|
|
88
|
+
return tools.filter(t => !DISCOVERY_TOOL_NAMES.has(t.name)).length;
|
|
89
|
+
}
|
|
90
|
+
|
|
82
91
|
/**
|
|
83
92
|
* Try to resolve a discovery tool call from cache.
|
|
84
93
|
* Returns the result string if handled, or null if not a discovery tool.
|
package/src/index.ts
CHANGED
|
@@ -29,7 +29,7 @@ export { buildToolsFromLayers, buildDiscoveryTools, buildDiscoveryToolsWithAlias
|
|
|
29
29
|
export type { ToolLayer, McpLayer, WebMcpLayer, SystemPromptResult, DiscoveryToolsResult, SchemaTransformOptions, BuildToolsResult } from './tool-layers.js';
|
|
30
30
|
|
|
31
31
|
// Discovery cache
|
|
32
|
-
export { DiscoveryCache } from './discovery-cache.js';
|
|
32
|
+
export { DiscoveryCache, DISCOVERY_TOOL_NAMES } from './discovery-cache.js';
|
|
33
33
|
export type { CachedRecipe, ServerCache } from './discovery-cache.js';
|
|
34
34
|
|
|
35
35
|
// Re-export core WebMCP types
|
package/src/loop.ts
CHANGED
|
@@ -92,6 +92,8 @@ export interface AgentLoopOptions {
|
|
|
92
92
|
maxIterations?: number;
|
|
93
93
|
maxTokens?: number;
|
|
94
94
|
maxTools?: number;
|
|
95
|
+
/** WASM-only: cap on conversation messages sent to the model. Default: derived from contextSize. */
|
|
96
|
+
maxMessages?: number;
|
|
95
97
|
temperature?: number;
|
|
96
98
|
topK?: number;
|
|
97
99
|
cacheEnabled?: boolean;
|
|
@@ -125,6 +127,7 @@ export async function runAgentLoop(
|
|
|
125
127
|
maxIterations = 5,
|
|
126
128
|
maxTokens,
|
|
127
129
|
maxTools,
|
|
130
|
+
maxMessages,
|
|
128
131
|
temperature,
|
|
129
132
|
topK,
|
|
130
133
|
cacheEnabled = true,
|
|
@@ -264,7 +267,7 @@ export async function runAgentLoop(
|
|
|
264
267
|
const t0 = performance.now();
|
|
265
268
|
let streamingText = '';
|
|
266
269
|
const response = await provider.chat(messages, iterationTools, {
|
|
267
|
-
signal, cacheEnabled, system: iterationSystemPrompt, maxTokens, maxTools, temperature, topK,
|
|
270
|
+
signal, cacheEnabled, system: iterationSystemPrompt, maxTokens, maxTools, maxMessages, temperature, topK,
|
|
268
271
|
onToken: callbacks.onToken ? (token) => {
|
|
269
272
|
callbacks.onToken!(token);
|
|
270
273
|
streamingText += token;
|
package/src/providers/wasm.ts
CHANGED
|
@@ -176,7 +176,7 @@ export class WasmProvider implements LLMProvider {
|
|
|
176
176
|
async chat(
|
|
177
177
|
messages: ChatMessage[],
|
|
178
178
|
tools: ProviderTool[],
|
|
179
|
-
options?: { signal?: AbortSignal; maxTokens?: number; temperature?: number; topK?: number; onToken?: (token: string) => void; system?: string; maxTools?: number }
|
|
179
|
+
options?: { signal?: AbortSignal; maxTokens?: number; temperature?: number; topK?: number; onToken?: (token: string) => void; system?: string; maxTools?: number; maxMessages?: number }
|
|
180
180
|
): Promise<LLMResponse> {
|
|
181
181
|
if (this.status !== 'ready') await this.initialize();
|
|
182
182
|
if (!this.inference) throw new Error('Model not initialized');
|
|
@@ -202,7 +202,7 @@ export class WasmProvider implements LLMProvider {
|
|
|
202
202
|
private async _chat(
|
|
203
203
|
messages: ChatMessage[],
|
|
204
204
|
tools: ProviderTool[],
|
|
205
|
-
options?: { signal?: AbortSignal; maxTokens?: number; temperature?: number; topK?: number; onToken?: (token: string) => void; system?: string; maxTools?: number }
|
|
205
|
+
options?: { signal?: AbortSignal; maxTokens?: number; temperature?: number; topK?: number; onToken?: (token: string) => void; system?: string; maxTools?: number; maxMessages?: number }
|
|
206
206
|
): Promise<LLMResponse> {
|
|
207
207
|
// Apply per-request options
|
|
208
208
|
if (options?.maxTokens || options?.temperature || options?.topK) {
|
|
@@ -222,7 +222,7 @@ export class WasmProvider implements LLMProvider {
|
|
|
222
222
|
|
|
223
223
|
// Aggressive clipping: Gemma struggles with long conversations — dynamic cap based on context size
|
|
224
224
|
const contextTokens = this.opts.contextSize ?? 4096;
|
|
225
|
-
const MAX_MESSAGES =
|
|
225
|
+
const MAX_MESSAGES = options?.maxMessages ?? Math.max(4, Math.floor(contextTokens / 512));
|
|
226
226
|
while (messages.length > MAX_MESSAGES) {
|
|
227
227
|
messages = messages.slice(1);
|
|
228
228
|
}
|
|
@@ -660,9 +660,23 @@ export class WasmProvider implements LLMProvider {
|
|
|
660
660
|
private buildPrompt(messages: ChatMessage[], tools: ProviderTool[], systemPrompt?: string, maxTools?: number): string {
|
|
661
661
|
const systemParts: string[] = [];
|
|
662
662
|
|
|
663
|
-
// Inject system prompt from settings if provided
|
|
663
|
+
// Inject system prompt from settings if provided.
|
|
664
|
+
// Rewrite paren syntax "tool_name()" / "tool_name(args)" to Gemma 4 native call syntax.
|
|
665
|
+
// Without this, Gemma mimics the paren syntax as plain text (regression from commit 2724b9e).
|
|
664
666
|
if (systemPrompt) {
|
|
665
|
-
|
|
667
|
+
const gemmaPrompt = systemPrompt.replace(
|
|
668
|
+
/\b([a-zA-Z_][a-zA-Z0-9_]*)\(([^)]*)\)/g,
|
|
669
|
+
(_full, name, args) => {
|
|
670
|
+
const trimmed = args.trim();
|
|
671
|
+
if (!trimmed) return `<|tool_call>call:${name}{}<tool_call|>`;
|
|
672
|
+
const argBody = trimmed
|
|
673
|
+
.split(',')
|
|
674
|
+
.map((a: string) => `${a.trim()}:<|"|>...<|"|>`)
|
|
675
|
+
.join(',');
|
|
676
|
+
return `<|tool_call>call:${name}{${argBody}}<tool_call|>`;
|
|
677
|
+
}
|
|
678
|
+
);
|
|
679
|
+
systemParts.push(gemmaPrompt);
|
|
666
680
|
}
|
|
667
681
|
|
|
668
682
|
if (tools.length > 0) {
|
package/src/tool-layers.ts
CHANGED
|
@@ -465,6 +465,8 @@ Unless a recipe specifies otherwise, use these tools to display your responses o
|
|
|
465
465
|
|
|
466
466
|
${actionTools.join('\n')}
|
|
467
467
|
|
|
468
|
+
widget_display may ONLY be called with data returned by a non-autoui DATA tool actually invoked in the current session. Fabricating IDs, URLs, names, dates, or any content not returned by a tool is a critical violation. If no DATA tool has been called yet, go back to STEP 1.
|
|
469
|
+
|
|
468
470
|
STEP 5 — Fallback
|
|
469
471
|
|
|
470
472
|
If previous steps failed, fall back to a classic chat without tool calling.`;
|
package/src/types.ts
CHANGED
|
@@ -51,7 +51,7 @@ export interface LLMProvider {
|
|
|
51
51
|
chat(
|
|
52
52
|
messages: ChatMessage[],
|
|
53
53
|
tools: ProviderTool[],
|
|
54
|
-
options?: { signal?: AbortSignal; cacheEnabled?: boolean; system?: string; maxTokens?: number; temperature?: number; topK?: number; onToken?: (token: string) => void; maxTools?: number }
|
|
54
|
+
options?: { signal?: AbortSignal; cacheEnabled?: boolean; system?: string; maxTokens?: number; temperature?: number; topK?: number; onToken?: (token: string) => void; maxTools?: number; maxMessages?: number }
|
|
55
55
|
): Promise<LLMResponse>;
|
|
56
56
|
}
|
|
57
57
|
|