@slashfi/agents-sdk 0.71.4 → 0.73.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/adk-tools.d.ts.map +1 -1
- package/dist/adk-tools.js +2 -4
- package/dist/adk-tools.js.map +1 -1
- package/dist/adk.d.ts +1 -1
- package/dist/adk.js +7 -27
- package/dist/adk.js.map +1 -1
- package/dist/agent-definitions/remote-registry.d.ts +15 -0
- package/dist/agent-definitions/remote-registry.d.ts.map +1 -1
- package/dist/agent-definitions/remote-registry.js +42 -17
- package/dist/agent-definitions/remote-registry.js.map +1 -1
- package/dist/cjs/adk-tools.js +2 -4
- package/dist/cjs/adk-tools.js.map +1 -1
- package/dist/cjs/agent-definitions/remote-registry.js +42 -17
- package/dist/cjs/agent-definitions/remote-registry.js.map +1 -1
- package/dist/cjs/config-store.js +125 -8
- package/dist/cjs/config-store.js.map +1 -1
- package/dist/cjs/events.js +11 -3
- package/dist/cjs/events.js.map +1 -1
- package/dist/cjs/fetch-types.js +3 -0
- package/dist/cjs/fetch-types.js.map +1 -0
- package/dist/cjs/index.js +8 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/key-manager.js +7 -1
- package/dist/cjs/key-manager.js.map +1 -1
- package/dist/cjs/logger.js +115 -0
- package/dist/cjs/logger.js.map +1 -0
- package/dist/cjs/registry-consumer.js.map +1 -1
- package/dist/cjs/registry.js +1 -1
- package/dist/cjs/registry.js.map +1 -1
- package/dist/cjs/server.js +70 -13
- package/dist/cjs/server.js.map +1 -1
- package/dist/config-store.d.ts +19 -0
- package/dist/config-store.d.ts.map +1 -1
- package/dist/config-store.js +125 -8
- package/dist/config-store.js.map +1 -1
- package/dist/events.d.ts +6 -1
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +11 -3
- package/dist/events.js.map +1 -1
- package/dist/fetch-types.d.ts +11 -0
- package/dist/fetch-types.d.ts.map +1 -0
- package/dist/fetch-types.js +2 -0
- package/dist/fetch-types.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/key-manager.d.ts +6 -0
- package/dist/key-manager.d.ts.map +1 -1
- package/dist/key-manager.js +7 -1
- package/dist/key-manager.js.map +1 -1
- package/dist/logger.d.ts +42 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +109 -0
- package/dist/logger.js.map +1 -0
- package/dist/registry-consumer.d.ts +8 -2
- package/dist/registry-consumer.d.ts.map +1 -1
- package/dist/registry-consumer.js.map +1 -1
- package/dist/registry.d.ts +6 -0
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +1 -1
- package/dist/registry.js.map +1 -1
- package/dist/server.d.ts +7 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +70 -13
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
- package/src/adk-tools.ts +2 -4
- package/src/adk.ts +7 -22
- package/src/agent-definitions/remote-registry.ts +56 -28
- package/src/config-store.ts +168 -9
- package/src/events.ts +16 -6
- package/src/fetch-types.ts +13 -0
- package/src/index.ts +13 -0
- package/src/key-manager.ts +12 -1
- package/src/logger.test.ts +206 -0
- package/src/logger.ts +123 -0
- package/src/registry-consumer.ts +13 -7
- package/src/registry.ts +7 -2
- package/src/server.ts +76 -42
package/src/registry-consumer.ts
CHANGED
|
@@ -39,6 +39,7 @@ import type {
|
|
|
39
39
|
ResolvedRegistry,
|
|
40
40
|
} from "./define-config.js";
|
|
41
41
|
import type { CallAgentRequest } from "./call-agent-schema.js";
|
|
42
|
+
import type { FetchFn } from "./fetch-types.js";
|
|
42
43
|
import type { SecuritySchemeSummary, CallAgentResponse } from "./types.js";
|
|
43
44
|
import {
|
|
44
45
|
isSecretUri,
|
|
@@ -331,7 +332,7 @@ async function defaultSecretResolver(
|
|
|
331
332
|
async function listFromMcpServer(
|
|
332
333
|
url: string,
|
|
333
334
|
auth: { token?: string; headers?: Record<string, string> },
|
|
334
|
-
fetchFn:
|
|
335
|
+
fetchFn: FetchFn,
|
|
335
336
|
): Promise<AgentListing[]> {
|
|
336
337
|
const serverUrl = url.replace(/\/$/, "");
|
|
337
338
|
|
|
@@ -409,7 +410,7 @@ function issuerFromMcpUrlAndServerInfo(
|
|
|
409
410
|
async function discoverRegistryViaMcp(
|
|
410
411
|
registryUrl: string,
|
|
411
412
|
authHeaders: Record<string, string>,
|
|
412
|
-
fetchFn:
|
|
413
|
+
fetchFn: FetchFn,
|
|
413
414
|
): Promise<RegistryConfiguration> {
|
|
414
415
|
const serverUrl = registryUrl.replace(/\/$/, "");
|
|
415
416
|
const headers: Record<string, string> = {
|
|
@@ -467,7 +468,7 @@ async function callMcpTool(
|
|
|
467
468
|
toolName: string,
|
|
468
469
|
params: Record<string, unknown>,
|
|
469
470
|
auth: { token?: string; headers?: Record<string, string> },
|
|
470
|
-
fetchFn:
|
|
471
|
+
fetchFn: FetchFn,
|
|
471
472
|
): Promise<unknown> {
|
|
472
473
|
const serverUrl = url.replace(/\/$/, "");
|
|
473
474
|
const headers: Record<string, string> = {
|
|
@@ -539,7 +540,7 @@ async function callHttpsTool(
|
|
|
539
540
|
_toolName: string,
|
|
540
541
|
params: Record<string, unknown>,
|
|
541
542
|
auth: { token?: string; headers?: Record<string, string> },
|
|
542
|
-
fetchFn:
|
|
543
|
+
fetchFn: FetchFn,
|
|
543
544
|
): Promise<unknown> {
|
|
544
545
|
const method = (params.method as string) ?? "GET";
|
|
545
546
|
const path = (params.path as string) ?? "";
|
|
@@ -582,8 +583,13 @@ export interface RegistryConsumerOptions {
|
|
|
582
583
|
/** Bearer token for authenticated registries */
|
|
583
584
|
token?: string;
|
|
584
585
|
|
|
585
|
-
/**
|
|
586
|
-
|
|
586
|
+
/**
|
|
587
|
+
* Custom fetch implementation. Forwarded to every outbound HTTP call the
|
|
588
|
+
* consumer makes (discovery, jwks, callRegistry, secret resolve). Hosts
|
|
589
|
+
* running in long-lived servers should pass a hardened fetch to avoid
|
|
590
|
+
* dead-socket hangs on rolling deploys.
|
|
591
|
+
*/
|
|
592
|
+
fetch?: FetchFn;
|
|
587
593
|
}
|
|
588
594
|
|
|
589
595
|
// ============================================
|
|
@@ -651,7 +657,7 @@ export async function createRegistryConsumer(
|
|
|
651
657
|
config: ConsumerConfig,
|
|
652
658
|
options: RegistryConsumerOptions = {},
|
|
653
659
|
): Promise<RegistryConsumer> {
|
|
654
|
-
const fetchFn = options.fetch ?? globalThis.fetch;
|
|
660
|
+
const fetchFn: FetchFn = options.fetch ?? globalThis.fetch;
|
|
655
661
|
const resolveSecretFn = options.resolveSecret ?? defaultSecretResolver;
|
|
656
662
|
|
|
657
663
|
// Normalize registries
|
package/src/registry.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { dirname, resolve } from "node:path";
|
|
8
8
|
import type { AgentEvent, BaseEvent, CallAgentToolCallEvent, CustomEventMap, EventCallback, EventType, ListAgentsResult, ListAgentsToolCallEvent } from "./events.js";
|
|
9
9
|
import { createEventBus } from "./events.js";
|
|
10
|
+
import type { Logger } from "./logger.js";
|
|
10
11
|
import type { SerializedAgentDefinition } from "./serialized.js";
|
|
11
12
|
import type {
|
|
12
13
|
AgentAction,
|
|
@@ -87,7 +88,11 @@ export interface AgentRegistryOptions {
|
|
|
87
88
|
contextFactory?: ContextFactory;
|
|
88
89
|
/** Lifecycle middleware hooks */
|
|
89
90
|
middleware?: RegistryMiddleware;
|
|
90
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Structured logger for SDK-internal events (listener errors, etc.).
|
|
93
|
+
* Defaults to the module-level default logger (JSON to stdout/stderr).
|
|
94
|
+
*/
|
|
95
|
+
logger?: Logger;
|
|
91
96
|
}
|
|
92
97
|
|
|
93
98
|
/**
|
|
@@ -231,7 +236,7 @@ export function createAgentRegistry(
|
|
|
231
236
|
): AgentRegistry {
|
|
232
237
|
const { defaultVisibility = "internal" } = options;
|
|
233
238
|
const agents = new Map<string, AgentDefinition>();
|
|
234
|
-
const eventBus = createEventBus();
|
|
239
|
+
const eventBus = createEventBus({ logger: options.logger });
|
|
235
240
|
|
|
236
241
|
/**
|
|
237
242
|
* Check if agent supports the requested action.
|
package/src/server.ts
CHANGED
|
@@ -44,6 +44,7 @@ import {
|
|
|
44
44
|
verifyJwtFromIssuer,
|
|
45
45
|
verifyJwtLocal,
|
|
46
46
|
} from "./jwt.js";
|
|
47
|
+
import { getDefaultLogger, type Logger } from "./logger.js";
|
|
47
48
|
import { type OIDCProviderConfig, createOIDCSignIn } from "./oidc-signin.js";
|
|
48
49
|
import type { AgentRegistry } from "./registry.js";
|
|
49
50
|
import {
|
|
@@ -206,6 +207,12 @@ export interface AgentServerOptions {
|
|
|
206
207
|
/** OAuth callback URL for shared OAuth flows */
|
|
207
208
|
oauthCallbackUrl?: string;
|
|
208
209
|
};
|
|
210
|
+
/**
|
|
211
|
+
* Structured logger for server-side errors (tool-call failures, JWT
|
|
212
|
+
* exchange errors, request errors, etc.). Defaults to the module-level
|
|
213
|
+
* default logger (single-line JSON).
|
|
214
|
+
*/
|
|
215
|
+
logger?: Logger;
|
|
209
216
|
}
|
|
210
217
|
|
|
211
218
|
export interface AgentServer {
|
|
@@ -522,6 +529,7 @@ export function createAgentServer(
|
|
|
522
529
|
secretStore,
|
|
523
530
|
oauthIdentityProvider,
|
|
524
531
|
} = options;
|
|
532
|
+
const logger = options.logger ?? getDefaultLogger();
|
|
525
533
|
|
|
526
534
|
// Build tool definitions and validation schemas from overrides
|
|
527
535
|
const toolDefs = getToolDefinitions(options.schemas);
|
|
@@ -607,7 +615,13 @@ export function createAgentServer(
|
|
|
607
615
|
const result = await handleToolCall(name, args ?? {}, auth);
|
|
608
616
|
return jsonRpcSuccess(request.id, result);
|
|
609
617
|
} catch (err) {
|
|
610
|
-
|
|
618
|
+
logger.error("mcp_tool_call_error", {
|
|
619
|
+
component: "agents-sdk.server",
|
|
620
|
+
tool: name,
|
|
621
|
+
caller_id: auth?.callerId,
|
|
622
|
+
caller_type: auth?.callerType,
|
|
623
|
+
error: err,
|
|
624
|
+
});
|
|
611
625
|
return jsonRpcSuccess(
|
|
612
626
|
request.id,
|
|
613
627
|
mcpResult(
|
|
@@ -907,22 +921,24 @@ export function createAgentServer(
|
|
|
907
921
|
callerType: "system",
|
|
908
922
|
});
|
|
909
923
|
if (addResult.success) {
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
924
|
+
logger.info("jwt_exchange_reverse_connection_stored", {
|
|
925
|
+
component: "agents-sdk.server",
|
|
926
|
+
issuer: assertionPayload.iss,
|
|
927
|
+
});
|
|
913
928
|
} else {
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
929
|
+
logger.error("jwt_exchange_reverse_connection_failed", {
|
|
930
|
+
component: "agents-sdk.server",
|
|
931
|
+
issuer: assertionPayload.iss,
|
|
932
|
+
error: addResult.error,
|
|
933
|
+
});
|
|
918
934
|
}
|
|
919
935
|
}
|
|
920
936
|
}
|
|
921
937
|
} catch (reverseErr) {
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
reverseErr,
|
|
925
|
-
);
|
|
938
|
+
logger.error("jwt_exchange_reverse_registration_failed", {
|
|
939
|
+
component: "agents-sdk.server",
|
|
940
|
+
error: reverseErr,
|
|
941
|
+
});
|
|
926
942
|
}
|
|
927
943
|
|
|
928
944
|
if (!exchangeResult) {
|
|
@@ -988,7 +1004,10 @@ export function createAgentServer(
|
|
|
988
1004
|
|
|
989
1005
|
return jsonResponse(exchangeResult);
|
|
990
1006
|
} catch (err) {
|
|
991
|
-
|
|
1007
|
+
logger.error("oauth_jwt_exchange_error", {
|
|
1008
|
+
component: "agents-sdk.server",
|
|
1009
|
+
error: err,
|
|
1010
|
+
});
|
|
992
1011
|
return jsonResponse(
|
|
993
1012
|
{
|
|
994
1013
|
error: "server_error",
|
|
@@ -1061,7 +1080,10 @@ export function createAgentServer(
|
|
|
1061
1080
|
refresh_token: tokenResult.refreshToken,
|
|
1062
1081
|
});
|
|
1063
1082
|
} catch (err) {
|
|
1064
|
-
|
|
1083
|
+
logger.error("oauth_token_error", {
|
|
1084
|
+
component: "agents-sdk.server",
|
|
1085
|
+
error: err,
|
|
1086
|
+
});
|
|
1065
1087
|
return jsonResponse(
|
|
1066
1088
|
{ error: "server_error", error_description: "Token exchange failed" },
|
|
1067
1089
|
500,
|
|
@@ -1190,36 +1212,31 @@ export function createAgentServer(
|
|
|
1190
1212
|
const allIssuerUrls = [
|
|
1191
1213
|
...new Set([...storeIssuers, ...configIssuerUrls]),
|
|
1192
1214
|
];
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
storeIssuers.length,
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
"urls:",
|
|
1201
|
-
allIssuerUrls,
|
|
1202
|
-
);
|
|
1215
|
+
logger.debug("oauth_authorize_issuer_check", {
|
|
1216
|
+
component: "agents-sdk.server",
|
|
1217
|
+
store_issuers: storeIssuers.length,
|
|
1218
|
+
config_issuers: configIssuerUrls.length,
|
|
1219
|
+
total_issuers: allIssuerUrls.length,
|
|
1220
|
+
issuer_urls: allIssuerUrls,
|
|
1221
|
+
});
|
|
1203
1222
|
for (const issuerUrl of allIssuerUrls) {
|
|
1204
1223
|
try {
|
|
1205
1224
|
const result = await verifyJwtFromIssuer(token, issuerUrl);
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
issuerUrl,
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
);
|
|
1225
|
+
logger.debug("oauth_authorize_verify", {
|
|
1226
|
+
component: "agents-sdk.server",
|
|
1227
|
+
issuer: issuerUrl,
|
|
1228
|
+
ok: !!result,
|
|
1229
|
+
});
|
|
1212
1230
|
if (result) {
|
|
1213
1231
|
claims = result as unknown as Record<string, unknown>;
|
|
1214
1232
|
break;
|
|
1215
1233
|
}
|
|
1216
1234
|
} catch (e: unknown) {
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
issuerUrl,
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
);
|
|
1235
|
+
logger.debug("oauth_authorize_verify_error", {
|
|
1236
|
+
component: "agents-sdk.server",
|
|
1237
|
+
issuer: issuerUrl,
|
|
1238
|
+
error: e,
|
|
1239
|
+
});
|
|
1223
1240
|
}
|
|
1224
1241
|
}
|
|
1225
1242
|
if (!claims) {
|
|
@@ -1500,7 +1517,12 @@ export function createAgentServer(
|
|
|
1500
1517
|
const res = jsonResponse(jsonRpcSuccess(body.id, result));
|
|
1501
1518
|
return cors ? addCors(res) : res;
|
|
1502
1519
|
} catch (err) {
|
|
1503
|
-
|
|
1520
|
+
logger.error("mcp_scoped_tool_call_error", {
|
|
1521
|
+
component: "agents-sdk.server",
|
|
1522
|
+
caller_id: effectiveAuth?.callerId,
|
|
1523
|
+
caller_type: effectiveAuth?.callerType,
|
|
1524
|
+
error: err,
|
|
1525
|
+
});
|
|
1504
1526
|
const res = jsonResponse(
|
|
1505
1527
|
jsonRpcSuccess(
|
|
1506
1528
|
body.id,
|
|
@@ -1534,7 +1556,12 @@ export function createAgentServer(
|
|
|
1534
1556
|
);
|
|
1535
1557
|
return cors ? addCors(res) : res;
|
|
1536
1558
|
} catch (err) {
|
|
1537
|
-
|
|
1559
|
+
logger.error("mcp_request_error", {
|
|
1560
|
+
component: "agents-sdk.server",
|
|
1561
|
+
method: req.method,
|
|
1562
|
+
url: req.url,
|
|
1563
|
+
error: err,
|
|
1564
|
+
});
|
|
1538
1565
|
const res = jsonResponse(
|
|
1539
1566
|
{
|
|
1540
1567
|
jsonrpc: "2.0",
|
|
@@ -1586,9 +1613,12 @@ export function createAgentServer(
|
|
|
1586
1613
|
fetch,
|
|
1587
1614
|
});
|
|
1588
1615
|
this.url = `http://${hostname}:${port}`;
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1616
|
+
logger.info("agent_server_listening", {
|
|
1617
|
+
component: "agents-sdk.server",
|
|
1618
|
+
url: this.url,
|
|
1619
|
+
hostname,
|
|
1620
|
+
port,
|
|
1621
|
+
});
|
|
1592
1622
|
},
|
|
1593
1623
|
|
|
1594
1624
|
async stop() {
|
|
@@ -1644,7 +1674,11 @@ export function createAgentServer(
|
|
|
1644
1674
|
issuer: issuerUrl,
|
|
1645
1675
|
scopes: scopes ?? ["*"],
|
|
1646
1676
|
});
|
|
1647
|
-
|
|
1677
|
+
logger.info("trusted_issuer_added", {
|
|
1678
|
+
component: "agents-sdk.server",
|
|
1679
|
+
issuer: issuerUrl,
|
|
1680
|
+
scopes: scopes ?? ["*"],
|
|
1681
|
+
});
|
|
1648
1682
|
}
|
|
1649
1683
|
},
|
|
1650
1684
|
};
|