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

@silyze/browsary-ai-provider

v2.0.0

Published

Browsary AI provider interface

Readme

Browsary AI Provider

The Browsary AI Provider package defines the core abstractions and interfaces for integrating AI-driven analysis and pipeline generation into the Browsary ecosystem.

Install

npm install @silyze/browsary-ai-provider

Usage

Create custom evaluators and providers by extending the supplied base classes:

import {
  AiEvaluator,
  AiProvider,
  AiEvaluationContext,
  AnalyzeOutput,
  AnalysisResult,
  AiResult,
  Pipeline,
  GenericNode,
} from "@silyze/browsary-ai-provider";

class MyAiEvaluator extends AiEvaluator<MyContext> {
  async evaluate<TArgs extends any[], TResult>(
    fn: (context: MyContext, ...args: TArgs) => TResult,
    ...args: TArgs
  ) {
    // call into your AI runtime and return the result
  }

  createContext<TConfig>(
    constructor: new (
      config: TConfig,
      functionCall: (
        context: MyContext,
        name: string,
        params: any,
        abortController?: AbortController
      ) => Promise<unknown>
    ) => AiProvider<MyContext, TConfig>,
    config: TConfig
  ): AiEvaluationContext<MyContext> {
    const provider = new constructor(config, this.evaluate.bind(this));
    return { agent: this, provider };
  }
}

class MyAiProvider extends AiProvider<MyContext, MyConfig> {
  async analyze(...) { /* implement analysis */ }
  async generate(...) { /* implement pipeline generation */ }
}

const evaluator = new MyAiEvaluator();
const { provider } = evaluator.createContext(MyAiProvider, myConfig);
const analysis = await provider.analyze(context, "Find buttons", {});
const { result: pipeline } = await provider.generate(context, analysis.result, {});

Tracking Usage

Expose token usage or other billing metrics by pairing calls to emitStart and emitEnd. They allow you to annotate requests with timestamps and usage numbers gathered from your underlying SDK.

const modelId = "gpt-4o";
const start = provider.emitStart({
  source: "model.prompt",
  model: modelId,
});

const sdk = await callIntoYourModel();

provider.emitEnd({
  source: "model.prompt",
  model: modelId,
  startedAt: start.startedAt,
  usage: {
    inputTokens: sdk.usage?.prompt_tokens,
    outputTokens: sdk.usage?.completion_tokens,
    totalTokens: sdk.usage?.total_tokens,
  },
});

Place these hooks around every model invocation to keep downstream systems aware of runtime cost.

Analyze vs. Generate

  • analyze runs first and produces an AnalysisResult that describes findings and raw AI output.
  • generate consumes the analysis and returns a Pipeline ready to be executed or merged.

API Reference

Types and Interfaces

AnalyzeOutput

export type AnalyzeOutput = {
  selectors: {
    selector: string;
    locatedAtUrl: string;
    description: string;
    type: "guess" | "tested-valid" | "tested-fail";
  }[];
  metadata: string[];
};
  • selectors: Array of discovered CSS selectors, including context and test status.
  • metadata: Additional context or notes collected during analysis.

AnalysisResult

export interface AnalysisResult {
  analysis: AnalyzeOutput;
  prompt: string;
}
  • analysis: The raw output of the AI analysis step.
  • prompt: The actual prompt sent to the AI model.

AiResult<T>

export type AiResult<T> = {
  result?: T;
  messages: object[];
};
  • result: The final produced value (for example AnalysisResult or Pipeline).
  • messages: Log of messages exchanged with the AI service.

AiEvaluationContext<TContext>

export interface AiEvaluationContext<TContext> {
  agent: AiEvaluator<TContext>;
  provider: AiProvider<TContext, unknown>;
}
  • agent: Instance of AiEvaluator, responsible for calling AI functions.
  • provider: The configured AiProvider instance.

Classes

AiEvaluator<TContext>

export abstract class AiEvaluator<TContext> {
  abstract evaluate<TArgs extends any[], TResult>(
    fn: (context: TContext, ...args: TArgs) => TResult,
    ...args: TArgs
  ): Promise<Awaited<TResult>>;

  abstract createContext<TConfig>(
    constructor: new (
      config: TConfig,
      functionCall: (
        context: TContext,
        name: string,
        params: any,
        abortController?: AbortController
      ) => Promise<unknown>
    ) => AiProvider<TContext, TConfig>,
    config: TConfig
  ): AiEvaluationContext<TContext>;
}
  • evaluate: Runs a pure function under AI supervision.
  • createContext: Instantiates a provider context for analysis and generation.

AiProvider<TContext, TConfig>

Abstract class implemented by concrete AI backends.

export abstract class AiProvider<TContext, TConfig = {}> {
  constructor(
    config: TConfig,
    functionCall: (
      context: TContext,
      name: string,
      params: any,
      abortController?: AbortController
    ) => Promise<unknown>
  );

  analyze(
    context: TContext,
    userPrompt: string,
    previousPipeline: Record<string, GenericNode>,
    onMessages?: (message: unknown[]) => Promise<void> | void,
    abortController?: AbortController
  ): Promise<AiResult<AnalysisResult>>;

  generate(
    context: TContext,
    analysisResult: AnalysisResult,
    previousPipeline: Record<string, GenericNode>,
    onMessages?: (message: unknown[]) => Promise<void> | void,
    abortController?: AbortController
  ): Promise<AiResult<Pipeline>>;
}
  • analyze: Produces an initial analysis of a user prompt against an existing pipeline.
  • generate: Builds or updates a Pipeline based on analysis results.

Aborting work

Use the optional AbortController argument on analyze and generate when you need to cancel long‑running operations. Provide the controller you manage upstream and propagate its signal into any downstream SDK calls (including those made through callFunctionWithTelemetry). Reject the promise when cancellation happens so callers can react and telemetry can close out properly.

Example Implementation

const evaluator = new MyAiEvaluator();
const { agent, provider } = evaluator.createContext(MyAiProvider, config);
const analysis = await provider.analyze(context, "Find buttons", {});
const { result: pipeline } = await provider.generate(context, analysis.result, {});