@dudko.dev/agent 0.0.48 → 0.0.49
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 +325 -34
- package/dist/cli.js +145 -116
- package/dist/index.cjs +105 -98
- package/dist/index.d.cts +549 -54
- package/dist/index.d.ts +549 -54
- package/dist/index.js +105 -98
- package/dist/sandbox-worker.js +6 -6
- package/dist/subagent-worker.js +90 -83
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -370,9 +370,10 @@ declare const createSafeFetch: (policy?: IEgressPolicy) => SafeFetch;
|
|
|
370
370
|
|
|
371
371
|
/**
|
|
372
372
|
* What the `web_search` tools of the two agent packages share: the result shape and its caps, how
|
|
373
|
-
* a search engine's answer is cleaned before a model reads it, and the built-in
|
|
374
|
-
*
|
|
375
|
-
* is made by each package's own safe
|
|
373
|
+
* a search engine's answer is cleaned before a model reads it, and the one built-in provider
|
|
374
|
+
* (Google Search through Gemini grounding) as a pure request builder and response parser (one
|
|
375
|
+
* HTTP call). Pure, no imports, no clock: the request itself is made by each package's own safe
|
|
376
|
+
* fetch.
|
|
376
377
|
*
|
|
377
378
|
* This file is a COPY, byte for byte, in `@dudko.dev/agent` (`src/web-search-shared.ts`) and
|
|
378
379
|
* `@dudko.dev/agent-web` (`src/tools/web-search-shared.ts`): change both. The Node package's
|
|
@@ -416,11 +417,24 @@ interface ISearchOptions {
|
|
|
416
417
|
* returns is treated like a built-in adapter's answer - cleaned, capped and filtered.
|
|
417
418
|
*/
|
|
418
419
|
type SearchEngine = (query: string, options: ISearchOptions) => Promise<ISearchResult[]>;
|
|
419
|
-
/**
|
|
420
|
-
|
|
420
|
+
/**
|
|
421
|
+
* The built-in provider. One: Google Search through the Gemini API's grounding (`google_search`),
|
|
422
|
+
* which needs a Gemini (Google AI Studio) key and nothing else. Any other search API is the
|
|
423
|
+
* host's `engine` function.
|
|
424
|
+
*/
|
|
425
|
+
type SearchProvider = 'google';
|
|
421
426
|
declare const SEARCH_PROVIDERS: readonly SearchProvider[];
|
|
422
|
-
/** Where
|
|
423
|
-
declare const SEARCH_API_BASE_URL: Record<
|
|
427
|
+
/** Where the provider's API lives (a `baseURL` of the host - a gateway - replaces it). */
|
|
428
|
+
declare const SEARCH_API_BASE_URL: Record<SearchProvider, string>;
|
|
429
|
+
/**
|
|
430
|
+
* The model the grounding call is made with when the host names none: the cheapest one that
|
|
431
|
+
* answered a free-tier key with grounding on the day it was measured (2026-11-26).
|
|
432
|
+
*/
|
|
433
|
+
declare const SEARCH_GOOGLE_DEFAULT_MODEL = "gemini-2.5-flash-lite";
|
|
434
|
+
/** The most of the grounding model's answer a model sees as `summary`. */
|
|
435
|
+
declare const SEARCH_MAX_SUMMARY_CHARS = 1000;
|
|
436
|
+
/** Said in every result of the google provider: what its URLs and its text are. */
|
|
437
|
+
declare const SEARCH_GOOGLE_NOTE: string;
|
|
424
438
|
/** One HTTP call to a search API. The key, if any, is in `headers` only - never in the URL. */
|
|
425
439
|
interface ISearchRequest {
|
|
426
440
|
url: string;
|
|
@@ -435,19 +449,48 @@ interface ISearchRequestInput {
|
|
|
435
449
|
freshness?: SearchFreshness;
|
|
436
450
|
apiKey?: string;
|
|
437
451
|
baseURL?: string;
|
|
452
|
+
/** The Gemini model that makes the grounding call (default SEARCH_GOOGLE_DEFAULT_MODEL). */
|
|
453
|
+
model?: string;
|
|
454
|
+
/** The current time in ms, for `freshness` (this file reads no clock). */
|
|
455
|
+
now?: number;
|
|
456
|
+
}
|
|
457
|
+
/** What a search spent in model tokens, as the API reported it. */
|
|
458
|
+
interface ISearchUsage {
|
|
459
|
+
inputTokens: number;
|
|
460
|
+
outputTokens: number;
|
|
461
|
+
totalTokens: number;
|
|
462
|
+
reasoningTokens: number;
|
|
463
|
+
}
|
|
464
|
+
/** A provider's answer, parsed: raw third-party values until `sanitizeSearchResults`. */
|
|
465
|
+
interface ISearchAnswer {
|
|
466
|
+
results: unknown[];
|
|
467
|
+
/** The grounding model's whole answer (raw). */
|
|
468
|
+
summary?: unknown;
|
|
469
|
+
/** Absent when the API reported none. */
|
|
470
|
+
usage?: ISearchUsage;
|
|
438
471
|
}
|
|
439
472
|
/**
|
|
440
|
-
* The request for one query, per the API's public documentation:
|
|
441
|
-
*
|
|
442
|
-
*
|
|
443
|
-
*
|
|
473
|
+
* The request for one query, per the Gemini API's public documentation:
|
|
474
|
+
* POST {base}/v1beta/models/{model}:generateContent header x-goog-api-key
|
|
475
|
+
* { systemInstruction, contents: [the query], tools: [{ google_search }], generationConfig }
|
|
476
|
+
* The query is the only text of the conversation in it. The API has no result count: the list
|
|
477
|
+
* is cut on the way back.
|
|
444
478
|
*/
|
|
445
479
|
declare const buildSearchRequest: (input: ISearchRequestInput) => ISearchRequest;
|
|
446
480
|
/**
|
|
447
|
-
*
|
|
448
|
-
*
|
|
481
|
+
* What a grounded answer holds, mapped to results of `{ title, url, snippet }` and nothing else,
|
|
482
|
+
* the model's answer, and what the call spent. A source is a `groundingChunks[].web` (`uri` is a
|
|
483
|
+
* Google redirect link, `title` the site's name); its snippet is the pieces of the answer that
|
|
484
|
+
* `groundingSupports` attribute to it (fragments as the API cut them, joined with an ellipsis). Still raw third-party values: `sanitizeSearchResults` is
|
|
485
|
+
* what makes them safe to show.
|
|
486
|
+
*/
|
|
487
|
+
declare const parseSearchResponse: (provider: SearchProvider, json: unknown) => ISearchAnswer;
|
|
488
|
+
/**
|
|
489
|
+
* What a failed call says to the model: the provider, the model, the status, the API's own error
|
|
490
|
+
* code word and what it usually means. Never the error's text: that is third-party text, and may
|
|
491
|
+
* echo what was sent. `body` is the parsed error body, if there was one.
|
|
449
492
|
*/
|
|
450
|
-
declare const
|
|
493
|
+
declare const searchStatusMessage: (provider: SearchProvider, status: number, model?: string, body?: unknown) => string;
|
|
451
494
|
interface ISanitizedSearch {
|
|
452
495
|
results: ISearchResult[];
|
|
453
496
|
/** Results dropped because the host's egress policy does not let the model reach them. */
|
|
@@ -458,18 +501,37 @@ interface ISanitizedSearch {
|
|
|
458
501
|
/**
|
|
459
502
|
* What a model sees of an engine's answer. `raw` is whatever came back - nothing about it is
|
|
460
503
|
* trusted: a result needs a valid http(s) URL, every field is cleaned and capped, duplicates go,
|
|
461
|
-
* `accepts` (the egress policy
|
|
462
|
-
* `maxResults` and at SEARCH_MAX_TOTAL_CHARS.
|
|
504
|
+
* `accepts` (the egress policy; it is also handed the result's raw title) drops links the model
|
|
505
|
+
* could not fetch, and the list stops at `maxResults` and at SEARCH_MAX_TOTAL_CHARS.
|
|
463
506
|
*/
|
|
464
507
|
declare const sanitizeSearchResults: (raw: unknown, options?: {
|
|
465
508
|
maxResults?: number;
|
|
466
|
-
accepts?: (url: URL) => boolean;
|
|
509
|
+
accepts?: (url: URL, title: unknown) => boolean;
|
|
467
510
|
}) => ISanitizedSearch;
|
|
511
|
+
/** What `web_search` returns to the model. */
|
|
512
|
+
interface ISearchToolResult {
|
|
513
|
+
query: string;
|
|
514
|
+
results: ISearchResult[];
|
|
515
|
+
/** The google provider, when no source came with a snippet: the grounding model's answer, cut. */
|
|
516
|
+
summary?: string;
|
|
517
|
+
/** The google provider: what its URLs and its text are. */
|
|
518
|
+
note?: string;
|
|
519
|
+
filtered?: number;
|
|
520
|
+
truncated?: true;
|
|
521
|
+
untrusted: true;
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* The tool's result, from the cleaned list and - for the google provider - the parsed answer.
|
|
525
|
+
* The model's `summary` is attached only when there are sources, none of them carries a snippet
|
|
526
|
+
* and none was filtered out: a summary cannot be cut to the sources that remain.
|
|
527
|
+
*/
|
|
528
|
+
declare const searchToolResult: (query: string, clean: ISanitizedSearch, answer?: ISearchAnswer) => ISearchToolResult;
|
|
468
529
|
|
|
469
530
|
interface ISearchConfig {
|
|
470
531
|
engine?: SearchEngine;
|
|
471
532
|
provider?: SearchProvider;
|
|
472
533
|
apiKey?: string;
|
|
534
|
+
model?: string;
|
|
473
535
|
baseURL?: string;
|
|
474
536
|
maxResults?: number;
|
|
475
537
|
allowPrivateNetwork?: boolean;
|
|
@@ -601,6 +663,335 @@ interface IMedia {
|
|
|
601
663
|
}
|
|
602
664
|
declare const createMedia: (config: IAgentConfig) => Promise<IMedia | undefined>;
|
|
603
665
|
|
|
666
|
+
/**
|
|
667
|
+
* MCP elicitation, the part the two agent packages share: a server asks the user for input in
|
|
668
|
+
* the middle of a tool call, the HOST answers through a callback, and the call goes on. Pure, no
|
|
669
|
+
* imports: the limits, what a request must look like before a host sees it, what an answer must
|
|
670
|
+
* look like before a server sees it, the one function that asks, and the two ways a tool call
|
|
671
|
+
* with questions is driven (`elicitation/create` requests on the 2025 revisions, `input_required`
|
|
672
|
+
* results on 2026-07-28).
|
|
673
|
+
*
|
|
674
|
+
* A consent boundary. The server's text is third-party data: cleaned and capped here, shown only
|
|
675
|
+
* to the host's callback and in the `mcp.elicitation-requested` event, never put into a prompt.
|
|
676
|
+
* The answer goes to the server that asked and nowhere else: nothing in this file logs, emits or
|
|
677
|
+
* returns a value the user entered - events and errors carry field NAMES only.
|
|
678
|
+
*
|
|
679
|
+
* This file is a COPY, byte for byte, in `@dudko.dev/agent` (`src/mcp-elicitation.ts`) and
|
|
680
|
+
* `@dudko.dev/agent-web` (`src/mcp/elicitation.ts`): change both. The Node package's
|
|
681
|
+
* `tests/mcp-elicitation-shared.test.ts` compares the two files and tests every guard here; each
|
|
682
|
+
* needs a mutation check.
|
|
683
|
+
*/
|
|
684
|
+
/** How long one question waits for the host's answer, by default: a human is reading it. */
|
|
685
|
+
declare const MCP_ELICITATION_TIMEOUT_MS = 300000;
|
|
686
|
+
/** The most questions one tool call may ask, by default. */
|
|
687
|
+
declare const MCP_ELICITATION_MAX_PER_TOOL_CALL = 5;
|
|
688
|
+
/** The most questions one run may be asked, by default (its helpers' calls included). */
|
|
689
|
+
declare const MCP_ELICITATION_MAX_PER_RUN = 20;
|
|
690
|
+
/** One field of a form: the flat subset of JSON Schema the specification allows, nothing else. */
|
|
691
|
+
interface McpElicitationFieldSchema {
|
|
692
|
+
type: 'string' | 'number' | 'integer' | 'boolean' | 'array';
|
|
693
|
+
title?: string;
|
|
694
|
+
description?: string;
|
|
695
|
+
default?: string | number | boolean | string[];
|
|
696
|
+
/** string */
|
|
697
|
+
minLength?: number;
|
|
698
|
+
maxLength?: number;
|
|
699
|
+
format?: 'email' | 'uri' | 'date' | 'date-time';
|
|
700
|
+
/** string: single-select, plain (`enumNames`: the older titled form). */
|
|
701
|
+
enum?: string[];
|
|
702
|
+
enumNames?: string[];
|
|
703
|
+
/** string: single-select with titles. */
|
|
704
|
+
oneOf?: {
|
|
705
|
+
const: string;
|
|
706
|
+
title: string;
|
|
707
|
+
}[];
|
|
708
|
+
/** number / integer */
|
|
709
|
+
minimum?: number;
|
|
710
|
+
maximum?: number;
|
|
711
|
+
/** array: multi-select. */
|
|
712
|
+
minItems?: number;
|
|
713
|
+
maxItems?: number;
|
|
714
|
+
items?: {
|
|
715
|
+
type?: 'string';
|
|
716
|
+
enum?: string[];
|
|
717
|
+
anyOf?: {
|
|
718
|
+
const: string;
|
|
719
|
+
title: string;
|
|
720
|
+
}[];
|
|
721
|
+
};
|
|
722
|
+
}
|
|
723
|
+
/** The form a server asks for, as a host is shown it: checked, cleaned and capped. */
|
|
724
|
+
interface McpElicitationSchema {
|
|
725
|
+
type: 'object';
|
|
726
|
+
properties: Record<string, McpElicitationFieldSchema>;
|
|
727
|
+
required?: string[];
|
|
728
|
+
}
|
|
729
|
+
/** What the host's callback is given. Every string in it is third-party text. */
|
|
730
|
+
interface McpElicitationRequest {
|
|
731
|
+
/** Unique per question; the same id is in the two events. */
|
|
732
|
+
id: string;
|
|
733
|
+
/** The server that asks: its key in the host's configuration. */
|
|
734
|
+
server: string;
|
|
735
|
+
/** The tool call during which it asks: the tool's name as the model called it. */
|
|
736
|
+
tool: string;
|
|
737
|
+
mode: 'form' | 'url';
|
|
738
|
+
/** The server's words, cleaned and capped (MCP_ELICITATION_MESSAGE_MAX_CHARS). */
|
|
739
|
+
message: string;
|
|
740
|
+
/** Form mode: the fields to fill in. */
|
|
741
|
+
requestedSchema?: McpElicitationSchema;
|
|
742
|
+
/**
|
|
743
|
+
* URL mode: the link the server wants the user to open. It is only handed over: nothing in
|
|
744
|
+
* these packages fetches or opens it. https, or http on a loopback host.
|
|
745
|
+
*/
|
|
746
|
+
url?: string;
|
|
747
|
+
/** URL mode on the 2025 revisions: the server's id for this interaction. */
|
|
748
|
+
elicitationId?: string;
|
|
749
|
+
runId?: string;
|
|
750
|
+
/** Set when a helper the model started is the one whose call asks (`elicitation.subagents`). */
|
|
751
|
+
subagent?: {
|
|
752
|
+
id: string;
|
|
753
|
+
depth: number;
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
type McpElicitationContent = Record<string, string | number | boolean | string[]>;
|
|
757
|
+
/**
|
|
758
|
+
* The host's answer. `accept` carries the form's values (form mode) or nothing (URL mode: it
|
|
759
|
+
* says the user agreed to open the link); `decline` is a no; `cancel` is "dismissed".
|
|
760
|
+
*/
|
|
761
|
+
type McpElicitationResult = {
|
|
762
|
+
action: 'accept';
|
|
763
|
+
content?: McpElicitationContent;
|
|
764
|
+
} | {
|
|
765
|
+
action: 'decline';
|
|
766
|
+
} | {
|
|
767
|
+
action: 'cancel';
|
|
768
|
+
};
|
|
769
|
+
interface McpElicitationContext {
|
|
770
|
+
/** Aborted when the answer is no longer wanted: the run stopped, or the time ran out. */
|
|
771
|
+
signal: AbortSignal;
|
|
772
|
+
}
|
|
773
|
+
/** `onElicitation`: the host decides, never the model. */
|
|
774
|
+
type McpElicitationHandler = (request: McpElicitationRequest, ctx: McpElicitationContext) => McpElicitationResult | Promise<McpElicitationResult>;
|
|
775
|
+
/** The `elicitation` settings beside `onElicitation`. */
|
|
776
|
+
interface McpElicitationOptions {
|
|
777
|
+
/**
|
|
778
|
+
* How long one question waits for an answer. Default 300 000. `0` or `Infinity` = no limit of
|
|
779
|
+
* its own (the question waits until the run is stopped), and so is a value above 2^31 - 1 (about
|
|
780
|
+
* 24.8 days, the most a timer holds). Negative or NaN: a configuration error.
|
|
781
|
+
*/
|
|
782
|
+
timeoutMs?: number;
|
|
783
|
+
/** Questions one tool call may ask. Default 5. */
|
|
784
|
+
maxPerToolCall?: number;
|
|
785
|
+
/** Questions one run may be asked. Default 20. */
|
|
786
|
+
maxPerRun?: number;
|
|
787
|
+
/** Also accept URL mode (a link to open). Default false: only forms are declared. */
|
|
788
|
+
url?: boolean;
|
|
789
|
+
/**
|
|
790
|
+
* Let a tool call made by a helper (a subagent) ask the user too. Default false: such a
|
|
791
|
+
* question is cancelled without the callback being called.
|
|
792
|
+
*/
|
|
793
|
+
subagents?: boolean;
|
|
794
|
+
}
|
|
795
|
+
/** Why a question was answered without the host deciding. */
|
|
796
|
+
type McpElicitationReason = 'unsupported-schema' | 'unsupported-mode' | 'insecure-url' | 'invalid-request' | 'subagent' | 'cap-per-call' | 'cap-per-run' | 'handler-error' | 'timeout' | 'invalid-answer' | 'aborted' | 'step-timeout' | 'after-failure' | 'no-tool-call';
|
|
797
|
+
type Checked<T> = {
|
|
798
|
+
ok: true;
|
|
799
|
+
value: T;
|
|
800
|
+
} | {
|
|
801
|
+
ok: false;
|
|
802
|
+
reason: string;
|
|
803
|
+
};
|
|
804
|
+
/**
|
|
805
|
+
* The form a server asked for, reduced to what the specification allows a form to be: a flat
|
|
806
|
+
* object of strings, numbers, booleans and selects. Anything else - a nested object, a list of
|
|
807
|
+
* objects, a type union, an unknown format, too many fields or options, a name that could not
|
|
808
|
+
* be sent back verbatim - is refused with a reason (the caller declines the request). Keywords
|
|
809
|
+
* outside the subset are dropped; titles and descriptions are cleaned and capped.
|
|
810
|
+
*/
|
|
811
|
+
declare const normalizeMcpElicitationSchema: (raw: unknown) => Checked<McpElicitationSchema>;
|
|
812
|
+
/**
|
|
813
|
+
* An accepted form, checked against the schema it answers: every value of the type and within
|
|
814
|
+
* the limits its field states, every required field there, and NO field the form did not ask
|
|
815
|
+
* for (what the server did not request is not sent to it). The result is a fresh object holding
|
|
816
|
+
* only the form's own fields. A refusal names the field and the rule, never the value.
|
|
817
|
+
*/
|
|
818
|
+
declare const validateMcpElicitationContent: (schema: McpElicitationSchema, content: unknown) => Checked<McpElicitationContent>;
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* What the MCP connectors of the two agent packages share: how a server's `instructions` reach a
|
|
822
|
+
* system prompt, how a tool result's `structuredContent` reaches the model, and what the
|
|
823
|
+
* per-server `protocol` option means. Pure, no imports.
|
|
824
|
+
*
|
|
825
|
+
* This file is a COPY, byte for byte, in `@dudko.dev/agent` (`src/mcp-shared.ts`) and
|
|
826
|
+
* `@dudko.dev/agent-web` (`src/mcp/shared.ts`): change both. The Node package's
|
|
827
|
+
* `tests/mcp-shared.test.ts` compares the two files and tests every cap and guard here.
|
|
828
|
+
*/
|
|
829
|
+
/** The `instructions` one connected MCP server returned in its `initialize` result. */
|
|
830
|
+
interface McpServerInstructions {
|
|
831
|
+
/** The server's name: its key in the host's configuration. */
|
|
832
|
+
server: string;
|
|
833
|
+
instructions: string;
|
|
834
|
+
}
|
|
835
|
+
/** The most one server's instructions take in a system prompt, in characters. */
|
|
836
|
+
declare const MCP_INSTRUCTIONS_MAX_CHARS_PER_SERVER = 2000;
|
|
837
|
+
/** The most all servers' instructions take together, in characters. */
|
|
838
|
+
declare const MCP_INSTRUCTIONS_MAX_CHARS_TOTAL = 8000;
|
|
839
|
+
/**
|
|
840
|
+
* The system-prompt section for the servers' instructions, or '' when no server sent any (the
|
|
841
|
+
* prompt is then exactly what it was). Each server's text is capped
|
|
842
|
+
* (MCP_INSTRUCTIONS_MAX_CHARS_PER_SERVER), so is the sum (MCP_INSTRUCTIONS_MAX_CHARS_TOTAL, in
|
|
843
|
+
* the order given: a server past the total is named as omitted), and every line of it is
|
|
844
|
+
* prefixed with "| ", so a server cannot write something that reads as a heading of this prompt
|
|
845
|
+
* or as another server's note.
|
|
846
|
+
*/
|
|
847
|
+
declare const renderMcpInstructions: (list: readonly McpServerInstructions[] | undefined) => string;
|
|
848
|
+
/**
|
|
849
|
+
* Which revisions of the protocol a connection to one server may use (the server config's
|
|
850
|
+
* `protocol`):
|
|
851
|
+
*
|
|
852
|
+
* - `'legacy'` (default): the 2025 revisions, the `initialize` handshake. Nothing of the 2026
|
|
853
|
+
* revision is sent.
|
|
854
|
+
* - `'auto'`: ask first (`server/discover`); a server that answers with 2026-07-28 is spoken to
|
|
855
|
+
* that way, any other is given the 2025 handshake. Decided once, at connect.
|
|
856
|
+
* - `'modern'`: 2026-07-28 only. A server that does not offer it fails the connect.
|
|
857
|
+
*/
|
|
858
|
+
type McpProtocolMode = 'legacy' | 'auto' | 'modern';
|
|
859
|
+
/** The revision `protocol: 'modern'` pins: the one this connector is tested against. */
|
|
860
|
+
declare const MCP_MODERN_PROTOCOL_VERSION = "2026-07-28";
|
|
861
|
+
/** What a connection negotiated with one server. */
|
|
862
|
+
interface McpServerProtocol {
|
|
863
|
+
/** The server's name: its key in the host's configuration. */
|
|
864
|
+
server: string;
|
|
865
|
+
/** The protocol revision in use, e.g. `2025-11-25` or `2026-07-28`. */
|
|
866
|
+
version: string;
|
|
867
|
+
/** `modern` from 2026-07-28 on (stateless, `server/discover`), `legacy` before. */
|
|
868
|
+
era: 'legacy' | 'modern';
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
/**
|
|
872
|
+
* MCP Skills (the `io.modelcontextprotocol/skills` extension, SEP-2640, Beta; written against
|
|
873
|
+
* base revision 2026-07-28): what the two agent packages share about a server's skills. The
|
|
874
|
+
* rules on a server's entries (`mcpSkillEntryRefusal`), the names a skill gets in the agent's
|
|
875
|
+
* catalog (`assignMcpSkillNames`: namespaced by the host's label of the server), the caps
|
|
876
|
+
* (`selectMcpSkills`), the files of a loaded skill the model may read (`resolveMcpSkillFile`),
|
|
877
|
+
* the preamble a skill's text is loaded under, the mark that carries a server's skills on its
|
|
878
|
+
* tools (`markMcpSkills` / `collectMcpSkillSources`), a skill the model names by URI
|
|
879
|
+
* (`mcpSkillUriRefusal`, `resolveMcpSkillServer`: `skills/get` to that one server only) and the
|
|
880
|
+
* person's consent before a skill's text enters the model's context (`decideMcpSkillConsent`,
|
|
881
|
+
* `mcpSkillConsentView`). Pure, no imports.
|
|
882
|
+
*
|
|
883
|
+
* A server's skills are third-party text. They reach the model only as knowledge, under
|
|
884
|
+
* `mcpSkillPreamble`, and - unless the host vetted the server (`consent: 'never'`) - only after a
|
|
885
|
+
* person saw them and said yes; nothing here (or anywhere) reads a skill's frontmatter beyond its
|
|
886
|
+
* `name` and `description` - `allowed-tools` included - and a file a skill bundles is read as
|
|
887
|
+
* text, never run.
|
|
888
|
+
*
|
|
889
|
+
* This file is a COPY, byte for byte, in `@dudko.dev/agent` (`src/mcp-skills.ts`) and
|
|
890
|
+
* `@dudko.dev/agent-web` (`src/mcp/skills.ts`): change both. The Node package's
|
|
891
|
+
* `tests/mcp-skills-shared.test.ts` compares the two files and tests every rule and cap here.
|
|
892
|
+
*/
|
|
893
|
+
/** The extension's identifier, in the client's and the server's `extensions` capability. */
|
|
894
|
+
declare const MCP_SKILLS_EXTENSION = "io.modelcontextprotocol/skills";
|
|
895
|
+
/** The specification's limits (Limits): files per skill, `SKILL.md` included. */
|
|
896
|
+
declare const MCP_SKILL_MAX_RESOURCES = 512;
|
|
897
|
+
/** The specification's limits (Limits): the sum of `size` over a skill's files, in bytes. */
|
|
898
|
+
declare const MCP_SKILL_MAX_TOTAL_BYTES: number;
|
|
899
|
+
/** The most skills one server puts in the agent's catalog. */
|
|
900
|
+
declare const MCP_SKILLS_MAX_PER_SERVER = 32;
|
|
901
|
+
/** The most skills all servers put in the agent's catalog together. */
|
|
902
|
+
declare const MCP_SKILLS_MAX_TOTAL = 64;
|
|
903
|
+
/** The most a catalog entry (the description and its origin tag) takes, in characters. */
|
|
904
|
+
declare const MCP_SKILL_DESCRIPTION_MAX_CHARS = 300;
|
|
905
|
+
/** The most of a skill's instructions (its `SKILL.md` body) the model is given, in characters. */
|
|
906
|
+
declare const MCP_SKILL_BODY_MAX_CHARS = 16000;
|
|
907
|
+
/** The most of one file of a skill the model is given, in characters. */
|
|
908
|
+
declare const MCP_SKILL_FILE_MAX_CHARS = 32000;
|
|
909
|
+
/**
|
|
910
|
+
* Why the agent does not take a skill entry from a server, or `undefined` when it does. The
|
|
911
|
+
* specification's rules on an entry, checked before anything of the skill is read:
|
|
912
|
+
*
|
|
913
|
+
* - its `uri` is a `SKILL.md` inside a named directory, whose last segment is the skill's
|
|
914
|
+
* frontmatter `name` (Resource Mapping; Frontmatter), and that name follows the Agent Skills
|
|
915
|
+
* naming rules;
|
|
916
|
+
* - a description to show in the catalog;
|
|
917
|
+
* - `resources` is the complete list of its files (Resources): `"dynamic"` content is declined
|
|
918
|
+
* (a host MAY: there is nothing to verify it against), anything else is invalid;
|
|
919
|
+
* - every file is `SKILL.md` or a file inside the skill's directory, listed once, with a
|
|
920
|
+
* `sha256:` digest and a byte size, and `SKILL.md` is listed;
|
|
921
|
+
* - at most {@link MCP_SKILL_MAX_RESOURCES} files and {@link MCP_SKILL_MAX_TOTAL_BYTES} bytes
|
|
922
|
+
* (Limits: "both limits are checkable from the entry alone").
|
|
923
|
+
*/
|
|
924
|
+
declare const mcpSkillEntryRefusal: (entry: unknown) => string | undefined;
|
|
925
|
+
/**
|
|
926
|
+
* How a skill of a server is introduced wherever its text is shown to the model (its
|
|
927
|
+
* instructions, and each file of it): third-party knowledge that cannot change the rules. The
|
|
928
|
+
* wording is the guard.
|
|
929
|
+
*/
|
|
930
|
+
declare const mcpSkillPreamble: (server: string, uri: string) => string;
|
|
931
|
+
/** The longest URI `load_skill` sends to a server, in characters. */
|
|
932
|
+
declare const MCP_SKILL_URI_MAX_CHARS = 512;
|
|
933
|
+
/**
|
|
934
|
+
* Why `load_skill` does not ask a server for the skill at `uri`, or `undefined` when it may. Checked
|
|
935
|
+
* before any request: a `skill://` URI - the conventional scheme; a URI the MODEL hands over (it
|
|
936
|
+
* read it in third-party text) is taken in no other, though a listing may use any - of the
|
|
937
|
+
* `SKILL.md` of a named directory, whose last segment is a skill name, within
|
|
938
|
+
* {@link MCP_SKILL_URI_MAX_CHARS}, with nothing invisible and no space in it.
|
|
939
|
+
*/
|
|
940
|
+
declare const mcpSkillUriRefusal: (uri: unknown) => string | undefined;
|
|
941
|
+
/** When a person is asked before a server's skill enters the model's context. */
|
|
942
|
+
type McpSkillConsent = 'ask' | 'once-per-skill' | 'never';
|
|
943
|
+
/** Every value of {@link McpSkillConsent}. */
|
|
944
|
+
declare const MCP_SKILL_CONSENTS: readonly McpSkillConsent[];
|
|
945
|
+
/**
|
|
946
|
+
* The default: asked the first time a skill would enter the context in the agent's life, and again
|
|
947
|
+
* only when its entry changed - often enough that every text a person did not see is shown, seldom
|
|
948
|
+
* enough that a yes still means something.
|
|
949
|
+
*/
|
|
950
|
+
declare const MCP_SKILL_CONSENT_DEFAULT: McpSkillConsent;
|
|
951
|
+
/** `skills` on a server's config, as an object. */
|
|
952
|
+
interface McpSkillsOptions {
|
|
953
|
+
/**
|
|
954
|
+
* `'once-per-skill'` (default): a person is asked the first time each skill would enter the
|
|
955
|
+
* model's context, and a yes holds for the agent's life while the skill's entry is the same;
|
|
956
|
+
* `'ask'`: asked in every run that loads it; `'never'`: never asked - for a server the host
|
|
957
|
+
* vetted (its skills load as soon as the model asks). Whatever the approval mode says.
|
|
958
|
+
*/
|
|
959
|
+
consent?: McpSkillConsent;
|
|
960
|
+
}
|
|
961
|
+
/** `skills` on a server's config: `true`, or options (on, with them); `false` / absent: off. */
|
|
962
|
+
type McpSkillsSetting = boolean | McpSkillsOptions;
|
|
963
|
+
/**
|
|
964
|
+
* What a person is shown before a server's skill enters the model's context - the request's
|
|
965
|
+
* `skill` (the core's `tool.approval-requested` event). Every string is the SERVER's, cleaned:
|
|
966
|
+
* show it as plain text, captioned as the server's.
|
|
967
|
+
*/
|
|
968
|
+
interface McpSkillConsentView {
|
|
969
|
+
/** The host's label of the server that serves it. */
|
|
970
|
+
server: string;
|
|
971
|
+
/** Its name in the agent's catalog (`<server>/<skill>`). */
|
|
972
|
+
name: string;
|
|
973
|
+
/** Its frontmatter name. */
|
|
974
|
+
skill: string;
|
|
975
|
+
/** The URI of its `SKILL.md` (cleaned, at most 200 characters). */
|
|
976
|
+
uri: string;
|
|
977
|
+
/** The description from its entry, on one line, at most {@link MCP_SKILL_DESCRIPTION_MAX_CHARS}. */
|
|
978
|
+
description: string;
|
|
979
|
+
/** Bytes of its `SKILL.md`, and of all its files. */
|
|
980
|
+
size: number;
|
|
981
|
+
totalSize: number;
|
|
982
|
+
/** Its other files, by path (at most {@link MCP_SKILL_FILES_SHOWN_MAX}), and how many there are. */
|
|
983
|
+
files: string[];
|
|
984
|
+
fileCount: number;
|
|
985
|
+
/** Its instructions exactly as the model would read them ({@link mcpSkillBodyPreview}). */
|
|
986
|
+
body: string;
|
|
987
|
+
/** Named by URI (`skills/get`), not in the server's listing. */
|
|
988
|
+
byUri?: true;
|
|
989
|
+
/** It sits inside this skill of the same server, whose approval does not cover it. */
|
|
990
|
+
nestedIn?: string;
|
|
991
|
+
/** Asked for this run only (`'ask'`) or, on a yes, for the agent's life (`'once-per-skill'`). */
|
|
992
|
+
consent: Exclude<McpSkillConsent, 'never'>;
|
|
993
|
+
}
|
|
994
|
+
|
|
604
995
|
declare const SPAWN_SUBAGENT_TOOL = "spawn_subagent";
|
|
605
996
|
type SubagentDefaultTools = 'read-only' | 'all';
|
|
606
997
|
interface IDynamicSubagentsConfig {
|
|
@@ -738,6 +1129,11 @@ interface ISkill {
|
|
|
738
1129
|
content: string;
|
|
739
1130
|
}[];
|
|
740
1131
|
origin?: ISkillOrigin;
|
|
1132
|
+
mcp?: IMcpSkillOrigin;
|
|
1133
|
+
}
|
|
1134
|
+
interface IMcpSkillOrigin {
|
|
1135
|
+
server: string;
|
|
1136
|
+
uri: string;
|
|
741
1137
|
}
|
|
742
1138
|
interface ISkillOrigin {
|
|
743
1139
|
kind: 'learned';
|
|
@@ -771,6 +1167,11 @@ interface IToolApprovalRequest {
|
|
|
771
1167
|
id: string;
|
|
772
1168
|
depth: number;
|
|
773
1169
|
};
|
|
1170
|
+
mcpSkills?: string[];
|
|
1171
|
+
skill?: McpSkillConsentView;
|
|
1172
|
+
}
|
|
1173
|
+
interface IToolApprovalContext {
|
|
1174
|
+
signal: AbortSignal;
|
|
774
1175
|
}
|
|
775
1176
|
type ToolApprovalDecision = boolean | {
|
|
776
1177
|
approved: boolean;
|
|
@@ -780,7 +1181,7 @@ type ToolApprovalDecision = boolean | {
|
|
|
780
1181
|
interface IToolApprovalConfig {
|
|
781
1182
|
mode?: ToolApprovalMode;
|
|
782
1183
|
rules?: Record<string, ToolPermission>;
|
|
783
|
-
onRequest?: (req: IToolApprovalRequest) => ToolApprovalDecision | Promise<ToolApprovalDecision>;
|
|
1184
|
+
onRequest?: (req: IToolApprovalRequest, ctx: IToolApprovalContext) => ToolApprovalDecision | Promise<ToolApprovalDecision>;
|
|
784
1185
|
timeoutMs?: number;
|
|
785
1186
|
}
|
|
786
1187
|
type PromptCachingSetting = boolean | {
|
|
@@ -800,6 +1201,8 @@ interface IMcpHttpServerConfig {
|
|
|
800
1201
|
authProvider?: OAuthClientProvider;
|
|
801
1202
|
fetch?: FetchLike;
|
|
802
1203
|
connectTimeoutMs?: number;
|
|
1204
|
+
protocol?: McpProtocolMode;
|
|
1205
|
+
skills?: McpSkillsSetting;
|
|
803
1206
|
}
|
|
804
1207
|
interface IMcpStdioServerConfig {
|
|
805
1208
|
command: string;
|
|
@@ -807,6 +1210,8 @@ interface IMcpStdioServerConfig {
|
|
|
807
1210
|
env?: Record<string, string>;
|
|
808
1211
|
cwd?: string;
|
|
809
1212
|
connectTimeoutMs?: number;
|
|
1213
|
+
protocol?: McpProtocolMode;
|
|
1214
|
+
skills?: McpSkillsSetting;
|
|
810
1215
|
}
|
|
811
1216
|
type IMcpServerConfig = IMcpHttpServerConfig | IMcpStdioServerConfig;
|
|
812
1217
|
interface IAgentStageOverride {
|
|
@@ -858,6 +1263,11 @@ interface IAgentConfig {
|
|
|
858
1263
|
toolApproval?: IToolApprovalConfig;
|
|
859
1264
|
toolSearchThreshold?: number;
|
|
860
1265
|
mcpConnectTimeoutMs?: number;
|
|
1266
|
+
onElicitation?: McpElicitationHandler;
|
|
1267
|
+
elicitation?: McpElicitationOptions;
|
|
1268
|
+
mcpSkills?: {
|
|
1269
|
+
consent?: McpSkillConsent;
|
|
1270
|
+
};
|
|
861
1271
|
mcpInstructions?: boolean;
|
|
862
1272
|
promptCaching?: PromptCachingSetting;
|
|
863
1273
|
llmTimeoutMs?: number;
|
|
@@ -920,7 +1330,7 @@ interface IStepResult {
|
|
|
920
1330
|
}
|
|
921
1331
|
type ReplanTrigger = 'failure' | 'always' | ((result: IStepResult) => boolean | Promise<boolean>);
|
|
922
1332
|
type ReplanCause = 'last-step' | 'clean-step' | 'llm-decision' | 'user-message' | 'decision-model';
|
|
923
|
-
type UsagePhase = 'plan' | 'execute' | 'replan' | 'synthesize' | 'compact' | 'subagent' | 'decision' | 'media';
|
|
1333
|
+
type UsagePhase = 'plan' | 'execute' | 'replan' | 'synthesize' | 'compact' | 'subagent' | 'decision' | 'media' | 'search';
|
|
924
1334
|
type AgentEventBody = {
|
|
925
1335
|
type: 'plan.thought-delta';
|
|
926
1336
|
delta: string;
|
|
@@ -1015,6 +1425,7 @@ type AgentEventBody = {
|
|
|
1015
1425
|
type: 'skill.activated';
|
|
1016
1426
|
name: string;
|
|
1017
1427
|
by: 'plan' | 'tool';
|
|
1428
|
+
server?: string;
|
|
1018
1429
|
} | {
|
|
1019
1430
|
type: 'tools.discovered';
|
|
1020
1431
|
step: IPlanStep;
|
|
@@ -1031,6 +1442,8 @@ type AgentEventBody = {
|
|
|
1031
1442
|
id: string;
|
|
1032
1443
|
depth: number;
|
|
1033
1444
|
};
|
|
1445
|
+
mcpSkills?: string[];
|
|
1446
|
+
skill?: McpSkillConsentView;
|
|
1034
1447
|
} | {
|
|
1035
1448
|
type: 'tool.approval-resolved';
|
|
1036
1449
|
id: string;
|
|
@@ -1038,6 +1451,29 @@ type AgentEventBody = {
|
|
|
1038
1451
|
approved: boolean;
|
|
1039
1452
|
reason?: string;
|
|
1040
1453
|
automatic: boolean;
|
|
1454
|
+
} | {
|
|
1455
|
+
type: 'mcp.elicitation-requested';
|
|
1456
|
+
id: string;
|
|
1457
|
+
server: string;
|
|
1458
|
+
tool: string;
|
|
1459
|
+
mode: 'form' | 'url';
|
|
1460
|
+
message: string;
|
|
1461
|
+
requestedSchema?: McpElicitationSchema;
|
|
1462
|
+
url?: string;
|
|
1463
|
+
step?: IPlanStep;
|
|
1464
|
+
subagent?: {
|
|
1465
|
+
id: string;
|
|
1466
|
+
depth: number;
|
|
1467
|
+
};
|
|
1468
|
+
} | {
|
|
1469
|
+
type: 'mcp.elicitation-answered';
|
|
1470
|
+
id: string;
|
|
1471
|
+
server: string;
|
|
1472
|
+
tool: string;
|
|
1473
|
+
action: 'accept' | 'decline' | 'cancel';
|
|
1474
|
+
automatic: boolean;
|
|
1475
|
+
reason?: McpElicitationReason;
|
|
1476
|
+
fields?: string[];
|
|
1041
1477
|
} | {
|
|
1042
1478
|
type: 'subagent.start';
|
|
1043
1479
|
id: string;
|
|
@@ -1204,6 +1640,7 @@ interface IAgent {
|
|
|
1204
1640
|
name: string;
|
|
1205
1641
|
description: string;
|
|
1206
1642
|
learned?: true;
|
|
1643
|
+
server?: string;
|
|
1207
1644
|
}[];
|
|
1208
1645
|
listLearnedSkills: () => ISkill[];
|
|
1209
1646
|
forgetSkill: (name: string) => Promise<boolean>;
|
|
@@ -1228,6 +1665,8 @@ declare class ToolDeniedError extends Error {
|
|
|
1228
1665
|
}
|
|
1229
1666
|
declare const markReadOnly: <T extends object>(tool: T, readOnly?: boolean) => T;
|
|
1230
1667
|
declare const isReadOnlyTool: (tool: unknown) => boolean;
|
|
1668
|
+
declare const markCodeExecution: <T extends object>(tool: T, codeExecution?: boolean) => T;
|
|
1669
|
+
declare const isCodeExecutionTool: (tool: unknown) => boolean;
|
|
1231
1670
|
/**
|
|
1232
1671
|
* The most specific rule matching `name`: an exact key wins, then the
|
|
1233
1672
|
* longest matching '*' glob (ties: the first declared). Pure.
|
|
@@ -1243,18 +1682,26 @@ interface IToolDecisionInput {
|
|
|
1243
1682
|
rules?: Record<string, ToolPermission>;
|
|
1244
1683
|
remembered?: ReadonlySet<string>;
|
|
1245
1684
|
builtIn?: boolean;
|
|
1685
|
+
codeExecution?: boolean;
|
|
1686
|
+
mcpSkills?: readonly string[];
|
|
1246
1687
|
}
|
|
1247
1688
|
interface IToolDecision {
|
|
1248
1689
|
permission: ToolPermission;
|
|
1249
|
-
source: 'builtin' | 'remembered' | 'rule' | 'mode';
|
|
1690
|
+
source: 'builtin' | 'remembered' | 'rule' | 'mode' | 'mcp-skill';
|
|
1250
1691
|
rule?: string;
|
|
1251
1692
|
}
|
|
1252
1693
|
/**
|
|
1253
1694
|
* Decide one call. Pure. Order: built-in -> remembered "always allow" ->
|
|
1254
1695
|
* most specific rule -> mode default (autopilot: allow; read-only: allow if
|
|
1255
1696
|
* readOnly else deny; ask-writes: allow if readOnly else ask; ask-all: ask).
|
|
1697
|
+
* Then one rule that only ever tightens: a call that runs code while the run acts on an MCP
|
|
1698
|
+
* server's skill is asked when it would have been allowed - by the mode, a rule or an "always
|
|
1699
|
+
* allow" alike (the Skills extension: no code runs here on a server's skill without a person's
|
|
1700
|
+
* approval). A deny stays a deny.
|
|
1256
1701
|
*/
|
|
1257
1702
|
declare const decideToolPermission: (input: IToolDecisionInput) => IToolDecision;
|
|
1703
|
+
/** How long a question waits for a decision when `toolApproval.timeoutMs` is not set: 5 minutes. */
|
|
1704
|
+
declare const TOOL_APPROVAL_TIMEOUT_MS = 300000;
|
|
1258
1705
|
|
|
1259
1706
|
declare const REPLAY_NOTE = "[not run again: this exact call already succeeded in an earlier attempt at this step, and its effect is in place. Its result then:]";
|
|
1260
1707
|
declare const isReplayedToolOutput: (output: unknown) => boolean;
|
|
@@ -1290,8 +1737,9 @@ declare const addUsage: (a: IUsage, b: IUsage) => IFilledUsage;
|
|
|
1290
1737
|
* OAuth 2.1 for remote MCP servers, from Node.
|
|
1291
1738
|
*
|
|
1292
1739
|
* The MCP SDK owns the protocol - discovery (RFC 9728), dynamic client
|
|
1293
|
-
* registration (RFC 7591) or a client ID metadata document (CIMD)
|
|
1294
|
-
*
|
|
1740
|
+
* registration (RFC 7591) or a client ID metadata document (CIMD) -
|
|
1741
|
+
* automatically or one of them only (`registration`) - PKCE, the code exchange
|
|
1742
|
+
* and the refresh on 401. What it does not own, and what this
|
|
1295
1743
|
* module supplies, is WHERE the resulting tokens live between processes, HOW an
|
|
1296
1744
|
* operator is asked to authorize, and the check of the `iss` parameter on the
|
|
1297
1745
|
* way back (RFC 9207).
|
|
@@ -1339,6 +1787,25 @@ declare class MemoryOAuthStore implements IOAuthStore {
|
|
|
1339
1787
|
set(key: string, value: string): Promise<void>;
|
|
1340
1788
|
delete(key: string): Promise<void>;
|
|
1341
1789
|
}
|
|
1790
|
+
/**
|
|
1791
|
+
* How the OAuth client is registered with a server's authorization server
|
|
1792
|
+
* (`INodeOAuthProviderOptions.registration`):
|
|
1793
|
+
*
|
|
1794
|
+
* - `'auto'` (the default): by the client ID metadata document (CIMD) when the
|
|
1795
|
+
* authorization server advertises `client_id_metadata_document_supported` and
|
|
1796
|
+
* a `clientMetadataUrl` is set, by dynamic client registration (DCR, RFC 7591)
|
|
1797
|
+
* otherwise. A client already in the store is used as it is.
|
|
1798
|
+
* - `'cimd'`: by the metadata document only. Needs `clientMetadataUrl`. An
|
|
1799
|
+
* authorization server that does not advertise support is refused before
|
|
1800
|
+
* anything is sent to its registration endpoint.
|
|
1801
|
+
* - `'dcr'`: by dynamic registration only, even with a `clientMetadataUrl` set:
|
|
1802
|
+
* the SDK is never shown the URL.
|
|
1803
|
+
*
|
|
1804
|
+
* The browser package has the same option, with the same names; change both.
|
|
1805
|
+
*/
|
|
1806
|
+
type McpOAuthRegistration = 'auto' | 'cimd' | 'dcr';
|
|
1807
|
+
/** How a stored client was registered: see {@link NodeOAuthProvider.registrationKind}. */
|
|
1808
|
+
type McpOAuthRegistrationKind = 'cimd' | 'dcr';
|
|
1342
1809
|
interface INodeOAuthProviderOptions {
|
|
1343
1810
|
/** The MCP endpoint being authorized. */
|
|
1344
1811
|
serverUrl: string;
|
|
@@ -1362,9 +1829,20 @@ interface INodeOAuthProviderOptions {
|
|
|
1362
1829
|
* this URL is used as the `client_id` and no dynamic registration is made;
|
|
1363
1830
|
* otherwise registration runs as before. A registration already in the store
|
|
1364
1831
|
* wins over both. Must be https with a non-root path, and the document served
|
|
1365
|
-
* there must list the same `redirect_uris` as `redirectUrl`.
|
|
1832
|
+
* there must list the same `redirect_uris` as `redirectUrl`. With
|
|
1833
|
+
* `registration: 'dcr'` it is never used as the `client_id`.
|
|
1366
1834
|
*/
|
|
1367
1835
|
clientMetadataUrl?: string;
|
|
1836
|
+
/**
|
|
1837
|
+
* How the client is registered: `'auto'` (default; as described for
|
|
1838
|
+
* `clientMetadataUrl`), `'cimd'` (the metadata document only: needs
|
|
1839
|
+
* `clientMetadataUrl`, and an authorization server without support is refused
|
|
1840
|
+
* before any registration request) or `'dcr'` (dynamic registration only).
|
|
1841
|
+
* A stored client of the other kind is not reused: it is forgotten, with the
|
|
1842
|
+
* tokens issued to it, and the operator authorizes again. See
|
|
1843
|
+
* {@link McpOAuthRegistration}.
|
|
1844
|
+
*/
|
|
1845
|
+
registration?: McpOAuthRegistration;
|
|
1368
1846
|
/** Defaults to a 0600 JSON file under ~/.agent. */
|
|
1369
1847
|
store?: IOAuthStore;
|
|
1370
1848
|
/** Treat the access token as expired this many seconds early. Default 30. */
|
|
@@ -1410,20 +1888,65 @@ declare class NodeOAuthProvider implements OAuthClientProvider {
|
|
|
1410
1888
|
private readonly _redirectUrl;
|
|
1411
1889
|
private readonly _clientMetadata;
|
|
1412
1890
|
private readonly _clientMetadataUrl?;
|
|
1891
|
+
private readonly _registration;
|
|
1413
1892
|
private readonly skewMs;
|
|
1414
1893
|
private readonly onAuthorizationUrl?;
|
|
1894
|
+
/** Once per provider: a stored client of the other kind is forgotten (see `settle`). */
|
|
1895
|
+
private settled?;
|
|
1415
1896
|
constructor(opts: INodeOAuthProviderOptions);
|
|
1416
1897
|
get redirectUrl(): string;
|
|
1417
1898
|
get clientMetadata(): OAuthClientMetadata;
|
|
1418
|
-
/**
|
|
1899
|
+
/**
|
|
1900
|
+
* The client ID metadata document URL (CIMD), when one was configured - and
|
|
1901
|
+
* not with `registration: 'dcr'`: the SDK uses this getter to decide, so a
|
|
1902
|
+
* URL it cannot see is a URL it never uses as the `client_id`.
|
|
1903
|
+
*/
|
|
1419
1904
|
get clientMetadataUrl(): string | undefined;
|
|
1905
|
+
/** How this provider registers its client: `'auto'`, `'cimd'` or `'dcr'`. */
|
|
1906
|
+
get registration(): McpOAuthRegistration;
|
|
1420
1907
|
private key;
|
|
1421
1908
|
private readJSON;
|
|
1422
1909
|
state(): Promise<string>;
|
|
1423
1910
|
/** Single-use CSRF check for the value that comes back on the redirect. */
|
|
1424
1911
|
verifyState(returned: string | undefined): Promise<boolean>;
|
|
1912
|
+
/** The stored client, without our stamp, and how it was registered. */
|
|
1913
|
+
private readClient;
|
|
1914
|
+
private kindOf;
|
|
1915
|
+
/**
|
|
1916
|
+
* May this provider use the stored client? Under `'auto'` any; under `'cimd'`
|
|
1917
|
+
* only the configured document itself; under `'dcr'` only one that was not
|
|
1918
|
+
* registered by a document.
|
|
1919
|
+
*/
|
|
1920
|
+
private fits;
|
|
1921
|
+
/** The client and the tokens issued to it go together: a token belongs to a client. */
|
|
1922
|
+
private forgetClient;
|
|
1923
|
+
/**
|
|
1924
|
+
* Under `'cimd'` / `'dcr'`, before the first read of the client or a token: a
|
|
1925
|
+
* stored client of the other kind (registered under another setting) is
|
|
1926
|
+
* forgotten with its tokens, so the setting is never served by the old
|
|
1927
|
+
* client - not even by its access token, which the transport would otherwise
|
|
1928
|
+
* keep sending until it expires. Once per provider (its setting is fixed); a
|
|
1929
|
+
* failure is not remembered.
|
|
1930
|
+
*/
|
|
1931
|
+
private settle;
|
|
1932
|
+
/**
|
|
1933
|
+
* `'cimd'` with no usable client: the SDK is about to choose between the
|
|
1934
|
+
* document and a dynamic registration, by the authorization server metadata
|
|
1935
|
+
* it has just saved (`saveDiscoveryState` comes first). Without support it
|
|
1936
|
+
* would register - so it is stopped HERE, before any request is made, and
|
|
1937
|
+
* what discovery found is forgotten, so the next attempt reads the server's
|
|
1938
|
+
* metadata again (a server that starts supporting CIMD is noticed).
|
|
1939
|
+
*/
|
|
1940
|
+
private assertCimdSupported;
|
|
1425
1941
|
clientInformation(): Promise<OAuthClientInformationMixed | undefined>;
|
|
1426
1942
|
saveClientInformation(info: OAuthClientInformationMixed): Promise<void>;
|
|
1943
|
+
/**
|
|
1944
|
+
* How the stored client was registered: `'cimd'` (its `client_id` is the
|
|
1945
|
+
* client ID metadata document), `'dcr'` (registered dynamically - or saved by
|
|
1946
|
+
* the host), or undefined when there is none this provider would use. Read it
|
|
1947
|
+
* after an authorization to tell the operator which way was taken.
|
|
1948
|
+
*/
|
|
1949
|
+
registrationKind(): Promise<McpOAuthRegistrationKind | undefined>;
|
|
1427
1950
|
tokens(): Promise<OAuthTokens | undefined>;
|
|
1428
1951
|
saveTokens(tokens: OAuthTokens): Promise<void>;
|
|
1429
1952
|
saveCodeVerifier(verifier: string): Promise<void>;
|
|
@@ -1484,34 +2007,6 @@ declare const finishMcpOAuth: (provider: NodeOAuthProvider, callback: {
|
|
|
1484
2007
|
iss?: string;
|
|
1485
2008
|
}, opts?: IOAuthRequestOptions) => Promise<void>;
|
|
1486
2009
|
|
|
1487
|
-
/**
|
|
1488
|
-
* What the MCP connectors of the two agent packages share: how a server's `instructions` reach a
|
|
1489
|
-
* system prompt, and how a tool result's `structuredContent` reaches the model. Pure, no imports.
|
|
1490
|
-
*
|
|
1491
|
-
* This file is a COPY, byte for byte, in `@dudko.dev/agent` (`src/mcp-shared.ts`) and
|
|
1492
|
-
* `@dudko.dev/agent-web` (`src/mcp/shared.ts`): change both. The Node package's
|
|
1493
|
-
* `tests/mcp-shared.test.ts` compares the two files and tests every cap and guard here.
|
|
1494
|
-
*/
|
|
1495
|
-
/** The `instructions` one connected MCP server returned in its `initialize` result. */
|
|
1496
|
-
interface McpServerInstructions {
|
|
1497
|
-
/** The server's name: its key in the host's configuration. */
|
|
1498
|
-
server: string;
|
|
1499
|
-
instructions: string;
|
|
1500
|
-
}
|
|
1501
|
-
/** The most one server's instructions take in a system prompt, in characters. */
|
|
1502
|
-
declare const MCP_INSTRUCTIONS_MAX_CHARS_PER_SERVER = 2000;
|
|
1503
|
-
/** The most all servers' instructions take together, in characters. */
|
|
1504
|
-
declare const MCP_INSTRUCTIONS_MAX_CHARS_TOTAL = 8000;
|
|
1505
|
-
/**
|
|
1506
|
-
* The system-prompt section for the servers' instructions, or '' when no server sent any (the
|
|
1507
|
-
* prompt is then exactly what it was). Each server's text is capped
|
|
1508
|
-
* (MCP_INSTRUCTIONS_MAX_CHARS_PER_SERVER), so is the sum (MCP_INSTRUCTIONS_MAX_CHARS_TOTAL, in
|
|
1509
|
-
* the order given: a server past the total is named as omitted), and every line of it is
|
|
1510
|
-
* prefixed with "| ", so a server cannot write something that reads as a heading of this prompt
|
|
1511
|
-
* or as another server's note.
|
|
1512
|
-
*/
|
|
1513
|
-
declare const renderMcpInstructions: (list: readonly McpServerInstructions[] | undefined) => string;
|
|
1514
|
-
|
|
1515
2010
|
/**
|
|
1516
2011
|
* Enterprise-Managed Authorization for remote MCP servers (the MCP extension
|
|
1517
2012
|
* `io.modelcontextprotocol/enterprise-managed-authorization`, also called Cross
|
|
@@ -2089,5 +2584,5 @@ interface ISubagentToolOptions {
|
|
|
2089
2584
|
*/
|
|
2090
2585
|
declare const createSubagentTool: (opts: ISubagentToolOptions) => Tool;
|
|
2091
2586
|
|
|
2092
|
-
export { DEFAULT_COMPACTION_THRESHOLD_RATIO, DEFAULT_DECISION_CONFIDENCE_THRESHOLD, DEFAULT_DECISION_TIMEOUT_MS, DirSkillStore, ENTERPRISE_MANAGED_AUTHORIZATION_EXTENSION, EgressError, EnterpriseOAuthError, FORGET_SKILL_TOOL, FileOAuthStore, GENERATE_IMAGE_TOOL, GENERATE_SPEECH_TOOL, MCP_INSTRUCTIONS_MAX_CHARS_PER_SERVER, MCP_INSTRUCTIONS_MAX_CHARS_TOTAL, MEDIA_AUDIO_TYPES, MEDIA_DEFAULT_MAX_CALLS, MEDIA_FOLDER, MEDIA_IMAGE_TYPES, MEDIA_MAX_ATTACHED_AUDIO, MEDIA_MAX_AUDIO_INPUT_BYTES, MEDIA_MAX_IMAGE_BYTES, MEDIA_MAX_PROMPT_CHARS, MEDIA_MAX_SPEECH_BYTES, MEDIA_MAX_SPEECH_CHARS, MEDIA_MAX_TRANSCRIPT_CHARS, MEDIA_TIMEOUT_MS, MediaBudgetError, MediaError, MemoryOAuthStore, MemorySkillStore, NodeEnterpriseOAuthProvider, NodeOAuthProvider, PIPELINE_LIMITS, PipelineNodeError, PipelineValidationError, REPLAY_NOTE, RUN_JS_TOOL, SAVE_SKILL_TOOL, SEARCH_API_BASE_URL, SEARCH_DEFAULT_MAX_RESULTS, SEARCH_MAX_QUERY_CHARS, SEARCH_MAX_RESULTS, SEARCH_MAX_SNIPPET_CHARS, SEARCH_MAX_TITLE_CHARS, SEARCH_MAX_TOTAL_CHARS, SEARCH_MAX_URL_CHARS, SEARCH_PROVIDERS, SPAWN_INPUT_SCHEMA, SPAWN_SUBAGENT_TOOL, SUBAGENT_DEFAULTS, SUBAGENT_MAX_DEPTH_LIMIT, SUMMARY_PREFIX, SandboxUnavailableError, SubagentSpawnError, TRANSCRIBE_AUDIO_TOOL, ToolBudgetError, ToolDeniedError, WEB_FETCH_TOOL, WEB_SEARCH_TOOL, acceptMedia, addUsage, adoptSubagentEvent, askDecisionModel, beginMcpOAuth, buildInstructions, buildMediaModelFromStage, buildSearchRequest, checkAuthorizationResponseIssuer, checkEgressUrl, checkLimits, checkRedirect, classifyAddress, compactHistory, createAgent, createEgressTools, createEnterpriseOAuthProvider, createLearning, createMedia, createNodeOAuthProvider, createPipeline, createRunControl, createSafeFetch, createSandboxTool, createSandboxTools, createSearchTools, createSubagentTool, createToolResultClearer, createWebFetchTool, createWebSearchTool, decideToolPermission, decisionModelFromAiSdk, defineSkill, estimateTokens, findSecret, finishMcpOAuth, getCurrentRunId, getCurrentRunSandbox, hostMatches, htmlToText, isReadOnlyTool, isReplayedToolOutput, loadSkillsFromDir, markReadOnly, matchToolRule, mediaUsageOf, mergeProviderOptions, nodeResolver, normalizePipeline, normalizeSkillName, normalizeUsage, parseSearchResponse, parseSkillMarkdown, redactHeaders, renderMcpInstructions, renderPipelineNodeInput, resolveCompaction, resolveDynamicSubagents, resolveEgressPolicy, resolveLimits, resolvePromptCaching, resolveSandboxLimits, resolveThinking, sanitizeSearchResults, searchEgressPolicy, searchTools, sniffMediaType, testPipelineCondition, truncateToolModelOutput, validatePipeline, withRollingBreakpoint, withToolOutputLimit, wrapTranscript };
|
|
2093
|
-
export type { AgentEvent, AgentStage, BudgetKind, DecisionFallbackReason, DecisionPoint, EgressErrorCode, EnterpriseAssertionAlgorithm, EnterpriseAssertionAudience, EnterpriseAssertionType, EnterpriseOAuthHop, EnterpriseOAuthLog, EnterprisePrivateKey, EscalationReason, EventHandler, IAgent, IAgentConfig, IAgentRunOptions, IAgentRunResult, IAgentStageOverride, IAiSdkDecisionOptions, IClearedInfo, ICloseOptions, ICompactHistoryOptions, ICompactHistoryResult, ICompactOptions, ICompactResult, ICompactionConfig, IConversationTurn, IDecisionAnswer, IDecisionCallOptions, IDecisionConfig, IDecisionEvent, IDecisionModel, IDecisionOption, IDecisionOutcome, IDecisionQuestion, IDynamicSubagentsConfig, IEgressPolicy, IEnterpriseIdpOptions, IEnterpriseOAuthProviderOptions, IEscalationConfig, ILearning, ILearningConfig, ILimitBreach, IMcpHttpServerConfig, IMcpServerConfig, IMcpStdioServerConfig, IMedia, IMediaConfig, IMediaFile, IMediaModelSpec, IMediaUsage, INodeOAuthProviderOptions, IOAuthRequestOptions, IOAuthStore, IPersistence, IPlan, IPlanStep, IResolvedAddress, IResolvedDynamicSubagents, IResolvedThinking, IRunFile, IRunSnapshot, ISandboxConfig, ISandboxError, ISandboxLimits, ISandboxResult, ISanitizedSearch, ISaveSkillInput, ISearchConfig, ISearchOptions, ISearchRequest, ISearchResult, ISearchToolsOptions, ISkill, ISkillOrigin, ISkillStore, IStepEscalation, IStepResult, IStepStartInfo, ISubagentProfile, ISubagentToolOptions, ISubagentsConfig, IThinkingConfig, ITokenLimits, IToolApprovalConfig, IToolApprovalRequest, IToolCatalogEntry, IToolDecision, IToolDecisionInput, IToolResultClearing, ITranscription, IUsage, IWebSearchOptions, LogLevel, McpServerInstructions, MediaImageModel, MediaKind, MediaModelKind, MediaSpeechModel, MediaTranscriptionModel, ModelTier, 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, SearchEngine, SearchFreshness, SearchProvider, StepComplexity, SubagentDefaultTools, SubagentInfo, SubagentIsolation, ThinkingLevel, ThinkingSetting, TierReason, TokenLimitKind, ToolApprovalDecision, ToolApprovalMode, ToolPermission, ToolSelectionStrategy, UsagePhase };
|
|
2587
|
+
export { DEFAULT_COMPACTION_THRESHOLD_RATIO, DEFAULT_DECISION_CONFIDENCE_THRESHOLD, DEFAULT_DECISION_TIMEOUT_MS, DirSkillStore, ENTERPRISE_MANAGED_AUTHORIZATION_EXTENSION, EgressError, EnterpriseOAuthError, FORGET_SKILL_TOOL, FileOAuthStore, GENERATE_IMAGE_TOOL, GENERATE_SPEECH_TOOL, MCP_ELICITATION_MAX_PER_RUN, MCP_ELICITATION_MAX_PER_TOOL_CALL, MCP_ELICITATION_TIMEOUT_MS, MCP_INSTRUCTIONS_MAX_CHARS_PER_SERVER, MCP_INSTRUCTIONS_MAX_CHARS_TOTAL, MCP_MODERN_PROTOCOL_VERSION, MCP_SKILLS_EXTENSION, MCP_SKILLS_MAX_PER_SERVER, MCP_SKILLS_MAX_TOTAL, MCP_SKILL_BODY_MAX_CHARS, MCP_SKILL_CONSENTS, MCP_SKILL_CONSENT_DEFAULT, MCP_SKILL_DESCRIPTION_MAX_CHARS, MCP_SKILL_FILE_MAX_CHARS, MCP_SKILL_MAX_RESOURCES, MCP_SKILL_MAX_TOTAL_BYTES, MCP_SKILL_URI_MAX_CHARS, MEDIA_AUDIO_TYPES, MEDIA_DEFAULT_MAX_CALLS, MEDIA_FOLDER, MEDIA_IMAGE_TYPES, MEDIA_MAX_ATTACHED_AUDIO, MEDIA_MAX_AUDIO_INPUT_BYTES, MEDIA_MAX_IMAGE_BYTES, MEDIA_MAX_PROMPT_CHARS, MEDIA_MAX_SPEECH_BYTES, MEDIA_MAX_SPEECH_CHARS, MEDIA_MAX_TRANSCRIPT_CHARS, MEDIA_TIMEOUT_MS, MediaBudgetError, MediaError, MemoryOAuthStore, MemorySkillStore, NodeEnterpriseOAuthProvider, NodeOAuthProvider, PIPELINE_LIMITS, PipelineNodeError, PipelineValidationError, REPLAY_NOTE, RUN_JS_TOOL, SAVE_SKILL_TOOL, SEARCH_API_BASE_URL, SEARCH_DEFAULT_MAX_RESULTS, SEARCH_GOOGLE_DEFAULT_MODEL, SEARCH_GOOGLE_NOTE, SEARCH_MAX_QUERY_CHARS, SEARCH_MAX_RESULTS, SEARCH_MAX_SNIPPET_CHARS, SEARCH_MAX_SUMMARY_CHARS, SEARCH_MAX_TITLE_CHARS, SEARCH_MAX_TOTAL_CHARS, SEARCH_MAX_URL_CHARS, SEARCH_PROVIDERS, SPAWN_INPUT_SCHEMA, SPAWN_SUBAGENT_TOOL, SUBAGENT_DEFAULTS, SUBAGENT_MAX_DEPTH_LIMIT, SUMMARY_PREFIX, SandboxUnavailableError, SubagentSpawnError, TOOL_APPROVAL_TIMEOUT_MS, TRANSCRIBE_AUDIO_TOOL, ToolBudgetError, ToolDeniedError, WEB_FETCH_TOOL, WEB_SEARCH_TOOL, acceptMedia, addUsage, adoptSubagentEvent, askDecisionModel, beginMcpOAuth, buildInstructions, buildMediaModelFromStage, buildSearchRequest, checkAuthorizationResponseIssuer, checkEgressUrl, checkLimits, checkRedirect, classifyAddress, compactHistory, createAgent, createEgressTools, createEnterpriseOAuthProvider, createLearning, createMedia, createNodeOAuthProvider, createPipeline, createRunControl, createSafeFetch, createSandboxTool, createSandboxTools, createSearchTools, createSubagentTool, createToolResultClearer, createWebFetchTool, createWebSearchTool, decideToolPermission, decisionModelFromAiSdk, defineSkill, estimateTokens, findSecret, finishMcpOAuth, getCurrentRunId, getCurrentRunSandbox, hostMatches, htmlToText, isCodeExecutionTool, isReadOnlyTool, isReplayedToolOutput, loadSkillsFromDir, markCodeExecution, markReadOnly, matchToolRule, mcpSkillEntryRefusal, mcpSkillPreamble, mcpSkillUriRefusal, mediaUsageOf, mergeProviderOptions, nodeResolver, normalizeMcpElicitationSchema, normalizePipeline, normalizeSkillName, normalizeUsage, parseSearchResponse, parseSkillMarkdown, redactHeaders, renderMcpInstructions, renderPipelineNodeInput, resolveCompaction, resolveDynamicSubagents, resolveEgressPolicy, resolveLimits, resolvePromptCaching, resolveSandboxLimits, resolveThinking, sanitizeSearchResults, searchEgressPolicy, searchStatusMessage, searchToolResult, searchTools, sniffMediaType, testPipelineCondition, truncateToolModelOutput, validateMcpElicitationContent, validatePipeline, withRollingBreakpoint, withToolOutputLimit, wrapTranscript };
|
|
2588
|
+
export type { AgentEvent, AgentStage, BudgetKind, DecisionFallbackReason, DecisionPoint, EgressErrorCode, EnterpriseAssertionAlgorithm, EnterpriseAssertionAudience, EnterpriseAssertionType, EnterpriseOAuthHop, EnterpriseOAuthLog, EnterprisePrivateKey, EscalationReason, EventHandler, IAgent, IAgentConfig, IAgentRunOptions, IAgentRunResult, IAgentStageOverride, IAiSdkDecisionOptions, IClearedInfo, ICloseOptions, ICompactHistoryOptions, ICompactHistoryResult, ICompactOptions, ICompactResult, ICompactionConfig, IConversationTurn, IDecisionAnswer, IDecisionCallOptions, IDecisionConfig, IDecisionEvent, IDecisionModel, IDecisionOption, IDecisionOutcome, IDecisionQuestion, IDynamicSubagentsConfig, IEgressPolicy, IEnterpriseIdpOptions, IEnterpriseOAuthProviderOptions, IEscalationConfig, ILearning, ILearningConfig, ILimitBreach, IMcpHttpServerConfig, IMcpServerConfig, IMcpSkillOrigin, IMcpStdioServerConfig, IMedia, IMediaConfig, IMediaFile, IMediaModelSpec, IMediaUsage, INodeOAuthProviderOptions, IOAuthRequestOptions, IOAuthStore, IPersistence, IPlan, IPlanStep, IResolvedAddress, IResolvedDynamicSubagents, IResolvedThinking, IRunFile, IRunSnapshot, ISandboxConfig, ISandboxError, ISandboxLimits, ISandboxResult, ISanitizedSearch, ISaveSkillInput, ISearchAnswer, ISearchConfig, ISearchOptions, ISearchRequest, ISearchResult, ISearchToolResult, ISearchToolsOptions, ISearchUsage, ISkill, ISkillOrigin, ISkillStore, IStepEscalation, IStepResult, IStepStartInfo, ISubagentProfile, ISubagentToolOptions, ISubagentsConfig, IThinkingConfig, ITokenLimits, IToolApprovalConfig, IToolApprovalContext, IToolApprovalRequest, IToolCatalogEntry, IToolDecision, IToolDecisionInput, IToolResultClearing, ITranscription, IUsage, IWebSearchOptions, LogLevel, McpElicitationContent, McpElicitationContext, McpElicitationFieldSchema, McpElicitationHandler, McpElicitationOptions, McpElicitationReason, McpElicitationRequest, McpElicitationResult, McpElicitationSchema, McpOAuthRegistration, McpOAuthRegistrationKind, McpProtocolMode, McpServerInstructions, McpServerProtocol, McpSkillConsent, McpSkillConsentView, McpSkillsOptions, McpSkillsSetting, MediaImageModel, MediaKind, MediaModelKind, MediaSpeechModel, MediaTranscriptionModel, ModelTier, 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, SearchEngine, SearchFreshness, SearchProvider, StepComplexity, SubagentDefaultTools, SubagentInfo, SubagentIsolation, ThinkingLevel, ThinkingSetting, TierReason, TokenLimitKind, ToolApprovalDecision, ToolApprovalMode, ToolPermission, ToolSelectionStrategy, UsagePhase };
|