Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions apps/desktop/scripts/vite-workspace-packages.test.mjs
Original file line numberDiff line numberDiff line change
Expand Up@@ -79,3 +79,28 @@ test('renderer loads a newly exported workspace module after its manifest change
}
throw failure;
});

test('renderer-facing Runtime Host protocol does not load Node crypto', async (t) => {
const repoRoot = await realpath(new URL('../../..', import.meta.url));
const root = join(repoRoot, 'apps/desktop/src/renderer');
const server = await createServer({
configFile: false,
root,
logLevel: 'silent',
server: { host: '127.0.0.1', port: 0 },
optimizeDeps: { noDiscovery: true, include: [] },
plugins: [workspacePackagesPlugin(repoRoot)],
});
t.after(() => server.close());
await server.listen();

const protocolModule = join(
repoRoot,
'packages/runtime-host/dist/protocol/client-capability.js',
);
const response = await fetch(`${server.resolvedUrls.local[0]}@fs/${protocolModule}`);
const transformed = await response.text();

assert.equal(response.status, 200, transformed);
assert.doesNotMatch(transformed, /vite-browser-external:node:crypto/u);
});
3 changes: 2 additions & 1 deletion apps/desktop/src/main/runtime-host-boot.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,7 +64,8 @@ import {
openRuntimeHostPeerEndpointOwner,
type RuntimeHostPeerEndpointOwner,
} from '@maka/runtime-host/peer-reachability';
import { clientCapabilityEntityId, type WorkspaceTarget } from "@maka/runtime-host/protocol";
import { clientCapabilityEntityId } from "@maka/runtime-host/client-capability-entity-id";
import type { WorkspaceTarget } from "@maka/runtime-host/protocol";
import { runtimeHostProfileUsesHostWorkspace } from "@maka/runtime-host/profile-kind";
import { createCredentialMcpOAuthStorage, McpClientManager } from "@maka/mcp";
import { createWorkBoardStore } from "@maka/storage/work-board-store";
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/main/runtime-host-native-capabilities.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,7 +30,6 @@ import {
CLIENT_CAPABILITY_MAX_OFFERS,
CLIENT_CAPABILITY_MAX_TOOLS,
CLIENT_CAPABILITY_MAX_TOOLS_PER_OFFER,
clientCapabilityEntityId,
decodeClientCapabilityReplaceInput,
decodeClientCapabilityToolDescriptor,
type ClientCapabilityCallFrame,
Expand All@@ -42,6 +41,7 @@ import {
type ClientCapabilityServiceOffer,
type ClientCapabilityToolDescriptor,
} from "@maka/runtime-host/protocol";
import { clientCapabilityEntityId } from "@maka/runtime-host/client-capability-entity-id";
import { toJSONSchema, z } from "zod";
import { withBrowserOriginAdmission } from './browser/browser-origin-admission.js';
import type { DesktopTargetScope } from '../shared/runtime-host-identity.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/mcp-capability-provider.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,10 +21,10 @@ import { createHash } from 'node:crypto';
import type { McpBoundTool, McpToolBinding } from '@maka/core/mcp';
import type { McpClientManager } from '@maka/mcp';
import type { ClientCapabilityProvider } from '@maka/runtime-host/client';
import { clientCapabilityEntityId } from '@maka/runtime-host/client-capability-entity-id';
import {
CLIENT_CAPABILITY_MAX_TOOLS,
CLIENT_CAPABILITY_MAX_TOOLS_PER_OFFER,
clientCapabilityEntityId,
decodeClientCapabilityReplaceInput,
type ClientCapabilityCallResult,
type ClientCapabilityOffer,
Expand Down
1 change: 1 addition & 0 deletions packages/runtime-host/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
"./adapter": "./dist/adapter/index.js",
"./protocol": "./dist/protocol/index.js",
"./client": "./dist/client/index.js",
"./client-capability-entity-id": "./dist/client-capability-entity-id.js",
"./webrtc-stun-policy": "./dist/webrtc-stun-policy.js",
"./peer-reachability": "./dist/peer-reachability/index.js",
"./peer-mesh": "./dist/peer-mesh/index.js",
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
{
"epoch": 109,
"files": ["packages/runtime-host/src/protocol/client-capability.ts"],
"reason": "Moves the Node-only clientCapabilityEntityId helper out of the browser-facing protocol module (#4700). Wire shape, validation limits, and error behavior are unchanged; older and newer peers decode identical frames."
}
28 changes: 28 additions & 0 deletions packages/runtime-host/src/client-capability-entity-id.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { createHash } from 'node:crypto';

/** Normalize an arbitrary Client Capability identity into a wire-safe entity id. */
export function clientCapabilityEntityId(value: string, maxLength = 128): string {
if (/^[A-Za-z0-9_-]+$/u.test(value) && value.length <= maxLength) return value;
const label = value.replace(/[^A-Za-z0-9_-]+/gu, '_').slice(0, maxLength - 25) || 'mcp';
const digest = createHash('sha256').update(value).digest('hex').slice(0, 24);
return `${label}_${digest}`;
}
13 changes: 0 additions & 13 deletions packages/runtime-host/src/protocol/client-capability.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,6 @@
* under the License.
*/

import { createHash } from 'node:crypto';
import { TOOL_ACTIVITY_KINDS, type ToolActivityKind } from '@maka/core/events';
import {
decodeInteractionAnswer,
Expand DownExpand Up@@ -85,18 +84,6 @@ export const CLIENT_CAPABILITY_MAX_OFFERS = 32;
export const CLIENT_CAPABILITY_MAX_SERVICES = 32;
export const CLIENT_CAPABILITY_MAX_TOOLS_PER_OFFER = 64;

/**
* Normalize an arbitrary Client Capability identity (an MCP server id or tool
* name from user configuration) into a wire-safe entity id: identities that
* already fit pass through unchanged, anything else becomes a readable label
* plus a collision-proof digest of the original value.
*/
export function clientCapabilityEntityId(value: string, maxLength = 128): string {
if (/^[A-Za-z0-9_-]+$/u.test(value) && value.length <= maxLength) return value;
const label = value.replace(/[^A-Za-z0-9_-]+/gu, '_').slice(0, maxLength - 25) || 'mcp';
const digest = createHash('sha256').update(value).digest('hex').slice(0, 24);
return `${label}_${digest}`;
}
export const CLIENT_CAPABILITY_MAX_TOOLS = 256;
export const CLIENT_CAPABILITY_MAX_MANIFEST_BYTES = 56 * 1024;
export const CLIENT_CAPABILITY_MAX_RESULT_BYTES = 24 * 1024 * 1024;
Expand Down
Loading