@gt-fe/eap-runtime 0.0.16 → 0.0.17

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 CHANGED
@@ -256,7 +256,7 @@ FOUNDATION_SERVICE_URL=...
256
256
  EAP_DEPLOYMENT_CONTEXT=dev
257
257
  EAP_PREINSTALL_ROOT=/abs/path/to/preinstall # 或 Agent 工程内预装树
258
258
  EAP_RUNTIME_STORAGE_PROFILE=dev
259
- EAP_TOOL_EXECUTION_MODE=mcp # 本地默认;http-debug 走 Gateway 调试口
259
+ EAP_TOOL_EXECUTION_MODE=mcp # 仅 createDevRuntime / eap chat;Hosting 的 TOOL_EXECUTION_MODE 不读
260
260
  # OPENAI_BASE_URL / OPENAI_API_KEY / EAP_DEFAULT_MODEL
261
261
  ```
262
262
 
@@ -1,9 +1,11 @@
1
1
  /**
2
2
  * createToolExecutor — 按部署上下文组装 Router + Gateway/Local 执行器
3
3
  *
4
- * server / hosting:**默认 MCP**(McpToolExecutor → POST /api/v1/mcp);
4
+ * server / hosting:**默认 MCP**(McpToolExecutor → POST {绝对基址}/api/v1/mcp);
5
5
  * `EAP_TOOL_GATEWAY_TRANSPORT=http` 时用 HttpToolExecutor(仅调试)。
6
6
  * desktop 经 ToolExecutionRouter 分流 Local / Gateway。
7
+ * desktop|dev 且 foundationUrl 不是绝对 http(s):不创建 Gateway 客户端,只挂 LocalToolExecutor。
8
+ * 不读 Hosting 的 TOOL_EXECUTION_MODE。
7
9
  */
8
10
  import type { ILocalToolInstallStore, LocalToolInstallRecord } from '@gt-fe/eap-contracts';
9
11
  import { type DeploymentContext } from './tool-execution-router.js';
@@ -1,12 +1,14 @@
1
1
  /**
2
2
  * createToolExecutor — 按部署上下文组装 Router + Gateway/Local 执行器
3
3
  *
4
- * server / hosting:**默认 MCP**(McpToolExecutor → POST /api/v1/mcp);
4
+ * server / hosting:**默认 MCP**(McpToolExecutor → POST {绝对基址}/api/v1/mcp);
5
5
  * `EAP_TOOL_GATEWAY_TRANSPORT=http` 时用 HttpToolExecutor(仅调试)。
6
6
  * desktop 经 ToolExecutionRouter 分流 Local / Gateway。
7
+ * desktop|dev 且 foundationUrl 不是绝对 http(s):不创建 Gateway 客户端,只挂 LocalToolExecutor。
8
+ * 不读 Hosting 的 TOOL_EXECUTION_MODE。
7
9
  */
8
10
  import { HttpToolExecutor } from './http-tool-executor.js';
9
- import { McpToolExecutor } from './mcp-tool-executor.js';
11
+ import { isAbsoluteHttpUrl, McpToolExecutor } from './mcp-tool-executor.js';
10
12
  import { LocalToolExecutor } from './local-tool-executor.js';
11
13
  import { ToolExecutionRouter, } from './tool-execution-router.js';
12
14
  import { withHarnessPrimitives } from './harness-primitives.js';
@@ -46,14 +48,19 @@ function createServerExecutor(foundationUrl, transport, timeout) {
46
48
  */
47
49
  export function createToolExecutor(options) {
48
50
  const installStore = options.installStore ?? new EmptyInstallStore();
51
+ const localExecutor = new LocalToolExecutor({ installStore });
52
+ const deploymentContext = resolveDeploymentContext(options.deploymentContext);
53
+ const hasGateway = isAbsoluteHttpUrl(options.foundationUrl);
54
+ if (!hasGateway && (deploymentContext === 'desktop' || deploymentContext === 'dev')) {
55
+ return withHarnessPrimitives(localExecutor);
56
+ }
49
57
  const transport = resolveGatewayTransport(options.gatewayTransport);
50
58
  const serverExecutor = createServerExecutor(options.foundationUrl, transport, options.httpTimeout);
51
- const localExecutor = new LocalToolExecutor({ installStore });
52
59
  return withHarnessPrimitives(new ToolExecutionRouter({
53
60
  httpExecutor: serverExecutor,
54
61
  localExecutor,
55
62
  installStore,
56
- deploymentContext: resolveDeploymentContext(options.deploymentContext),
63
+ deploymentContext,
57
64
  toolTypes: options.toolTypes,
58
65
  toolRuntimes: options.toolRuntimes,
59
66
  forceToolServer: options.forceToolServer,
@@ -3,7 +3,7 @@ export { hydrateMcpTools, isMcpDiscoverStub, needsMcpHydration, parseListedTools
3
3
  export { toLoadedToolMap, type LoadedToolDefinition, type LoadedToolMap, type LoadedToolManifestRef, } from './loaded-tool-definition.js';
4
4
  export { ToolOrchestrator } from './tool-orchestrator.js';
5
5
  export { HttpToolExecutor, type HttpToolExecutorOptions, } from './http-tool-executor.js';
6
- export { McpToolExecutor, type McpToolExecutorOptions, } from './mcp-tool-executor.js';
6
+ export { McpToolExecutor, isAbsoluteHttpUrl, type McpToolExecutorOptions, } from './mcp-tool-executor.js';
7
7
  export { LocalToolExecutor, isLocalPreferredExecution, resolveCodeExecutionFromRequest } from './local-tool-executor.js';
8
8
  export { DevMcpExecutor, type DevMcpExecutorOptions, } from './dev-mcp-executor.js';
9
9
  export { DevHttpExecutor, buildHttpToolUrl, resolveHttpExecutionFromRequest, type DevHttpExecution, } from './dev-http-executor.js';
@@ -2,7 +2,7 @@ export { hydrateMcpTools, isMcpDiscoverStub, needsMcpHydration, parseListedTools
2
2
  export { toLoadedToolMap, } from './loaded-tool-definition.js';
3
3
  export { ToolOrchestrator } from './tool-orchestrator.js';
4
4
  export { HttpToolExecutor, } from './http-tool-executor.js';
5
- export { McpToolExecutor, } from './mcp-tool-executor.js';
5
+ export { McpToolExecutor, isAbsoluteHttpUrl, } from './mcp-tool-executor.js';
6
6
  export { LocalToolExecutor, isLocalPreferredExecution, resolveCodeExecutionFromRequest } from './local-tool-executor.js';
7
7
  export { DevMcpExecutor, } from './dev-mcp-executor.js';
8
8
  export { DevHttpExecutor, buildHttpToolUrl, resolveHttpExecutionFromRequest, } from './dev-http-executor.js';
@@ -4,6 +4,8 @@
4
4
  * @see docs/contracts/tool-execution.md §2.0
5
5
  */
6
6
  import type { IToolExecutor, McpListedTool, ToolCallRequest, ToolCallResult } from './tool-executor.interface.js';
7
+ /** Tool Gateway 基址:必须是绝对 http(s)。空串 / 相对路径禁止 fetch。 */
8
+ export declare function isAbsoluteHttpUrl(value: unknown): boolean;
7
9
  export interface McpToolExecutorOptions {
8
10
  baseUrl: string;
9
11
  timeout?: number;
@@ -4,8 +4,24 @@
4
4
  * @see docs/contracts/tool-execution.md §2.0
5
5
  */
6
6
  import { ErrorCodes } from '@gt-fe/eap-contracts';
7
+ import { emitRuntimeLog } from '../common/logger.js';
7
8
  import { abortOrTimeoutMessage, isAbortError } from './timeout.js';
8
9
  import { nextListCursor, parseListedTools } from './mcp-list.js';
10
+ /** Tool Gateway 基址:必须是绝对 http(s)。空串 / 相对路径禁止 fetch。 */
11
+ export function isAbsoluteHttpUrl(value) {
12
+ if (typeof value !== 'string')
13
+ return false;
14
+ const trimmed = value.trim();
15
+ if (!trimmed)
16
+ return false;
17
+ try {
18
+ const url = new URL(trimmed);
19
+ return url.protocol === 'http:' || url.protocol === 'https:';
20
+ }
21
+ catch {
22
+ return false;
23
+ }
24
+ }
9
25
  function resolveAgentCode(request) {
10
26
  return request.authContext.agentCode;
11
27
  }
@@ -49,7 +65,14 @@ export class McpToolExecutor {
49
65
  /** endpoint+user+agent → in-flight / completed tools/list */
50
66
  listCache = new Map();
51
67
  constructor(options) {
52
- this.baseUrl = options.baseUrl.replace(/\/+$/, '');
68
+ if (!isAbsoluteHttpUrl(options.baseUrl)) {
69
+ emitRuntimeLog('warn', 'tool', 'McpToolExecutor 基址不是绝对 http(s),拒绝请求', {
70
+ event: 'runtime.tool.gateway_base_invalid',
71
+ baseUrl: options.baseUrl,
72
+ });
73
+ throw new Error(`McpToolExecutor 需要绝对 http(s) 基址,收到 ${JSON.stringify(options.baseUrl ?? '')}`);
74
+ }
75
+ this.baseUrl = options.baseUrl.trim().replace(/\/+$/, '');
53
76
  this.timeout = options.timeout ?? 30_000;
54
77
  const path = options.mcpPath ?? '/api/v1/mcp';
55
78
  this.mcpUrl = `${this.baseUrl}${path.startsWith('/') ? path : `/${path}`}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gt-fe/eap-runtime",
3
- "version": "0.0.16",
3
+ "version": "0.0.17",
4
4
  "description": "Enterprise Agent Platform \u2014 Runtime\u6838\u5fc3\uff1aGraph\u6267\u884c\u5f15\u64ce\u3001Task\u751f\u547d\u5468\u671f\u3001Session\u7ba1\u7406\u3001Checkpoint\u6301\u4e45\u5316",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",