ruflo 3.6.11 → 3.6.13

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.
Files changed (29) hide show
  1. package/package.json +4 -1
  2. package/src/ruvocal/.claude-flow/data/pending-insights.jsonl +25 -0
  3. package/src/ruvocal/.claude-flow/neural/stats.json +6 -0
  4. package/src/ruvocal/.dockerignore +5 -1
  5. package/src/ruvocal/.gcloudignore +18 -0
  6. package/src/ruvocal/README.md +107 -133
  7. package/src/ruvocal/cloudbuild.yaml +68 -0
  8. package/src/ruvocal/config/branding.env.example +19 -0
  9. package/src/ruvocal/mcp-bridge/index.js +15 -1
  10. package/src/ruvocal/src/lib/components/FoundationBackground.svelte +242 -0
  11. package/src/ruvocal/src/lib/components/NavMenu.svelte +18 -0
  12. package/src/ruvocal/src/lib/components/RufloHelpModal.svelte +411 -0
  13. package/src/ruvocal/src/lib/components/chat/ChatWindow.svelte +122 -4
  14. package/src/ruvocal/src/lib/components/wasm/GalleryPanel.svelte +357 -0
  15. package/src/ruvocal/src/lib/constants/mcpExamples.ts +56 -77
  16. package/src/ruvocal/src/lib/constants/routerExamples.ts +51 -127
  17. package/src/ruvocal/src/lib/constants/rvagentPresets.ts +206 -0
  18. package/src/ruvocal/src/lib/server/textGeneration/mcp/wasmTools.test.ts +633 -0
  19. package/src/ruvocal/src/lib/stores/mcpServers.ts +195 -6
  20. package/src/ruvocal/src/lib/stores/wasmMcp.ts +472 -0
  21. package/src/ruvocal/src/lib/types/Settings.ts +7 -0
  22. package/src/ruvocal/src/lib/types/Tool.ts +4 -1
  23. package/src/ruvocal/src/lib/wasm/idb.ts +438 -0
  24. package/src/ruvocal/src/lib/wasm/index.ts +1213 -0
  25. package/src/ruvocal/src/lib/wasm/tests/wasm-capabilities.test.ts +565 -0
  26. package/src/ruvocal/src/lib/wasm/wasm.worker.ts +332 -0
  27. package/src/ruvocal/src/lib/wasm/workerClient.ts +166 -0
  28. package/src/ruvocal/static/wasm/rvagent_wasm.js +1539 -0
  29. package/src/ruvocal/static/wasm/rvagent_wasm_bg.wasm +0 -0
@@ -0,0 +1,472 @@
1
+ /**
2
+ * WASM MCP Server Store
3
+ * Provides a local, browser-based MCP server using rvagent-wasm
4
+ * with IndexedDB persistence for the virtual filesystem
5
+ */
6
+
7
+ import { writable, derived, get } from "svelte/store";
8
+ import { browser } from "$app/environment";
9
+ import { loadWasm, isWasmLoaded, getWasm } from "$lib/wasm";
10
+ import { isWorkerEnabled, callMcpInWorker } from "$lib/wasm/workerClient";
11
+ import type { WasmMcpServer, WasmGallery, GalleryTemplate, SearchResult } from "$lib/wasm";
12
+ import * as idb from "$lib/wasm/idb";
13
+
14
+ // Store state types
15
+ interface WasmMcpState {
16
+ loaded: boolean;
17
+ loading: boolean;
18
+ error: string | null;
19
+ mcpServer: WasmMcpServer | null;
20
+ gallery: WasmGallery | null;
21
+ activeTemplateId: string | null;
22
+ activeTemplateName: string | null;
23
+ }
24
+
25
+ interface JsonRpcRequest {
26
+ jsonrpc: "2.0";
27
+ id: number | string | null;
28
+ method: string;
29
+ params?: unknown;
30
+ }
31
+
32
+ interface JsonRpcResponse {
33
+ jsonrpc: "2.0";
34
+ id: number | string | null;
35
+ result?: unknown;
36
+ error?: {
37
+ code: number;
38
+ message: string;
39
+ data?: unknown;
40
+ };
41
+ }
42
+
43
+ // Initial state
44
+ const initialState: WasmMcpState = {
45
+ loaded: false,
46
+ loading: false,
47
+ error: null,
48
+ mcpServer: null,
49
+ gallery: null,
50
+ activeTemplateId: null,
51
+ activeTemplateName: null,
52
+ };
53
+
54
+ // Create the store
55
+ const wasmMcpState = writable<WasmMcpState>(initialState);
56
+
57
+ // Derived stores for convenience
58
+ export const wasmLoaded = derived(wasmMcpState, ($state) => $state.loaded);
59
+ export const wasmLoading = derived(wasmMcpState, ($state) => $state.loading);
60
+ export const wasmError = derived(wasmMcpState, ($state) => $state.error);
61
+ export const activeTemplate = derived(wasmMcpState, ($state) => ({
62
+ id: $state.activeTemplateId,
63
+ name: $state.activeTemplateName,
64
+ }));
65
+
66
+ // Request ID counter
67
+ let requestId = 0;
68
+
69
+ /**
70
+ * Initialize the WASM MCP server
71
+ */
72
+ export async function initWasmMcp(): Promise<boolean> {
73
+ if (!browser) return false;
74
+
75
+ const state = get(wasmMcpState);
76
+ if (state.loaded || state.loading) return state.loaded;
77
+
78
+ wasmMcpState.update((s) => ({ ...s, loading: true, error: null }));
79
+
80
+ try {
81
+ // Load WASM module
82
+ const wasm = await loadWasm();
83
+ if (!wasm) {
84
+ throw new Error("Failed to load WASM module");
85
+ }
86
+
87
+ // Create MCP server and gallery instances
88
+ const mcpServer = new wasm.WasmMcpServer();
89
+ const gallery = new wasm.WasmGallery();
90
+
91
+ // Initialize the MCP server
92
+ const initResponse = callMcpInternal(mcpServer, "initialize", {
93
+ protocolVersion: "2024-11-05",
94
+ clientInfo: { name: "ruvocal-ui", version: "1.0.0" },
95
+ });
96
+
97
+ if (initResponse.error) {
98
+ throw new Error(`MCP initialization failed: ${initResponse.error.message}`);
99
+ }
100
+
101
+ // Load persisted filesystem state from IndexedDB
102
+ await syncFromIndexedDB(mcpServer);
103
+
104
+ // Check for persisted active template
105
+ const savedTemplateId = await idb.getSetting<string>("activeTemplateId");
106
+ let templateName: string | null = null;
107
+
108
+ if (savedTemplateId) {
109
+ try {
110
+ const template = gallery.get(savedTemplateId);
111
+ gallery.setActive(savedTemplateId);
112
+ templateName = template.name;
113
+ } catch {
114
+ // Template not found, ignore
115
+ }
116
+ }
117
+
118
+ wasmMcpState.set({
119
+ loaded: true,
120
+ loading: false,
121
+ error: null,
122
+ mcpServer,
123
+ gallery,
124
+ activeTemplateId: savedTemplateId,
125
+ activeTemplateName: templateName,
126
+ });
127
+
128
+ console.log("[WASM MCP] Server initialized successfully");
129
+ return true;
130
+ } catch (error) {
131
+ const errorMsg = error instanceof Error ? error.message : "Unknown error";
132
+ wasmMcpState.update((s) => ({
133
+ ...s,
134
+ loading: false,
135
+ error: errorMsg,
136
+ }));
137
+ console.error("[WASM MCP] Initialization failed:", error);
138
+ return false;
139
+ }
140
+ }
141
+
142
+ /**
143
+ * Internal MCP call helper
144
+ */
145
+ function callMcpInternal(
146
+ mcpServer: WasmMcpServer,
147
+ method: string,
148
+ params?: unknown
149
+ ): JsonRpcResponse {
150
+ const request: JsonRpcRequest = {
151
+ jsonrpc: "2.0",
152
+ id: ++requestId,
153
+ method,
154
+ params,
155
+ };
156
+
157
+ const responseJson = mcpServer.handle_message(JSON.stringify(request));
158
+ return JSON.parse(responseJson) as JsonRpcResponse;
159
+ }
160
+
161
+ /**
162
+ * Call an MCP method on the WASM server
163
+ */
164
+ export async function callMcp(method: string, params?: unknown): Promise<JsonRpcResponse> {
165
+ // Off-main-thread path (opt-in via ?worker=1 or
166
+ // localStorage.setItem("ruflo:wasm-worker","true")) — see workerClient.ts.
167
+ if (isWorkerEnabled()) {
168
+ try {
169
+ return (await callMcpInWorker(method, params)) as JsonRpcResponse;
170
+ } catch (err) {
171
+ return {
172
+ jsonrpc: "2.0",
173
+ id: null,
174
+ error: {
175
+ code: -32603,
176
+ message: err instanceof Error ? err.message : "worker call failed",
177
+ },
178
+ };
179
+ }
180
+ }
181
+
182
+ const state = get(wasmMcpState);
183
+
184
+ if (!state.loaded || !state.mcpServer) {
185
+ return {
186
+ jsonrpc: "2.0",
187
+ id: null,
188
+ error: { code: -32603, message: "WASM MCP server not initialized" },
189
+ };
190
+ }
191
+
192
+ const response = callMcpInternal(state.mcpServer, method, params);
193
+
194
+ // Persist file changes to IndexedDB
195
+ if (method === "tools/call" && response.result) {
196
+ const toolParams = params as { name: string; arguments?: Record<string, unknown> };
197
+ if (
198
+ ["write_file", "edit_file", "delete_file"].includes(toolParams.name) &&
199
+ !response.error
200
+ ) {
201
+ await syncToIndexedDB(state.mcpServer);
202
+ }
203
+ }
204
+
205
+ return response;
206
+ }
207
+
208
+ /**
209
+ * Execute a tool via MCP
210
+ */
211
+ export async function executeTool(
212
+ name: string,
213
+ args: Record<string, unknown>
214
+ ): Promise<{ success: boolean; result?: unknown; error?: string }> {
215
+ const response = await callMcp("tools/call", { name, arguments: args });
216
+
217
+ if (response.error) {
218
+ return { success: false, error: response.error.message };
219
+ }
220
+
221
+ return { success: true, result: response.result };
222
+ }
223
+
224
+ /**
225
+ * List available MCP tools
226
+ */
227
+ export async function listTools(): Promise<
228
+ Array<{ name: string; description: string; inputSchema: unknown }>
229
+ > {
230
+ const response = await callMcp("tools/list");
231
+
232
+ if (response.error || !response.result) {
233
+ return [];
234
+ }
235
+
236
+ const result = response.result as { tools: Array<{ name: string; description: string; inputSchema: unknown }> };
237
+ return result.tools || [];
238
+ }
239
+
240
+ /**
241
+ * Get available prompts from active template
242
+ */
243
+ export async function listPrompts(): Promise<Array<{ name: string; description: string }>> {
244
+ const response = await callMcp("prompts/list");
245
+
246
+ if (response.error || !response.result) {
247
+ return [];
248
+ }
249
+
250
+ const result = response.result as { prompts: Array<{ name: string; description: string }> };
251
+ return result.prompts || [];
252
+ }
253
+
254
+ // ---------------------------------------------------------------------------
255
+ // Gallery Operations
256
+ // ---------------------------------------------------------------------------
257
+
258
+ /**
259
+ * List all gallery templates
260
+ */
261
+ export function listGalleryTemplates(): GalleryTemplate[] {
262
+ const state = get(wasmMcpState);
263
+ if (!state.gallery) return [];
264
+
265
+ try {
266
+ return state.gallery.list() as unknown as GalleryTemplate[];
267
+ } catch {
268
+ return [];
269
+ }
270
+ }
271
+
272
+ /**
273
+ * Search gallery templates
274
+ */
275
+ export function searchGalleryTemplates(query: string): SearchResult[] {
276
+ const state = get(wasmMcpState);
277
+ if (!state.gallery) return [];
278
+
279
+ try {
280
+ return state.gallery.search(query) as unknown as SearchResult[];
281
+ } catch {
282
+ return [];
283
+ }
284
+ }
285
+
286
+ /**
287
+ * Get a gallery template by ID
288
+ */
289
+ export function getGalleryTemplate(id: string): GalleryTemplate | null {
290
+ const state = get(wasmMcpState);
291
+ if (!state.gallery) return null;
292
+
293
+ try {
294
+ return state.gallery.get(id) as unknown as GalleryTemplate;
295
+ } catch {
296
+ return null;
297
+ }
298
+ }
299
+
300
+ /**
301
+ * Load a gallery template as active
302
+ */
303
+ export async function loadGalleryTemplate(id: string): Promise<boolean> {
304
+ const state = get(wasmMcpState);
305
+ if (!state.gallery || !state.mcpServer) return false;
306
+
307
+ try {
308
+ // Load via MCP (sets active in both gallery and MCP server)
309
+ const response = await callMcp("gallery/load", { id });
310
+
311
+ if (response.error) {
312
+ console.error("[WASM MCP] Failed to load template:", response.error.message);
313
+ return false;
314
+ }
315
+
316
+ const result = response.result as { template_id: string; name: string };
317
+
318
+ // Update store state
319
+ wasmMcpState.update((s) => ({
320
+ ...s,
321
+ activeTemplateId: result.template_id,
322
+ activeTemplateName: result.name,
323
+ }));
324
+
325
+ // Persist to IndexedDB
326
+ await idb.setSetting("activeTemplateId", result.template_id);
327
+
328
+ console.log(`[WASM MCP] Loaded template: ${result.name}`);
329
+ return true;
330
+ } catch (error) {
331
+ console.error("[WASM MCP] Failed to load template:", error);
332
+ return false;
333
+ }
334
+ }
335
+
336
+ /**
337
+ * Get gallery categories with counts
338
+ */
339
+ export function getGalleryCategories(): Record<string, number> {
340
+ const state = get(wasmMcpState);
341
+ if (!state.gallery) return {};
342
+
343
+ try {
344
+ return state.gallery.getCategories() as unknown as Record<string, number>;
345
+ } catch {
346
+ return {};
347
+ }
348
+ }
349
+
350
+ /**
351
+ * Load a template as RVF bytes and save to IndexedDB
352
+ */
353
+ export async function saveTemplateAsRvf(templateId: string): Promise<string | null> {
354
+ const state = get(wasmMcpState);
355
+ if (!state.gallery) return null;
356
+
357
+ try {
358
+ const template = state.gallery.get(templateId);
359
+ const rvfBytes = state.gallery.loadRvf(templateId);
360
+
361
+ const containerId = crypto.randomUUID();
362
+ await idb.saveRvfContainer(containerId, template.name, rvfBytes, templateId);
363
+
364
+ console.log(`[WASM MCP] Saved RVF container: ${containerId}`);
365
+ return containerId;
366
+ } catch (error) {
367
+ console.error("[WASM MCP] Failed to save RVF:", error);
368
+ return null;
369
+ }
370
+ }
371
+
372
+ // ---------------------------------------------------------------------------
373
+ // IndexedDB Sync
374
+ // ---------------------------------------------------------------------------
375
+
376
+ /**
377
+ * Sync virtual filesystem from IndexedDB to WASM backend
378
+ */
379
+ async function syncFromIndexedDB(mcpServer: WasmMcpServer): Promise<void> {
380
+ try {
381
+ const files = await idb.listFiles();
382
+
383
+ for (const file of files) {
384
+ callMcpInternal(mcpServer, "tools/call", {
385
+ name: "write_file",
386
+ arguments: { path: file.path, content: file.content },
387
+ });
388
+ }
389
+
390
+ console.log(`[WASM MCP] Synced ${files.length} files from IndexedDB`);
391
+ } catch (error) {
392
+ console.error("[WASM MCP] Failed to sync from IndexedDB:", error);
393
+ }
394
+ }
395
+
396
+ /**
397
+ * Sync virtual filesystem from WASM backend to IndexedDB
398
+ */
399
+ async function syncToIndexedDB(mcpServer: WasmMcpServer): Promise<void> {
400
+ try {
401
+ // List all files in WASM backend
402
+ const listResponse = callMcpInternal(mcpServer, "tools/call", {
403
+ name: "list_files",
404
+ arguments: {},
405
+ });
406
+
407
+ if (listResponse.error || !listResponse.result) return;
408
+
409
+ const result = listResponse.result as { content: Array<{ text: string }> };
410
+ const filesContent = result.content?.[0]?.text;
411
+ if (!filesContent) return;
412
+
413
+ const wasmFiles = JSON.parse(filesContent) as string[];
414
+
415
+ // Get current IndexedDB files
416
+ const idbFiles = await idb.listFiles();
417
+ const idbPaths = new Set(idbFiles.map((f) => f.path));
418
+
419
+ // Sync each file
420
+ for (const path of wasmFiles) {
421
+ const readResponse = callMcpInternal(mcpServer, "tools/call", {
422
+ name: "read_file",
423
+ arguments: { path },
424
+ });
425
+
426
+ if (!readResponse.error && readResponse.result) {
427
+ const readResult = readResponse.result as { content: Array<{ text: string }> };
428
+ const content = readResult.content?.[0]?.text;
429
+ if (content) {
430
+ await idb.writeFile(path, content);
431
+ idbPaths.delete(path);
432
+ }
433
+ }
434
+ }
435
+
436
+ // Remove files that no longer exist in WASM backend
437
+ for (const path of idbPaths) {
438
+ await idb.deleteFile(path);
439
+ }
440
+
441
+ console.log(`[WASM MCP] Synced ${wasmFiles.length} files to IndexedDB`);
442
+ } catch (error) {
443
+ console.error("[WASM MCP] Failed to sync to IndexedDB:", error);
444
+ }
445
+ }
446
+
447
+ /**
448
+ * Force full sync to IndexedDB
449
+ */
450
+ export async function forceSyncToIndexedDB(): Promise<void> {
451
+ const state = get(wasmMcpState);
452
+ if (state.mcpServer) {
453
+ await syncToIndexedDB(state.mcpServer);
454
+ }
455
+ }
456
+
457
+ /**
458
+ * Clear all persisted data
459
+ */
460
+ export async function clearPersistedData(): Promise<void> {
461
+ await idb.clearFiles();
462
+ await idb.setSetting("activeTemplateId", null);
463
+ console.log("[WASM MCP] Cleared all persisted data");
464
+ }
465
+
466
+ // Auto-initialize on module load in browser
467
+ if (browser) {
468
+ // Defer initialization to avoid blocking
469
+ setTimeout(() => {
470
+ initWasmMcp().catch(console.error);
471
+ }, 100);
472
+ }
@@ -62,6 +62,12 @@ export interface Settings extends Timestamps {
62
62
  */
63
63
  autopilotEnabled: boolean;
64
64
 
65
+ /**
66
+ * Maximum number of autopilot steps (tool call loops) before stopping.
67
+ * Default is 10. Range: 1-50.
68
+ */
69
+ autopilotMaxSteps: number;
70
+
65
71
  /**
66
72
  * Organization to bill inference requests to (HuggingChat only).
67
73
  * Stores the org's preferred_username. If empty/undefined, bills to personal account.
@@ -83,4 +89,5 @@ export const DEFAULT_SETTINGS = {
83
89
  directPaste: false,
84
90
  hapticsEnabled: true,
85
91
  autopilotEnabled: true,
92
+ autopilotMaxSteps: 10,
86
93
  } satisfies SettingsEditable;
@@ -57,7 +57,7 @@ export interface MCPServer {
57
57
  id: string;
58
58
  name: string;
59
59
  url: string;
60
- type: "base" | "custom";
60
+ type: "base" | "custom" | "wasm";
61
61
  headers?: KeyValuePair[];
62
62
  env?: KeyValuePair[];
63
63
  status?: ServerStatus;
@@ -66,6 +66,9 @@ export interface MCPServer {
66
66
  errorMessage?: string;
67
67
  // Indicates server reports or appears to require OAuth or other auth
68
68
  authRequired?: boolean;
69
+ // For WASM servers: active template info
70
+ wasmTemplateId?: string;
71
+ wasmTemplateName?: string;
69
72
  }
70
73
 
71
74
  export interface MCPServerApi {