@dudko.dev/agent 0.0.58 → 0.0.60

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
@@ -423,531 +423,450 @@ declare class SandboxUnavailableError extends Error {
423
423
  constructor(message: string);
424
424
  }
425
425
 
426
- declare const GENERATE_IMAGE_TOOL = "generate_image";
427
- declare const GENERATE_SPEECH_TOOL = "generate_speech";
428
- declare const TRANSCRIBE_AUDIO_TOOL = "transcribe_audio";
429
- type MediaKind = 'image' | 'speech' | 'transcription';
430
- declare const MEDIA_DEFAULT_MAX_CALLS = 8;
431
- declare const MEDIA_TIMEOUT_MS = 120000;
432
- declare const MEDIA_MAX_IMAGE_BYTES: number;
433
- declare const MEDIA_MAX_SPEECH_BYTES: number;
434
- declare const MEDIA_MAX_AUDIO_INPUT_BYTES: number;
435
- declare const MEDIA_MAX_PROMPT_CHARS = 4000;
436
- declare const MEDIA_MAX_SPEECH_CHARS = 4000;
437
- declare const MEDIA_MAX_TRANSCRIPT_CHARS = 20000;
438
- declare const MEDIA_MAX_ATTACHED_AUDIO = 4;
439
- declare const MEDIA_MAX_REFERENCE_IMAGES = 4;
440
- declare const MEDIA_MAX_REFERENCE_BYTES: number;
441
- declare const MEDIA_MAX_REFERENCE_TOTAL_BYTES: number;
442
- declare const MEDIA_MAX_REFERENCE_SIDE = 4096;
443
- declare const MEDIA_MAX_REFERENCE_SOURCE_BYTES: number;
444
- declare const MEDIA_MAX_REFERENCE_SOURCE_PIXELS = 200000000;
445
- declare const MEDIA_FIT_TIMEOUT_MS = 30000;
446
- declare const MEDIA_FOLDER = "media";
447
- declare class MediaError extends Error {
448
- constructor(message: string);
449
- toJSON(): string;
450
- }
451
- declare class MediaBudgetError extends MediaError {
452
- constructor(cap: number);
453
- }
454
- declare const MEDIA_IMAGE_TYPES: Readonly<Record<string, string>>;
455
- declare const MEDIA_AUDIO_TYPES: Readonly<Record<string, string>>;
456
- declare const MEDIA_REFERENCE_TYPES: Readonly<Record<string, string>>;
457
- declare const sniffMediaType: (bytes: Uint8Array) => string | undefined;
458
- interface IAcceptedMedia {
459
- mediaType: string;
460
- ext: string;
461
- }
462
- declare const acceptMedia: (family: "image" | "audio", bytes: Uint8Array, maxBytes: number, what: string) => IAcceptedMedia;
463
- interface IImageSize {
464
- width: number;
465
- height: number;
466
- }
467
- declare const imageDimensions: (bytes: Uint8Array) => IImageSize | undefined;
468
- interface IAcceptedReference extends IAcceptedMedia, IImageSize {
469
- }
470
- declare const acceptReference: (bytes: Uint8Array, what: string) => IAcceptedReference;
471
- interface IReferencePicture {
472
- bytes: Uint8Array;
473
- mediaType: string;
474
- width: number;
475
- height: number;
476
- path: string;
477
- }
478
- interface IReferenceBounds {
479
- maxSide: number;
480
- maxBytes: number;
481
- }
482
- interface IFitReferenceOptions {
483
- signal: AbortSignal;
484
- }
485
- interface IFittedReference {
486
- bytes: Uint8Array;
487
- mediaType?: string;
488
- }
489
- type MediaFitReference = (picture: IReferencePicture, bounds: IReferenceBounds, options: IFitReferenceOptions) => Promise<IFittedReference | undefined>;
490
- declare const acceptReferenceSource: (bytes: Uint8Array, what: string) => IAcceptedReference;
491
- interface IReferenceUse {
492
- used: boolean;
493
- count: number;
494
- paths: string[];
495
- fitted?: string[];
496
- }
497
- interface IReferenceResult extends IReferenceUse {
426
+ /**
427
+ * MCP Skills (the `io.modelcontextprotocol/skills` extension, SEP-2640, Beta; written against
428
+ * base revision 2026-07-28): what the two agent packages share about a server's skills. The
429
+ * rules on a server's entries (`mcpSkillEntryRefusal`), the names a skill gets in the agent's
430
+ * catalog (`assignMcpSkillNames`: namespaced by the host's label of the server), the caps
431
+ * (`selectMcpSkills`), the files of a loaded skill the model may read (`resolveMcpSkillFile`),
432
+ * the preamble a skill's text is loaded under, the mark that carries a server's skills on its
433
+ * tools (`markMcpSkills` / `collectMcpSkillSources`), a skill the model names by URI
434
+ * (`mcpSkillUriRefusal`, `resolveMcpSkillServer`: `skills/get` to that one server only), the
435
+ * person's consent before a skill's text enters the model's context (`decideMcpSkillConsent`,
436
+ * `mcpSkillConsentView`) and a directory of a skill (`skillDirectoryOf`, `resolveMcpSkillPath`,
437
+ * `skillDirectoryListing` - for every kind of skill - and, for a server that serves
438
+ * `resources/directory/read`, `compareMcpSkillDirectory`) and, for a server the host trusts with
439
+ * its generated skills (`skills: { dynamic: true }`), the snapshot such a skill is read into
440
+ * before anyone is asked (`startMcpSkillWalk`, `takeMcpSkillWalkListing`,
441
+ * `mcpSkillSnapshotBytesRefusal`, `mcpSkillSnapshotEntry`). Pure, no imports (a digest is
442
+ * computed with the platform's WebCrypto, `globalThis.crypto.subtle`, or a function passed in).
443
+ *
444
+ * A server's skills are third-party text. They reach the model only as knowledge, under
445
+ * `mcpSkillPreamble`, and - unless the host vetted the server (`consent: 'never'`) - only after a
446
+ * person saw them and said yes; nothing here (or anywhere) reads a skill's frontmatter beyond its
447
+ * `name` and `description` - `allowed-tools` included - and a file a skill bundles is read as
448
+ * text, never run.
449
+ *
450
+ * This file is a COPY, byte for byte, in `@dudko.dev/agent` (`src/mcp-skills.ts`) and
451
+ * `@dudko.dev/agent-web` (`src/mcp/skills.ts`): change both. The Node package's
452
+ * `tests/mcp-skills-shared.test.ts` compares the two files and tests every rule and cap here.
453
+ */
454
+ /** The extension's identifier, in the client's and the server's `extensions` capability. */
455
+ declare const MCP_SKILLS_EXTENSION = "io.modelcontextprotocol/skills";
456
+ /** The specification's limits (Limits): files per skill, `SKILL.md` included. */
457
+ declare const MCP_SKILL_MAX_RESOURCES = 512;
458
+ /** The specification's limits (Limits): the sum of `size` over a skill's files, in bytes. */
459
+ declare const MCP_SKILL_MAX_TOTAL_BYTES: number;
460
+ /** The most skills one server puts in the agent's catalog. */
461
+ declare const MCP_SKILLS_MAX_PER_SERVER = 32;
462
+ /** The most skills all servers put in the agent's catalog together. */
463
+ declare const MCP_SKILLS_MAX_TOTAL = 64;
464
+ /** The most a catalog entry (the description and its origin tag) takes, in characters. */
465
+ declare const MCP_SKILL_DESCRIPTION_MAX_CHARS = 300;
466
+ /** The most of a skill's instructions (its `SKILL.md` body) the model is given, in characters. */
467
+ declare const MCP_SKILL_BODY_MAX_CHARS = 16000;
468
+ /** The most of one file of a skill the model is given, in characters. */
469
+ declare const MCP_SKILL_FILE_MAX_CHARS = 32000;
470
+ /**
471
+ * Why the agent does not take a skill entry from a server, or `undefined` when it does. The
472
+ * specification's rules on an entry, checked before anything of the skill is read:
473
+ *
474
+ * - its `uri` is a `SKILL.md` inside a named directory, whose last segment is the skill's
475
+ * frontmatter `name` (Resource Mapping; Frontmatter), and that name follows the Agent Skills
476
+ * naming rules;
477
+ * - a description to show in the catalog;
478
+ * - `resources` is the complete list of its files (Resources): `"dynamic"` content is declined
479
+ * (a host MAY: there is nothing to verify it against, and a consent could not bind to its
480
+ * content) - unless `options.dynamic` (the server's `skills: { dynamic: true }`: the host
481
+ * trusts that server with its generated skills, which are then read into a snapshot before
482
+ * anyone is asked, see {@link mcpSkillSnapshotEntry}); anything else is invalid;
483
+ * - every file is `SKILL.md` or a file inside the skill's directory, listed once, with a
484
+ * `sha256:` digest and a byte size, and `SKILL.md` is listed;
485
+ * - at most {@link MCP_SKILL_MAX_RESOURCES} files and {@link MCP_SKILL_MAX_TOTAL_BYTES} bytes
486
+ * (Limits: "both limits are checkable from the entry alone"; a generated skill's are counted
487
+ * on what its snapshot reads).
488
+ */
489
+ declare const mcpSkillEntryRefusal: (entry: unknown, options?: {
490
+ dynamic?: boolean;
491
+ }) => string | undefined;
492
+ /**
493
+ * How a skill of a server is introduced wherever its text is shown to the model (its
494
+ * instructions, and each file of it): third-party knowledge that cannot change the rules. The
495
+ * wording is the guard.
496
+ */
497
+ declare const mcpSkillPreamble: (server: string, uri: string) => string;
498
+ /**
499
+ * The most entries of one `resources/directory/read` answer looked at: the specification's 512
500
+ * files per skill, and room for the directories among them. The rest are not looked at.
501
+ */
502
+ declare const MCP_SKILL_DIRECTORY_ENTRIES_MAX: number;
503
+ /** What `read_skill_file` answers for a directory of a skill (every path inside the skill). */
504
+ interface SkillDirectoryListing {
505
+ /** The skill's name in the catalog. */
506
+ name: string;
507
+ /** The directory: `.` for the skill's root, else its path inside the skill. */
508
+ directory: string;
509
+ /** Its files (each read with `read_skill_file`), sorted. */
510
+ files: string[];
511
+ /** Its subdirectories (each listed the same way), sorted. */
512
+ directories: string[];
513
+ /** How many more it holds than the two lists show ({@link MCP_SKILL_FILES_SHOWN_MAX} in all). */
514
+ more?: number;
515
+ /** Shown above, but no longer listed by the skill's MCP server: a read of them will fail. */
516
+ notServed?: string[];
517
+ /** The skill changed on its MCP server since it was loaded ({@link mcpSkillDirectoryNote}). */
498
518
  note?: string;
499
519
  }
500
- interface IMediaUsage {
501
- mediaCalls: number;
502
- imagesGenerated: number;
503
- speechCharacters: number;
504
- transcriptionSeconds: number;
520
+ /** The longest URI `load_skill` sends to a server, in characters. */
521
+ declare const MCP_SKILL_URI_MAX_CHARS = 512;
522
+ /**
523
+ * Why `load_skill` does not ask a server for the skill at `uri`, or `undefined` when it may. Checked
524
+ * before any request: a `skill://` URI - the conventional scheme; a URI the MODEL hands over (it
525
+ * read it in third-party text) is taken in no other, though a listing may use any - of the
526
+ * `SKILL.md` of a named directory, whose last segment is a skill name, within
527
+ * {@link MCP_SKILL_URI_MAX_CHARS}, with nothing invisible and no space in it.
528
+ */
529
+ declare const mcpSkillUriRefusal: (uri: unknown) => string | undefined;
530
+ /** When a person is asked before a server's skill enters the model's context. */
531
+ type McpSkillConsent = 'ask' | 'once-per-skill' | 'never';
532
+ /** Every value of {@link McpSkillConsent}. */
533
+ declare const MCP_SKILL_CONSENTS: readonly McpSkillConsent[];
534
+ /**
535
+ * The default: asked the first time a skill would enter the context in the agent's life, and again
536
+ * only when its entry changed - often enough that every text a person did not see is shown, seldom
537
+ * enough that a yes still means something.
538
+ */
539
+ declare const MCP_SKILL_CONSENT_DEFAULT: McpSkillConsent;
540
+ /** `skills` on a server's config, as an object. */
541
+ interface McpSkillsOptions {
542
+ /**
543
+ * `'once-per-skill'` (default): a person is asked the first time each skill would enter the
544
+ * model's context, and a yes holds for the agent's life while the skill's entry is the same;
545
+ * `'ask'`: asked in every run that loads it; `'never'`: never asked - for a server the host
546
+ * vetted (its skills load as soon as the model asks). Whatever the approval mode says.
547
+ */
548
+ consent?: McpSkillConsent;
549
+ /**
550
+ * `true`: also take this server's GENERATED skills (`"resources": "dynamic"` - no checksums;
551
+ * declined by default). When one would enter the model's context, the agent first reads all
552
+ * of it - `SKILL.md` and, if the server serves `resources/directory/read`, every file its
553
+ * directories list, within the specification's limits - computes each file's digest itself,
554
+ * and holds that copy in memory: the person approves that copy (the consent binds to its
555
+ * digests), and the model is given only that copy, never a later read. Per server, for a
556
+ * server you trust with this; there is no agent-wide switch.
557
+ */
558
+ dynamic?: boolean;
505
559
  }
506
- declare const mediaUsageOf: (usage: Partial<IMediaUsage> | undefined) => IMediaUsage | undefined;
507
- interface ITranscriptBlock {
560
+ /** `skills` on a server's config: `true`, or options (on, with them); `false` / absent: off. */
561
+ type McpSkillsSetting = boolean | McpSkillsOptions;
562
+ /**
563
+ * What a person is shown before a server's skill enters the model's context - the request's
564
+ * `skill` (the core's `tool.approval-requested` event). Every string is the SERVER's, cleaned:
565
+ * show it as plain text, captioned as the server's.
566
+ */
567
+ interface McpSkillConsentView {
568
+ /** The host's label of the server that serves it. */
569
+ server: string;
570
+ /** Its name in the agent's catalog (`<server>/<skill>`). */
508
571
  name: string;
509
- text: string;
510
- language?: string;
511
- durationInSeconds?: number;
572
+ /** Its frontmatter name. */
573
+ skill: string;
574
+ /** The URI of its `SKILL.md` (cleaned, at most 200 characters). */
575
+ uri: string;
576
+ /** The description from its entry, on one line, at most {@link MCP_SKILL_DESCRIPTION_MAX_CHARS}. */
577
+ description: string;
578
+ /** Bytes of its `SKILL.md`, and of all its files. */
579
+ size: number;
580
+ totalSize: number;
581
+ /** Its other files, by path (at most {@link MCP_SKILL_FILES_SHOWN_MAX}), and how many there are. */
582
+ files: string[];
583
+ fileCount: number;
584
+ /** Its instructions exactly as the model would read them ({@link mcpSkillBodyPreview}). */
585
+ body: string;
586
+ /** Named by URI (`skills/get`), not in the server's listing. */
587
+ byUri?: true;
588
+ /** It sits inside this skill of the same server, whose approval does not cover it. */
589
+ nestedIn?: string;
590
+ /**
591
+ * Generated by the server (`"resources": "dynamic"`, taken with `skills: { dynamic: true }`):
592
+ * there are no checksums. The size, the files and the text are those of the copy the agent just
593
+ * read (its snapshot), and only that copy is used - say so.
594
+ */
595
+ dynamic?: true;
596
+ /**
597
+ * (with `dynamic`) The server cannot list the skill's files (no `resources/directory/read`): the
598
+ * copy is its `SKILL.md` alone, and no other file of it can be read.
599
+ */
600
+ noFileListing?: true;
601
+ /** Asked for this run only (`'ask'`) or, on a yes, for the agent's life (`'once-per-skill'`). */
602
+ consent: Exclude<McpSkillConsent, 'never'>;
512
603
  }
513
- declare const wrapTranscript: (block: ITranscriptBlock) => string;
604
+ /**
605
+ * The most directories one snapshot reads (`resources/directory/read`, the skill's root
606
+ * included). One read is one directory, its pages walked by the SDK (bounded by its own page cap).
607
+ */
608
+ declare const MCP_SKILL_SNAPSHOT_MAX_DIRECTORIES = 64;
609
+ /** The deepest directory of a skill a snapshot reads: its root is 0, `templates` 1, ... */
610
+ declare const MCP_SKILL_SNAPSHOT_MAX_DEPTH = 8;
611
+ /** The most bytes the snapshots of one agent hold in memory together. */
612
+ declare const MCP_SKILL_SNAPSHOTS_MAX_BYTES: number;
514
613
 
515
- type IMediaModelSpec = IAgentStageOverride & {
516
- model: string;
517
- };
518
- type MediaImageModel = Exclude<ImageModel, string>;
519
- type MediaSpeechModel = Exclude<SpeechModel, string>;
520
- type MediaTranscriptionModel = Exclude<TranscriptionModel, string>;
521
- interface IMediaConfig {
522
- imageModel?: MediaImageModel | IMediaModelSpec;
523
- imageInputs?: boolean;
524
- fitReference?: MediaFitReference;
525
- fitTimeoutMs?: number;
526
- speechModel?: MediaSpeechModel | IMediaModelSpec;
527
- transcriptionModel?: MediaTranscriptionModel | IMediaModelSpec;
528
- maxCalls?: number;
529
- timeoutMs?: number;
530
- dir?: string;
531
- voice?: string;
532
- speechFormat?: string;
533
- }
534
- interface IRunFile {
535
- data: string | Uint8Array;
536
- mediaType?: string;
537
- name?: string;
538
- }
539
- interface IMediaFile {
540
- path: string;
541
- mediaType: string;
542
- bytes: number;
543
- references?: IReferenceResult;
614
+ /**
615
+ * Thrown from inside a tool's execute when the call was not approved. The AI
616
+ * SDK records it as a failed tool call (`ok: false`), so the replanner sees
617
+ * it; `toJSON` keeps the message when a trace is serialised.
618
+ */
619
+ declare class ToolDeniedError extends Error {
620
+ readonly reason?: string;
621
+ constructor(reason?: string);
622
+ toJSON(): string;
544
623
  }
545
- interface ITranscription {
546
- path: string;
547
- text: string;
548
- language?: string;
549
- durationInSeconds?: number;
550
- truncated?: true;
551
- untrusted: true;
624
+ declare const markReadOnly: <T extends object>(tool: T, readOnly?: boolean) => T;
625
+ declare const isReadOnlyTool: (tool: unknown) => boolean;
626
+ declare const markCodeExecution: <T extends object>(tool: T, codeExecution?: boolean) => T;
627
+ declare const isCodeExecutionTool: (tool: unknown) => boolean;
628
+ /**
629
+ * The most specific rule matching `name`: an exact key wins, then the
630
+ * longest matching '*' glob (ties: the first declared). Pure.
631
+ */
632
+ declare const matchToolRule: (rules: Record<string, ToolPermission> | undefined, name: string) => {
633
+ pattern: string;
634
+ permission: ToolPermission;
635
+ } | undefined;
636
+ interface IToolDecisionInput {
637
+ name: string;
638
+ readOnly: boolean;
639
+ mode: ToolApprovalMode;
640
+ rules?: Record<string, ToolPermission>;
641
+ remembered?: ReadonlySet<string>;
642
+ builtIn?: boolean;
643
+ codeExecution?: boolean;
644
+ mcpSkills?: readonly string[];
552
645
  }
553
- interface IMedia {
554
- tools: ToolSet;
555
- attach: (input: string, files: IRunFile[], signal?: AbortSignal) => Promise<string>;
646
+ interface IToolDecision {
647
+ permission: ToolPermission;
648
+ source: 'builtin' | 'remembered' | 'rule' | 'mode' | 'mcp-skill';
649
+ rule?: string;
556
650
  }
557
- declare const createMedia: (config: IAgentConfig) => Promise<IMedia | undefined>;
651
+ /**
652
+ * Decide one call. Pure. Order: built-in -> remembered "always allow" ->
653
+ * most specific rule -> mode default (autopilot: allow; read-only: allow if
654
+ * readOnly else deny; ask-writes: allow if readOnly else ask; ask-all: ask).
655
+ * Then one rule that only ever tightens: a call that runs code while the run acts on an MCP
656
+ * server's skill is asked when it would have been allowed - by the mode, a rule or an "always
657
+ * allow" alike (the Skills extension: no code runs here on a server's skill without a person's
658
+ * approval). A deny stays a deny.
659
+ */
660
+ declare const decideToolPermission: (input: IToolDecisionInput) => IToolDecision;
661
+ /** How long a question waits for a decision when `toolApproval.timeoutMs` is not set: 5 minutes. */
662
+ declare const TOOL_APPROVAL_TIMEOUT_MS = 300000;
558
663
 
664
+ declare const ASK_USER_TOOL = "ask_user";
665
+ /** How long one question waits for the person, by default: a human is reading it. */
666
+ declare const ASK_USER_TIMEOUT_MS = 300000;
559
667
  /**
560
- * MCP elicitation, the part the two agent packages share: a server asks the user for input in
561
- * the middle of a tool call, the HOST answers through a callback, and the call goes on. Pure, no
562
- * imports: the limits, what a request must look like before a host sees it, what an answer must
563
- * look like before a server sees it, the one function that asks, and the two ways a tool call
564
- * with questions is driven (`elicitation/create` requests on the 2025 revisions, `input_required`
565
- * results on 2026-07-28).
566
- *
567
- * A consent boundary. The server's text is third-party data: cleaned and capped here, shown only
568
- * to the host's callback and in the `mcp.elicitation-requested` event, never put into a prompt.
569
- * The answer goes to the server that asked and nowhere else: nothing in this file logs, emits or
570
- * returns a value the user entered - events and errors carry field NAMES only.
571
- *
572
- * This file is a COPY, byte for byte, in `@dudko.dev/agent` (`src/mcp-elicitation.ts`) and
573
- * `@dudko.dev/agent-web` (`src/mcp/elicitation.ts`): change both. The Node package's
574
- * `tests/mcp-elicitation-shared.test.ts` compares the two files and tests every guard here; each
575
- * needs a mutation check.
668
+ * The longest wait a timer holds (2^31 - 1 ms, about 24.8 days). `setTimeout` fires a longer one -
669
+ * Infinity included - after about 1 ms, so a `timeoutMs` past it is taken as no limit at all.
576
670
  */
577
- /** How long one question waits for the host's answer, by default: a human is reading it. */
578
- declare const MCP_ELICITATION_TIMEOUT_MS = 300000;
579
- /** The most questions one tool call may ask, by default. */
580
- declare const MCP_ELICITATION_MAX_PER_TOOL_CALL = 5;
581
- /** The most questions one run may be asked, by default (its helpers' calls included). */
582
- declare const MCP_ELICITATION_MAX_PER_RUN = 20;
583
- /** One field of a form: the flat subset of JSON Schema the specification allows, nothing else. */
584
- interface McpElicitationFieldSchema {
585
- type: 'string' | 'number' | 'integer' | 'boolean' | 'array';
586
- title?: string;
671
+ declare const ASK_USER_TIMEOUT_MAX_MS = 2147483647;
672
+ /** The most questions one run may ask, by default (its helpers' and subagents' included). */
673
+ declare const ASK_USER_MAX_PER_RUN = 3;
674
+ /** A question offers at least this many options... */
675
+ declare const ASK_USER_MIN_OPTIONS = 2;
676
+ /** ...and at most this many. */
677
+ declare const ASK_USER_MAX_OPTIONS = 6;
678
+ /** The longest question, in characters (after cleaning). */
679
+ declare const ASK_USER_QUESTION_MAX_CHARS = 500;
680
+ /** The longest option label. */
681
+ declare const ASK_USER_LABEL_MAX_CHARS = 80;
682
+ /** The longest option description. */
683
+ declare const ASK_USER_DESCRIPTION_MAX_CHARS = 200;
684
+ /** The most of a person's own words (`{ other }`) the model is given; the rest is cut. */
685
+ declare const ASK_USER_OTHER_MAX_CHARS = 2000;
686
+ /** One option of a question, as the person is shown it. Both strings are the MODEL's, cleaned. */
687
+ interface AskUserOption {
688
+ label: string;
587
689
  description?: string;
588
- default?: string | number | boolean | string[];
589
- /** string */
590
- minLength?: number;
591
- maxLength?: number;
592
- format?: 'email' | 'uri' | 'date' | 'date-time';
593
- /** string: single-select, plain (`enumNames`: the older titled form). */
594
- enum?: string[];
595
- enumNames?: string[];
596
- /** string: single-select with titles. */
597
- oneOf?: {
598
- const: string;
599
- title: string;
600
- }[];
601
- /** number / integer */
602
- minimum?: number;
603
- maximum?: number;
604
- /** array: multi-select. */
605
- minItems?: number;
606
- maxItems?: number;
607
- items?: {
608
- type?: 'string';
609
- enum?: string[];
610
- anyOf?: {
611
- const: string;
612
- title: string;
613
- }[];
614
- };
615
690
  }
616
- /** The form a server asks for, as a host is shown it: checked, cleaned and capped. */
617
- interface McpElicitationSchema {
618
- type: 'object';
619
- properties: Record<string, McpElicitationFieldSchema>;
620
- required?: string[];
691
+ /** A question as checked and cleaned: what a host shows and an event carries. */
692
+ interface AskUserQuestion {
693
+ question: string;
694
+ options: AskUserOption[];
695
+ /** The person may pick several options. */
696
+ multiple: boolean;
697
+ /** The person may answer in their own words instead of picking. */
698
+ allowOther: boolean;
621
699
  }
622
- /** What the host's callback is given. Every string in it is third-party text. */
623
- interface McpElicitationRequest {
700
+ /** What the host's `onQuestion` is given. Every string in it is the model's text, cleaned. */
701
+ interface AskUserRequest<TStep = unknown> extends AskUserQuestion {
624
702
  /** Unique per question; the same id is in the two events. */
625
703
  id: string;
626
- /** The server that asks: its key in the host's configuration. */
627
- server: string;
628
- /** The tool call during which it asks: the tool's name as the model called it. */
629
- tool: string;
630
- mode: 'form' | 'url';
631
- /** The server's words, cleaned and capped (MCP_ELICITATION_MESSAGE_MAX_CHARS). */
632
- message: string;
633
- /** Form mode: the fields to fill in. */
634
- requestedSchema?: McpElicitationSchema;
704
+ /** The plan step whose tool call asks. */
705
+ step?: TStep;
706
+ runId?: string;
707
+ /** Set when a helper or a subagent of the run asks, not the run itself: its id and depth. */
708
+ subagent?: {
709
+ id: string;
710
+ depth: number;
711
+ };
712
+ }
713
+ /**
714
+ * The person's answer: the labels they picked (exactly as offered; one unless `multiple`), their
715
+ * own words (only when `allowOther`), or that they would rather not answer.
716
+ */
717
+ type AskUserAnswer = {
718
+ choice: string[];
719
+ } | {
720
+ other: string;
721
+ } | {
722
+ declined: true;
723
+ };
724
+ interface AskUserContext {
635
725
  /**
636
- * URL mode: the link the server wants the user to open. It is only handed over: nothing in
637
- * these packages fetches or opens it. https, or http on a loopback host.
726
+ * Aborted when the question ends WITHOUT the host's answer: no answer within `timeoutMs`
727
+ * (`signal.reason` is an Error named 'TimeoutError'), the run was stopped, or the handler
728
+ * failed. Take the prompt down then: an answer given later is ignored. Never aborted once the
729
+ * host has answered.
638
730
  */
639
- url?: string;
640
- /** URL mode on the 2025 revisions: the server's id for this interaction. */
641
- elicitationId?: string;
642
- runId?: string;
643
- /** Set when a helper the model started is the one whose call asks (`elicitation.subagents`). */
731
+ signal: AbortSignal;
732
+ }
733
+ /** How a question ended. `automatic`: nobody decided (a time limit, a stop, a failed handler). */
734
+ type AskUserAction = 'choice' | 'other' | 'declined' | 'timeout' | 'stopped';
735
+ /** Why a question was closed as `declined` without the person deciding. */
736
+ type AskUserReason = 'handler-error' | 'invalid-answer' | 'cannot-park';
737
+ /** The two events of a question. Neither ever carries the person's own words. */
738
+ type AskUserEvent<TStep = unknown> = {
739
+ type: 'user.question-asked';
740
+ id: string;
741
+ question: string;
742
+ options: AskUserOption[];
743
+ multiple: boolean;
744
+ allowOther: boolean;
745
+ step?: TStep;
644
746
  subagent?: {
645
747
  id: string;
646
748
  depth: number;
647
749
  };
750
+ } | {
751
+ type: 'user.question-answered';
752
+ id: string;
753
+ action: AskUserAction;
754
+ /** true when nobody decided: a time limit, a stop, a failed handler, an unusable answer. */
755
+ automatic: boolean;
756
+ /** Action 'choice': the labels picked. Never the text of an `other` answer. */
757
+ choice?: string[];
758
+ /** Action 'declined' with `automatic`: why. */
759
+ reason?: AskUserReason;
760
+ };
761
+ /** A bad `ask_user` input: the tool call fails with this message, which says what to fix. */
762
+ declare class AskUserInputError extends Error {
763
+ constructor(message: string);
764
+ toJSON(): string;
648
765
  }
649
- type McpElicitationContent = Record<string, string | number | boolean | string[]>;
766
+ /** The model's text as a person may be shown it: a string, invisible characters removed, trimmed. */
767
+ declare const cleanAskUserText: (raw: unknown, oneLine?: boolean) => string;
650
768
  /**
651
- * The host's answer. `accept` carries the form's values (form mode) or nothing (URL mode: it
652
- * says the user agreed to open the link); `decline` is a no; `cancel` is "dismissed".
769
+ * Check and clean the model's `ask_user` arguments: 2-6 options, no two labels alike (letter case
770
+ * and spaces aside), each label 1-80 characters, a description at most 200, a question of 1-500 -
771
+ * all measured after cleaning. An option may be given as a bare string (its label). Throws
772
+ * {@link AskUserInputError} with what to fix.
653
773
  */
654
- type McpElicitationResult = {
655
- action: 'accept';
656
- content?: McpElicitationContent;
774
+ declare const checkAskUserInput: (raw: unknown) => AskUserQuestion;
775
+ /** An answer as checked: what the model is told. */
776
+ type AskUserCheckedAnswer = {
777
+ kind: 'choice';
778
+ choice: string[];
657
779
  } | {
658
- action: 'decline';
780
+ kind: 'other';
781
+ text: string;
659
782
  } | {
660
- action: 'cancel';
783
+ kind: 'declined';
661
784
  };
662
- interface McpElicitationContext {
663
- /** Aborted when the answer is no longer wanted: the run stopped, or the time ran out. */
664
- signal: AbortSignal;
665
- }
666
- /** `onElicitation`: the host decides, never the model. */
667
- type McpElicitationHandler = (request: McpElicitationRequest, ctx: McpElicitationContext) => McpElicitationResult | Promise<McpElicitationResult>;
668
- /** The `elicitation` settings beside `onElicitation`. */
669
- interface McpElicitationOptions {
670
- /**
671
- * How long one question waits for an answer. Default 300 000. `0` or `Infinity` = no limit of
672
- * its own (the question waits until the run is stopped), and so is a value above 2^31 - 1 (about
673
- * 24.8 days, the most a timer holds). Negative or NaN: a configuration error.
674
- */
675
- timeoutMs?: number;
676
- /** Questions one tool call may ask. Default 5. */
677
- maxPerToolCall?: number;
678
- /** Questions one run may be asked. Default 20. */
679
- maxPerRun?: number;
680
- /** Also accept URL mode (a link to open). Default false: only forms are declared. */
681
- url?: boolean;
682
- /**
683
- * Let a tool call made by a helper (a subagent) ask the user too. Default false: such a
684
- * question is cancelled without the callback being called.
685
- */
686
- subagents?: boolean;
687
- }
688
- /** Why a question was answered without the host deciding. */
689
- 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';
690
- type Checked<T> = {
785
+ /**
786
+ * Check the host's answer against the question: exactly one of `choice` (labels that were
787
+ * offered, no repeats, one unless `multiple`), `other` (a non-empty text, only when `allowOther`;
788
+ * cleaned and cut at {@link ASK_USER_OTHER_MAX_CHARS}) or `declined: true`. Anything else is not
789
+ * an answer.
790
+ */
791
+ declare const checkAskUserAnswer: (q: AskUserQuestion, raw: unknown) => {
691
792
  ok: true;
692
- value: T;
793
+ value: AskUserCheckedAnswer;
693
794
  } | {
694
795
  ok: false;
695
796
  reason: string;
696
797
  };
697
- /**
698
- * The form a server asked for, reduced to what the specification allows a form to be: a flat
699
- * object of strings, numbers, booleans and selects. Anything else - a nested object, a list of
700
- * objects, a type union, an unknown format, too many fields or options, a name that could not
701
- * be sent back verbatim - is refused with a reason (the caller declines the request). Keywords
702
- * outside the subset are dropped; titles and descriptions are cleaned and capped.
703
- */
704
- declare const normalizeMcpElicitationSchema: (raw: unknown) => Checked<McpElicitationSchema>;
705
- /**
706
- * An accepted form, checked against the schema it answers: every value of the type and within
707
- * the limits its field states, every required field there, and NO field the form did not ask
708
- * for (what the server did not request is not sent to it). The result is a fresh object holding
709
- * only the form's own fields. A refusal names the field and the rule, never the value.
710
- */
711
- declare const validateMcpElicitationContent: (schema: McpElicitationSchema, content: unknown) => Checked<McpElicitationContent>;
712
798
 
713
- /**
714
- * What the MCP connectors of the two agent packages share: how a server's `instructions` reach a
715
- * system prompt, how a tool result's `structuredContent` reaches the model, and what the
716
- * per-server `protocol` option means. Pure, no imports.
717
- *
718
- * This file is a COPY, byte for byte, in `@dudko.dev/agent` (`src/mcp-shared.ts`) and
719
- * `@dudko.dev/agent-web` (`src/mcp/shared.ts`): change both. The Node package's
720
- * `tests/mcp-shared.test.ts` compares the two files and tests every cap and guard here.
721
- */
722
- /** The `instructions` one connected MCP server returned in its `initialize` result. */
723
- interface McpServerInstructions {
724
- /** The server's name: its key in the host's configuration. */
725
- server: string;
726
- instructions: string;
727
- }
728
- /** The most one server's instructions take in a system prompt, in characters. */
729
- declare const MCP_INSTRUCTIONS_MAX_CHARS_PER_SERVER = 2000;
730
- /** The most all servers' instructions take together, in characters. */
731
- declare const MCP_INSTRUCTIONS_MAX_CHARS_TOTAL = 8000;
732
- /**
733
- * The system-prompt section for the servers' instructions, or '' when no server sent any (the
734
- * prompt is then exactly what it was). Each server's text is capped
735
- * (MCP_INSTRUCTIONS_MAX_CHARS_PER_SERVER), so is the sum (MCP_INSTRUCTIONS_MAX_CHARS_TOTAL, in
736
- * the order given: a server past the total is named as omitted), and every line of it is
737
- * prefixed with "| ", so a server cannot write something that reads as a heading of this prompt
738
- * or as another server's note.
739
- */
740
- declare const renderMcpInstructions: (list: readonly McpServerInstructions[] | undefined) => string;
741
- /**
742
- * Which revisions of the protocol a connection to one server may use (the server config's
743
- * `protocol`):
744
- *
745
- * - `'legacy'` (default): the 2025 revisions, the `initialize` handshake. Nothing of the 2026
746
- * revision is sent.
747
- * - `'auto'`: ask first (`server/discover`); a server that answers with 2026-07-28 is spoken to
748
- * that way, any other is given the 2025 handshake. Decided once, at connect.
749
- * - `'modern'`: 2026-07-28 only. A server that does not offer it fails the connect.
750
- */
751
- type McpProtocolMode = 'legacy' | 'auto' | 'modern';
752
- /** The revision `protocol: 'modern'` pins: the one this connector is tested against. */
753
- declare const MCP_MODERN_PROTOCOL_VERSION = "2026-07-28";
754
- /** What a connection negotiated with one server. */
755
- interface McpServerProtocol {
756
- /** The server's name: its key in the host's configuration. */
757
- server: string;
758
- /** The protocol revision in use, e.g. `2025-11-25` or `2026-07-28`. */
759
- version: string;
760
- /** `modern` from 2026-07-28 on (stateless, `server/discover`), `legacy` before. */
761
- era: 'legacy' | 'modern';
799
+ declare const SPAWN_SUBAGENT_TOOL = "spawn_subagent";
800
+ type SubagentDefaultTools = 'read-only' | 'all';
801
+ interface IDynamicSubagentsConfig {
802
+ maxDepth?: number;
803
+ maxChildren?: number;
804
+ maxConcurrent?: number;
805
+ budgetShare?: number;
806
+ minTokens?: number;
807
+ timeoutMs?: number;
808
+ defaultTools?: SubagentDefaultTools;
762
809
  }
763
-
764
- /**
765
- * MCP Skills (the `io.modelcontextprotocol/skills` extension, SEP-2640, Beta; written against
766
- * base revision 2026-07-28): what the two agent packages share about a server's skills. The
767
- * rules on a server's entries (`mcpSkillEntryRefusal`), the names a skill gets in the agent's
768
- * catalog (`assignMcpSkillNames`: namespaced by the host's label of the server), the caps
769
- * (`selectMcpSkills`), the files of a loaded skill the model may read (`resolveMcpSkillFile`),
770
- * the preamble a skill's text is loaded under, the mark that carries a server's skills on its
771
- * tools (`markMcpSkills` / `collectMcpSkillSources`), a skill the model names by URI
772
- * (`mcpSkillUriRefusal`, `resolveMcpSkillServer`: `skills/get` to that one server only), the
773
- * person's consent before a skill's text enters the model's context (`decideMcpSkillConsent`,
774
- * `mcpSkillConsentView`) and a directory of a skill (`skillDirectoryOf`, `resolveMcpSkillPath`,
775
- * `skillDirectoryListing` - for every kind of skill - and, for a server that serves
776
- * `resources/directory/read`, `compareMcpSkillDirectory`) and, for a server the host trusts with
777
- * its generated skills (`skills: { dynamic: true }`), the snapshot such a skill is read into
778
- * before anyone is asked (`startMcpSkillWalk`, `takeMcpSkillWalkListing`,
779
- * `mcpSkillSnapshotBytesRefusal`, `mcpSkillSnapshotEntry`). Pure, no imports (a digest is
780
- * computed with the platform's WebCrypto, `globalThis.crypto.subtle`, or a function passed in).
781
- *
782
- * A server's skills are third-party text. They reach the model only as knowledge, under
783
- * `mcpSkillPreamble`, and - unless the host vetted the server (`consent: 'never'`) - only after a
784
- * person saw them and said yes; nothing here (or anywhere) reads a skill's frontmatter beyond its
785
- * `name` and `description` - `allowed-tools` included - and a file a skill bundles is read as
786
- * text, never run.
787
- *
788
- * This file is a COPY, byte for byte, in `@dudko.dev/agent` (`src/mcp-skills.ts`) and
789
- * `@dudko.dev/agent-web` (`src/mcp/skills.ts`): change both. The Node package's
790
- * `tests/mcp-skills-shared.test.ts` compares the two files and tests every rule and cap here.
791
- */
792
- /** The extension's identifier, in the client's and the server's `extensions` capability. */
793
- declare const MCP_SKILLS_EXTENSION = "io.modelcontextprotocol/skills";
794
- /** The specification's limits (Limits): files per skill, `SKILL.md` included. */
795
- declare const MCP_SKILL_MAX_RESOURCES = 512;
796
- /** The specification's limits (Limits): the sum of `size` over a skill's files, in bytes. */
797
- declare const MCP_SKILL_MAX_TOTAL_BYTES: number;
798
- /** The most skills one server puts in the agent's catalog. */
799
- declare const MCP_SKILLS_MAX_PER_SERVER = 32;
800
- /** The most skills all servers put in the agent's catalog together. */
801
- declare const MCP_SKILLS_MAX_TOTAL = 64;
802
- /** The most a catalog entry (the description and its origin tag) takes, in characters. */
803
- declare const MCP_SKILL_DESCRIPTION_MAX_CHARS = 300;
804
- /** The most of a skill's instructions (its `SKILL.md` body) the model is given, in characters. */
805
- declare const MCP_SKILL_BODY_MAX_CHARS = 16000;
806
- /** The most of one file of a skill the model is given, in characters. */
807
- declare const MCP_SKILL_FILE_MAX_CHARS = 32000;
808
- /**
809
- * Why the agent does not take a skill entry from a server, or `undefined` when it does. The
810
- * specification's rules on an entry, checked before anything of the skill is read:
811
- *
812
- * - its `uri` is a `SKILL.md` inside a named directory, whose last segment is the skill's
813
- * frontmatter `name` (Resource Mapping; Frontmatter), and that name follows the Agent Skills
814
- * naming rules;
815
- * - a description to show in the catalog;
816
- * - `resources` is the complete list of its files (Resources): `"dynamic"` content is declined
817
- * (a host MAY: there is nothing to verify it against, and a consent could not bind to its
818
- * content) - unless `options.dynamic` (the server's `skills: { dynamic: true }`: the host
819
- * trusts that server with its generated skills, which are then read into a snapshot before
820
- * anyone is asked, see {@link mcpSkillSnapshotEntry}); anything else is invalid;
821
- * - every file is `SKILL.md` or a file inside the skill's directory, listed once, with a
822
- * `sha256:` digest and a byte size, and `SKILL.md` is listed;
823
- * - at most {@link MCP_SKILL_MAX_RESOURCES} files and {@link MCP_SKILL_MAX_TOTAL_BYTES} bytes
824
- * (Limits: "both limits are checkable from the entry alone"; a generated skill's are counted
825
- * on what its snapshot reads).
826
- */
827
- declare const mcpSkillEntryRefusal: (entry: unknown, options?: {
828
- dynamic?: boolean;
829
- }) => string | undefined;
830
- /**
831
- * How a skill of a server is introduced wherever its text is shown to the model (its
832
- * instructions, and each file of it): third-party knowledge that cannot change the rules. The
833
- * wording is the guard.
834
- */
835
- declare const mcpSkillPreamble: (server: string, uri: string) => string;
836
- /**
837
- * The most entries of one `resources/directory/read` answer looked at: the specification's 512
838
- * files per skill, and room for the directories among them. The rest are not looked at.
839
- */
840
- declare const MCP_SKILL_DIRECTORY_ENTRIES_MAX: number;
841
- /** What `read_skill_file` answers for a directory of a skill (every path inside the skill). */
842
- interface SkillDirectoryListing {
843
- /** The skill's name in the catalog. */
844
- name: string;
845
- /** The directory: `.` for the skill's root, else its path inside the skill. */
846
- directory: string;
847
- /** Its files (each read with `read_skill_file`), sorted. */
848
- files: string[];
849
- /** Its subdirectories (each listed the same way), sorted. */
850
- directories: string[];
851
- /** How many more it holds than the two lists show ({@link MCP_SKILL_FILES_SHOWN_MAX} in all). */
852
- more?: number;
853
- /** Shown above, but no longer listed by the skill's MCP server: a read of them will fail. */
854
- notServed?: string[];
855
- /** The skill changed on its MCP server since it was loaded ({@link mcpSkillDirectoryNote}). */
856
- note?: string;
810
+ interface ISubagentsConfig {
811
+ dynamic?: boolean | IDynamicSubagentsConfig;
857
812
  }
858
- /** The longest URI `load_skill` sends to a server, in characters. */
859
- declare const MCP_SKILL_URI_MAX_CHARS = 512;
860
- /**
861
- * Why `load_skill` does not ask a server for the skill at `uri`, or `undefined` when it may. Checked
862
- * before any request: a `skill://` URI - the conventional scheme; a URI the MODEL hands over (it
863
- * read it in third-party text) is taken in no other, though a listing may use any - of the
864
- * `SKILL.md` of a named directory, whose last segment is a skill name, within
865
- * {@link MCP_SKILL_URI_MAX_CHARS}, with nothing invisible and no space in it.
866
- */
867
- declare const mcpSkillUriRefusal: (uri: unknown) => string | undefined;
868
- /** When a person is asked before a server's skill enters the model's context. */
869
- type McpSkillConsent = 'ask' | 'once-per-skill' | 'never';
870
- /** Every value of {@link McpSkillConsent}. */
871
- declare const MCP_SKILL_CONSENTS: readonly McpSkillConsent[];
813
+ interface IResolvedDynamicSubagents {
814
+ maxDepth: number;
815
+ maxChildren: number;
816
+ maxConcurrent: number;
817
+ budgetShare: number;
818
+ minTokens: number;
819
+ timeoutMs: number;
820
+ defaultTools: SubagentDefaultTools;
821
+ }
822
+ declare const SUBAGENT_DEFAULTS: IResolvedDynamicSubagents;
823
+ declare const SUBAGENT_MAX_DEPTH_LIMIT = 4;
872
824
  /**
873
- * The default: asked the first time a skill would enter the context in the agent's life, and again
874
- * only when its entry changed - often enough that every text a person did not see is shown, seldom
875
- * enough that a yes still means something.
825
+ * The effective settings, or undefined when the feature is off (nothing is mounted, nothing is
826
+ * added to a prompt). A bad value is a configuration error, thrown when the agent is created.
876
827
  */
877
- declare const MCP_SKILL_CONSENT_DEFAULT: McpSkillConsent;
878
- /** `skills` on a server's config, as an object. */
879
- interface McpSkillsOptions {
880
- /**
881
- * `'once-per-skill'` (default): a person is asked the first time each skill would enter the
882
- * model's context, and a yes holds for the agent's life while the skill's entry is the same;
883
- * `'ask'`: asked in every run that loads it; `'never'`: never asked - for a server the host
884
- * vetted (its skills load as soon as the model asks). Whatever the approval mode says.
885
- */
886
- consent?: McpSkillConsent;
887
- /**
888
- * `true`: also take this server's GENERATED skills (`"resources": "dynamic"` - no checksums;
889
- * declined by default). When one would enter the model's context, the agent first reads all
890
- * of it - `SKILL.md` and, if the server serves `resources/directory/read`, every file its
891
- * directories list, within the specification's limits - computes each file's digest itself,
892
- * and holds that copy in memory: the person approves that copy (the consent binds to its
893
- * digests), and the model is given only that copy, never a later read. Per server, for a
894
- * server you trust with this; there is no agent-wide switch.
895
- */
896
- dynamic?: boolean;
897
- }
898
- /** `skills` on a server's config: `true`, or options (on, with them); `false` / absent: off. */
899
- type McpSkillsSetting = boolean | McpSkillsOptions;
828
+ declare const resolveDynamicSubagents: (subagents: ISubagentsConfig | undefined) => IResolvedDynamicSubagents | undefined;
900
829
  /**
901
- * What a person is shown before a server's skill enters the model's context - the request's
902
- * `skill` (the core's `tool.approval-requested` event). Every string is the SERVER's, cleaned:
903
- * show it as plain text, captioned as the server's.
830
+ * A spawn that was refused: the model reads the message as the tool's error and can correct the
831
+ * call or carry on without a helper.
904
832
  */
905
- interface McpSkillConsentView {
906
- /** The host's label of the server that serves it. */
907
- server: string;
908
- /** Its name in the agent's catalog (`<server>/<skill>`). */
909
- name: string;
910
- /** Its frontmatter name. */
911
- skill: string;
912
- /** The URI of its `SKILL.md` (cleaned, at most 200 characters). */
913
- uri: string;
914
- /** The description from its entry, on one line, at most {@link MCP_SKILL_DESCRIPTION_MAX_CHARS}. */
915
- description: string;
916
- /** Bytes of its `SKILL.md`, and of all its files. */
917
- size: number;
918
- totalSize: number;
919
- /** Its other files, by path (at most {@link MCP_SKILL_FILES_SHOWN_MAX}), and how many there are. */
920
- files: string[];
921
- fileCount: number;
922
- /** Its instructions exactly as the model would read them ({@link mcpSkillBodyPreview}). */
923
- body: string;
924
- /** Named by URI (`skills/get`), not in the server's listing. */
925
- byUri?: true;
926
- /** It sits inside this skill of the same server, whose approval does not cover it. */
927
- nestedIn?: string;
928
- /**
929
- * Generated by the server (`"resources": "dynamic"`, taken with `skills: { dynamic: true }`):
930
- * there are no checksums. The size, the files and the text are those of the copy the agent just
931
- * read (its snapshot), and only that copy is used - say so.
932
- */
933
- dynamic?: true;
934
- /**
935
- * (with `dynamic`) The server cannot list the skill's files (no `resources/directory/read`): the
936
- * copy is its `SKILL.md` alone, and no other file of it can be read.
937
- */
938
- noFileListing?: true;
939
- /** Asked for this run only (`'ask'`) or, on a yes, for the agent's life (`'once-per-skill'`). */
940
- consent: Exclude<McpSkillConsent, 'never'>;
833
+ declare class SubagentSpawnError extends Error {
834
+ constructor(message: string);
835
+ toJSON(): string;
941
836
  }
837
+ declare const SPAWN_INPUT_SCHEMA: {
838
+ readonly type: "object";
839
+ readonly properties: {
840
+ readonly task: {
841
+ readonly type: "string";
842
+ readonly description: "The complete, self-contained sub-task. The helper sees nothing of your context except this text: include every fact, id and constraint it needs, and say what to return.";
843
+ };
844
+ readonly role: {
845
+ readonly type: "string";
846
+ readonly description: "Optional: who the helper should be for this task and how to work, in a sentence or two (e.g. \"a careful code reviewer; report only real bugs\").";
847
+ };
848
+ readonly tools: {
849
+ readonly type: "array";
850
+ readonly items: {
851
+ readonly type: "string";
852
+ };
853
+ readonly description: "Optional: the names of YOUR tools the helper may use. Only tools you have can be named. Omit it for the default set; pass [] for a helper that only reasons.";
854
+ };
855
+ };
856
+ readonly required: string[];
857
+ readonly additionalProperties: false;
858
+ };
942
859
  /**
943
- * The most directories one snapshot reads (`resources/directory/read`, the skill's root
944
- * included). One read is one directory, its pages walked by the SDK (bounded by its own page cap).
860
+ * A child's event on its way up through the subagent `parentId` (the `subagent.event` envelope is
861
+ * added by the caller). A `subagent.start` is emitted with `depth: 1` and the id of the run that
862
+ * made the call as `parentId`; each subagent it passes through on the way up adds one level, and
863
+ * the first one - its real parent - puts its own id in `parentId`. So at the top of the stream
864
+ * every start carries its true depth and parent, whatever mix of static and dynamic subagents,
865
+ * threads and workers is below.
945
866
  */
946
- declare const MCP_SKILL_SNAPSHOT_MAX_DIRECTORIES = 64;
947
- /** The deepest directory of a skill a snapshot reads: its root is 0, `templates` 1, ... */
948
- declare const MCP_SKILL_SNAPSHOT_MAX_DEPTH = 8;
949
- /** The most bytes the snapshots of one agent hold in memory together. */
950
- declare const MCP_SKILL_SNAPSHOTS_MAX_BYTES: number;
867
+ declare const adoptSubagentEvent: <E extends {
868
+ type: string;
869
+ }>(event: E, parentId: string) => E;
951
870
 
952
871
  interface IRunLease {
953
872
  acquire: (runId: string, options: IRunLeaseOptions) => boolean | Promise<boolean>;
@@ -975,261 +894,400 @@ declare class RunLeaseError extends Error {
975
894
  }
976
895
  declare const RUN_LEASE_DEFAULT_TTL_MS = 30000;
977
896
 
978
- declare const isModelCallRefused: (err: unknown, seen?: Set<unknown>) => boolean;
979
- declare const redactHeaders: (headers: Record<string, string> | undefined) => Record<string, string> | undefined;
980
- type IFilledUsage = Required<Omit<IUsage, 'decisionCalls' | keyof IMediaUsage>> & Pick<IUsage, 'decisionCalls'> & Partial<IMediaUsage>;
981
- interface ISdkUsageLike {
982
- inputTokens?: number;
983
- outputTokens?: number;
984
- totalTokens?: number;
985
- inputTokenDetails?: {
986
- cacheReadTokens?: number;
987
- cacheWriteTokens?: number;
988
- };
989
- outputTokenDetails?: {
990
- reasoningTokens?: number;
991
- };
992
- decisionCalls?: number;
993
- reasoningTokens?: number;
994
- cachedInputTokens?: number;
995
- mediaCalls?: number;
996
- imagesGenerated?: number;
997
- speechCharacters?: number;
998
- transcriptionSeconds?: number;
999
- }
1000
- declare const normalizeUsage: (usage: ISdkUsageLike | undefined | null) => IFilledUsage;
1001
- declare const isAuthError: (err: unknown, seen?: Set<unknown>) => boolean;
1002
- declare const addUsage: (a: IUsage, b: IUsage) => IFilledUsage;
897
+ 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:]";
898
+ declare const isReplayedToolOutput: (output: unknown) => boolean;
1003
899
 
1004
- type ModelCallStage = AgentStage | 'compaction' | 'route';
1005
- interface IModelCall {
1006
- runId?: string;
1007
- stage: ModelCallStage;
1008
- provider?: string;
1009
- modelId: string;
1010
- estimatedInputTokens?: number;
1011
- maxOutputTokens?: number;
900
+ declare const GENERATE_IMAGE_TOOL = "generate_image";
901
+ declare const GENERATE_SPEECH_TOOL = "generate_speech";
902
+ declare const TRANSCRIBE_AUDIO_TOOL = "transcribe_audio";
903
+ type MediaKind = 'image' | 'speech' | 'transcription';
904
+ declare const MEDIA_DEFAULT_MAX_CALLS = 8;
905
+ declare const MEDIA_TIMEOUT_MS = 120000;
906
+ declare const MEDIA_MAX_IMAGE_BYTES: number;
907
+ declare const MEDIA_MAX_SPEECH_BYTES: number;
908
+ declare const MEDIA_MAX_AUDIO_INPUT_BYTES: number;
909
+ declare const MEDIA_MAX_PROMPT_CHARS = 4000;
910
+ declare const MEDIA_MAX_SPEECH_CHARS = 4000;
911
+ declare const MEDIA_MAX_TRANSCRIPT_CHARS = 20000;
912
+ declare const MEDIA_MAX_ATTACHED_AUDIO = 4;
913
+ declare const MEDIA_MAX_REFERENCE_IMAGES = 4;
914
+ declare const MEDIA_MAX_REFERENCE_BYTES: number;
915
+ declare const MEDIA_MAX_REFERENCE_TOTAL_BYTES: number;
916
+ declare const MEDIA_MAX_REFERENCE_SIDE = 4096;
917
+ declare const MEDIA_MAX_REFERENCE_SOURCE_BYTES: number;
918
+ declare const MEDIA_MAX_REFERENCE_SOURCE_PIXELS = 200000000;
919
+ declare const MEDIA_FIT_TIMEOUT_MS = 30000;
920
+ declare const MEDIA_FOLDER = "media";
921
+ declare class MediaError extends Error {
922
+ constructor(message: string);
923
+ toJSON(): string;
1012
924
  }
1013
- interface ISharedLimits {
1014
- beforeModelCall: (call: IModelCall, context: {
1015
- signal?: AbortSignal;
1016
- }) => void | Promise<void>;
1017
- afterModelCall?: (call: IModelCall, usage: IUsage, outcome: {
1018
- ok: boolean;
1019
- }) => void | Promise<void>;
925
+ declare class MediaBudgetError extends MediaError {
926
+ constructor(cap: number);
927
+ }
928
+ declare const MEDIA_IMAGE_TYPES: Readonly<Record<string, string>>;
929
+ declare const MEDIA_AUDIO_TYPES: Readonly<Record<string, string>>;
930
+ declare const MEDIA_REFERENCE_TYPES: Readonly<Record<string, string>>;
931
+ declare const sniffMediaType: (bytes: Uint8Array) => string | undefined;
932
+ interface IAcceptedMedia {
933
+ mediaType: string;
934
+ ext: string;
935
+ }
936
+ declare const acceptMedia: (family: "image" | "audio", bytes: Uint8Array, maxBytes: number, what: string) => IAcceptedMedia;
937
+ interface IImageSize {
938
+ width: number;
939
+ height: number;
940
+ }
941
+ declare const imageDimensions: (bytes: Uint8Array) => IImageSize | undefined;
942
+ interface IAcceptedReference extends IAcceptedMedia, IImageSize {
943
+ }
944
+ declare const acceptReference: (bytes: Uint8Array, what: string) => IAcceptedReference;
945
+ interface IReferencePicture {
946
+ bytes: Uint8Array;
947
+ mediaType: string;
948
+ width: number;
949
+ height: number;
950
+ path: string;
951
+ }
952
+ interface IReferenceBounds {
953
+ maxSide: number;
954
+ maxBytes: number;
955
+ }
956
+ interface IFitReferenceOptions {
957
+ signal: AbortSignal;
958
+ }
959
+ interface IFittedReference {
960
+ bytes: Uint8Array;
961
+ mediaType?: string;
962
+ }
963
+ type MediaFitReference = (picture: IReferencePicture, bounds: IReferenceBounds, options: IFitReferenceOptions) => Promise<IFittedReference | undefined>;
964
+ declare const acceptReferenceSource: (bytes: Uint8Array, what: string) => IAcceptedReference;
965
+ interface IReferenceUse {
966
+ used: boolean;
967
+ count: number;
968
+ paths: string[];
969
+ fitted?: string[];
970
+ }
971
+ interface IReferenceResult extends IReferenceUse {
972
+ note?: string;
973
+ }
974
+ interface IMediaUsage {
975
+ mediaCalls: number;
976
+ imagesGenerated: number;
977
+ speechCharacters: number;
978
+ transcriptionSeconds: number;
1020
979
  }
1021
- declare class ModelCallRefusedError extends Error {
1022
- readonly call: IModelCall;
1023
- constructor(call: IModelCall, cause: unknown);
1024
- toJSON(): string;
980
+ declare const mediaUsageOf: (usage: Partial<IMediaUsage> | undefined) => IMediaUsage | undefined;
981
+ interface ITranscriptBlock {
982
+ name: string;
983
+ text: string;
984
+ language?: string;
985
+ durationInSeconds?: number;
1025
986
  }
987
+ declare const wrapTranscript: (block: ITranscriptBlock) => string;
1026
988
 
1027
- declare const SPAWN_SUBAGENT_TOOL = "spawn_subagent";
1028
- type SubagentDefaultTools = 'read-only' | 'all';
1029
- interface IDynamicSubagentsConfig {
1030
- maxDepth?: number;
1031
- maxChildren?: number;
1032
- maxConcurrent?: number;
1033
- budgetShare?: number;
1034
- minTokens?: number;
989
+ type IMediaModelSpec = IAgentStageOverride & {
990
+ model: string;
991
+ };
992
+ type MediaImageModel = Exclude<ImageModel, string>;
993
+ type MediaSpeechModel = Exclude<SpeechModel, string>;
994
+ type MediaTranscriptionModel = Exclude<TranscriptionModel, string>;
995
+ interface IMediaConfig {
996
+ imageModel?: MediaImageModel | IMediaModelSpec;
997
+ imageInputs?: boolean;
998
+ fitReference?: MediaFitReference;
999
+ fitTimeoutMs?: number;
1000
+ viewGenerated?: boolean;
1001
+ speechModel?: MediaSpeechModel | IMediaModelSpec;
1002
+ transcriptionModel?: MediaTranscriptionModel | IMediaModelSpec;
1003
+ maxCalls?: number;
1035
1004
  timeoutMs?: number;
1036
- defaultTools?: SubagentDefaultTools;
1005
+ dir?: string;
1006
+ voice?: string;
1007
+ speechFormat?: string;
1037
1008
  }
1038
- interface ISubagentsConfig {
1039
- dynamic?: boolean | IDynamicSubagentsConfig;
1009
+ interface IRunFile {
1010
+ data: string | Uint8Array;
1011
+ mediaType?: string;
1012
+ name?: string;
1040
1013
  }
1041
- interface IResolvedDynamicSubagents {
1042
- maxDepth: number;
1043
- maxChildren: number;
1044
- maxConcurrent: number;
1045
- budgetShare: number;
1046
- minTokens: number;
1047
- timeoutMs: number;
1048
- defaultTools: SubagentDefaultTools;
1014
+ interface IMediaFile {
1015
+ path: string;
1016
+ mediaType: string;
1017
+ bytes: number;
1018
+ references?: IReferenceResult;
1019
+ pictureNote?: string;
1049
1020
  }
1050
- declare const SUBAGENT_DEFAULTS: IResolvedDynamicSubagents;
1051
- declare const SUBAGENT_MAX_DEPTH_LIMIT = 4;
1052
- /**
1053
- * The effective settings, or undefined when the feature is off (nothing is mounted, nothing is
1054
- * added to a prompt). A bad value is a configuration error, thrown when the agent is created.
1055
- */
1056
- declare const resolveDynamicSubagents: (subagents: ISubagentsConfig | undefined) => IResolvedDynamicSubagents | undefined;
1057
- /**
1058
- * A spawn that was refused: the model reads the message as the tool's error and can correct the
1059
- * call or carry on without a helper.
1060
- */
1061
- declare class SubagentSpawnError extends Error {
1062
- constructor(message: string);
1063
- toJSON(): string;
1021
+ interface ITranscription {
1022
+ path: string;
1023
+ text: string;
1024
+ language?: string;
1025
+ durationInSeconds?: number;
1026
+ truncated?: true;
1027
+ untrusted: true;
1064
1028
  }
1065
- declare const SPAWN_INPUT_SCHEMA: {
1066
- readonly type: "object";
1067
- readonly properties: {
1068
- readonly task: {
1069
- readonly type: "string";
1070
- readonly description: "The complete, self-contained sub-task. The helper sees nothing of your context except this text: include every fact, id and constraint it needs, and say what to return.";
1071
- };
1072
- readonly role: {
1073
- readonly type: "string";
1074
- readonly description: "Optional: who the helper should be for this task and how to work, in a sentence or two (e.g. \"a careful code reviewer; report only real bugs\").";
1075
- };
1076
- readonly tools: {
1077
- readonly type: "array";
1078
- readonly items: {
1079
- readonly type: "string";
1080
- };
1081
- readonly description: "Optional: the names of YOUR tools the helper may use. Only tools you have can be named. Omit it for the default set; pass [] for a helper that only reasons.";
1082
- };
1029
+ interface IMedia {
1030
+ tools: ToolSet;
1031
+ pictures?: {
1032
+ setting: boolean | undefined;
1083
1033
  };
1084
- readonly required: string[];
1085
- readonly additionalProperties: false;
1086
- };
1087
- /**
1088
- * A child's event on its way up through the subagent `parentId` (the `subagent.event` envelope is
1089
- * added by the caller). A `subagent.start` is emitted with `depth: 1` and the id of the run that
1090
- * made the call as `parentId`; each subagent it passes through on the way up adds one level, and
1091
- * the first one - its real parent - puts its own id in `parentId`. So at the top of the stream
1092
- * every start carries its true depth and parent, whatever mix of static and dynamic subagents,
1093
- * threads and workers is below.
1094
- */
1095
- declare const adoptSubagentEvent: <E extends {
1096
- type: string;
1097
- }>(event: E, parentId: string) => E;
1034
+ attach: (input: string, files: IRunFile[], signal?: AbortSignal) => Promise<string>;
1035
+ }
1036
+ declare const createMedia: (config: IAgentConfig) => Promise<IMedia | undefined>;
1098
1037
 
1099
- declare const ASK_USER_TOOL = "ask_user";
1100
- /** How long one question waits for the person, by default: a human is reading it. */
1101
- declare const ASK_USER_TIMEOUT_MS = 300000;
1102
1038
  /**
1103
- * The longest wait a timer holds (2^31 - 1 ms, about 24.8 days). `setTimeout` fires a longer one -
1104
- * Infinity included - after about 1 ms, so a `timeoutMs` past it is taken as no limit at all.
1039
+ * MCP elicitation, the part the two agent packages share: a server asks the user for input in
1040
+ * the middle of a tool call, the HOST answers through a callback, and the call goes on. Pure, no
1041
+ * imports: the limits, what a request must look like before a host sees it, what an answer must
1042
+ * look like before a server sees it, the one function that asks, and the two ways a tool call
1043
+ * with questions is driven (`elicitation/create` requests on the 2025 revisions, `input_required`
1044
+ * results on 2026-07-28).
1045
+ *
1046
+ * A consent boundary. The server's text is third-party data: cleaned and capped here, shown only
1047
+ * to the host's callback and in the `mcp.elicitation-requested` event, never put into a prompt.
1048
+ * The answer goes to the server that asked and nowhere else: nothing in this file logs, emits or
1049
+ * returns a value the user entered - events and errors carry field NAMES only.
1050
+ *
1051
+ * This file is a COPY, byte for byte, in `@dudko.dev/agent` (`src/mcp-elicitation.ts`) and
1052
+ * `@dudko.dev/agent-web` (`src/mcp/elicitation.ts`): change both. The Node package's
1053
+ * `tests/mcp-elicitation-shared.test.ts` compares the two files and tests every guard here; each
1054
+ * needs a mutation check.
1105
1055
  */
1106
- declare const ASK_USER_TIMEOUT_MAX_MS = 2147483647;
1107
- /** The most questions one run may ask, by default (its helpers' and subagents' included). */
1108
- declare const ASK_USER_MAX_PER_RUN = 3;
1109
- /** A question offers at least this many options... */
1110
- declare const ASK_USER_MIN_OPTIONS = 2;
1111
- /** ...and at most this many. */
1112
- declare const ASK_USER_MAX_OPTIONS = 6;
1113
- /** The longest question, in characters (after cleaning). */
1114
- declare const ASK_USER_QUESTION_MAX_CHARS = 500;
1115
- /** The longest option label. */
1116
- declare const ASK_USER_LABEL_MAX_CHARS = 80;
1117
- /** The longest option description. */
1118
- declare const ASK_USER_DESCRIPTION_MAX_CHARS = 200;
1119
- /** The most of a person's own words (`{ other }`) the model is given; the rest is cut. */
1120
- declare const ASK_USER_OTHER_MAX_CHARS = 2000;
1121
- /** One option of a question, as the person is shown it. Both strings are the MODEL's, cleaned. */
1122
- interface AskUserOption {
1123
- label: string;
1056
+ /** How long one question waits for the host's answer, by default: a human is reading it. */
1057
+ declare const MCP_ELICITATION_TIMEOUT_MS = 300000;
1058
+ /** The most questions one tool call may ask, by default. */
1059
+ declare const MCP_ELICITATION_MAX_PER_TOOL_CALL = 5;
1060
+ /** The most questions one run may be asked, by default (its helpers' calls included). */
1061
+ declare const MCP_ELICITATION_MAX_PER_RUN = 20;
1062
+ /** One field of a form: the flat subset of JSON Schema the specification allows, nothing else. */
1063
+ interface McpElicitationFieldSchema {
1064
+ type: 'string' | 'number' | 'integer' | 'boolean' | 'array';
1065
+ title?: string;
1124
1066
  description?: string;
1125
- }
1126
- /** A question as checked and cleaned: what a host shows and an event carries. */
1127
- interface AskUserQuestion {
1128
- question: string;
1129
- options: AskUserOption[];
1130
- /** The person may pick several options. */
1131
- multiple: boolean;
1132
- /** The person may answer in their own words instead of picking. */
1133
- allowOther: boolean;
1134
- }
1135
- /** What the host's `onQuestion` is given. Every string in it is the model's text, cleaned. */
1136
- interface AskUserRequest<TStep = unknown> extends AskUserQuestion {
1137
- /** Unique per question; the same id is in the two events. */
1138
- id: string;
1139
- /** The plan step whose tool call asks. */
1140
- step?: TStep;
1141
- runId?: string;
1142
- /** Set when a helper or a subagent of the run asks, not the run itself: its id and depth. */
1143
- subagent?: {
1144
- id: string;
1145
- depth: number;
1067
+ default?: string | number | boolean | string[];
1068
+ /** string */
1069
+ minLength?: number;
1070
+ maxLength?: number;
1071
+ format?: 'email' | 'uri' | 'date' | 'date-time';
1072
+ /** string: single-select, plain (`enumNames`: the older titled form). */
1073
+ enum?: string[];
1074
+ enumNames?: string[];
1075
+ /** string: single-select with titles. */
1076
+ oneOf?: {
1077
+ const: string;
1078
+ title: string;
1079
+ }[];
1080
+ /** number / integer */
1081
+ minimum?: number;
1082
+ maximum?: number;
1083
+ /** array: multi-select. */
1084
+ minItems?: number;
1085
+ maxItems?: number;
1086
+ items?: {
1087
+ type?: 'string';
1088
+ enum?: string[];
1089
+ anyOf?: {
1090
+ const: string;
1091
+ title: string;
1092
+ }[];
1146
1093
  };
1147
1094
  }
1148
- /**
1149
- * The person's answer: the labels they picked (exactly as offered; one unless `multiple`), their
1150
- * own words (only when `allowOther`), or that they would rather not answer.
1151
- */
1152
- type AskUserAnswer = {
1153
- choice: string[];
1154
- } | {
1155
- other: string;
1156
- } | {
1157
- declined: true;
1158
- };
1159
- interface AskUserContext {
1160
- /**
1161
- * Aborted when the question ends WITHOUT the host's answer: no answer within `timeoutMs`
1162
- * (`signal.reason` is an Error named 'TimeoutError'), the run was stopped, or the handler
1163
- * failed. Take the prompt down then: an answer given later is ignored. Never aborted once the
1164
- * host has answered.
1165
- */
1166
- signal: AbortSignal;
1095
+ /** The form a server asks for, as a host is shown it: checked, cleaned and capped. */
1096
+ interface McpElicitationSchema {
1097
+ type: 'object';
1098
+ properties: Record<string, McpElicitationFieldSchema>;
1099
+ required?: string[];
1167
1100
  }
1168
- /** How a question ended. `automatic`: nobody decided (a time limit, a stop, a failed handler). */
1169
- type AskUserAction = 'choice' | 'other' | 'declined' | 'timeout' | 'stopped';
1170
- /** Why a question was closed as `declined` without the person deciding. */
1171
- type AskUserReason = 'handler-error' | 'invalid-answer' | 'cannot-park';
1172
- /** The two events of a question. Neither ever carries the person's own words. */
1173
- type AskUserEvent<TStep = unknown> = {
1174
- type: 'user.question-asked';
1101
+ /** What the host's callback is given. Every string in it is third-party text. */
1102
+ interface McpElicitationRequest {
1103
+ /** Unique per question; the same id is in the two events. */
1175
1104
  id: string;
1176
- question: string;
1177
- options: AskUserOption[];
1178
- multiple: boolean;
1179
- allowOther: boolean;
1180
- step?: TStep;
1105
+ /** The server that asks: its key in the host's configuration. */
1106
+ server: string;
1107
+ /** The tool call during which it asks: the tool's name as the model called it. */
1108
+ tool: string;
1109
+ mode: 'form' | 'url';
1110
+ /** The server's words, cleaned and capped (MCP_ELICITATION_MESSAGE_MAX_CHARS). */
1111
+ message: string;
1112
+ /** Form mode: the fields to fill in. */
1113
+ requestedSchema?: McpElicitationSchema;
1114
+ /**
1115
+ * URL mode: the link the server wants the user to open. It is only handed over: nothing in
1116
+ * these packages fetches or opens it. https, or http on a loopback host.
1117
+ */
1118
+ url?: string;
1119
+ /** URL mode on the 2025 revisions: the server's id for this interaction. */
1120
+ elicitationId?: string;
1121
+ runId?: string;
1122
+ /** Set when a helper the model started is the one whose call asks (`elicitation.subagents`). */
1181
1123
  subagent?: {
1182
1124
  id: string;
1183
1125
  depth: number;
1184
1126
  };
1185
- } | {
1186
- type: 'user.question-answered';
1187
- id: string;
1188
- action: AskUserAction;
1189
- /** true when nobody decided: a time limit, a stop, a failed handler, an unusable answer. */
1190
- automatic: boolean;
1191
- /** Action 'choice': the labels picked. Never the text of an `other` answer. */
1192
- choice?: string[];
1193
- /** Action 'declined' with `automatic`: why. */
1194
- reason?: AskUserReason;
1195
- };
1196
- /** A bad `ask_user` input: the tool call fails with this message, which says what to fix. */
1197
- declare class AskUserInputError extends Error {
1198
- constructor(message: string);
1199
- toJSON(): string;
1200
1127
  }
1201
- /** The model's text as a person may be shown it: a string, invisible characters removed, trimmed. */
1202
- declare const cleanAskUserText: (raw: unknown, oneLine?: boolean) => string;
1128
+ type McpElicitationContent = Record<string, string | number | boolean | string[]>;
1203
1129
  /**
1204
- * Check and clean the model's `ask_user` arguments: 2-6 options, no two labels alike (letter case
1205
- * and spaces aside), each label 1-80 characters, a description at most 200, a question of 1-500 -
1206
- * all measured after cleaning. An option may be given as a bare string (its label). Throws
1207
- * {@link AskUserInputError} with what to fix.
1130
+ * The host's answer. `accept` carries the form's values (form mode) or nothing (URL mode: it
1131
+ * says the user agreed to open the link); `decline` is a no; `cancel` is "dismissed".
1208
1132
  */
1209
- declare const checkAskUserInput: (raw: unknown) => AskUserQuestion;
1210
- /** An answer as checked: what the model is told. */
1211
- type AskUserCheckedAnswer = {
1212
- kind: 'choice';
1213
- choice: string[];
1133
+ type McpElicitationResult = {
1134
+ action: 'accept';
1135
+ content?: McpElicitationContent;
1214
1136
  } | {
1215
- kind: 'other';
1216
- text: string;
1137
+ action: 'decline';
1217
1138
  } | {
1218
- kind: 'declined';
1139
+ action: 'cancel';
1219
1140
  };
1220
- /**
1221
- * Check the host's answer against the question: exactly one of `choice` (labels that were
1222
- * offered, no repeats, one unless `multiple`), `other` (a non-empty text, only when `allowOther`;
1223
- * cleaned and cut at {@link ASK_USER_OTHER_MAX_CHARS}) or `declined: true`. Anything else is not
1224
- * an answer.
1225
- */
1226
- declare const checkAskUserAnswer: (q: AskUserQuestion, raw: unknown) => {
1141
+ interface McpElicitationContext {
1142
+ /** Aborted when the answer is no longer wanted: the run stopped, or the time ran out. */
1143
+ signal: AbortSignal;
1144
+ }
1145
+ /** `onElicitation`: the host decides, never the model. */
1146
+ type McpElicitationHandler = (request: McpElicitationRequest, ctx: McpElicitationContext) => McpElicitationResult | Promise<McpElicitationResult>;
1147
+ /** The `elicitation` settings beside `onElicitation`. */
1148
+ interface McpElicitationOptions {
1149
+ /**
1150
+ * How long one question waits for an answer. Default 300 000. `0` or `Infinity` = no limit of
1151
+ * its own (the question waits until the run is stopped), and so is a value above 2^31 - 1 (about
1152
+ * 24.8 days, the most a timer holds). Negative or NaN: a configuration error.
1153
+ */
1154
+ timeoutMs?: number;
1155
+ /** Questions one tool call may ask. Default 5. */
1156
+ maxPerToolCall?: number;
1157
+ /** Questions one run may be asked. Default 20. */
1158
+ maxPerRun?: number;
1159
+ /** Also accept URL mode (a link to open). Default false: only forms are declared. */
1160
+ url?: boolean;
1161
+ /**
1162
+ * Let a tool call made by a helper (a subagent) ask the user too. Default false: such a
1163
+ * question is cancelled without the callback being called.
1164
+ */
1165
+ subagents?: boolean;
1166
+ }
1167
+ /** Why a question was answered without the host deciding. */
1168
+ 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';
1169
+ type Checked<T> = {
1227
1170
  ok: true;
1228
- value: AskUserCheckedAnswer;
1171
+ value: T;
1229
1172
  } | {
1230
1173
  ok: false;
1231
1174
  reason: string;
1232
1175
  };
1176
+ /**
1177
+ * The form a server asked for, reduced to what the specification allows a form to be: a flat
1178
+ * object of strings, numbers, booleans and selects. Anything else - a nested object, a list of
1179
+ * objects, a type union, an unknown format, too many fields or options, a name that could not
1180
+ * be sent back verbatim - is refused with a reason (the caller declines the request). Keywords
1181
+ * outside the subset are dropped; titles and descriptions are cleaned and capped.
1182
+ */
1183
+ declare const normalizeMcpElicitationSchema: (raw: unknown) => Checked<McpElicitationSchema>;
1184
+ /**
1185
+ * An accepted form, checked against the schema it answers: every value of the type and within
1186
+ * the limits its field states, every required field there, and NO field the form did not ask
1187
+ * for (what the server did not request is not sent to it). The result is a fresh object holding
1188
+ * only the form's own fields. A refusal names the field and the rule, never the value.
1189
+ */
1190
+ declare const validateMcpElicitationContent: (schema: McpElicitationSchema, content: unknown) => Checked<McpElicitationContent>;
1191
+
1192
+ /**
1193
+ * What the MCP connectors of the two agent packages share: how a server's `instructions` reach a
1194
+ * system prompt, how a tool result's `structuredContent` reaches the model, and what the
1195
+ * per-server `protocol` option means. Pure, no imports.
1196
+ *
1197
+ * This file is a COPY, byte for byte, in `@dudko.dev/agent` (`src/mcp-shared.ts`) and
1198
+ * `@dudko.dev/agent-web` (`src/mcp/shared.ts`): change both. The Node package's
1199
+ * `tests/mcp-shared.test.ts` compares the two files and tests every cap and guard here.
1200
+ */
1201
+ /** The `instructions` one connected MCP server returned in its `initialize` result. */
1202
+ interface McpServerInstructions {
1203
+ /** The server's name: its key in the host's configuration. */
1204
+ server: string;
1205
+ instructions: string;
1206
+ }
1207
+ /** The most one server's instructions take in a system prompt, in characters. */
1208
+ declare const MCP_INSTRUCTIONS_MAX_CHARS_PER_SERVER = 2000;
1209
+ /** The most all servers' instructions take together, in characters. */
1210
+ declare const MCP_INSTRUCTIONS_MAX_CHARS_TOTAL = 8000;
1211
+ /**
1212
+ * The system-prompt section for the servers' instructions, or '' when no server sent any (the
1213
+ * prompt is then exactly what it was). Each server's text is capped
1214
+ * (MCP_INSTRUCTIONS_MAX_CHARS_PER_SERVER), so is the sum (MCP_INSTRUCTIONS_MAX_CHARS_TOTAL, in
1215
+ * the order given: a server past the total is named as omitted), and every line of it is
1216
+ * prefixed with "| ", so a server cannot write something that reads as a heading of this prompt
1217
+ * or as another server's note.
1218
+ */
1219
+ declare const renderMcpInstructions: (list: readonly McpServerInstructions[] | undefined) => string;
1220
+ /**
1221
+ * Which revisions of the protocol a connection to one server may use (the server config's
1222
+ * `protocol`):
1223
+ *
1224
+ * - `'legacy'` (default): the 2025 revisions, the `initialize` handshake. Nothing of the 2026
1225
+ * revision is sent.
1226
+ * - `'auto'`: ask first (`server/discover`); a server that answers with 2026-07-28 is spoken to
1227
+ * that way, any other is given the 2025 handshake. Decided once, at connect.
1228
+ * - `'modern'`: 2026-07-28 only. A server that does not offer it fails the connect.
1229
+ */
1230
+ type McpProtocolMode = 'legacy' | 'auto' | 'modern';
1231
+ /** The revision `protocol: 'modern'` pins: the one this connector is tested against. */
1232
+ declare const MCP_MODERN_PROTOCOL_VERSION = "2026-07-28";
1233
+ /** What a connection negotiated with one server. */
1234
+ interface McpServerProtocol {
1235
+ /** The server's name: its key in the host's configuration. */
1236
+ server: string;
1237
+ /** The protocol revision in use, e.g. `2025-11-25` or `2026-07-28`. */
1238
+ version: string;
1239
+ /** `modern` from 2026-07-28 on (stateless, `server/discover`), `legacy` before. */
1240
+ era: 'legacy' | 'modern';
1241
+ }
1242
+
1243
+ declare const isModelCallRefused: (err: unknown, seen?: Set<unknown>) => boolean;
1244
+ declare const redactHeaders: (headers: Record<string, string> | undefined) => Record<string, string> | undefined;
1245
+ type IFilledUsage = Required<Omit<IUsage, 'decisionCalls' | keyof IMediaUsage>> & Pick<IUsage, 'decisionCalls'> & Partial<IMediaUsage>;
1246
+ interface ISdkUsageLike {
1247
+ inputTokens?: number;
1248
+ outputTokens?: number;
1249
+ totalTokens?: number;
1250
+ inputTokenDetails?: {
1251
+ cacheReadTokens?: number;
1252
+ cacheWriteTokens?: number;
1253
+ };
1254
+ outputTokenDetails?: {
1255
+ reasoningTokens?: number;
1256
+ };
1257
+ decisionCalls?: number;
1258
+ reasoningTokens?: number;
1259
+ cachedInputTokens?: number;
1260
+ mediaCalls?: number;
1261
+ imagesGenerated?: number;
1262
+ speechCharacters?: number;
1263
+ transcriptionSeconds?: number;
1264
+ }
1265
+ declare const normalizeUsage: (usage: ISdkUsageLike | undefined | null) => IFilledUsage;
1266
+ declare const isAuthError: (err: unknown, seen?: Set<unknown>) => boolean;
1267
+ declare const addUsage: (a: IUsage, b: IUsage) => IFilledUsage;
1268
+
1269
+ type ModelCallStage = AgentStage | 'compaction' | 'route';
1270
+ interface IModelCall {
1271
+ runId?: string;
1272
+ stage: ModelCallStage;
1273
+ provider?: string;
1274
+ modelId: string;
1275
+ estimatedInputTokens?: number;
1276
+ maxOutputTokens?: number;
1277
+ }
1278
+ interface ISharedLimits {
1279
+ beforeModelCall: (call: IModelCall, context: {
1280
+ signal?: AbortSignal;
1281
+ }) => void | Promise<void>;
1282
+ afterModelCall?: (call: IModelCall, usage: IUsage, outcome: {
1283
+ ok: boolean;
1284
+ }) => void | Promise<void>;
1285
+ }
1286
+ declare class ModelCallRefusedError extends Error {
1287
+ readonly call: IModelCall;
1288
+ constructor(call: IModelCall, cause: unknown);
1289
+ toJSON(): string;
1290
+ }
1233
1291
 
1234
1292
  type ProviderType = 'openai' | 'anthropic' | 'openai-compatible' | 'google' | 'xai' | 'azure' | 'amazon-bedrock' | 'google-vertex' | 'deepseek' | 'gateway' | 'cloudflare';
1235
1293
  type AgentModel = Exclude<LanguageModel, string>;
@@ -1955,59 +2013,6 @@ interface IAgent {
1955
2013
  }
1956
2014
  declare const createAgent: (config: IAgentConfig, baseEventHandler?: EventHandler) => Promise<IAgent>;
1957
2015
 
1958
- /**
1959
- * Thrown from inside a tool's execute when the call was not approved. The AI
1960
- * SDK records it as a failed tool call (`ok: false`), so the replanner sees
1961
- * it; `toJSON` keeps the message when a trace is serialised.
1962
- */
1963
- declare class ToolDeniedError extends Error {
1964
- readonly reason?: string;
1965
- constructor(reason?: string);
1966
- toJSON(): string;
1967
- }
1968
- declare const markReadOnly: <T extends object>(tool: T, readOnly?: boolean) => T;
1969
- declare const isReadOnlyTool: (tool: unknown) => boolean;
1970
- declare const markCodeExecution: <T extends object>(tool: T, codeExecution?: boolean) => T;
1971
- declare const isCodeExecutionTool: (tool: unknown) => boolean;
1972
- /**
1973
- * The most specific rule matching `name`: an exact key wins, then the
1974
- * longest matching '*' glob (ties: the first declared). Pure.
1975
- */
1976
- declare const matchToolRule: (rules: Record<string, ToolPermission> | undefined, name: string) => {
1977
- pattern: string;
1978
- permission: ToolPermission;
1979
- } | undefined;
1980
- interface IToolDecisionInput {
1981
- name: string;
1982
- readOnly: boolean;
1983
- mode: ToolApprovalMode;
1984
- rules?: Record<string, ToolPermission>;
1985
- remembered?: ReadonlySet<string>;
1986
- builtIn?: boolean;
1987
- codeExecution?: boolean;
1988
- mcpSkills?: readonly string[];
1989
- }
1990
- interface IToolDecision {
1991
- permission: ToolPermission;
1992
- source: 'builtin' | 'remembered' | 'rule' | 'mode' | 'mcp-skill';
1993
- rule?: string;
1994
- }
1995
- /**
1996
- * Decide one call. Pure. Order: built-in -> remembered "always allow" ->
1997
- * most specific rule -> mode default (autopilot: allow; read-only: allow if
1998
- * readOnly else deny; ask-writes: allow if readOnly else ask; ask-all: ask).
1999
- * Then one rule that only ever tightens: a call that runs code while the run acts on an MCP
2000
- * server's skill is asked when it would have been allowed - by the mode, a rule or an "always
2001
- * allow" alike (the Skills extension: no code runs here on a server's skill without a person's
2002
- * approval). A deny stays a deny.
2003
- */
2004
- declare const decideToolPermission: (input: IToolDecisionInput) => IToolDecision;
2005
- /** How long a question waits for a decision when `toolApproval.timeoutMs` is not set: 5 minutes. */
2006
- declare const TOOL_APPROVAL_TIMEOUT_MS = 300000;
2007
-
2008
- 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:]";
2009
- declare const isReplayedToolOutput: (output: unknown) => boolean;
2010
-
2011
2016
  /** The bounds on what comes from outside the run (a deferred call's note, an answer). */
2012
2017
  declare const JOURNAL_LIMITS: Readonly<{
2013
2018
  noteChars: 2000;