Skip to main content

Built and signed on GitHub Actions

Works with
This package works with DenoIt is unknown whether this package works with Cloudflare Workers, Node.js, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
•JSR Score100%•
License
Apache-2.0
•
Downloads48/wk
•
Publisheda day ago (0.0.10)

The AI plugin for NetScript: one install scaffolds an app-owned, in-process chat, tool, and agent surface — typed userland files that call the AI engine directly, with no gateway in between.

@netscript/plugin-ai

JSR CI Docs

The AI plugin for NetScript: one install scaffolds an app-owned, in-process chat, tool, and agent surface — typed userland files that call the AI engine directly, with no gateway in between.

Most AI integrations bolt a proxy service onto your app and hide the interesting code behind it. @netscript/plugin-ai takes the opposite stance: netscript plugin install ai emits a small set of typed files under ai/ — a composition root, a model registry, a streaming chat route, a chat island, and starter tool and agent stubs — and every one of them is yours to edit. The generated route calls the AI engine inside your app's own server process; no AI gateway or extra network hop is scaffolded.

The plugin itself ships no runtime AI logic. The engine lives in @netscript/ai and the durable-chat runtime in @netscript/fresh; the scaffolded files import those installed dependencies directly, so upgrading the engine never means regenerating your code.

Why teams use it

  • App-owned output — every scaffolded file is a typed wrapper importing the installed dependency, never a copy of framework source; edit them like any other file in your repo.
  • Fully in-process by default — the generated chat stream route runs the agent loop inside your server, keeping latency, secrets, and observability in one place.
  • Streaming with cancellation — the chat route threads the request's AbortSignal into the agent loop and the chat connection exposes stop(), so clients can cancel a generation mid-stream.
  • Typed model registry — ai/models.ts centralizes provider ids and provider:model-id refs; change models by editing data, not routes.
  • MCP client-side, where it belongs — the scaffolded tool registry (ai/mcp/registry.ts) bridges MCP client transports from @netscript/ai/mcp into your tools; the plugin scaffolds no MCP server.
  • Opt-in persistence — thread persistence is a flag away, backed by a Deno KV thread store.

MCP servers through service discovery

Add an app-owned MCP server by its Aspire resource name:

netscript plugin ai mcp add orders --service=orders-mcp --path=/mcp --auth=ORDERS_MCP_TOKEN

This creates ai/mcp/orders.ts and updates ai/mcp/registry.ts. The generated configuration uses getServiceUrl from @netscript/sdk/discovery and joins the MCP path with Web URL. The endpoint is resolved when the configuration module loads in the app process, so generation needs no running server. Configure discovery before importing the registry. For this example, the default endpoint comes from services__orders-mcp__http__0; a missing value throws an error naming the service and expected variable. There is no fallback port.

Make the consuming app reference the MCP server resource in your Aspire AppHost so that Aspire injects its endpoint. Your app owns that server, its tools and authorization. --auth names an environment variable containing the Authorization header value (include Bearer if the server expects bearer authentication); the generated source stores the variable name, not the token. The plugin's scaffold --mcp option emits the skill-loader tool and does not create this app-data MCP server.

Option Service mode behavior
--service=<name> Logical Aspire resource name, using letters, digits and hyphens; starts with a letter.
--path=/mcp Defaults to /mcp; a root-relative path replaces any path in the discovered base URL.
--protocol=http http by default; https selects services__<name>__https__0.
--auth=<ENV> Optional existing HTTP token configuration; the value becomes the Authorization header.

Exactly one of --service, --url or --stdio is required. Empty or valueless flags, invalid protocols and ambiguous transport selections fail before changing the server file or registry. --path and --protocol require service mode. Paths cannot contain an origin, query, fragment, dot segments, whitespace or encoded separators.

Fixed URLs and stdio commands remain available:

netscript plugin ai mcp add docs --url=https://docs.example.test/mcp --auth=DOCS_MCP_TOKEN
netscript plugin ai mcp add local --stdio=mcp-local-server
netscript plugin ai mcp list

New JSR installs receive the SDK alias through the CLI's plugin import wiring. For an existing JSR project installed before service mode was added, add the SDK to the root import map before loading the new config: run deno add jsr:@netscript/sdk@<version> from the project root, replacing <version> with the exact NetScript version already used by the project. Local-source projects resolve the copied SDK workspace member and must not add a published SDK pin.

Excluding helpers from generated registries

netscript generate plugins selects definition modules from ai/tools/*.ts and ai/agents/*.ts. Keep a helper or a dependency-injected factory beside those definitions by putting this exact comment on its first line:

// @netscript-registry-ignore
export function scopedId(scope: string, name: string): string {
  return `${scope}.${name}`;
}

For example, add it to ai/tools/helper.ts. The directive is shared by all plugin runtime registries and standalone registry compilers. It excludes the whole module before generating imports; ordinary imports from your application keep working. Use a separate module for a top-level tool definition that should remain registered.

The marker must be the complete first-line comment, before any license header or code. Indentation, a UTF-8 BOM and CRLF are accepted; a later comment, a string containing the marker, or extra text on the line does not opt out. Existing manifest suffix and filename exclusions still apply.

Regenerate and inspect the result:

netscript generate plugins
netscript plugin doctor

Doctor names eligible modules carrying the directive as Explicitly excluded registry modules, on both healthy and stale registries. Remove the directive and regenerate to register the module again. Unmarked modules retain the plugin's existing definition validation. Keep the CLI, shared plugin package and installed plugins on matching release versions so their selector and inspection protocol agree.

AI tool definition-shape selection still applies after explicit exclusions. Factory-only tools that the existing shape check skips implicitly do not become explicitly excluded modules.

Architecture

flowchart LR
    M["aiPlugin manifest"] --> C["netscript plugin install ai"]
    C --> F["Scaffolded ai/ workspace<br/>(app-owned typed files)"]
    F --> R["chat-stream route<br/>(in-process agent loop)"]
    R --> E["@netscript/ai engine<br/>providers · tools · agents"]
    F --> U["chat.tsx island<br/>(streams chunks, stop())"]

Install

From the root of a NetScript project:

netscript plugin install ai --name ai

To consume the plugin programmatically (custom hosts, tests, tooling), add it as a library:

deno add jsr:@netscript/plugin-ai@<version>

Pin <version> to match your installed CLI; bare jsr:@netscript/* specifiers do not resolve on the pre-release line.

Quick example

Install the plugin and inspect what it emitted:

$ netscript plugin install ai --name ai
Installed ai plugin "ai" on port 8095.
Created 7 plugin files.
Regenerated 12 Aspire helper files.
File Purpose
ai/ai.ts Composition root: wires @netscript/ai once.
ai/models.ts Provider ids + provider:model-id refs (edit freely).
ai/routes/chat-stream.ts In-process POST route: runs the agent loop directly.
ai/routes/chat.tsx Chat island rendering streamed assistant parts.
ai/tools/echo.ts Starter Standard-Schema tool over @netscript/ai/tools.
ai/agents/assistant.ts Starter bounded agent loop over @netscript/ai/agent.
ai/mcp/registry.ts Tool registry bridging MCP client transports.

As a library, the manifest is inspectable data, and the adapter connector previews exactly what an install will emit:

import { aiPlugin } from '@netscript/plugin-ai';
import { aiAdapterPlugin } from '@netscript/plugin-ai/adapter';
import { collectInstallArtifacts } from '@netscript/plugin/adapter';

console.log(aiPlugin.name); // "@netscript/plugin-ai"

// Paths emitted by the default (in-process) install topology.
for (const artifact of collectInstallArtifacts(aiAdapterPlugin)) {
  console.log(artifact.path); // e.g. "ai/ai.ts", "ai/routes/chat-stream.ts"
}

// Add-only resources hosts can scaffold incrementally (tool, agent, thread-store).
console.log(aiAdapterPlugin.resources?.map((resource) => resource.name));

Public surface

Entry What it gives you
. aiPlugin plus the AI_PLUGIN_ID / AI_WORKSPACE_NAME constants
./adapter The adapter connector hosts drive to install and add resources
./contracts The versioned /v1/ai contract from @netscript/plugin-ai-core
./scaffold The plugin-owned scaffolder netscript plugin install ai executes

The always-current symbol list is deno doc jsr:@netscript/plugin-ai@<version> (pin <version> on the pre-release line, as above).

Docs

Compatibility

The scaffolded surface runs wherever your NetScript app runs (Deno 2.9+); thread persistence uses Deno KV. The manifest and contracts are plain data and types, importable in any TypeScript environment. Provider API keys are read by your app's own configuration — the plugin stores no credentials.

License

Apache-2.0 — see LICENSE. Published to JSR with cryptographically verified provenance.

Built and signed on
GitHub Actions

Add Package

deno add jsr:@netscript/plugin-ai

Import symbol

import * as plugin_ai from "@netscript/plugin-ai";
or

Import directly with a jsr specifier

import * as plugin_ai from "jsr:@netscript/plugin-ai@^0.0.10";