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 🙏

© 2024 – Pkg Stats / Ryan Hefner

window-ai-manager

v1.0.8

Published

A library for managing AI text sessions in the browser using the window.ai API. Currently, this library is only compatible with the Chrome browser.

Downloads

10

Readme

WindowAIManager

A library for managing AI text sessions in the browser using the window.ai API.

Description

WindowAIManager is a JavaScript library (written in Typescript) designed to facilitate interactions with AI text sessions in the browser. It leverages the window.ai API, which is available in desktop versions of Chrome starting from version 127.0.6512.0. This library includes functionalities for creating, managing, and destroying AI text sessions, as well as rendering markdown to HTML using the marked library internally.

Installation

To install the library, use npm:

npm install window-ai-manager

Usage

Basic Usage

const WindowAIManager = require('window-ai-manager')
const aiManager = new WindowAIManager()

async function main() {
    // Check if a text session can be created
    const canCreate = await aiManager.canCreateSession()
    console.log('Can create session:', canCreate)

    // Create a new session
    if (canCreate !== 'no') {
        await aiManager.createSession('session1')
        console.log('Session created')

        // Send a prompt and get the response
        const response = await aiManager.prompt('session1', 'Write me a poem')
        console.log('AI Response:', response)

        // Send a streaming prompt
        await aiManager.promptStreaming('session1', 'Write me an extra-long poem', (chunk) => {
            console.log('Streaming chunk:', chunk)
        })

        // Destroy the session
        await aiManager.destroySession('session1')
        console.log('Session destroyed')
    }
}

main().catch(console.error)

Markdown Rendering

const WindowAIManager = require('window-ai-manager')
const aiManager = new WindowAIManager()

const markdown = '# Hello, world!'
const html = aiManager.renderMarkdown(markdown)
console.log('Rendered HTML:', html)

Destroying All Sessions

const WindowAIManager = require('window-ai-manager')
const aiManager = new WindowAIManager()

async function main() {
    await aiManager.createSession('session1')
    await aiManager.createSession('session2')

    // Destroy all sessions
    await aiManager.destroyAllSessions()
    console.log('All sessions destroyed')
}

main().catch(console.error)

Requirements

This library only works in desktop versions of Chrome starting from version 127.0.6512.0. It uses the window.ai API, which is currently available only in development channel releases of Chrome.

API

canCreateSession(): Promise<'readily' | 'after-download' | 'no'> Checks if a text session can be created.

createSession(sessionId: string): Promise<void> Creates a new text session with the given session ID.

prompt(sessionId: string, text: string): Promise<string> Sends a prompt to the specified session and returns the response.

promptStreaming(sessionId: string, text: string, onChunkReceived: (chunk: string) => void): Promise<string> Sends a streaming prompt to the specified session and processes the chunks received.

destroySession(sessionId: string): Promise<void> Destroys the specified session and removes it from the map.

destroyAllSessions(): Promise<void> Destroys all active sessions and clears the map.

renderMarkdown(markdown: string): string Renders markdown text to HTML.

License

This project is licensed under the MIT License.