@cuylabs/agent-core 4.1.0 → 4.3.0
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/dist/{chunk-US7S4FYW.js → chunk-UMIVJDEJ.js} +120 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -2
- package/dist/mcp/index.d.ts +48 -4
- package/dist/mcp/index.js +3 -1
- package/package.json +1 -1
|
@@ -464,13 +464,115 @@ var DefaultMCPManager = class {
|
|
|
464
464
|
}
|
|
465
465
|
};
|
|
466
466
|
|
|
467
|
+
// src/mcp/diagnostics.ts
|
|
468
|
+
function createDiagnosticFetch(options = {}) {
|
|
469
|
+
const baseFetch = options.fetch ?? globalThis.fetch;
|
|
470
|
+
return async (input, init) => {
|
|
471
|
+
let timedOut = false;
|
|
472
|
+
let timeoutId;
|
|
473
|
+
let timeoutController;
|
|
474
|
+
let requestInit = init;
|
|
475
|
+
if (options.timeoutMs !== void 0 && options.timeoutMs > 0) {
|
|
476
|
+
timeoutController = new AbortController();
|
|
477
|
+
timeoutId = setTimeout(() => {
|
|
478
|
+
timedOut = true;
|
|
479
|
+
timeoutController?.abort();
|
|
480
|
+
}, options.timeoutMs);
|
|
481
|
+
requestInit = {
|
|
482
|
+
...init,
|
|
483
|
+
signal: init?.signal ? AbortSignal.any([init.signal, timeoutController.signal]) : timeoutController.signal
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
try {
|
|
487
|
+
return await baseFetch(input, requestInit);
|
|
488
|
+
} catch (error) {
|
|
489
|
+
const reason = timedOut && options.timeoutMs ? `; timed out after ${options.timeoutMs}ms` : "";
|
|
490
|
+
throw enrichMcpFetchError(
|
|
491
|
+
`${options.label ?? "MCP HTTP fetch failed"} (${describeFetchTarget(
|
|
492
|
+
input,
|
|
493
|
+
init
|
|
494
|
+
)}${reason})`,
|
|
495
|
+
error,
|
|
496
|
+
options.redactValues
|
|
497
|
+
);
|
|
498
|
+
} finally {
|
|
499
|
+
if (timeoutId) {
|
|
500
|
+
clearTimeout(timeoutId);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
function enrichMcpFetchError(message, error, redactValues = []) {
|
|
506
|
+
const errorMessage = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
507
|
+
const causeSummary = summarizeCause(error);
|
|
508
|
+
const redactedMessage = redactSensitiveText(
|
|
509
|
+
`${message}: ${errorMessage}${causeSummary ? `; ${causeSummary}` : ""}`,
|
|
510
|
+
redactValues
|
|
511
|
+
);
|
|
512
|
+
return new Error(redactedMessage, { cause: error });
|
|
513
|
+
}
|
|
514
|
+
function redactSensitiveText(text, values) {
|
|
515
|
+
return values.reduce((redacted, value) => {
|
|
516
|
+
if (!value) {
|
|
517
|
+
return redacted;
|
|
518
|
+
}
|
|
519
|
+
return redacted.split(value).join("[redacted]");
|
|
520
|
+
}, text);
|
|
521
|
+
}
|
|
522
|
+
async function readDiagnosticBody(response, maxChars = 500) {
|
|
523
|
+
const body = await response.text().catch(() => "");
|
|
524
|
+
return body.length > maxChars ? `${body.slice(0, maxChars)}...` : body;
|
|
525
|
+
}
|
|
526
|
+
function summarizeCause(error) {
|
|
527
|
+
const cause = error instanceof Error ? error.cause : void 0;
|
|
528
|
+
if (!cause) {
|
|
529
|
+
return void 0;
|
|
530
|
+
}
|
|
531
|
+
if (cause instanceof Error) {
|
|
532
|
+
const details = cause;
|
|
533
|
+
return [
|
|
534
|
+
`cause=${cause.name}: ${cause.message}`,
|
|
535
|
+
typeof details.code === "string" ? `code=${details.code}` : void 0,
|
|
536
|
+
typeof details.syscall === "string" ? `syscall=${details.syscall}` : void 0,
|
|
537
|
+
typeof details.hostname === "string" ? `hostname=${details.hostname}` : void 0
|
|
538
|
+
].filter(Boolean).join(" ");
|
|
539
|
+
}
|
|
540
|
+
return `cause=${String(cause)}`;
|
|
541
|
+
}
|
|
542
|
+
function describeFetchTarget(input, init) {
|
|
543
|
+
const method = init?.method ?? (input instanceof Request && input.method ? input.method : void 0) ?? "GET";
|
|
544
|
+
const rawUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input instanceof Request ? input.url : void 0;
|
|
545
|
+
if (!rawUrl) {
|
|
546
|
+
return `method=${method} url=unknown`;
|
|
547
|
+
}
|
|
548
|
+
try {
|
|
549
|
+
const url = new URL(rawUrl);
|
|
550
|
+
return `method=${method} host=${url.host} path=${url.pathname}`;
|
|
551
|
+
} catch {
|
|
552
|
+
return `method=${method} url=unparseable`;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
467
556
|
// src/mcp/auth.ts
|
|
468
557
|
var ClientCredentialsProvider = class {
|
|
469
558
|
_tokens;
|
|
470
559
|
_expiresAt;
|
|
471
560
|
_options;
|
|
561
|
+
_tokenFetch;
|
|
562
|
+
_redactValues;
|
|
472
563
|
constructor(options) {
|
|
473
564
|
this._options = options;
|
|
565
|
+
this._redactValues = [
|
|
566
|
+
options.clientId,
|
|
567
|
+
options.clientSecret,
|
|
568
|
+
...options.redactValues ?? []
|
|
569
|
+
];
|
|
570
|
+
this._tokenFetch = createDiagnosticFetch({
|
|
571
|
+
fetch: options.fetch,
|
|
572
|
+
timeoutMs: options.timeoutMs,
|
|
573
|
+
label: `${options.diagnosticsLabel ?? "ClientCredentialsProvider"} token fetch failed`,
|
|
574
|
+
redactValues: this._redactValues
|
|
575
|
+
});
|
|
474
576
|
}
|
|
475
577
|
// ── OAuthClientProvider: required ─────────────────────────────────────────
|
|
476
578
|
get redirectUrl() {
|
|
@@ -541,13 +643,16 @@ var ClientCredentialsProvider = class {
|
|
|
541
643
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
542
644
|
});
|
|
543
645
|
this.addClientAuthentication(headers);
|
|
544
|
-
const response = await
|
|
646
|
+
const response = await this._tokenFetch(tokenUrl, {
|
|
545
647
|
method: "POST",
|
|
546
648
|
headers,
|
|
547
649
|
body: params.toString()
|
|
548
650
|
});
|
|
549
651
|
if (!response.ok) {
|
|
550
|
-
const body =
|
|
652
|
+
const body = redactSensitiveText(
|
|
653
|
+
await readDiagnosticBody(response),
|
|
654
|
+
this._redactValues
|
|
655
|
+
);
|
|
551
656
|
throw new Error(
|
|
552
657
|
`ClientCredentialsProvider: token fetch failed (HTTP ${response.status}): ${body}`
|
|
553
658
|
);
|
|
@@ -592,15 +697,27 @@ function sseServer(url, options) {
|
|
|
592
697
|
};
|
|
593
698
|
}
|
|
594
699
|
function serviceAccountServer(url, credentials, options) {
|
|
700
|
+
const redactValues = [
|
|
701
|
+
credentials.clientId,
|
|
702
|
+
credentials.clientSecret,
|
|
703
|
+
...credentials.redactValues ?? []
|
|
704
|
+
];
|
|
595
705
|
return {
|
|
596
706
|
transport: "http",
|
|
597
707
|
url,
|
|
598
708
|
authProvider: new ClientCredentialsProvider(credentials),
|
|
599
|
-
...options
|
|
709
|
+
...options,
|
|
710
|
+
fetch: createDiagnosticFetch({
|
|
711
|
+
fetch: options?.fetch,
|
|
712
|
+
timeoutMs: options?.timeout,
|
|
713
|
+
label: `${credentials.diagnosticsLabel ?? "serviceAccountServer"} HTTP fetch failed`,
|
|
714
|
+
redactValues
|
|
715
|
+
})
|
|
600
716
|
};
|
|
601
717
|
}
|
|
602
718
|
|
|
603
719
|
export {
|
|
720
|
+
createDiagnosticFetch,
|
|
604
721
|
ClientCredentialsProvider,
|
|
605
722
|
createMCPManager,
|
|
606
723
|
stdioServer,
|
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export { ToolHostProvider, ToolHostProviderSummary, ToolHostRegistry, defaultToo
|
|
|
12
12
|
export { AdapterSettings, CacheCapabilitySource, CapabilityCache, CapabilityOverrides, Directory, EngineSpec, ModelCapabilityResolver, ModelSpec, NetworkStatus, PatternCapabilitySource, RemoteCapabilityFetcher, RemoteCapabilitySource, ResolutionResult, Resolver, applyCapabilityOverride, configureResolver, createResolver, extractModelId, extractProvider, findCapabilityOverride, getDefaultResolver, getModelId, getNetworkStatus, getProviderCompatibility, getProviderId, inferContextWindow, inferProvider, likelySupportsReasoning } from './models/index.js';
|
|
13
13
|
export { C as CapabilitySource, D as DEFAULT_RESOLVER_OPTIONS, I as InputModality, M as ModelCapabilities, a as ModelEntry, O as OutputModality, P as ProviderCompatibility, R as ResolverOptions, S as SourcePriority, b as SourceResult, c as buildAnthropicOptions, d as buildBedrockOptions, e as buildGoogleOptions, f as buildGroqOptions, g as buildOpenAIOptions, h as buildOpenRouterOptions, i as buildReasoningOptions, j as buildReasoningOptionsSync, k as buildXAIOptions, l as getProviderOptionsKey, m as getReasoningConfig, n as getReasoningConfigSync, s as supportsReasoning, o as supportsReasoningSync } from './index-BCqEGzBj.js';
|
|
14
14
|
export { H as HttpTransportConfig, M as MCPConfig, a as MCPManager, b as MCPPromptInfo, c as MCPResourceInfo, d as MCPResourceTemplateInfo, e as MCPServerConfig, f as MCPServerStatus, R as RemoteTransportConfig, S as SseTransportConfig, g as StdioTransportConfig } from './types-DMjoFKKv.js';
|
|
15
|
-
export { ClientCredentialsOptions, ClientCredentialsProvider, createMCPManager, httpServer, serviceAccountServer, sseServer, stdioServer } from './mcp/index.js';
|
|
15
|
+
export { ClientCredentialsOptions, ClientCredentialsProvider, DiagnosticFetchOptions, ServiceAccountServerConfig, ServiceAccountServerOptions, createDiagnosticFetch, createMCPManager, httpServer, serviceAccountServer, sseServer, stdioServer } from './mcp/index.js';
|
|
16
16
|
export { AgentTaskChatAdapter, AgentTaskCheckpointReason, AgentTaskCheckpointStrategy, AgentTaskCheckpointStrategyInput, AgentTaskExecutionCheckpoint, AgentTaskExecutionContext, AgentTaskExecutionRun, AgentTaskExecutionSnapshot, AgentTaskObserver, AgentTaskPayload, AgentTaskResult, AgentTaskResumeSnapshot, AgentTaskRunner, AgentTaskRunnerOptions, AgentWorkflowAssistantMessageSnapshot, AgentWorkflowCommitResult, AgentWorkflowInputCommitPlan, AgentWorkflowInterventionSnapshot, AgentWorkflowMessageSnapshot, AgentWorkflowModelStepPlan, AgentWorkflowModelStepResult, AgentWorkflowOperationPlan, AgentWorkflowOutputCommitPlan, AgentWorkflowReplayDecision, AgentWorkflowStepCommitPlan, AgentWorkflowSystemMessageSnapshot, AgentWorkflowToolBatchPlan, AgentWorkflowToolBatchResult, AgentWorkflowToolCallPlan, AgentWorkflowToolCallResult, AgentWorkflowToolCallSnapshot, AgentWorkflowToolMessageSnapshot, AgentWorkflowTurnPhase, AgentWorkflowTurnState, AgentWorkflowUserMessageSnapshot, ContextOverflowError, CreateAgentWorkflowTurnStateOptions, DoomLoopError, applyAgentWorkflowCommitResult, applyAgentWorkflowModelStepResult, applyAgentWorkflowToolBatchResult, applyAgentWorkflowToolCallResult, applyWorkflowInterventions, cloneAgentWorkflowTurnState, commitOutput, commitStep, createAgentTaskRunner, createAgentTurnStepCommitBatch, createAgentWorkflowTurnState, defaultAgentTaskCheckpointStrategy, drainWorkflowInterventions, failAgentWorkflowTurnState, planNextAgentWorkflowOperation, prepareModelStep, processStepStream, queueWorkflowFollowUps, recordAgentWorkflowReplayDecision, restoreAgentWorkflowMessage, restoreAgentWorkflowMessages, runModelStep, runToolBatch, snapshotAgentWorkflowMessage, snapshotAgentWorkflowMessages } from './execution/index.js';
|
|
17
17
|
export { c as convertAgentMessagesToModelMessages } from './model-messages-COIqIS5e.js';
|
|
18
18
|
export { CacheTTL, PromptCacheConfig, createTelemetryConfig, otelMiddleware, promptCacheMiddleware } from './middleware/index.js';
|
package/dist/index.js
CHANGED
|
@@ -310,15 +310,16 @@ import {
|
|
|
310
310
|
supportsReasoning,
|
|
311
311
|
supportsReasoningSync
|
|
312
312
|
} from "./chunk-GJFP5L2V.js";
|
|
313
|
+
import "./chunk-SPBFQXOT.js";
|
|
313
314
|
import {
|
|
314
315
|
ClientCredentialsProvider,
|
|
316
|
+
createDiagnosticFetch,
|
|
315
317
|
createMCPManager,
|
|
316
318
|
httpServer,
|
|
317
319
|
serviceAccountServer,
|
|
318
320
|
sseServer,
|
|
319
321
|
stdioServer
|
|
320
|
-
} from "./chunk-
|
|
321
|
-
import "./chunk-SPBFQXOT.js";
|
|
322
|
+
} from "./chunk-UMIVJDEJ.js";
|
|
322
323
|
import {
|
|
323
324
|
MiddlewareRunner,
|
|
324
325
|
approvalMiddleware,
|
|
@@ -3488,6 +3489,7 @@ export {
|
|
|
3488
3489
|
createConditionalApprovalRule,
|
|
3489
3490
|
createConsoleLogger,
|
|
3490
3491
|
createDangerouslyAllowAllApprovalPolicy,
|
|
3492
|
+
createDiagnosticFetch,
|
|
3491
3493
|
createDispatchExternalTaskControl,
|
|
3492
3494
|
createDispatchTaskExecutor,
|
|
3493
3495
|
createDispatchTools,
|
package/dist/mcp/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { H as HttpTransportConfig, b as MCPPromptInfo, c as MCPResourceInfo, d as MCPResourceTemplateInfo,
|
|
1
|
+
import { R as RemoteTransportConfig, e as MCPServerConfig, M as MCPConfig, a as MCPManager, g as StdioTransportConfig } from '../types-DMjoFKKv.js';
|
|
2
|
+
export { H as HttpTransportConfig, b as MCPPromptInfo, c as MCPResourceInfo, d as MCPResourceTemplateInfo, f as MCPServerStatus, S as SseTransportConfig } from '../types-DMjoFKKv.js';
|
|
3
3
|
import { OAuthClientProvider } from '@modelcontextprotocol/sdk/client/auth.js';
|
|
4
4
|
import { OAuthClientMetadata, OAuthClientInformation, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
|
|
5
5
|
import '@modelcontextprotocol/sdk/types.js';
|
|
@@ -35,6 +35,26 @@ interface ClientCredentialsOptions {
|
|
|
35
35
|
* @default 60
|
|
36
36
|
*/
|
|
37
37
|
expiryBufferSeconds?: number;
|
|
38
|
+
/**
|
|
39
|
+
* Fetch implementation for the token endpoint.
|
|
40
|
+
* Defaults to `globalThis.fetch`.
|
|
41
|
+
*/
|
|
42
|
+
fetch?: typeof fetch;
|
|
43
|
+
/**
|
|
44
|
+
* Abort the token fetch if no response is received before this many
|
|
45
|
+
* milliseconds.
|
|
46
|
+
*/
|
|
47
|
+
timeoutMs?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Human-readable operation label used in token-fetch diagnostics.
|
|
50
|
+
* @default "ClientCredentialsProvider"
|
|
51
|
+
*/
|
|
52
|
+
diagnosticsLabel?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Extra values to redact from diagnostic text. `clientId` and `clientSecret`
|
|
55
|
+
* are always redacted automatically.
|
|
56
|
+
*/
|
|
57
|
+
redactValues?: string[];
|
|
38
58
|
}
|
|
39
59
|
/**
|
|
40
60
|
* OAuth `client_credentials` provider for machine-to-machine MCP authentication.
|
|
@@ -74,6 +94,8 @@ declare class ClientCredentialsProvider implements OAuthClientProvider {
|
|
|
74
94
|
private _tokens?;
|
|
75
95
|
private _expiresAt?;
|
|
76
96
|
private readonly _options;
|
|
97
|
+
private readonly _tokenFetch;
|
|
98
|
+
private readonly _redactValues;
|
|
77
99
|
constructor(options: ClientCredentialsOptions);
|
|
78
100
|
get redirectUrl(): undefined;
|
|
79
101
|
get clientMetadata(): OAuthClientMetadata;
|
|
@@ -90,6 +112,8 @@ declare class ClientCredentialsProvider implements OAuthClientProvider {
|
|
|
90
112
|
private _fetchTokens;
|
|
91
113
|
}
|
|
92
114
|
|
|
115
|
+
type ServiceAccountServerOptions = Omit<RemoteTransportConfig, "transport" | "url" | "authProvider"> & Pick<MCPServerConfig, "capabilities" | "enabled" | "name" | "onUncaughtError" | "timeout">;
|
|
116
|
+
type ServiceAccountServerConfig = RemoteTransportConfig & Pick<MCPServerConfig, "capabilities" | "enabled" | "name" | "onUncaughtError" | "timeout">;
|
|
93
117
|
/**
|
|
94
118
|
* Create an MCP manager for connecting to multiple MCP servers.
|
|
95
119
|
*/
|
|
@@ -130,6 +154,26 @@ declare function sseServer(url: string, options?: Omit<RemoteTransportConfig, "t
|
|
|
130
154
|
* });
|
|
131
155
|
* ```
|
|
132
156
|
*/
|
|
133
|
-
declare function serviceAccountServer(url: string, credentials: ClientCredentialsOptions, options?:
|
|
157
|
+
declare function serviceAccountServer(url: string, credentials: ClientCredentialsOptions, options?: ServiceAccountServerOptions): ServiceAccountServerConfig;
|
|
158
|
+
|
|
159
|
+
interface DiagnosticFetchOptions {
|
|
160
|
+
/**
|
|
161
|
+
* Base fetch implementation. Defaults to `globalThis.fetch`.
|
|
162
|
+
*/
|
|
163
|
+
fetch?: typeof fetch;
|
|
164
|
+
/**
|
|
165
|
+
* Human-readable operation label used in wrapped network errors.
|
|
166
|
+
*/
|
|
167
|
+
label?: string;
|
|
168
|
+
/**
|
|
169
|
+
* Abort the fetch if no response is received before this many milliseconds.
|
|
170
|
+
*/
|
|
171
|
+
timeoutMs?: number;
|
|
172
|
+
/**
|
|
173
|
+
* Values to redact from diagnostic text.
|
|
174
|
+
*/
|
|
175
|
+
redactValues?: string[];
|
|
176
|
+
}
|
|
177
|
+
declare function createDiagnosticFetch(options?: DiagnosticFetchOptions): typeof fetch;
|
|
134
178
|
|
|
135
|
-
export { type ClientCredentialsOptions, ClientCredentialsProvider, MCPConfig, MCPManager, RemoteTransportConfig, StdioTransportConfig, createMCPManager, httpServer, serviceAccountServer, sseServer, stdioServer };
|
|
179
|
+
export { type ClientCredentialsOptions, ClientCredentialsProvider, type DiagnosticFetchOptions, MCPConfig, MCPManager, MCPServerConfig, RemoteTransportConfig, type ServiceAccountServerConfig, type ServiceAccountServerOptions, StdioTransportConfig, createDiagnosticFetch, createMCPManager, httpServer, serviceAccountServer, sseServer, stdioServer };
|
package/dist/mcp/index.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ClientCredentialsProvider,
|
|
3
|
+
createDiagnosticFetch,
|
|
3
4
|
createMCPManager,
|
|
4
5
|
httpServer,
|
|
5
6
|
serviceAccountServer,
|
|
6
7
|
sseServer,
|
|
7
8
|
stdioServer
|
|
8
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-UMIVJDEJ.js";
|
|
9
10
|
import "../chunk-S6AKEPAX.js";
|
|
10
11
|
export {
|
|
11
12
|
ClientCredentialsProvider,
|
|
13
|
+
createDiagnosticFetch,
|
|
12
14
|
createMCPManager,
|
|
13
15
|
httpServer,
|
|
14
16
|
serviceAccountServer,
|