@dropout-ai/runtime

中文文档
0.5.3发布于 2026/01/20MITTypeScriptCommonJS零依赖近 30 天下载 8270

Invisible Node.js runtime for understanding behavioral impact of AI interactions.

原始使用文档
文档目录12 节
  1. 🚀 Quick Start (Wizard)
  2. 🛠️ Manual Installation & Usage
  3. 1. Install the Package
  4. 2. Initialize (The "Universal" Method)
  5. ⚙️ Configuration
  6. 🔑 Session Management
  7. When to Call startNewSession()
  8. Example Usage
  9. TypeScript Example
  10. ❓ Troubleshooting
  11. Non-Node.js Usage (REST API)
  12. License

🕵️ Dropout AI Runtime (@dropout-ai/runtime)

Universal AI Behavior Analysis & Capture for Node.js

Dropout is a lightweight, "install-and-forget" runtime that automatically captures AI interactions (prompts & responses) from your application without requiring code changes to your API calls. It acts as a passive observer, patching the network layer to ensure you never miss a conversation.

  • 🔌 Universal: Works with OpenAI, Anthropic, Genkit, LangChain, Axios, and fetch.
  • 🛡️ Safe: Designed for production with silent failure modes and browser guards.
  • ⚡ Zero-Latency: Uses fire-and-forget logging to ensure your app stays fast.
  • 🔋 Robust: Explicit initialization ensures you always know when it's running.

🚀 Quick Start (Wizard)

The easiest way to get started is to run our installer. It will install the package and give you the exact code snippet to copy.

npx @dropout-ai/wizard@latest


🛠️ Manual Installation & Usage

If you prefer to install manually, follow these two steps.

1. Install the Package

npm install @dropout-ai/runtime
# or
pnpm add @dropout-ai/runtime

2. Initialize (The "Universal" Method)

To start capturing, you must explicitly initialize Dropout. Place this code snippet as early as possible in your application lifecycle (before you make any AI calls).

It is safe to call init() multiple times; it will only run once.

➤ For Next.js (App Router)

File: src/instrumentation.ts (or instrumentation.ts in root)

export async function register() {
  if (process.env.NEXT_RUNTIME === 'nodejs') {
    const { default: Dropout } = await import('@dropout-ai/runtime');

    Dropout.init({
      apiKey: process.env.DROPOUT_API_KEY,
      projectId: process.env.DROPOUT_PROJECT_ID,
      debug: true // Set to false in production
    });
  }
}

➤ For Node.js / Express / Fastify

File: index.js or server.js (Top of file)

require('dotenv').config(); // Ensure env vars are loaded first
const Dropout = require('@dropout-ai/runtime');

Dropout.init({
  apiKey: process.env.DROPOUT_API_KEY,
  projectId: process.env.DROPOUT_PROJECT_ID,
  debug: process.env.NODE_ENV !== 'production'
});

const express = require('express');
const app = express();
// ...

➤ For NestJS

File: src/main.ts

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import Dropout from '@dropout-ai/runtime';

async function bootstrap() {
  // ✅ Initialize before the app starts
  Dropout.init({
    apiKey: process.env.DROPOUT_API_KEY,
    projectId: process.env.DROPOUT_PROJECT_ID,
    debug: true
  });

  const app = await NestFactory.create(AppModule);
  await app.listen(3000);
}
bootstrap();


⚙️ Configuration

OptionTypeDescriptionRequired
projectIdstringYour Project ID from the dashboard.✅
apiKeystringYour Secret Key (dp_live_...).✅
debugbooleanSet true to see "🟢 Online" logs and errors in console.No
privacystringfull (capture text) or mask (metadata only). Default: full.No
sessionIdstringOptional initial session ID. If not provided, one is generated.No
captureEndpointstringCustom capture endpoint (for testing). Default: production URL.No

🔑 Session Management

Important: A session represents a single conversation thread. By default, Dropout generates one session ID when initialized and uses it for all interactions. For proper analytics, you should call startNewSession() whenever the user starts a new conversation.

When to Call startNewSession()

Call this method when:

  • User clicks "New Chat" button
  • User switches to a different conversation thread
  • User switches AI models (if you want to treat that as a new conversation)
  • Page refreshes and you want to start a fresh session

Example Usage

const Dropout = require('@dropout-ai/runtime');

// Initialize once at app startup
const dropout = Dropout.init({
  apiKey: process.env.DROPOUT_API_KEY,
  projectId: process.env.DROPOUT_PROJECT_ID
});

// Later, when user clicks "New Chat":
app.post('/api/new-chat', (req, res) => {
  const newSessionId = dropout.startNewSession();
  console.log(`Started new session: ${newSessionId}`);
  res.json({ sessionId: newSessionId });
});

// Or with a custom session ID:
dropout.startNewSession('user_123_chat_456');

TypeScript Example

import Dropout from '@dropout-ai/runtime';

const dropout = Dropout.init({
  apiKey: process.env.DROPOUT_API_KEY!,
  projectId: process.env.DROPOUT_PROJECT_ID!
});

// Access current session
console.log(dropout.currentSessionId);

// Start new session
const newSessionId = dropout.startNewSession();

❓ Troubleshooting

Q: How do I know if it's working? Set debug: true in your config. When your app starts, you should see this message immediately:

[Dropout] 🟢 Online | Project: <Your-Project-ID>

Q: I don't see any logs.

  1. Check that you called Dropout.init().
  2. Ensure your apiKey and projectId are not undefined (log them to check).
  3. If using Next.js, ensure instrumentation.ts is in the correct folder (src/ if you use it).

Q: Does this work with Edge Functions? No. This runtime relies on Node.js core modules (http, https). It does not support Vercel Edge Runtime or Cloudflare Workers.


Non-Node.js Usage (REST API)

If you are using Python, Go, or other languages, you can manually send interaction logs to our ingestion endpoint.

Endpoint: POST https://hipughmjlwmwjxzyxfzs.supabase.co/functions/v1/capture-sealed Headers: x-dropout-key: <YOUR_API_KEY>

json { "project_id": "your_project_id", "turn_role": "assistant", "content": "AI response text...", "model": "gpt-4", "provider": "openai" }

License

MIT

版本与发布记录

@dropout-ai/runtime 共发布 38 个版本,首次发布于 2026/01/09;过去 12 个月发布了 38 个版本。

版本发布日期距今
0.5.3latest2026/01/209 个月前
0.5.22026/01/209 个月前
0.5.12026/01/209 个月前
0.5.02026/01/199 个月前
0.4.52026/01/199 个月前
0.4.42026/01/169 个月前

关于 @dropout-ai/runtime 的常见问题

@dropout-ai/runtime 是什么?

Invisible Node.js runtime for understanding behavioral impact of AI interactions.

如何安装 @dropout-ai/runtime?

在项目目录运行 npm install @dropout-ai/runtime,或使用 pnpm add / yarn add / bun add。

@dropout-ai/runtime 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dropout-ai/runtime 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@dropout-ai/runtime 可以商用吗?

@dropout-ai/runtime 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dropout-ai/runtime 的下载量有多少?

根据 npm 官方下载统计,@dropout-ai/runtime 在 2026/10/13 – 2026/11/11 这 30 天内被下载 8,270 次,日均约 276 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dropout-ai/runtime 还在维护吗?

最新版本 0.5.3 发布于 2026/01/20(9 个月前);至今共发布 38 个版本,其中过去 12 个月发布了 38 个;首次发布于 2026/01/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。