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 🙏

© 2025 – Pkg Stats / Ryan Hefner

dify-sdk

v0.0.18

Published

dify-sdk

Readme

Dify SDK

Dify SDK 是一个用于与 Dify 平台交互的 TypeScript/JavaScript SDK。它提供了与 Dify API 的完整集成,支持发送消息、管理会话、处理文件上传等功能。通过 Dify SDK,开发者可以轻松地将 Dify 的功能集成到自己的应用中。

安装

使用 npm 安装 Dify SDK:

npm install dify-sdk
# or
yarn add dify-sdk
# or
bun add dify-sdk

快速开始

初始化客户端

首先,初始化 DifyClient 并配置 API 密钥和基础 URL:

import { DifyClient } from 'dify-sdk/lib/clients/dify.client';

const difyClient = new DifyClient({
  baseUrl: 'https://api.dify.ai', // 替换为实际的 Dify API 地址
  apiKey: 'your-api-key', // 替换为你的 API 密钥
});

主要方法

以下是 Dify SDK 的主要方法:

发送消息

使用 sendMessage 方法发送消息,支持流式响应和阻塞模式:

const result = await difyClient.sendMessage({
  query: '你好,Dify!',
  response_mode: 'streaming', // 或 'blocking'
  user: 'user-001',
  chunkCompletionCallback: (chunk) => {
    console.log('chuck: ...', chunk);
  }
});

if (Array.isArray(result)) {
  result.forEach(chunk => {
    console.log(chunk.answer); // 处理流式响应的数据块
  });
} else {
  console.log(result.answer); // 处理阻塞模式的完整响应
}

获取会话列表

使用 getConversations 方法获取用户的会话列表:

const conversations = await difyClient.getConversations({
  user: 'user-001',
  limit: 10,
});

console.log(conversations.data); // 输出会话列表

上传文件

使用 uploadFile 方法上传文件:

const fileResponse = await difyClient.uploadFile({
  file: new File(['file content'], 'example.txt'),
  user: 'user-001',
});

console.log(fileResponse.id); // 输出文件 ID

获取消息列表

使用 getMessages 方法获取指定会话的消息列表:

const messages = await difyClient.getMessages({
  conversation_id: 'conversation-id',
  user: 'user-001',
});

console.log(messages.data); // 输出消息列表

停止响应

使用 stopMessageResponse 方法停止流式响应:

const stopResponse = await difyClient.stopMessageResponse({
  task_id: 'task-id',
  user: 'user-001',
});

console.log(stopResponse.result); // 输出停止结果

其他方法

Dify SDK 还提供了许多其他功能,例如创建反馈、获取建议问题、删除会话、重命名会话、语音转文字、文字转语音等。详细信息请查看源代码

以上是 Dify SDK 的 README 文件,包含了主要方法的示例和其他功能的说明。如果需要更多详细信息,请查看源代码。