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

@ophirai/protocol

v0.3.0

Published

Core protocol definitions for the Ophir Agent Negotiation Protocol — types, schemas, state machine, SLA metrics, and error codes

Downloads

335

Readme

@ophir/protocol

Core protocol definitions for the Ophir Agent Negotiation Protocol. This package contains TypeScript types, Zod validation schemas, constants, and error codes shared by all Ophir packages.

Installation

npm install @ophir/protocol

Usage

import {
  METHODS,
  DEFAULT_CONFIG,
  RFQParamsSchema,
  QuoteParamsSchema,
  CounterParamsSchema,
  AcceptParamsSchema,
  RejectParamsSchema,
  DisputeParamsSchema,
  OphirError,
  OphirErrorCode,
} from '@ophir/protocol';

import type {
  RFQParams,
  QuoteParams,
  CounterParams,
  AcceptParams,
  RejectParams,
  DisputeParams,
  FinalTerms,
  SLAMetricName,
  NegotiationState,
} from '@ophir/protocol';

Validate an incoming message

import { RFQParamsSchema, QuoteParamsSchema } from '@ophir/protocol';

// Throws ZodError if validation fails
const rfq = RFQParamsSchema.parse(incomingData);
const quote = QuoteParamsSchema.parse(incomingData);

Access protocol constants

import { METHODS, DEFAULT_CONFIG } from '@ophir/protocol';

METHODS.RFQ;       // "negotiate/rfq"
METHODS.QUOTE;     // "negotiate/quote"
METHODS.COUNTER;   // "negotiate/counter"
METHODS.ACCEPT;    // "negotiate/accept"
METHODS.REJECT;    // "negotiate/reject"
METHODS.DISPUTE;   // "negotiate/dispute"

DEFAULT_CONFIG.rfq_timeout_ms;      // 300000 (5 minutes)
DEFAULT_CONFIG.quote_timeout_ms;    // 120000 (2 minutes)
DEFAULT_CONFIG.counter_timeout_ms;  // 120000 (2 minutes)
DEFAULT_CONFIG.max_negotiation_rounds;  // 5

Handle errors

import { OphirError, OphirErrorCode } from '@ophir/protocol';

try {
  // ... protocol operation
} catch (err) {
  if (err instanceof OphirError) {
    console.error(err.code);     // e.g., "OPHIR_002"
    console.error(err.message);  // Human-readable description
    console.error(err.data);     // Optional structured context
  }
}

What is included

Types

TypeScript interfaces for every protocol message:

  • RFQParams, QuoteParams, CounterParams, AcceptParams, RejectParams, DisputeParams
  • FinalTerms, AgentIdentity, ServiceRequirement, BudgetConstraint
  • SLARequirement, SLAMetric, SLAMetricName
  • PricingOffer, VolumeDiscount, EscrowRequirement
  • ViolationEvidence, NegotiationState

Schemas

Zod validation schemas for runtime message validation:

  • RFQParamsSchema, QuoteParamsSchema, CounterParamsSchema
  • AcceptParamsSchema, RejectParamsSchema, DisputeParamsSchema

Constants

  • METHODS -- RPC method name constants
  • DEFAULT_CONFIG -- Default timeouts, currency, escrow seeds, max rounds

Errors

  • OphirErrorCode -- Enum of all error codes (OPHIR_001 through OPHIR_504)
  • OphirError -- Typed error class with code, message, and optional data

Error code ranges:

  • OPHIR_001–006: Message validation
  • OPHIR_100–104: Negotiation
  • OPHIR_200–204: Escrow
  • OPHIR_300–301: Dispute
  • OPHIR_400–403: Infrastructure
  • OPHIR_500–504: Clearinghouse (margin, exposure, netting, circuit breaker, PoD)

SLA metric types

uptime_pct | p50_latency_ms | p99_latency_ms | accuracy_pct |
throughput_rpm | error_rate_pct | time_to_first_byte_ms | custom

State machine

import { isValidTransition, isTerminalState, getValidNextStates } from '@ophirai/protocol';
IDLE → RFQ_SENT → QUOTES_RECEIVED → COUNTERING → ACCEPTED →
MARGIN_ASSESSED → ESCROWED → ACTIVE → COMPLETED
                                   ↘ DISPUTED → RESOLVED

Any non-terminal state → REJECTED (terminal)

12 states. Terminal: COMPLETED, REJECTED, RESOLVED.

Documentation