Skip to content

API Reference — JavaScript

Package toolnexus (npm). See the combined API Reference for every symbol shown in eight-language synced tabs.

  • createToolkit(opts: ToolkitOptions): Promise<Toolkit> — the aggregator.
  • ToolkitOptions: mcpConfig, skillsDir, skills, skillProvider, skillsFilter, skillSampleLimit, builtins, agents, extraTools, waitFor, disableTools, disableSkills, signal.
  • Equivalents: create_toolkit (py) · CreateToolkit (go) · Toolkit.create (java) · Toolkit.CreateAsync (c#) · Toolnexus.create_toolkit (elixir).
  • loadSkills(input: string | string[] | LoadSkillsOptions): SkillSource
  • listSkills(input): SkillInventory — { skills, skipped }; skip reasons missing-name · malformed-frontmatter · duplicate-name · unreadable.
  • SkillDef { name, description?, content, resources?, base? }
  • LoadSkillsOptions { dirs?, skills?, filter?, sampleLimit? }
  • Equivalents: load_skills / list_skills (py) · LoadSkills / LoadSkillsWith / ListSkills (go) · SkillSource.load / loadWith / listSkills (java) · SkillSource.Load / LoadWith / ListSkills (c#) · Toolnexus.Skill.load / Toolnexus.Skill.list (elixir).
  • loadMcp(config): Promise<McpSource>
  • toOpenAI(tk) · toAnthropic(tk) · toGemini(tk)
  • createClient(opts): Client → client.ask(prompt, tk), client.stream(...).

Tools you build — native, HTTP, built-ins

Section titled “Tools you build — native, HTTP, built-ins”
  • defineTool({ name, description, inputSchema?, run }) — your function as a Tool. Decorator sugar: @tool(description, { name?, inputSchema? }) + collectTools(obj).
  • httpTool({ name, description, method, url, headers?, query?, body?, resultMode?, timeout? }) — an endpoint as a Tool.
  • builtins toggle → ten built-ins: bash · read · write · edit · grep · glob · webfetch · question · apply_patch · todowrite.
  • Equivalents: define_tool/tool · http_tool (py) · NativeTool/NativeToolReflect · HTTPTool (go) · NativeTool.of · HttpTool.of (java) · NativeTool.Of · HttpTool.Of (c#) · Toolnexus.Native.define_tool · Toolnexus.Http.tool (elixir).
  • agents.agent(name, spec): Agent — spec { does, uses?, soul?, soulFile?, team?, budget?, model?, waitFor? }.
  • agent.run(prompt, opts): Promise<AgentRunResult> — { status, text, totalTokens, turns, runtime }.
  • agent.asTool(opts): Tool (delegate as one tool) · composeSoul(dir): { soul, found }.
  • Equivalents: agent / .run / .as_tool / compose_soul (py) · agents.New / .Run / .AsTool / ComposeSoul (go) · Agents.agent / .run / .asTool / Agents.composeSoul (java) · new Agent / .RunAsync / .AsTool / Home.ComposeSoul (c#) · Agents.agent / Agents.run / Agents.as_tool / Agents.compose_soul (elixir).
  • tk.serve(addr, { client, a2a, onTask?, mcp?, onCall? }): Promise<ServeHandle> — expose the toolkit; handle.url, handle.stop().
  • agent({ card, headers?, timeout?, pollEvery? }) + createToolkit({ agents }) / tk.addAgent(cardUrl) — consume a peer’s skills as <agent>_<skill> tools.
  • Equivalents: serve / add_agent (py) · Serve / AddAgent (go) · serve / addAgent (java) · ServeAsync / AddAgentAsync (c#) · Toolkit.serve / Toolkit.add_agent (elixir).
  • waitFor?: (req: Request) => Promise<Answer> (toolkit option).
  • Request { id, kind, prompt, url?, data?, expiresAt? } · Answer { id, ok, data?, reason? }.
  • pending({ kind, prompt, url?, data? }): ToolResult · authRequired(url, prompt?) · pendingOf(result): Request | undefined.
  • Equivalents: wait_for / pending / auth_required / pending_of (py) · WaitFor / Pending / AuthRequired / PendingOf (go) · waitFor / ToolResult.pending / authRequired / pendingOf (java) · WithWaitFor / ToolResult.Pending / AuthRequired / PendingOf (c#) · wait_for / ToolResult.pending? (elixir).

Guide: Media generation · recipe: Generate images, video and speech · SPEC §7G.

  • createMedia(clients: MediaClient | MediaClient[]): Media — a verb goes to the first client whose supports(verb) is true; only MediaUnavailableError falls through to the next one.
  • Built-in clients, each new X(config?: MediaClientConfig): A2EMediaClient (A2E_API_KEY) · ElevenLabsMediaClient (ELEVENLABS_API_KEY) · OpenAIMediaClient (OPENAI_API_KEY) · OpenRouterMediaClient (OPENROUTER_API_KEY) · FalMediaClient (FAL_API_KEY) — and the CLI clients GrokMediaClient (grok) · CodexMediaClient (codex).
  • MediaClientConfig { model?, models?: Partial<Record<MediaVerb, string>>, key?, url?, command?: string | string[], loop?: { intervalMs?, timeoutMs?, onProgress? }, gather?: { mode?: "url" | "download" | "inline", dir?, maxBytes?, keep? }, fetch?: typeof fetch } — key defaults to the env var read at call time; timeoutMs 600000; gather.mode default download (style clients url) into <tmp>/toolnexus-media, maxBytes 100 MiB.
  • Verbs, each (input: XArgs & MediaCallOptions): Promise<MediaResult>: image(ImageArgs { prompt, width?, height?, aspectRatio?, seed? }) · video(VideoArgs { prompt, image?, seconds?, aspectRatio? }) · speech(SpeechArgs { text, voice? }) · music(MusicArgs { prompt, seconds?, instrumental?, lyrics? }) · transcribe(TranscribeArgs { audio, language? }) · cloneVoice(CloneVoiceArgs { name, samples }) · talk(TalkArgs { image, audio?, text?, voice? }). File inputs (image, audio, samples) take a URL or a local path.
  • MediaCallOptions = MediaContext { signal?: AbortSignal, deadline?: number | Date, progress?: (p: MediaProgress) => void, providerOptions? } — MediaProgress { verb, client, jobId?, status, elapsedMs }; providerOptions top-level keys overwrite the request body last.
  • generate(verb: MediaVerb | string, args?, ctx?: MediaContext): Promise<MediaResult> · supports(verb): boolean.
  • MediaResult { files: MediaFile[], text?, jobId?, status } · MediaFile { type: "image" | "audio" | "file", mimeType, url?, path?, data? } (which are set follows gather.mode).
  • MediaClient { readonly name, supports(verb), args?(verb): MediaArgSpec[], image?(args, ctx) … talk?(args, ctx) } — implement it for your own provider; every verb is optional.
  • media.tools(): Tool[] — generate_image · generate_video · generate_speech · generate_music · transcribe_audio · clone_voice · talking_video (source "media"), one per verb any client supports; or createToolkit({ media }). Only image parts are sent back to the model.
  • RunResult.files: RunFile[] — { type, mimeType, url?, data?, name?, from, callId }, in call order; the same parts are on toolCalls[].parts.
  • Errors: the function face throws MediaError { message, status: "failed" | "timeout" | "cancelled" | "unavailable", jobId? }; MediaUnavailableError is its unavailable subclass. A media tool never throws (isError: true, message as output). An aborted signal rejects with signal.reason (or an AbortError).
  • Advanced: styleMediaClient(style: MediaStyle, config?) / StyleMediaClient turn a JSON style into a client; loadMediaStyle(path) reads one; A2E_STYLE is the embedded a2e preset. MEDIA_VERBS exports the canonical verb table.
  • Equivalents: create_media (py) · CreateMedia (go) · Media.create (java) · Media.Create (c#) · Toolnexus.Media.create (elixir) · toolnexus.media/create-media (clojure) · create_media (rust).