import { type AgentTool, type TextContentBlock, type DeferredToolSessionSnapshot } from '@zhin.js/ai'; import type { SkillDescriptor } from '@zhin.js/skill'; import type { AgentDecisionRuntime } from '../decision/types.js'; import { resolveDeferredToolsConfig } from '../tool-catalog/resolve-config.js'; import { type ToolCatalogItem, type ToolTier } from '../tool-catalog/types.js'; import type { AgentCapabilities, ToolCapability } from './capability-ingress.js'; /** * Injected capability ceiling. It must return a subset of the given projection * and throw when the projection is not trusted by the ceiling's owner. */ export interface DeferredCapabilityCeiling { project(capabilities: AgentCapabilities): Readonly>; } /** * Reserved, model-invisible control namespace of the Agent runtime. Control * tools use this prefix and it is always filtered out of model-visible * capabilities. It is a naming convention, not a dependency on Workroom code. */ export declare const RESERVED_CONTROL_TOOL_PREFIX = "workroom_"; /** * Reserved model-invisible control namespace; always filtered out of * model-visible capabilities. */ export declare function isReservedControlToolName(name: string): boolean; export interface DeferredCapabilityController { loadedToolNames(): string[]; loadedSkillInstructions(): string[]; loadedSkillBlocks(): TextContentBlock[]; /** Marks only a successful, unmodified runtime load_skill result. */ modelOutputBlocks(name: string, args: unknown, text: string): TextContentBlock[] | undefined; /** Load a public catalog tool into the session. Returns false when it is not in this turn's catalog. */ load(name: string): Promise; } export interface DeferredCapabilityPlan { readonly capabilities: readonly ToolCapability[]; readonly allTools: readonly AgentTool[]; readonly resolvedTools: readonly AgentTool[]; readonly catalog: readonly ToolCatalogItem[]; readonly deferredStats: string; readonly controller: DeferredCapabilityController; } /** * The legacy `authority` option no longer exists; passing it at runtime throws * (fail-closed) instead of being silently ignored. */ export interface DeferredCapabilityPlanOptions { readonly capabilities: AgentCapabilities; /** * Optional injected capability ceiling (e.g. a Workroom Assignment). * Ordinary chat omits it and retains its own capability projection. */ readonly ceiling?: DeferredCapabilityCeiling; readonly sessionSnapshot: DeferredToolSessionSnapshot; readonly config: Parameters[0]; readonly platform?: string; /** * Scene tier of the resident tool set (ADR 0042 §2). Omitted means `full` * (scheduled / detached / sub-agent turns keep the whole default set). The tier * only chooses which authorized tools start loaded; it never grants access. */ readonly toolTier?: ToolTier; readonly persistSnapshot: (snapshot: DeferredToolSessionSnapshot) => Promise; readonly decision?: AgentDecisionRuntime; } export interface AgentSkillIntentPrimeResult { readonly snapshot: DeferredToolSessionSnapshot; /** * The session snapshot as projected for these capabilities, before priming. With * {@link restoreProjectedOutEntries} it rebuilds the full snapshot to persist. */ readonly projected?: DeferredToolSessionSnapshot; readonly skill?: SkillDescriptor; readonly skills?: readonly SkillDescriptor[]; } /** * Deterministically activates one Agent-private Skill when the current intent * has a unique best keyword match. Public Skills and ambiguous matches remain * deferred so the runtime keeps its progressive-disclosure boundary. */ export declare function primeAgentSkillForIntent(options: Readonly<{ capabilities: Pick; sessionSnapshot: DeferredToolSessionSnapshot; intent: string; config: DeferredCapabilityPlanOptions['config']; }>): AgentSkillIntentPrimeResult; /** Most public Skills one turn's hint names (#1250 b27). */ export declare const PUBLIC_SKILL_HINT_MAX = 2; /** Only the first this many declared keywords of a Skill count towards its hint score. */ export declare const PUBLIC_SKILL_HINT_KEYWORDS = 12; /** * Public Skills whose frontmatter keywords occur in the current intent: the best-scoring ones (at * most {@link PUBLIC_SKILL_HINT_MAX}), already loaded ones excluded. Only a hint for the prompt * (#1250 b27): public Skills are third-party guidance and are never activated by keyword, because * activation injects their instructions and unlocks their tools for the session (see * {@link primeAgentSkillForIntent}); the model still decides whether to `load_skill`. * * Third-party keywords must not buy a hint by stuffing: a Skill scores the length of its single * longest matching keyword (no sum), only its first {@link PUBLIC_SKILL_HINT_KEYWORDS} keywords * count, and a keyword scores only its content: spaces, stopwords and CJK function characters do not * count. Keywords left with under 2 content CJK characters, non-CJK keywords under 3 letters / * digits or without a letter (numbers, symbols, emoji), content that only repeats a 1-2 character * unit (呵呵, hhh, hahaha), stopwords and keywords over {@link SKILL_KEYWORD_MAX_CHARS} characters * are ignored; invisible format characters (zero-width space, BOM) are dropped from keywords and * intent alike. ASCII keywords match whole ASCII words * (`api` does not match `rapid` but matches `写api`); CJK keywords ignore spaces. The hint names the * top {@link PUBLIC_SKILL_HINT_MAX} scores, so one higher-scoring Skill never hides every other. */ export declare function suggestPublicSkillsForIntent(skills: readonly SkillDescriptor[], intent: string, loadedSkills?: readonly string[]): readonly SkillDescriptor[]; /** Model recommendation never enlarges the immutable, already-authorized projection. */ export declare function primeSkillsForIntent(options: Readonly<{ capabilities: Pick; sessionSnapshot: DeferredToolSessionSnapshot; intent: string; config: DeferredCapabilityPlanOptions['config']; decision?: AgentDecisionRuntime; signal: AbortSignal; }>): Promise; /** * Turn-owned deferred capability authority. It has no filesystem, registry, * AsyncLocalStorage, or classic Tool dependency: everything comes from the * immutable generation projection and the session snapshot. */ export declare function createDeferredCapabilityPlan(options: DeferredCapabilityPlanOptions): DeferredCapabilityPlan; /** * Upper bound on plugin tools that may become resident through their own * `alwaysLoaded: true` flag in one turn. Each resident schema is sent on every * model call, so a misbehaving plugin set must not silently flood the context. * Tools past the limit stay deferred (still reachable via `discover` / * `load_tool`) and a warning names them once. Operators who need more can list * tools in `deferredTools.alwaysLoadedTools`, which this limit does not touch. */ export declare const MAX_DECLARED_RESIDENT_TOOLS = 8; /** * Names of public tools whose author set `alwaysLoaded: true`, in projection * order and capped at {@link MAX_DECLARED_RESIDENT_TOOLS}. * * - Absent or `false` keeps the tool deferred (the default for every plugin). * - `deferredTools.alwaysLoadedMode: replace` means the operator's list is the * complete resident set, so author declarations are ignored. * - Only public (non-hidden) capabilities that already passed ingress and the * capability ceiling are considered; the flag never grants access. */ export declare function declaredResidentToolNames(tools: readonly Pick[], config: DeferredCapabilityPlanOptions['config']): string[]; export declare function capabilityAsAgentTool(tool: ToolCapability): AgentTool; /** Ranked rows first, then keyword rows the ranker did not select; each name once. */ export declare function mergeDiscoverRows(ranked: readonly T[], keyword: readonly T[]): T[]; /** Maximum best discover matches auto-loaded for the next model request. */ export declare const DISCOVER_SCHEMA_LIMIT = 3; /** * Re-attaches session entries that this turn's projection hid (narrower turn policy, * another entry Agent, collaboration tools absent) to the snapshot a turn persists. * A turn with a narrower catalog must not erase what the session loaded (#1250 * deferred-tools-break-prefix): the next turn with the wider catalog gets the same * tool list back. Hidden entries keep their first-load position. */ export declare function restoreProjectedOutEntries(stored: DeferredToolSessionSnapshot, projected: DeferredToolSessionSnapshot, next: DeferredToolSessionSnapshot): DeferredToolSessionSnapshot;