npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@yeshwanthyk/sdk

v0.2.5

Published

Headless SDK for the Marvin coding agent. Run AI-powered coding tasks programmatically.

Readme

@yeshwanthyk/sdk

Headless SDK for the Marvin coding agent. Run AI-powered coding tasks programmatically.

Install

npm install @yeshwanthyk/sdk
# or
bun add @yeshwanthyk/sdk

Quick Start

import { runAgent } from "@yeshwanthyk/sdk"

const result = await runAgent({
  prompt: "Explain this code",
})

if (result.ok) {
  console.log(result.value.text)
} else {
  console.error(result.error.message)
}

API

runAgent(options): Promise<Result<SdkResult, SdkError>>

One-shot prompt execution. Returns a Result type (ok/error).

const result = await runAgent({
  // Required
  prompt: "Your prompt",

  // Optional - Provider/Model
  provider: "anthropic",           // default: from config
  model: "claude-sonnet-4-20250514", // default: from config
  thinking: "high",                // off | minimal | low | medium | high | xhigh
  systemPrompt: "Custom system prompt",

  // Optional - Model parameters
  maxTokens: 4096,
  temperature: 0.7,

  // Optional - Execution control
  signal: AbortSignal.timeout(30000),
  timeout: 30000,                  // ms
  retry: {
    maxAttempts: 3,                // primary model attempts
    fallbackAttempts: 2,           // fallback model attempts
    initialDelayMs: 100,           // backoff start
  },

  // Optional - Tool control
  tools: ["read", "write"],        // allowlist (only these tools)
  disableTools: ["bash"],          // blocklist (disable these tools)

  // Optional - Attachments
  attachments: [
    { type: "image", content: base64String, mimeType: "image/png" }
  ],
})

createAgentSession(options): Promise

Multi-turn conversation session with memory.

const session = await createAgentSession({
  // Same options as runAgent (except prompt)
  // Plus:
  restore: previousState,  // Restore from exported state
})

// Chat (maintains conversation history)
const result = await session.chat("Hello")
const result2 = await session.chat("What did I just say?")

// Get current state
const snapshot = await session.snapshot()

// Abort current request
session.abort()

// Export for persistence
const state = await session.export()
// state is JSON-serializable

// Clean up
await session.close()

runAgentStream(options): AsyncIterable

Streaming events for real-time UI updates.

for await (const event of runAgentStream({ prompt: "..." })) {
  if (event.type === "agent") {
    if (event.event.type === "message_update") {
      const update = event.event.assistantMessageEvent
      if (update.type === "text_delta") {
        process.stdout.write(update.delta)
      }
    } else if (event.event.type === "tool_execution_start") {
      console.log("Tool:", event.event.toolName)
    }
  }
}

Effect API (for Effect users)

All functions have *Effect variants returning Effect types:

import { runAgentEffect, runAgentStreamEffect } from "@yeshwanthyk/sdk"
import { Effect, Stream } from "effect"

// Full error type visibility in signature
const effect: Effect.Effect<SdkResult, SdkError> = runAgentEffect({ prompt: "..." })

// Stream with backpressure and composition
const stream: Stream.Stream<SdkEvent, SdkError> = runAgentStreamEffect({ prompt: "..." })

// Compose streams
const limited = stream.pipe(Stream.take(10))
const withTimeout = stream.pipe(Stream.timeout(Duration.seconds(30)))

Error Handling

Errors are discriminated unions with _tag, code, and retryable:

if (!result.ok) {
  const error = result.error

  // Pattern match on error type
  switch (error._tag) {
    case "ConfigError":
      // code: "CONFIG_MISSING" | "CONFIG_INVALID"
      // retryable: false
      break

    case "ProviderError":
      // code: "AUTH" | "RATE_LIMITED" | "OVERLOADED" | "MODEL_NOT_FOUND"
      // retryable: true for RATE_LIMITED, OVERLOADED
      if (error.retryable) {
        // Implement retry logic
      }
      break

    case "RequestError":
      // code: "TIMEOUT" | "ABORTED" | "CONTEXT_LENGTH" | "NETWORK"
      // retryable: true for TIMEOUT, NETWORK
      break

    case "HookError":
      // code: "HOOK_FAILED"
      // retryable: false
      break
  }
}

Result Shape

interface SdkResult {
  text: string               // Final assistant response
  messages: AppMessage[]     // Full conversation history
  toolCalls: ToolCall[]      // Tools that were called
  usage?: Usage              // Token counts and cost
  provider: string           // Provider used
  model: string              // Model used
  sessionId: string | null   // Session ID if persisted
  stopReason: StopReason     // "complete" | "maxTokens" | "aborted" | "error"
  durationMs: number         // Request duration in milliseconds
}

Configuration

The SDK reads configuration from ~/.config/marvin/config.json:

{
  "provider": "anthropic",
  "model": "claude-sonnet-4-20250514",
  "thinking": "high"
}

Override via options or environment variables (ANTHROPIC_API_KEY, etc).

Examples

See examples/ for runnable examples:

  • examples/basic.ts - Simple one-shot usage
  • examples/streaming.ts - Real-time streaming
  • examples/session.ts - Multi-turn with export/import
  • examples/abort.ts - Cancellation patterns

Run with:

cd packages/sdk
bun run examples/basic.ts

License

MIT