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

dashscope-sdk-nodejs

v0.6.0

Published

DashScope Node.js SDK - Official Node.js client library for Alibaba Cloud DashScope API

Readme

DashScope Node.js SDK

基于Python SDK实现的Node.js SDK,百分百复刻Python SDK的功能和API设计。

已完成的功能模块

1. 核心模块结构

  • src/common/constants.ts - 常量定义
  • src/common/error.ts - 异常类定义
  • src/common/api_key.ts - API密钥管理
  • src/common/utils.ts - 工具函数
  • src/version.ts - SDK版本信息

2. API实体模块

  • src/api_entities/dashscope_response.ts - 响应数据结构
    • DashScopeAPIResponse - 基础响应类
    • GenerationResponse - 生成响应
    • MultiModalConversationResponse - 多模态对话响应
    • Message, Role, Choice等辅助类型

3. 客户端模块

  • src/client/base_api.ts - 基础API客户端
    • BaseApi - 同步API基类
    • BaseAsyncApi - 异步API基类
    • BaseAioApi - 异步/等待API基类

4. AIGC模块

  • src/aigc/generation.ts - 文本生成API
    • Generation - 同步生成API
    • AioGeneration - 异步生成API
    • 支持流式响应
    • 支持插件系统
    • 支持消息历史

5. 主入口

  • src/index.ts - 主导出文件
    • 导出所有公共API
    • 默认导出配置

API设计特点

1. 与Python SDK保持一致的API设计

// Python SDK风格
import { Generation } from 'dashscope-sdk-nodejs';

const response = await Generation.call(
  'qwen-turbo',
  '你好,请介绍一下自己',
  undefined, // history
  apiKey,
  messages,
  plugins,
  workspace,
  options
);

2. 完整的TypeScript类型支持

  • 所有API都有完整的类型定义
  • 自动类型推断
  • 编译时类型检查

3. 错误处理

import { AuthenticationError, InvalidParameter } from 'dashscope-sdk-nodejs';

try {
  await Generation.call(...);
} catch (error) {
  if (error instanceof AuthenticationError) {
    // 处理认证错误
  }
}

4. 流式响应支持

const stream = await Generation.call(
  'qwen-turbo',
  '写一个故事',
  undefined,
  apiKey,
  undefined,
  undefined,
  undefined,
  { stream: true }
);

for await (const chunk of stream) {
  console.log(chunk.output.text);
}

安装和使用

安装

npm install dashscope-sdk-nodejs

基本使用

import { Generation, saveApiKey } from 'dashscope-sdk-nodejs';

// 设置API密钥
saveApiKey('your-api-key');

// 调用生成API
const response = await Generation.call(
  'qwen-turbo',
  '你好,请介绍一下自己'
);

console.log(response.output.text);

异步API使用

import { AioGeneration } from 'dashscope-sdk-nodejs';

const response = await AioGeneration.call(
  'qwen-turbo',
  '写一首关于春天的诗'
);

console.log(response.output.text);

项目结构

dashscope-sdk-nodejs/
├── src/
│   ├── common/          # 通用模块
│   │   ├── constants.ts
│   │   ├── error.ts
│   │   ├── api_key.ts
│   │   └── utils.ts
│   ├── api_entities/    # API实体
│   │   └── dashscope_response.ts
│   ├── client/          # 客户端
│   │   └── base_api.ts
│   ├── aigc/           # AIGC功能
│   │   └── generation.ts
│   ├── version.ts      # 版本信息
│   └── index.ts        # 主入口
├── package.json
├── tsconfig.json
├── rollup.config.js
└── README.md

开发状态

✅ 已完成核心模块的实现 ✅ 已完成API客户端基础架构 ✅ 已完成文本生成API ✅ 已完成TypeScript类型定义 ⏳ 需要进一步测试和验证 ⏳ 需要添加更多API模块(图像生成、语音识别等) ⏳ 需要完善文档和示例

下一步计划

  1. 添加更多AIGC API模块

    • 图像生成
    • 语音识别
    • 语音合成
    • 多模态对话
  2. 完善测试套件

    • 单元测试
    • 集成测试
    • 端到端测试
  3. 优化构建和发布流程

    • 自动化构建
    • CI/CD流水线
    • 版本发布管理
  4. 完善文档

    • API文档
    • 使用示例
    • 最佳实践指南

贡献

欢迎提交Issue和Pull Request来帮助改进这个项目。

许可证

MIT License