@ethisyscore/extension-runtime 1.71.0 → 1.71.2

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.
@@ -6,6 +6,7 @@ import { SduiNode, RenderMode } from '@ethisyscore/protocol';
6
6
  import { RemoteConnection } from '@remote-dom/core';
7
7
  import { P as PortBridgeClient, T as ThemePayload, L as LocalePayload } from '../bridge-client-DzRcKIJT.cjs';
8
8
  export { A as A11yPayload, B as BridgePortShim, D as DensityPayload, N as NavPayload, S as SessionTokenPayload, c as createPortBridgeClient } from '../bridge-client-DzRcKIJT.cjs';
9
+ export { M as MCP_ERROR_CODES, a as McpErrorCode, b as McpToolError, c as classifyHostError, d as classifyHostResponse, i as isMcpErrorCode, e as isMcpToolError, f as isRetryableMcpErrorCode, m as mcpErrorCodeFromHttpStatus } from '../mcp-error-CCZQd8Xl.cjs';
9
10
 
10
11
  /**
11
12
  * A single client-push event delivered from the host to a plugin surface. The host
@@ -6,6 +6,7 @@ import { SduiNode, RenderMode } from '@ethisyscore/protocol';
6
6
  import { RemoteConnection } from '@remote-dom/core';
7
7
  import { P as PortBridgeClient, T as ThemePayload, L as LocalePayload } from '../bridge-client-DD99netz.js';
8
8
  export { A as A11yPayload, B as BridgePortShim, D as DensityPayload, N as NavPayload, S as SessionTokenPayload, c as createPortBridgeClient } from '../bridge-client-DD99netz.js';
9
+ export { M as MCP_ERROR_CODES, a as McpErrorCode, b as McpToolError, c as classifyHostError, d as classifyHostResponse, i as isMcpErrorCode, e as isMcpToolError, f as isRetryableMcpErrorCode, m as mcpErrorCodeFromHttpStatus } from '../mcp-error-CCZQd8Xl.js';
9
10
 
10
11
  /**
11
12
  * A single client-push event delivered from the host to a plugin surface. The host
@@ -462,6 +462,100 @@ function defaultConnectionFactory(port) {
462
462
  };
463
463
  }
464
464
 
465
+ // src/bridge/mcp-error.ts
466
+ var MCP_ERROR_CODES = [
467
+ "unauthorized",
468
+ "forbidden",
469
+ "not_found",
470
+ "invalid_request",
471
+ "conflict",
472
+ "rate_limited",
473
+ "timeout",
474
+ "unavailable",
475
+ "internal"
476
+ ];
477
+ function isMcpErrorCode(value) {
478
+ return typeof value === "string" && MCP_ERROR_CODES.includes(value);
479
+ }
480
+ var RETRYABLE = ["rate_limited", "timeout", "unavailable"];
481
+ function isRetryableMcpErrorCode(code) {
482
+ return RETRYABLE.includes(code);
483
+ }
484
+ var McpToolError = class extends Error {
485
+ /** Machine-readable classification. `internal` when the host sent none. */
486
+ code;
487
+ /**
488
+ * Marks the instance for {@link isMcpToolError}. A structural marker rather than a prototype
489
+ * check because the error can be constructed in one bundle and inspected in another, where
490
+ * `instanceof` compares two different class objects and answers false.
491
+ */
492
+ isMcpToolError = true;
493
+ constructor(message, code = "internal") {
494
+ super(message);
495
+ this.name = "McpHostError";
496
+ this.code = code;
497
+ }
498
+ /** True when this failure is worth retrying unchanged. */
499
+ get retryable() {
500
+ return isRetryableMcpErrorCode(this.code);
501
+ }
502
+ };
503
+ function isMcpToolError(value) {
504
+ return value instanceof McpToolError || value !== null && typeof value === "object" && value.isMcpToolError === true && isMcpErrorCode(value.code);
505
+ }
506
+ function mcpErrorCodeFromHttpStatus(status) {
507
+ switch (status) {
508
+ case 401:
509
+ return "unauthorized";
510
+ case 403:
511
+ return "forbidden";
512
+ case 404:
513
+ return "not_found";
514
+ case 400:
515
+ case 422:
516
+ return "invalid_request";
517
+ case 409:
518
+ case 412:
519
+ return "conflict";
520
+ case 429:
521
+ return "rate_limited";
522
+ case 408:
523
+ case 504:
524
+ return "timeout";
525
+ case 502:
526
+ case 503:
527
+ return "unavailable";
528
+ default:
529
+ return "internal";
530
+ }
531
+ }
532
+ function classifyHostResponse(response) {
533
+ if (response.ok) {
534
+ return void 0;
535
+ }
536
+ if (isMcpErrorCode(response.mcpErrorCode)) {
537
+ return response.mcpErrorCode;
538
+ }
539
+ return typeof response.status === "number" ? mcpErrorCodeFromHttpStatus(response.status) : "internal";
540
+ }
541
+ function classifyHostError(err) {
542
+ if (err === null || typeof err !== "object") {
543
+ return "internal";
544
+ }
545
+ const candidate = err;
546
+ if (isMcpErrorCode(candidate.mcpErrorCode)) {
547
+ return candidate.mcpErrorCode;
548
+ }
549
+ const status = typeof candidate.status === "number" ? candidate.status : typeof candidate.statusCode === "number" ? candidate.statusCode : void 0;
550
+ if (status !== void 0) {
551
+ return mcpErrorCodeFromHttpStatus(status);
552
+ }
553
+ if (candidate.name === "AbortError" || candidate.name === "TimeoutError") {
554
+ return "timeout";
555
+ }
556
+ return "internal";
557
+ }
558
+
465
559
  // src/plugin/createPortMcpTransport.ts
466
560
  var WIRE_INVOKE_TOOL_REQUEST = "ethisys:mcp:invokeTool";
467
561
  var WIRE_INVOKE_TOOL_RESULT = "ethisys:mcp:invokeTool:result";
@@ -499,11 +593,10 @@ function createPortMcpTransport(port, options = {}) {
499
593
  if (reply.ok === true) {
500
594
  resolver.resolve(reply.data);
501
595
  } else {
502
- const error = new Error(
503
- typeof reply.error === "string" ? reply.error : "Unknown host error"
504
- );
505
- error.name = "McpHostError";
506
- resolver.reject(error);
596
+ resolver.reject(new McpToolError(
597
+ typeof reply.error === "string" ? reply.error : "Unknown host error",
598
+ isMcpErrorCode(reply.code) ? reply.code : "internal"
599
+ ));
507
600
  }
508
601
  }
509
602
  shim.addEventListener("message", onMessage);
@@ -802,6 +895,6 @@ function useAuth(transport) {
802
895
  };
803
896
  }
804
897
 
805
- export { BridgeClientContext, ClientPushContext, ExtensionRuntimeProvider, HostIdentityContext, PluginRealtimeContext, createPortBridgeClient, createPortMcpTransport, createRemoteRoot, decodeJwtPayload, defineDeclarativePlugin, defineEthisysPlugin, unwrapItems, useAuth, useBridgeClient, useBridgeLocale, useBridgeTheme, useClientPushSubscription, useExtensionRuntimeTransport, useFrontendSessionToken, useHostIdentity, useMcpQuery, useMcpResource, useMcpTool, usePluginRealtimeSource };
898
+ export { BridgeClientContext, ClientPushContext, ExtensionRuntimeProvider, HostIdentityContext, MCP_ERROR_CODES, McpToolError, PluginRealtimeContext, classifyHostError, classifyHostResponse, createPortBridgeClient, createPortMcpTransport, createRemoteRoot, decodeJwtPayload, defineDeclarativePlugin, defineEthisysPlugin, isMcpErrorCode, isMcpToolError, isRetryableMcpErrorCode, mcpErrorCodeFromHttpStatus, unwrapItems, useAuth, useBridgeClient, useBridgeLocale, useBridgeTheme, useClientPushSubscription, useExtensionRuntimeTransport, useFrontendSessionToken, useHostIdentity, useMcpQuery, useMcpResource, useMcpTool, usePluginRealtimeSource };
806
899
  //# sourceMappingURL=index.js.map
807
900
  //# sourceMappingURL=index.js.map