@anthropic-ai/sdk
Version:
The official TypeScript library for the Anthropic API
73 lines • 4.15 kB
TypeScript
/**
* Node-only skill plumbing for the agent toolset: downloading a session
* agent's skills into the workdir and extracting the archives. Kept in its own
* file because it is a distinct concern from the tool implementations in
* `node.ts` — distinct enough, and large enough, to review on its own.
*/
import type { Anthropic } from "../../client.js";
import type { AgentToolContext } from "./node.js";
/**
* Download the session agent's skills into `{ctx.workdir}/skills/<name>/`.
*
* No-op (returns a no-op cleanup) unless both `ctx.client` and `ctx.sessionId`
* are set. Looks up the session's resolved agent and, for each skill, fetches
* its files via `client.beta.skills.versions.download` and extracts the archive
* (a zip or tar.* archive) into a directory named after the skill. A failure on
* one skill is logged and does not block the others. Call this before starting
* the session tool runner (e.g. right after the bash session / workdir is
* ready).
*
* Returns a cleanup function that removes the skill directories this call
* created — call it once the work item is done so downloaded skills do not
* accumulate in the workdir across sessions.
*/
export declare function setupSkills(ctx: AgentToolContext): Promise<() => Promise<void>>;
/**
* Resolve `version` to the concrete numeric timestamp the
* `/v1/skills/{id}/versions/{version}` endpoints require — `session.agent.skills[].version`
* can be an alias such as `"latest"`, which those endpoints reject. Numeric
* versions pass through unchanged.
*/
export declare function resolveSkillVersion(client: Anthropic, skillId: string, version: string): Promise<string>;
/**
* Pair an archive's name listing (`unzip -Z1` / `tar -tf`) with its typed
* listing (`unzip -Z --h --t` / `tar -tvf`) and split the members into plain
* (regular file or directory) and special (everything else). Special members
* are excluded from extraction rather than rejected; the archive is refused
* only when the two listings disagree in length or a special member's name
* cannot be passed back to the CLI verbatim (see {@link canExcludeVerbatim}).
*/
export declare function classifyArchiveListing(cmd: 'unzip' | 'tar', names: string, typed: string): {
plain: string[];
special: string[];
};
/**
* Walk `dir` with `lstat` semantics and reject anything that is not a regular
* file or directory. Never follows a link and never descends into anything
* but a real directory.
*/
export declare function assertOnlyPlainEntries(dir: string): Promise<void>;
/**
* Extract a skill download (a zip or tar.* archive) into `dest`. Streams the
* response body straight to a temp file beside `dest` (so the whole archive is
* never buffered in memory — skills can contain large binaries), then shells out
* to `unzip`/`tar` — consistent with the rest of the toolset, which already
* invokes `bash` and `rg`. Both `unzip` and `tar` must be available on `PATH`; a
* missing binary surfaces as a clear error (see {@link runArchiveTool}). Refuses
* any member that would escape `dest` (zip-slip / tar-slip): skill archives
* come from the API, but skills can be third-party. Members that are not a
* regular file or directory (symlink, hardlink, device, fifo) are excluded
* from extraction rather than rejected; an archive whose special members
* cannot be excluded reliably is refused (see {@link classifyArchiveListing}).
* `tar` matches exclusions unanchored, so a plain member sharing a special
* member's name may be dropped too. The staging tree is verified to hold only
* regular files and directories before anything is promoted into `dest`.
*
* The skill bundle's single wrapper directory is stripped: the archive is
* extracted into a staging dir and the wrapper's contents are promoted into
* `dest`, so files land at `dest/SKILL.md` rather than a doubled
* `dest/<skill>/SKILL.md` (`unzip` has no `--strip-components`, so this is
* done uniformly by staging + promote rather than per-tool flags).
*/
export declare function extractSkillArchive(resp: Response, dest: string): Promise<void>;
//# sourceMappingURL=skills.d.ts.map