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

ragent-oss

v0.1.0

Published

TypeScript SDK for ragent-oss storage gateway

Readme

ragent-oss TypeScript SDK

ragent-oss 存储网关的 TypeScript 客户端库。零运行时依赖,仅使用全局 fetch

安装

bun add ragent-oss
# 或
npm install ragent-oss

快速开始

import { RagentOssClient } from "ragent-oss";

const client = new RagentOssClient({
  baseUrl: "https://oss.ragents.net",
  apiKey: "your-api-key",
});

// 获取预签名上传 URL
const { objectKey, uploadUrl, headers } = await client.presign({
  filename: "report.pdf",
  contentType: "application/pdf",
  category: "knowledge",
});

// 上传文件到预签名 URL
await fetch(uploadUrl, {
  method: "PUT",
  headers,
  body: fileContent,
});

// 获取签名下载 URL
const { url } = await client.sign({ objectKey });

// 删除文件
await client.delete({ objectKey });

浏览器上传(带进度)

import { RagentOssClient } from "ragent-oss";
import { upload } from "ragent-oss/upload";

const client = new RagentOssClient({
  baseUrl: "https://oss.ragents.net",
  apiKey: "your-api-key",
});

const controller = new AbortController();

const { objectKey } = await upload(client, {
  file: document.querySelector("input[type=file]").files[0],
  category: "knowledge",
  onProgress: (percent) => console.log(`${percent}%`),
  signal: controller.signal, // 可选:取消上传
});

API 参考

new RagentOssClient(config)

| 参数 | 类型 | 说明 | |------|------|------| | config.baseUrl | string | 服务地址,如 https://oss.ragents.net | | config.apiKey | string | API 密钥(通过 X-API-Key 请求头发送) |

client.health()

检查服务状态,不需要认证。

返回:Promise<{ status: string; storage: string }>

client.presign(req)

获取预签名上传 URL。

| 参数 | 类型 | 说明 | |------|------|------| | req.filename | string | 原始文件名(用于提取扩展名) | | req.contentType | string | MIME 类型 | | req.category | string | 存储分类 |

返回:Promise<{ objectKey: string; uploadUrl: string; headers: Record<string, string> }>

client.sign(req)

获取签名下载 URL。

| 参数 | 类型 | 说明 | |------|------|------| | req.objectKey | string | 对象键 | | req.expiresIn | number? | 过期时间(秒),默认 86400(24 小时) |

返回:Promise<{ url: string }>

client.delete(req)

删除对象。

| 参数 | 类型 | 说明 | |------|------|------| | req.objectKey | string | 要删除的对象键 |

返回:Promise<{ success: boolean }>

client.download(objectKey, expiresIn?)

便捷方法:sign + fetch,直接下载文件内容。

返回:Promise<ArrayBuffer>

upload(client, options)

浏览器端上传辅助函数(使用 XHR 支持进度回调)。

| 参数 | 类型 | 说明 | |------|------|------| | client | RagentOssClient | 客户端实例 | | options.file | Blob \| File | 要上传的文件 | | options.category | string | 存储分类 | | options.onProgress | (percent: number) => void | 进度回调(0-100) | | options.signal | AbortSignal? | 取消信号 |

返回:Promise<{ objectKey: string }>

错误处理

import {
  RagentOssError,
  AuthenticationError,
  ValidationError,
  UploadError,
  NetworkError,
} from "ragent-oss";

try {
  await client.presign({ ... });
} catch (err) {
  if (err instanceof AuthenticationError) {
    // 401 - API 密钥无效
  } else if (err instanceof ValidationError) {
    // 422 - 请求参数错误
  } else if (err instanceof NetworkError) {
    // 网络不可达
  }
}

| 错误类 | 触发条件 | |--------|----------| | AuthenticationError | HTTP 401 | | ValidationError | HTTP 422 | | UploadError | PUT 上传失败 | | NetworkError | 网络不可达 | | RagentOssError | 其他 HTTP 错误(基类) |