@dudko.dev/agent 0.0.44 → 0.0.46

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/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { OAuthClientProvider } from '@modelcontextprotocol/sdk/client/auth.js';
1
+ import { OAuthClientProvider, OAuthDiscoveryState } from '@modelcontextprotocol/sdk/client/auth.js';
2
2
  import { FetchLike } from '@modelcontextprotocol/sdk/shared/transport.js';
3
3
  import { ToolSet, LanguageModel, Tool, SystemModelMessage, ModelMessage } from 'ai';
4
4
  import { OAuthClientMetadata, OAuthClientInformationMixed, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
5
+ import { JsonWebKey, KeyObject } from 'node:crypto';
5
6
 
6
7
  /**
7
8
  * Steering a run that is already going.
@@ -54,6 +55,201 @@ interface RunControl {
54
55
  }
55
56
  declare const createRunControl: () => RunControl;
56
57
 
58
+ interface PipelineDefinition {
59
+ version: 1;
60
+ name?: string;
61
+ entry: string;
62
+ nodes: PipelineNode[];
63
+ edges: PipelineEdge[];
64
+ limits?: {
65
+ maxNodeVisits?: number;
66
+ maxRuns?: number;
67
+ };
68
+ }
69
+ interface PipelineNode {
70
+ id: string;
71
+ name?: string;
72
+ instructions?: string;
73
+ model?: string;
74
+ skills?: string[];
75
+ tools?: string[];
76
+ mcpServers?: string[];
77
+ routes?: PipelineRoute[];
78
+ join?: 'all' | 'any';
79
+ settings?: Record<string, unknown>;
80
+ position?: {
81
+ x: number;
82
+ y: number;
83
+ };
84
+ }
85
+ interface PipelineRoute {
86
+ label: string;
87
+ description?: string;
88
+ }
89
+ type PipelineCondition = {
90
+ kind: 'always';
91
+ } | {
92
+ kind: 'contains';
93
+ text: string;
94
+ caseSensitive?: boolean;
95
+ } | {
96
+ kind: 'matches';
97
+ pattern: string;
98
+ flags?: string;
99
+ } | {
100
+ kind: 'route';
101
+ label: string;
102
+ } | {
103
+ kind: 'otherwise';
104
+ };
105
+ interface PipelineEdge {
106
+ id?: string;
107
+ from: string;
108
+ to: string;
109
+ when?: PipelineCondition;
110
+ }
111
+ declare const PIPELINE_LIMITS: {
112
+ readonly maxNodeVisits: 3;
113
+ readonly maxRuns: 25;
114
+ readonly maxNodeVisitsCeiling: 100;
115
+ readonly maxRunsCeiling: 1000;
116
+ readonly maxNodes: 200;
117
+ readonly maxEdges: 1000;
118
+ readonly maxRoutes: 20;
119
+ readonly maxPatternLength: 500;
120
+ readonly maxPatternProgram: 1000;
121
+ readonly conditionInputChars: 50000;
122
+ };
123
+ interface PipelineUsage {
124
+ inputTokens: number;
125
+ outputTokens: number;
126
+ totalTokens: number;
127
+ reasoningTokens?: number;
128
+ cachedInputTokens?: number;
129
+ cacheWriteTokens?: number;
130
+ }
131
+ interface PipelineNodeSource {
132
+ nodeId: string;
133
+ name?: string;
134
+ text: string;
135
+ }
136
+ interface PipelineNodeInput {
137
+ request: string;
138
+ from: PipelineNodeSource[];
139
+ visit: number;
140
+ }
141
+ interface PipelineNodeOutput {
142
+ text: string;
143
+ usage?: PipelineUsage;
144
+ route?: string;
145
+ }
146
+ interface PipelineNodeContext<E = never> {
147
+ signal: AbortSignal;
148
+ pipeline: PipelineDefinition;
149
+ emit: (event: E) => void;
150
+ }
151
+ type PipelineNodeRunner<E = never> = (node: PipelineNode, input: PipelineNodeInput, ctx: PipelineNodeContext<E>) => Promise<PipelineNodeOutput>;
152
+ type PipelineStop = 'maxRuns' | 'maxNodeVisits' | 'aborted';
153
+ type PipelineEvent = {
154
+ type: 'pipeline.started';
155
+ pipeline?: string;
156
+ } | {
157
+ type: 'pipeline.node.started';
158
+ nodeId: string;
159
+ visit: number;
160
+ from: string[];
161
+ } | {
162
+ type: 'pipeline.node.finished';
163
+ nodeId: string;
164
+ visit: number;
165
+ text: string;
166
+ route?: string;
167
+ usage?: PipelineUsage;
168
+ } | {
169
+ type: 'pipeline.node.failed';
170
+ nodeId: string;
171
+ visit: number;
172
+ error: string;
173
+ } | {
174
+ type: 'pipeline.node.skipped';
175
+ nodeId: string;
176
+ from: string[];
177
+ reason: 'maxRuns' | 'maxNodeVisits';
178
+ } | {
179
+ type: 'pipeline.edge';
180
+ from: string;
181
+ to: string;
182
+ edgeId: string;
183
+ visit: number;
184
+ fired: boolean;
185
+ } | {
186
+ type: 'pipeline.finished';
187
+ stoppedBy?: PipelineStop;
188
+ runs: number;
189
+ };
190
+ type PipelineTraceEntry = {
191
+ type: 'node';
192
+ nodeId: string;
193
+ visit: number;
194
+ wave: number;
195
+ from: string[];
196
+ text: string;
197
+ route?: string;
198
+ usage?: PipelineUsage;
199
+ } | {
200
+ type: 'edge';
201
+ from: string;
202
+ to: string;
203
+ edgeId: string;
204
+ visit: number;
205
+ fired: boolean;
206
+ } | {
207
+ type: 'dropped';
208
+ nodeId: string;
209
+ from: string[];
210
+ reason: 'maxRuns' | 'maxNodeVisits';
211
+ };
212
+ interface PipelineResult {
213
+ text: string;
214
+ outputs: Record<string, {
215
+ visit: number;
216
+ text: string;
217
+ route?: string;
218
+ }[]>;
219
+ trace: PipelineTraceEntry[];
220
+ usage: PipelineUsage;
221
+ stoppedBy?: PipelineStop;
222
+ runs: number;
223
+ }
224
+ interface PipelineIssue {
225
+ code: string;
226
+ message: string;
227
+ nodeId?: string;
228
+ edgeId?: string;
229
+ edgeIndex?: number;
230
+ }
231
+ interface PipelineValidation {
232
+ ok: boolean;
233
+ errors: PipelineIssue[];
234
+ warnings: PipelineIssue[];
235
+ }
236
+ declare class PipelineValidationError extends Error {
237
+ errors: PipelineIssue[];
238
+ constructor(errors: PipelineIssue[]);
239
+ }
240
+ declare class PipelineNodeError extends Error {
241
+ nodeId: string;
242
+ visit: number;
243
+ constructor(nodeId: string, visit: number, cause: unknown);
244
+ }
245
+ declare const testPipelineCondition: (when: PipelineCondition | undefined, output: {
246
+ text: string;
247
+ route?: string;
248
+ }, matcher?: (text: string) => boolean) => boolean;
249
+ declare const normalizePipeline: (definition: PipelineDefinition) => PipelineDefinition;
250
+ declare const validatePipeline: (definition: PipelineDefinition) => PipelineValidation;
251
+ declare const renderPipelineNodeInput: (input: PipelineNodeInput) => string;
252
+
57
253
  type EgressErrorCode = 'disabled' | 'bad-url' | 'bad-protocol' | 'bad-port' | 'bad-method' | 'credentials-in-url' | 'denied-host' | 'not-allowed-host' | 'denied-address' | 'dns' | 'bad-redirect' | 'too-many-redirects' | 'too-large' | 'timeout';
58
254
  declare class EgressError extends Error {
59
255
  readonly code: EgressErrorCode;
@@ -99,6 +295,38 @@ declare const checkRedirect: (from: URL, to: URL) => void;
99
295
  type SafeFetch = (input: string | URL, init?: RequestInit) => Promise<Response>;
100
296
  declare const createSafeFetch: (policy?: IEgressPolicy) => SafeFetch;
101
297
 
298
+ declare const RUN_JS_TOOL = "run_js";
299
+ interface ISandboxConfig {
300
+ timeoutMs?: number;
301
+ memoryLimitBytes?: number;
302
+ maxOutputChars?: number;
303
+ maxCodeChars?: number;
304
+ files?: boolean;
305
+ }
306
+ interface ISandboxLimits {
307
+ timeoutMs: number;
308
+ memoryLimitBytes: number;
309
+ maxOutputChars: number;
310
+ maxCodeChars: number;
311
+ }
312
+ declare const resolveSandboxLimits: (config: ISandboxConfig | undefined) => ISandboxLimits;
313
+ interface ISandboxError {
314
+ name: string;
315
+ message: string;
316
+ stack?: string;
317
+ }
318
+ interface ISandboxResult {
319
+ ok: boolean;
320
+ stdout: string;
321
+ result?: unknown;
322
+ error?: ISandboxError;
323
+ truncated: boolean;
324
+ durationMs: number;
325
+ }
326
+ declare class SandboxUnavailableError extends Error {
327
+ constructor(message: string);
328
+ }
329
+
102
330
  type ProviderType = 'openai' | 'anthropic' | 'openai-compatible' | 'google' | 'xai' | 'azure' | 'amazon-bedrock' | 'google-vertex' | 'deepseek' | 'gateway' | 'cloudflare';
103
331
  type LogLevel = 'none' | 'error' | 'warn' | 'info' | 'debug';
104
332
  type ToolSelectionStrategy = 'all' | 'plan-narrowed' | 'search' | 'auto';
@@ -241,6 +469,7 @@ interface IAgentConfig {
241
469
  mcpServers: Record<string, IMcpServerConfig>;
242
470
  egress?: boolean | IEgressPolicy;
243
471
  learning?: boolean | ILearningConfig;
472
+ sandbox?: boolean | ISandboxConfig;
244
473
  tools?: ToolSet;
245
474
  availableTools?: string[];
246
475
  excludedTools?: string[];
@@ -468,9 +697,11 @@ type AgentEventBody = {
468
697
  type: 'error';
469
698
  error: Error;
470
699
  phase: 'plan' | 'execute' | 'replan' | 'synthesize' | 'init';
471
- };
700
+ } | PipelineEvent;
472
701
  type AgentEvent = AgentEventBody & {
473
702
  runId?: string;
703
+ nodeId?: string;
704
+ visit?: number;
474
705
  };
475
706
  type EventHandler = (event: AgentEvent) => void;
476
707
  interface IStepStartInfo {
@@ -629,9 +860,11 @@ declare const addUsage: (a: IUsage, b: IUsage) => Required<IUsage>;
629
860
  * OAuth 2.1 for remote MCP servers, from Node.
630
861
  *
631
862
  * The MCP SDK owns the protocol - discovery (RFC 9728), dynamic client
632
- * registration (RFC 7591), PKCE, the code exchange and the refresh on 401.
633
- * What it does not own, and what this module supplies, is WHERE the resulting
634
- * tokens live between processes and HOW an operator is asked to authorize.
863
+ * registration (RFC 7591) or a client ID metadata document (CIMD), PKCE, the
864
+ * code exchange and the refresh on 401. What it does not own, and what this
865
+ * module supplies, is WHERE the resulting tokens live between processes, HOW an
866
+ * operator is asked to authorize, and the check of the `iss` parameter on the
867
+ * way back (RFC 9207).
635
868
  *
636
869
  * Pass the result to `mcpServers[name].authProvider`.
637
870
  */
@@ -689,8 +922,19 @@ interface INodeOAuthProviderOptions {
689
922
  clientName?: string;
690
923
  /** Fallback scope when the server advertises none. */
691
924
  scope?: string;
692
- /** Merged over the defaults (e.g. `software_id`, `contacts`). */
693
- clientMetadata?: Partial<OAuthClientMetadata>;
925
+ /** Merged over the defaults (e.g. `software_id`, `contacts`, `application_type`). */
926
+ clientMetadata?: Partial<OAuthClientMetadata> & {
927
+ application_type?: string;
928
+ };
929
+ /**
930
+ * URL of a client ID metadata document (CIMD) you host. When the
931
+ * authorization server advertises `client_id_metadata_document_supported`,
932
+ * this URL is used as the `client_id` and no dynamic registration is made;
933
+ * otherwise registration runs as before. A registration already in the store
934
+ * wins over both. Must be https with a non-root path, and the document served
935
+ * there must list the same `redirect_uris` as `redirectUrl`.
936
+ */
937
+ clientMetadataUrl?: string;
694
938
  /** Defaults to a 0600 JSON file under ~/.agent. */
695
939
  store?: IOAuthStore;
696
940
  /** Treat the access token as expired this many seconds early. Default 30. */
@@ -702,6 +946,25 @@ interface INodeOAuthProviderOptions {
702
946
  */
703
947
  onAuthorizationUrl?: (url: URL) => void | Promise<void>;
704
948
  }
949
+ /**
950
+ * RFC 9207: is the `iss` parameter of an authorization response the
951
+ * authorization server this flow was started with? Throws when it is not; the
952
+ * caller must not exchange the code then (a mix-up attack hands the code of an
953
+ * honest server to another one's token endpoint).
954
+ *
955
+ * - expected issuer: the `issuer` of the stored authorization server metadata,
956
+ * else the authorization server URL discovery used;
957
+ * - `iss` present: it must equal the expected issuer, compared as plain strings
958
+ * (RFC 9207 section 2.4: no normalization);
959
+ * - `iss` absent: refused when the metadata says
960
+ * `authorization_response_iss_parameter_supported: true`;
961
+ * - no stored discovery state (a store written by an older version): `iss` is
962
+ * compared with the issuer stamped on the stored client information, and with
963
+ * nothing to compare against the response is accepted.
964
+ *
965
+ * The browser package carries the same function; change both.
966
+ */
967
+ declare const checkAuthorizationResponseIssuer: (iss: string | undefined, discoveryState: OAuthDiscoveryState | undefined, clientIssuer?: string) => void;
705
968
  /**
706
969
  * A persistent `OAuthClientProvider`. Also exposes `isAccessTokenExpired`,
707
970
  * which `connectMcpServers` uses to refresh a known-dead token before the
@@ -715,11 +978,14 @@ declare class NodeOAuthProvider implements OAuthClientProvider {
715
978
  private readonly ns;
716
979
  private readonly _redirectUrl;
717
980
  private readonly _clientMetadata;
981
+ private readonly _clientMetadataUrl?;
718
982
  private readonly skewMs;
719
983
  private readonly onAuthorizationUrl?;
720
984
  constructor(opts: INodeOAuthProviderOptions);
721
985
  get redirectUrl(): string;
722
986
  get clientMetadata(): OAuthClientMetadata;
987
+ /** The client ID metadata document URL (CIMD), when one was configured. */
988
+ get clientMetadataUrl(): string | undefined;
723
989
  private key;
724
990
  private readJSON;
725
991
  state(): Promise<string>;
@@ -731,17 +997,25 @@ declare class NodeOAuthProvider implements OAuthClientProvider {
731
997
  saveTokens(tokens: OAuthTokens): Promise<void>;
732
998
  saveCodeVerifier(verifier: string): Promise<void>;
733
999
  codeVerifier(): Promise<string>;
1000
+ /**
1001
+ * What discovery found (the authorization server, its metadata, the resource
1002
+ * metadata). The SDK reuses it instead of discovering again, and
1003
+ * {@link finishMcpOAuth} reads the expected issuer from it.
1004
+ */
1005
+ saveDiscoveryState(state: OAuthDiscoveryState): Promise<void>;
1006
+ discoveryState(): Promise<OAuthDiscoveryState | undefined>;
734
1007
  redirectToAuthorization(url: URL): Promise<void>;
735
1008
  /**
736
1009
  * Called by the SDK when the server rejects what we hold: `'tokens'` on an
737
- * `invalid_grant` (dead refresh token), `'client'` / `'all'` on an
738
- * `invalid_client` (the AS forgot our dynamic registration).
1010
+ * `invalid_grant` (dead refresh token), `'all'` on an `invalid_client` (the
1011
+ * AS forgot our dynamic registration). `'client'`, `'verifier'` and
1012
+ * `'discovery'` are in its type and handled the same way: one key each.
739
1013
  */
740
- invalidateCredentials(scope: 'all' | 'client' | 'tokens' | 'verifier'): Promise<void>;
1014
+ invalidateCredentials(scope: 'all' | 'client' | 'tokens' | 'verifier' | 'discovery'): Promise<void>;
741
1015
  /** True when there is no access token, or it expires within the skew window. */
742
1016
  isAccessTokenExpired(): Promise<boolean>;
743
1017
  isAuthorized(): Promise<boolean>;
744
- /** Forget tokens, registration, verifier and state for this server. */
1018
+ /** Forget tokens, registration, verifier, state and discovery for this server. */
745
1019
  reset(): Promise<void>;
746
1020
  }
747
1021
  /** Convenience factory mirroring the rest of the package's `createX` style. */
@@ -759,15 +1033,315 @@ interface IOAuthRequestOptions {
759
1033
  */
760
1034
  declare const beginMcpOAuth: (provider: NodeOAuthProvider, opts?: IOAuthRequestOptions) => Promise<"AUTHORIZED" | "REDIRECT">;
761
1035
  /**
762
- * Complete the flow with the `code` (and `state`) the authorization server sent
763
- * back. Verifies `state`, exchanges the code with the stored PKCE verifier and
764
- * persists the tokens. Throws unless the exchange fully succeeded.
1036
+ * Complete the flow with the `code` (and `state`, and `iss` when the redirect
1037
+ * carried one) the authorization server sent back. Verifies `state`, then the
1038
+ * issuer (RFC 9207, {@link checkAuthorizationResponseIssuer}), exchanges the
1039
+ * code with the stored PKCE verifier and persists the tokens. Throws unless the
1040
+ * exchange fully succeeded.
765
1041
  */
766
1042
  declare const finishMcpOAuth: (provider: NodeOAuthProvider, callback: {
767
1043
  code: string;
768
1044
  state?: string;
1045
+ iss?: string;
769
1046
  }, opts?: IOAuthRequestOptions) => Promise<void>;
770
1047
 
1048
+ /**
1049
+ * Enterprise-Managed Authorization for remote MCP servers (the MCP extension
1050
+ * `io.modelcontextprotocol/enterprise-managed-authorization`, also called Cross
1051
+ * App Access): the organization's identity provider decides which MCP servers
1052
+ * a user's client may reach, and no one is sent to a consent page.
1053
+ *
1054
+ * Two hops, both plain HTTP POSTs:
1055
+ *
1056
+ * 1. at the IdP - an RFC 8693 token exchange turns the user's ID token into an
1057
+ * Identity Assertion JWT Authorization Grant (ID-JAG) addressed to the MCP
1058
+ * server's authorization server;
1059
+ * 2. at the MCP authorization server - an RFC 7523 `jwt-bearer` grant turns the
1060
+ * ID-JAG into an ordinary access token.
1061
+ *
1062
+ * The MCP SDK owns discovery (RFC 9728 / RFC 8414), the second hop and the
1063
+ * retry on a 401; this module supplies the first hop and the checks around it.
1064
+ * Only the resulting access token is stored. The ID token, the ID-JAG and the
1065
+ * client assertions pass through memory and are never written, logged or put
1066
+ * in an error.
1067
+ *
1068
+ * The client authenticates on each hop with a secret or with a signed
1069
+ * assertion (`private_key_jwt`, RFC 7523 section 2.2). By default the audience
1070
+ * of that assertion is the issuer identifier of the server it is for and
1071
+ * nothing else, as draft-ietf-oauth-rfc7523bis requires: an assertion made for
1072
+ * the IdP is of no use at the authorization server, and the other way round.
1073
+ * For a server built to RFC 7523 as published, `assertionAudience:
1074
+ * 'token-endpoint'` and `assertionType: 'JWT'` produce the older form - see
1075
+ * `EnterpriseAssertionAudience` for what that gives up.
1076
+ *
1077
+ * Follows draft-ietf-oauth-identity-assertion-authz-grant and the extension's
1078
+ * 2026-07-28 revision. The browser package carries the same provider; change both.
1079
+ *
1080
+ * Pass the result to `mcpServers[name].authProvider`.
1081
+ */
1082
+ /** The extension identifier a client declares in its capabilities. */
1083
+ declare const ENTERPRISE_MANAGED_AUTHORIZATION_EXTENSION = "io.modelcontextprotocol/enterprise-managed-authorization";
1084
+ /** Which part of the flow refused. */
1085
+ type EnterpriseOAuthHop = 'discovery' | 'idp' | 'authorization-server';
1086
+ /**
1087
+ * A failure of the enterprise flow, with the hop that refused: `'discovery'`
1088
+ * (what the MCP server published cannot be trusted or used), `'idp'` (the token
1089
+ * exchange) or `'authorization-server'` (the `jwt-bearer` grant). The message
1090
+ * is short and safe to show: never a request body, a token, an assertion, a
1091
+ * secret or a key. What the authorization server said in full goes to the log
1092
+ * (`onLog`), redacted the same way.
1093
+ */
1094
+ declare class EnterpriseOAuthError extends Error {
1095
+ readonly hop: EnterpriseOAuthHop;
1096
+ /** The OAuth `error` code the server answered with, when it sent one. */
1097
+ readonly code?: string;
1098
+ constructor(hop: EnterpriseOAuthHop, message: string, code?: string);
1099
+ }
1100
+ /** Signature algorithms for a `private_key_jwt` client assertion. */
1101
+ type EnterpriseAssertionAlgorithm = 'ES256' | 'ES384' | 'ES512' | 'RS256' | 'RS384' | 'RS512' | 'PS256' | 'PS384' | 'PS512';
1102
+ /**
1103
+ * The private key that signs a client assertion: a PEM string (PKCS#8 or the
1104
+ * older SEC1 / PKCS#1), a JWK object, or a `KeyObject`. It must be a key for
1105
+ * the chosen `algorithm` (an EC P-256 key for ES256, an RSA key for RS256...).
1106
+ */
1107
+ type EnterprisePrivateKey = string | JsonWebKey | KeyObject;
1108
+ /**
1109
+ * What a `private_key_jwt` client assertion names as its audience (`aud`).
1110
+ *
1111
+ * - `'issuer'` (the default): the issuer identifier of the server the
1112
+ * assertion is for, as draft-ietf-oauth-rfc7523bis requires.
1113
+ * - `'token-endpoint'`: the URL of that server's token endpoint, which is what
1114
+ * RFC 7523 as published describes and what many deployed identity providers
1115
+ * check for.
1116
+ *
1117
+ * The default is the issuer because an assertion addressed to a token endpoint
1118
+ * URL is exactly what the bis draft forbids. The token endpoint is one field of
1119
+ * a metadata document; a client that reads its audience from metadata can be
1120
+ * handed a document that names an honest server's endpoint (audience
1121
+ * injection), and then signs an assertion the party that served the document
1122
+ * can replay at that honest server. The issuer identifier is the one value a
1123
+ * client checks before it trusts the rest of the document. This provider never
1124
+ * takes either value from the MCP server alone - the IdP's endpoint is
1125
+ * configuration, and the authorization server's is used only after its
1126
+ * metadata matched `expectedIssuer` - so `'token-endpoint'` here costs the
1127
+ * defence in depth, not the check itself. Use it only for a server that
1128
+ * refuses the issuer form.
1129
+ */
1130
+ type EnterpriseAssertionAudience = 'issuer' | 'token-endpoint';
1131
+ /**
1132
+ * The `typ` header of a client assertion: `client-authentication+jwt` (the
1133
+ * default, from draft-ietf-oauth-rfc7523bis: a token typed this way cannot be
1134
+ * mistaken for another kind of JWT) or `JWT`, for a server that refuses a
1135
+ * `typ` it does not know.
1136
+ */
1137
+ type EnterpriseAssertionType = 'client-authentication+jwt' | 'JWT';
1138
+ /** Where the provider reports what it will not put in an error. */
1139
+ type EnterpriseOAuthLog = (level: 'info' | 'warn' | 'error', message: string) => void;
1140
+ interface IEnterpriseIdpOptions {
1141
+ /**
1142
+ * The IdP's token endpoint, where the token exchange is posted. Configured,
1143
+ * not discovered: it is where the user's ID token and the client's IdP
1144
+ * credentials go, so nothing fetched at run time may choose it.
1145
+ */
1146
+ tokenEndpoint: string;
1147
+ /**
1148
+ * The IdP's issuer identifier. REQUIRED with `private_key_jwt`, where it is
1149
+ * the audience of the client assertion - unless `assertionAudience` is
1150
+ * `'token-endpoint'`, which addresses the assertion to `tokenEndpoint`.
1151
+ */
1152
+ issuer?: string;
1153
+ /** This client's `client_id` at the IdP (the audience of the ID token). */
1154
+ clientId: string;
1155
+ /** This client's secret at the IdP. Omit for a client the IdP treats as public. */
1156
+ clientSecret?: string;
1157
+ /**
1158
+ * How the client authenticates at the IdP. With a secret: in an
1159
+ * `Authorization: Basic` header (the default, which every OAuth server must
1160
+ * accept) or in the form body. `'private_key_jwt'`: a signed assertion, which
1161
+ * needs `privateKey`, `algorithm` and `issuer` (or `assertionAudience:
1162
+ * 'token-endpoint'`).
1163
+ */
1164
+ clientAuthMethod?: 'client_secret_basic' | 'client_secret_post' | 'private_key_jwt';
1165
+ /** The key for `private_key_jwt`. Never stored, logged or put in an error. */
1166
+ privateKey?: EnterprisePrivateKey;
1167
+ /** `kid` header of the assertion: the key's id in the JWKS the IdP holds. */
1168
+ keyId?: string;
1169
+ /** Signature algorithm of the assertion. */
1170
+ algorithm?: EnterpriseAssertionAlgorithm;
1171
+ /**
1172
+ * The audience of the assertion: `'issuer'` (the default: `issuer`) or
1173
+ * `'token-endpoint'` (`tokenEndpoint`, for an IdP built to RFC 7523 - the
1174
+ * weaker form, see `EnterpriseAssertionAudience`). Only with `private_key_jwt`.
1175
+ */
1176
+ assertionAudience?: EnterpriseAssertionAudience;
1177
+ /**
1178
+ * The `typ` header of the assertion: `'client-authentication+jwt'` (the
1179
+ * default) or `'JWT'` for an IdP that refuses the new one. Only with
1180
+ * `private_key_jwt`.
1181
+ */
1182
+ assertionType?: EnterpriseAssertionType;
1183
+ }
1184
+ interface IEnterpriseOAuthProviderOptions {
1185
+ /** The MCP endpoint being authorized. */
1186
+ serverUrl: string;
1187
+ /**
1188
+ * This client's `client_id` at the MCP server's authorization server: a
1189
+ * pre-registered identifier, or the https URL of a client ID metadata
1190
+ * document (CIMD) you host. A URL must be https with a path of its own, and
1191
+ * cannot be used with `clientSecret`: a document anyone can read establishes
1192
+ * no shared secret, so such a client is public or uses `private_key_jwt`
1193
+ * with the keys the document lists (`jwks` / `jwks_uri`).
1194
+ */
1195
+ clientId: string;
1196
+ /**
1197
+ * Its secret there. The grant is meant for confidential clients. A secret
1198
+ * needs `expectedIssuer`: without it the MCP server's metadata would choose
1199
+ * who receives the secret, and the constructor throws.
1200
+ */
1201
+ clientSecret?: string;
1202
+ /**
1203
+ * How the client authenticates at the authorization server. Left out, the
1204
+ * SDK decides: a secret is sent the way the server's metadata allows (Basic
1205
+ * first), no secret means `client_id` alone. `'private_key_jwt'` signs an
1206
+ * assertion and needs `privateKey`, `algorithm` and `expectedIssuer`.
1207
+ */
1208
+ clientAuthMethod?: 'client_secret_basic' | 'client_secret_post' | 'private_key_jwt' | 'none';
1209
+ /** The key for `private_key_jwt`. Never stored, logged or put in an error. */
1210
+ privateKey?: EnterprisePrivateKey;
1211
+ /** `kid` header of the assertion: the key's id in the JWKS the server holds. */
1212
+ keyId?: string;
1213
+ /** Signature algorithm of the assertion. */
1214
+ algorithm?: EnterpriseAssertionAlgorithm;
1215
+ /**
1216
+ * The audience of the assertion for the authorization server: `'issuer'`
1217
+ * (the default: the issuer discovery found, once it matched
1218
+ * `expectedIssuer`) or `'token-endpoint'` (the token endpoint from that same
1219
+ * metadata, for a server built to RFC 7523 - the weaker form, see
1220
+ * `EnterpriseAssertionAudience`). The endpoint is read only from metadata
1221
+ * whose issuer is `expectedIssuer`, and must be https or loopback. Only with
1222
+ * `private_key_jwt`.
1223
+ */
1224
+ assertionAudience?: EnterpriseAssertionAudience;
1225
+ /**
1226
+ * The `typ` header of the assertion: `'client-authentication+jwt'` (the
1227
+ * default) or `'JWT'` for a server that refuses the new one. Only with
1228
+ * `private_key_jwt`.
1229
+ */
1230
+ assertionType?: EnterpriseAssertionType;
1231
+ /**
1232
+ * The issuer of the MCP server's authorization server. Anything else the MCP
1233
+ * server points at is refused before a credential leaves the process.
1234
+ * REQUIRED with `clientSecret` and with `private_key_jwt`: neither the
1235
+ * receiver of a secret nor the audience of a signed assertion may come from
1236
+ * the MCP server's metadata alone. A client with no credential at the
1237
+ * authorization server may omit it: then the only thing sent there is the
1238
+ * ID-JAG, which the IdP addressed to that one server and which is of no use
1239
+ * to any other.
1240
+ */
1241
+ expectedIssuer?: string;
1242
+ /** The enterprise identity provider. */
1243
+ idp: IEnterpriseIdpOptions;
1244
+ /**
1245
+ * The user's OpenID Connect ID token from the IdP. How it was obtained (the
1246
+ * single sign-on of your application) is yours; it is called each time a new
1247
+ * ID-JAG is needed, so return a current one. The value is never stored.
1248
+ */
1249
+ getIdToken: () => string | Promise<string>;
1250
+ /** Scopes to ask the IdP for (space-separated). */
1251
+ scope?: string;
1252
+ /** Defaults to a 0600 JSON file under ~/.agent. Holds the access token only. */
1253
+ store?: IOAuthStore;
1254
+ /** Treat the access token as expired this many seconds early. Default 30. */
1255
+ expirySkewSeconds?: number;
1256
+ /** Custom fetch for the request to the IdP. */
1257
+ fetch?: FetchLike;
1258
+ /**
1259
+ * Receives the detail a refusal's error leaves out (what the authorization
1260
+ * server answered), redacted. `connectMcpServers` passes its own log; this is
1261
+ * for a provider used without it.
1262
+ */
1263
+ onLog?: EnterpriseOAuthLog;
1264
+ }
1265
+ /**
1266
+ * A non-interactive `OAuthClientProvider`: no redirect, no browser, no human.
1267
+ * On first use, and whenever the access token is missing, expired or rejected,
1268
+ * the SDK asks it for a token request and it answers with a fresh ID-JAG.
1269
+ */
1270
+ declare class NodeEnterpriseOAuthProvider implements OAuthClientProvider {
1271
+ #private;
1272
+ readonly serverUrl: string;
1273
+ /** The MCP extension this provider implements; the connector declares it. */
1274
+ readonly extension = "io.modelcontextprotocol/enterprise-managed-authorization";
1275
+ /**
1276
+ * Present only with an explicit `clientAuthMethod`: the SDK then leaves the
1277
+ * client authentication of the grant to it (a `private_key_jwt` assertion is
1278
+ * signed here, for the issuer discovery found and `expectedIssuer` confirmed).
1279
+ */
1280
+ addClientAuthentication?: OAuthClientProvider['addClientAuthentication'];
1281
+ constructor(opts: IEnterpriseOAuthProviderOptions);
1282
+ /** Never set: this is what tells the SDK the flow has no human step. */
1283
+ get redirectUrl(): undefined;
1284
+ get clientMetadata(): OAuthClientMetadata;
1285
+ /**
1286
+ * The pre-registered client, from configuration and never from the store.
1287
+ * With `expectedIssuer` it carries that stamp, and the SDK then refuses to
1288
+ * present it to any other authorization server.
1289
+ */
1290
+ clientInformation(): OAuthClientInformationMixed;
1291
+ tokens(): Promise<OAuthTokens | undefined>;
1292
+ saveTokens(tokens: OAuthTokens): Promise<void>;
1293
+ saveDiscoveryState(state: OAuthDiscoveryState): Promise<void>;
1294
+ discoveryState(): Promise<OAuthDiscoveryState | undefined>;
1295
+ /**
1296
+ * Called by the SDK inside `auth()`, after discovery and before the token
1297
+ * request to the MCP authorization server: get an ID token from the host,
1298
+ * exchange it at the IdP for an ID-JAG addressed to exactly the authorization
1299
+ * server and resource discovery found for this server, and hand the SDK the
1300
+ * `jwt-bearer` request. Throws before anything reaches the authorization
1301
+ * server when discovery cannot be trusted or the IdP's answer is not an ID-JAG.
1302
+ */
1303
+ prepareTokenRequest(scope?: string): Promise<URLSearchParams>;
1304
+ /** The codes of the interactive flow: this provider has none. */
1305
+ redirectToAuthorization(): never;
1306
+ saveCodeVerifier(): never;
1307
+ codeVerifier(): never;
1308
+ /**
1309
+ * Called by the SDK when the authorization server rejects what it was sent.
1310
+ * The client is configuration, so there is nothing of it to forget; tokens
1311
+ * and discovery are dropped as asked.
1312
+ */
1313
+ invalidateCredentials(scope: 'all' | 'client' | 'tokens' | 'verifier' | 'discovery'): Promise<void>;
1314
+ /** True when there is no access token, or it expires within the skew window. */
1315
+ isAccessTokenExpired(): Promise<boolean>;
1316
+ isAuthorized(): Promise<boolean>;
1317
+ /**
1318
+ * The fetch to give the transport that carries this provider (the connector
1319
+ * does). It changes one thing: when the request that carries the ID-JAG is
1320
+ * refused, the caller gets an `EnterpriseOAuthError` (`hop:
1321
+ * 'authorization-server'`) with a short message - the OAuth error code and
1322
+ * the status - and what the server said in full goes to `log`, redacted.
1323
+ * That holds whenever the SDK asks for a token, at connect or in the middle
1324
+ * of a session, so an application never has the server's raw words to show.
1325
+ * A refusal is final: every grant is already a fresh one, so the SDK's
1326
+ * "drop the token and try again" would only repeat the IdP exchange.
1327
+ */
1328
+ transportFetch(base?: FetchLike, log?: EnterpriseOAuthLog): FetchLike;
1329
+ /**
1330
+ * Run the whole flow now (discovery, IdP exchange, grant) and store the
1331
+ * access token. `connectMcpServers` calls it before connecting when there is
1332
+ * no usable token; call it yourself to fail early. A refusal is an
1333
+ * `EnterpriseOAuthError` whose `hop` says who refused.
1334
+ */
1335
+ authorize(opts?: {
1336
+ fetch?: FetchLike;
1337
+ onLog?: EnterpriseOAuthLog;
1338
+ }): Promise<void>;
1339
+ /** Forget the access token and what discovery found for this server. */
1340
+ reset(): Promise<void>;
1341
+ }
1342
+ /** Convenience factory mirroring the rest of the package's `createX` style. */
1343
+ declare const createEnterpriseOAuthProvider: (opts: IEnterpriseOAuthProviderOptions) => NodeEnterpriseOAuthProvider;
1344
+
771
1345
  type ProviderOptionsMap = Record<string, Record<string, unknown>>;
772
1346
  interface IResolvedThinking {
773
1347
  reasoning?: ThinkingLevel;
@@ -979,6 +1553,39 @@ interface IWebFetchOptions {
979
1553
  declare const createWebFetchTool: (options?: IWebFetchOptions) => Tool;
980
1554
  declare const createEgressTools: (egress: boolean | IEgressPolicy | undefined) => ToolSet | undefined;
981
1555
 
1556
+ interface ISandboxDeps {
1557
+ workerUrl?: URL;
1558
+ peerInstalled?: () => boolean;
1559
+ }
1560
+ declare const createSandboxTool: (config?: ISandboxConfig, deps?: ISandboxDeps) => Tool;
1561
+ declare const createSandboxTools: (sandbox: boolean | ISandboxConfig | undefined, deps?: ISandboxDeps) => ToolSet | undefined;
1562
+
1563
+ interface PipelineOptions {
1564
+ runNode?: PipelineNodeRunner<AgentEvent>;
1565
+ resolveNode?: (node: PipelineNode) => IAgentConfig | Promise<IAgentConfig>;
1566
+ }
1567
+ interface PipelineRunOptions {
1568
+ input: string;
1569
+ signal?: AbortSignal;
1570
+ onEvent?: EventHandler;
1571
+ }
1572
+ interface Pipeline {
1573
+ definition: PipelineDefinition;
1574
+ run: (options: PipelineRunOptions) => Promise<PipelineResult>;
1575
+ close: () => Promise<void>;
1576
+ }
1577
+ declare const createPipeline: (definition: PipelineDefinition, options: PipelineOptions) => Pipeline;
1578
+ type PipelineModelConfig = Pick<IAgentConfig, 'model'> & Partial<Pick<IAgentConfig, 'providerType' | 'baseURL' | 'apiKey' | 'providerOptions' | 'planner' | 'synthesizer'>>;
1579
+ interface NodeResolverOptions {
1580
+ base: IAgentConfig;
1581
+ models?: Record<string, PipelineModelConfig>;
1582
+ skills?: Record<string, ISkill>;
1583
+ tools?: Record<string, ToolSet>;
1584
+ mcpServers?: Record<string, IMcpServerConfig>;
1585
+ configure?: (config: IAgentConfig, node: PipelineNode) => IAgentConfig | Promise<IAgentConfig>;
1586
+ }
1587
+ declare const nodeResolver: (options: NodeResolverOptions) => NonNullable<PipelineOptions["resolveNode"]>;
1588
+
982
1589
  type SubagentIsolation = 'worker' | 'in-process';
983
1590
  interface ISubagentProfile {
984
1591
  description: string;
@@ -1005,5 +1612,5 @@ interface ISubagentToolOptions {
1005
1612
  */
1006
1613
  declare const createSubagentTool: (opts: ISubagentToolOptions) => Tool;
1007
1614
 
1008
- export { DEFAULT_COMPACTION_THRESHOLD_RATIO, DirSkillStore, EgressError, FORGET_SKILL_TOOL, FileOAuthStore, MemoryOAuthStore, MemorySkillStore, NodeOAuthProvider, SAVE_SKILL_TOOL, SUMMARY_PREFIX, ToolBudgetError, ToolDeniedError, WEB_FETCH_TOOL, addUsage, beginMcpOAuth, buildInstructions, checkEgressUrl, checkLimits, checkRedirect, classifyAddress, compactHistory, createAgent, createEgressTools, createLearning, createNodeOAuthProvider, createRunControl, createSafeFetch, createSubagentTool, createToolResultClearer, createWebFetchTool, decideToolPermission, defineSkill, estimateTokens, findSecret, finishMcpOAuth, getCurrentRunId, getCurrentRunSandbox, hostMatches, htmlToText, isReadOnlyTool, loadSkillsFromDir, markReadOnly, matchToolRule, mergeProviderOptions, normalizeSkillName, normalizeUsage, parseSkillMarkdown, redactHeaders, resolveCompaction, resolveEgressPolicy, resolveLimits, resolvePromptCaching, resolveThinking, searchTools, truncateToolModelOutput, withRollingBreakpoint, withToolOutputLimit };
1009
- export type { AgentEvent, AgentStage, BudgetKind, EgressErrorCode, EventHandler, IAgent, IAgentConfig, IAgentRunOptions, IAgentRunResult, IAgentStageOverride, IClearedInfo, ICloseOptions, ICompactHistoryOptions, ICompactHistoryResult, ICompactOptions, ICompactResult, ICompactionConfig, IConversationTurn, IEgressPolicy, ILearning, ILearningConfig, ILimitBreach, IMcpHttpServerConfig, IMcpServerConfig, IMcpStdioServerConfig, INodeOAuthProviderOptions, IOAuthRequestOptions, IOAuthStore, IPersistence, IPlan, IPlanStep, IResolvedAddress, IResolvedThinking, IRunSnapshot, ISaveSkillInput, ISearchToolsOptions, ISkill, ISkillOrigin, ISkillStore, IStepResult, IStepStartInfo, ISubagentProfile, ISubagentToolOptions, IThinkingConfig, ITokenLimits, IToolApprovalConfig, IToolApprovalRequest, IToolCatalogEntry, IToolDecision, IToolDecisionInput, IToolResultClearing, IUsage, LogLevel, PromptCachingSetting, ProviderType, ReplanCause, ReplanTrigger, RunControl, SafeFetch, SubagentInfo, SubagentIsolation, ThinkingLevel, ThinkingSetting, TokenLimitKind, ToolApprovalDecision, ToolApprovalMode, ToolPermission, ToolSelectionStrategy, UsagePhase };
1615
+ export { DEFAULT_COMPACTION_THRESHOLD_RATIO, DirSkillStore, ENTERPRISE_MANAGED_AUTHORIZATION_EXTENSION, EgressError, EnterpriseOAuthError, FORGET_SKILL_TOOL, FileOAuthStore, MemoryOAuthStore, MemorySkillStore, NodeEnterpriseOAuthProvider, NodeOAuthProvider, PIPELINE_LIMITS, PipelineNodeError, PipelineValidationError, RUN_JS_TOOL, SAVE_SKILL_TOOL, SUMMARY_PREFIX, SandboxUnavailableError, ToolBudgetError, ToolDeniedError, WEB_FETCH_TOOL, addUsage, beginMcpOAuth, buildInstructions, checkAuthorizationResponseIssuer, checkEgressUrl, checkLimits, checkRedirect, classifyAddress, compactHistory, createAgent, createEgressTools, createEnterpriseOAuthProvider, createLearning, createNodeOAuthProvider, createPipeline, createRunControl, createSafeFetch, createSandboxTool, createSandboxTools, createSubagentTool, createToolResultClearer, createWebFetchTool, decideToolPermission, defineSkill, estimateTokens, findSecret, finishMcpOAuth, getCurrentRunId, getCurrentRunSandbox, hostMatches, htmlToText, isReadOnlyTool, loadSkillsFromDir, markReadOnly, matchToolRule, mergeProviderOptions, nodeResolver, normalizePipeline, normalizeSkillName, normalizeUsage, parseSkillMarkdown, redactHeaders, renderPipelineNodeInput, resolveCompaction, resolveEgressPolicy, resolveLimits, resolvePromptCaching, resolveSandboxLimits, resolveThinking, searchTools, testPipelineCondition, truncateToolModelOutput, validatePipeline, withRollingBreakpoint, withToolOutputLimit };
1616
+ export type { AgentEvent, AgentStage, BudgetKind, EgressErrorCode, EnterpriseAssertionAlgorithm, EnterpriseAssertionAudience, EnterpriseAssertionType, EnterpriseOAuthHop, EnterpriseOAuthLog, EnterprisePrivateKey, EventHandler, IAgent, IAgentConfig, IAgentRunOptions, IAgentRunResult, IAgentStageOverride, IClearedInfo, ICloseOptions, ICompactHistoryOptions, ICompactHistoryResult, ICompactOptions, ICompactResult, ICompactionConfig, IConversationTurn, IEgressPolicy, IEnterpriseIdpOptions, IEnterpriseOAuthProviderOptions, ILearning, ILearningConfig, ILimitBreach, IMcpHttpServerConfig, IMcpServerConfig, IMcpStdioServerConfig, INodeOAuthProviderOptions, IOAuthRequestOptions, IOAuthStore, IPersistence, IPlan, IPlanStep, IResolvedAddress, IResolvedThinking, IRunSnapshot, ISandboxConfig, ISandboxError, ISandboxLimits, ISandboxResult, ISaveSkillInput, ISearchToolsOptions, ISkill, ISkillOrigin, ISkillStore, IStepResult, IStepStartInfo, ISubagentProfile, ISubagentToolOptions, IThinkingConfig, ITokenLimits, IToolApprovalConfig, IToolApprovalRequest, IToolCatalogEntry, IToolDecision, IToolDecisionInput, IToolResultClearing, IUsage, LogLevel, NodeResolverOptions, Pipeline, PipelineCondition, PipelineDefinition, PipelineEdge, PipelineEvent, PipelineIssue, PipelineModelConfig, PipelineNode, PipelineNodeContext, PipelineNodeInput, PipelineNodeOutput, PipelineNodeRunner, PipelineNodeSource, PipelineOptions, PipelineResult, PipelineRoute, PipelineRunOptions, PipelineStop, PipelineTraceEntry, PipelineUsage, PipelineValidation, PromptCachingSetting, ProviderType, ReplanCause, ReplanTrigger, RunControl, SafeFetch, SubagentInfo, SubagentIsolation, ThinkingLevel, ThinkingSetting, TokenLimitKind, ToolApprovalDecision, ToolApprovalMode, ToolPermission, ToolSelectionStrategy, UsagePhase };