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

titbit-dify

v1.0.2

Published

dify agent api for titbit framework

Downloads

7

Readme

Dify平台的API调用Titbit框架扩展

它针对titbit框架中调用dify的api,所以需要安装titbit框架。

安装

  1. 安装titbit框架
  2. 安装此扩展
npm install titbit
npm install titbit-dify

使用过程


const {dify} = require('titbit-dify')
const Titbit = require('titbit')

let app = new Titbit({
    debug: true
})

//dify的配置
let agentConfig = {
    //用于开发者标记和识别,非必填
    name: 'agent测试',
    type: 'agent',
    //你在dify的agent创建的api key
    key: 'app-xxxxxx',
    //请求协议
    protocol: 'https:',
    //请求域名,可以是ip地址
    host: 'xx.x.com',
    //端口,默认
    //port: 443,
    api: '/v1/chat-messages',

    //IP协议版本,默认是IPv4
    family: 4
}

let agentConfig2 = {
    //用于开发者标记和识别,非必填
    name: 'chat测试',
    //用于开发者标记和识别,非必填
    type: 'chat',
    //你在dify的agent创建的api key
    key: 'app-xxxxxx',
    //请求协议
    protocol: 'https:',
    //请求域名,可以是ip地址
    host: 'xx.x.com',
    //端口,默认
    //port: 443,
    api: '/v1/chat-messages',

    //IP协议版本,默认是IPv4
    family: 4
}

app.post('/api/aichat', async ctx => {
    if (!ctx.body.query) {
      return ctx.status(400).send('没有输入的问题,请输入具体问题。')
    }

    try {
        await dify.agentChat(ctx, agentConfig)
    } catch (err) {
        return ctx.status(400).send(err.message)
    }
})

app.post('/api/chat', async ctx => {
    if (!ctx.body.query) {
      return ctx.status(400).send('没有输入的问题,请输入具体问题。')
    }

    try {
        let data = await dify.agentBlockingChat(ctx, agentConfig2)
        let jdata = JSON.parse(data)
        //只返回结果
        ctx.send(jdata.answer)
    } catch (err) {
        return ctx.status(400).send(err.message)
    }
})


app.run(3003)

其他接口

dify.agentBlockingChat(ctx, agentConfig)

阻塞模式的对话,一次请求直接返回结果,用于dify中创建聊天助手,agent不支持这种模式。

dify.getConversations(ctx, agentConfig)

获取会话列表

dify.deleteConversations(ctx, agentConfig, conversationId)

删除会话。

dify.getHistoryMessages(ctx, agentConfig)

获取历史消息。

dify.stopTask(ctx, agentConfig, taskId)

终止任务,对应操作:前端按钮点击终止当前对话任务。