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

@kognitivedev/cloud-web-search

v0.2.30

Published

Cloud web search SDK for Kognitive hosted job APIs

Readme

@kognitivedev/cloud-web-search

Cloud web-search SDK for Kognitive's hosted /api/cloud/web-search/* job APIs.

Use it when you want a first-class TypeScript client for:

  • creating hosted search and research jobs
  • polling current job state
  • waiting for completion
  • cancelling queued or running jobs
  • subscribing to live progress over SSE
  • validating server payloads before they reach application code

Installation

bun add @kognitivedev/cloud-web-search

Quick Start

import { KognitiveCloudWebSearchClient } from "@kognitivedev/cloud-web-search";

const webSearch = new KognitiveCloudWebSearchClient({
  baseUrl: process.env.COGNITIVE_API_URL ?? "http://localhost:3001",
  apiKey: process.env.COGNITIVE_API_KEY,
});

const job = await webSearch.jobs.create({
  mode: "research",
  instructions: "Research the latest Bun release updates.",
  responseInstructions: "Return a concise summary.",
  responseSchema: {
    type: "object",
    properties: {
      summary: { type: "string" },
    },
    required: ["summary"],
  },
  parameters: {
    maxPages: 4,
    timeRange: "month",
  },
});

const completed = await webSearch.jobs.waitForCompletion(job.id, {
  parseOutput(value) {
    if (!value || typeof value !== "object" || Array.isArray(value) || typeof value.summary !== "string") {
      throw new Error("Expected { summary: string }");
    }

    return { summary: value.summary };
  },
});

console.log(completed.result?.output?.summary);
console.log(completed.result?.sources);

API Surface

@kognitivedev/cloud-web-search centers on hosted job lifecycle methods:

  • jobs.list()
  • jobs.create()
  • jobs.createSearch()
  • jobs.createResearch()
  • jobs.get()
  • jobs.result()
  • jobs.cancel()
  • jobs.waitForCompletion()
  • jobs.stream()
  • jobs.subscribe()
  • jobs.streamUrl()

All requests use the same project API key model as the backend cloud web-search endpoints.

Typed Output

jobs.get(), jobs.result(), jobs.waitForCompletion(), and jobs.subscribe() accept parseOutput so you can turn result.output from unknown into a typed shape at the SDK boundary.

const envelope = await webSearch.jobs.result(job.id, {
  parseOutput(value) {
    if (!value || typeof value !== "object" || Array.isArray(value) || typeof value.summary !== "string") {
      throw new Error("Expected { summary: string }");
    }

    return { summary: value.summary };
  },
});

envelope.result?.output?.summary;

Streaming Progress

Use jobs.subscribe() when you want normalized progress events without manually parsing SSE frames:

const stream = await webSearch.jobs.subscribe(job.id);

for await (const event of stream) {
  switch (event.type) {
    case "snapshot":
      console.log("job status:", event.job.status);
      break;
    case "progress":
      console.log(`[${event.progress.stage}] ${event.progress.message}`);
      break;
    case "completed":
      console.log("done:", event.result?.text);
      break;
    case "error":
      console.error(event.errorMessage);
      break;
    case "cancelled":
      console.log("job cancelled");
      break;
    case "event":
      console.log("raw job event:", event.event.eventType);
      break;
    case "unknown":
      console.log("unrecognized frame:", event.frame.event);
      break;
  }
}

The SDK handles both stream shapes the backend can emit:

  • canonical lifecycle frames such as job.snapshot, job.progress, and job.completed
  • persisted job-event replay frames where the SSE event: name is the stored eventType

The low-level readSSEStream() parser is chunk-safe and supports:

  • multi-line data: fields
  • CRLF, LF, and CR line endings
  • SSE comments
  • id: and retry: fields
  • EOF flush for the final event

If you want the raw SSE response instead, use:

const response = await webSearch.jobs.stream(job.id);

Polling For Completion

const { job: finalJob, result } = await webSearch.jobs.waitForCompletion(job.id, {
  intervalMs: 1_000,
  timeoutMs: 120_000,
});

console.log(finalJob.status);
console.log(result?.text);

waitForCompletion() polls jobs.get() until the job reaches a terminal state:

  • returns { job, result } when the job completes successfully
  • throws when the job ends in error
  • throws when the job is cancelled

Cancellation

await webSearch.jobs.cancel(job.id);

Cancellation is best-effort at the job layer. Completed, failed, or already-cancelled jobs are returned unchanged by the backend.

Error Model

The SDK fails fast on malformed server payloads instead of returning optimistic casts:

  • CloudWebSearchValidationError for invalid REST or stream payloads
  • CloudWebSearchStreamProtocolError when the SSE response cannot be consumed as a stream

Related Packages

  • @kognitivedev/web-search for the in-process workflow/tool package
  • @kognitivedev/flows for hosted cloud-flow APIs