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

agent-survey

v0.0.3

Published

TypeScript-first survey engine with JSON, JavaScript, and TypeScript definitions

Readme

agent-survey

  • 中文文档
  • A TypeScript-first survey engine.
  • Survey definitions can be TypeScript, JavaScript, or JSON.
  • The core package has no model, provider, CLI, console, or filesystem assumptions.

Install

pnpm add agent-survey

Node.js 22.19 or later can also run the repository's TypeScript source directly.

Core API

Survey describes only the questionnaire. The caller supplies an Answerer and runtime policy to runSurvey:

import { runSurvey, type Survey } from 'agent-survey';

const survey: Survey = {
  name: 'Example',
  instructions: 'Answer concisely.',
  initialStep: 'question',
  steps: [{
    id: 'question',
    prompt: 'What should we improve?',
    validateFn: answer => answer.length >= 2,
    saveAs: 'suggestion',
  }],
};

const result = await runSurvey(survey, {
  answerer: {
    name: 'my-answerer',
    answer: async request => getAnswer(request.prompt),
  },
  maxSteps: 50,
  maxRetries: 3,
  rememberHistory: true,
});

rememberHistory defaults to true. Set it to false to expose only the current prompt and an empty context view to the Answerer. The runner still keeps its private context for validation, routing, and final results.

Model selection, provider credentials, timeouts, maximum steps, retry counts, logging, and process behavior are not Survey fields.

Optional Adapters

The pi-ai adapter is an explicit subpath import:

import { createPiAnswerer } from 'agent-survey/pi';

const answerer = createPiAnswerer({
  provider: 'anthropic',
  model: 'deepseek-v4-flash',
  baseUrl: 'https://example.test',
  thinking: true,
});

Node transcript helpers are separate from the core:

import { createTranscriptWriter } from 'agent-survey/node';

const transcript = createTranscriptWriter('./survey.ts');
await runSurvey(survey, {
  answerer,
  onAnswerStream(event) {
    if (event.type === 'thinkingDelta') process.stdout.write(event.delta);
    if (event.type === 'textDelta') process.stdout.write(event.delta);
  },
  onEvent: event => transcript.write(event),
});

Survey Sources

loadSurvey(path) returns one complete Survey. Directory discovery order:

  1. survey.ts
  2. survey.js
  3. survey.mjs
  4. survey.mts
  5. flow.json

TypeScript and JavaScript can put real functions directly in jumpFn and validateFn. JSON uses jumpFnName and validateFnName; an optional sibling functions.ts or functions.js supplies Survey.functionDict.

Steps can require typed JSON5 answers with answerFormat, and can declare options with configurable labels and optional shuffling. Display labels are mapped back to stable option values in context.optionMappings.

See Survey format for the complete contract.

CLI

The CLI is a convenience wrapper that combines the core, the pi-ai adapter, environment configuration, terminal output, and transcript files:

pnpm start flows/survey
pnpm start flows/adaptive-planner --model deepseek-v4-flash
pnpm start flows/configurable-survey --var topic=dog
pnpm start flows/configurable-survey --config flows/configurable-survey/inputs.shopping.json
pnpm start flows/poem-memory --no-history
pnpm start flows/proposition-judgment --var 'proposition=所有质数都是奇数。'
pnpm start flows/proposition-judgment --var 'proposition=所有质数都是奇数。' --no-thinking
pnpm start flows/fantasy-character --var 'characterDescription=an elven spellblade who guards an ancient forest'

flows/fantasy-character first creates a character using the schema included in the prompt, then checks flows/fantasy-character/catalog.jsonl. It asks for race or class data only when the referenced entity is missing. The consistent result is stored in context.variables.bundle, and new catalog entities are appended only after every required answer passes validation.

The CLI streams thinking and answer text to the terminal. Thinking is enabled by default; use --no-thinking to disable it and --thinking to enable it explicitly. These switches configure the pi-ai Answerer and are not Survey fields.

The CLI reads ANTHROPIC_API_KEY and the selected provider's baseUrl from ~/.pi/agent/models.json. These settings belong to the CLI/Answerer, not the Survey.

Markdown transcripts include model thinking when the Answerer returns it in the opaque SurveyAnswer.raw response. Streaming deltas are not duplicated in the transcript; it records the final response once.

Repository Development

pnpm install
pnpm typecheck
pnpm test
pnpm build
pnpm check

The package publishes ESM JavaScript and declarations from dist/, with root, ./pi, and ./node exports plus the agent-survey CLI binary.