Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@ragpipe/plugin-cloudflare

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ragpipe/plugin-cloudflare - npm Package Compare versions

Comparing version
0.1.0-alpha.1
to
0.1.0
+70
README.md
# @ragpipe/plugin-cloudflare
Cloudflare Workers AI embedding and generation plugin for [ragpipe](https://github.com/yungblud/ragpipe).
## Install
```bash
pnpm add ragpipe @ragpipe/plugin-cloudflare
```
## Usage
```ts
import { defineConfig } from "ragpipe";
import { cloudflareEmbedding, cloudflareGeneration } from "@ragpipe/plugin-cloudflare";
export default defineConfig({
embedding: cloudflareEmbedding({
accountId: process.env.CLOUDFLARE_ACCOUNT_ID!,
apiToken: process.env.CLOUDFLARE_API_TOKEN!,
model: "@cf/qwen/qwen3-embedding-0.6b",
}),
generation: cloudflareGeneration({
accountId: process.env.CLOUDFLARE_ACCOUNT_ID!,
apiToken: process.env.CLOUDFLARE_API_TOKEN!,
model: "@cf/openai/gpt-oss-20b",
systemPrompt: "Answer based on the provided context.",
}),
// ... vectorStore
});
```
## API
### `cloudflareEmbedding(options)`
Returns an `EmbeddingPlugin` that calls the Cloudflare Workers AI Embedding API.
| Option | Type | Default | Description |
|---|---|---|---|
| `accountId` | `string` | — | Cloudflare account ID (required) |
| `apiToken` | `string` | — | Cloudflare API token (required) |
| `model` | `string` | — | Embedding model name (required) |
- **Batch support**: `embedMany()` sends an array of texts in a single API call
### `cloudflareGeneration(options)`
Returns a `GenerationPlugin` that calls the Cloudflare Workers AI Generation API.
| Option | Type | Default | Description |
|---|---|---|---|
| `accountId` | `string` | — | Cloudflare account ID (required) |
| `apiToken` | `string` | — | Cloudflare API token (required) |
| `model` | `string` | — | Generation model name (required) |
| `systemPrompt` | `string` | `"Answer based on the provided context."` | Default system instruction |
- **Streaming**: `generateStream()` returns an `AsyncIterable<string>` via SSE
- **History**: Pass `{ history }` to include conversation context
- **Per-call override**: Pass `{ systemPrompt }` at call time to override the default
## Get an API Token
1. Go to [Cloudflare Dashboard](https://dash.cloudflare.com/profile/api-tokens)
2. Create a token with **Workers AI** read permission
3. Set `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN` in your environment
## License
MIT
+4
-3

@@ -54,3 +54,4 @@ "use strict";

name: "cloudflare",
dimensions: 768,
dimensions: options.dimensions ?? 768,
model,
async embed(text) {

@@ -67,5 +68,4 @@ const vectors = await callApi([text]);

// src/generation.ts
var DEFAULT_MODEL = "@cf/meta/llama-3.1-8b-instruct";
function cloudflareGeneration(options) {
const model = options.model ?? DEFAULT_MODEL;
const { model } = options;
const baseUrl = `https://api.cloudflare.com/client/v4/accounts/${options.accountId}/ai/run/${model}`;

@@ -91,2 +91,3 @@ function buildMessages(question, context, opts) {

name: "cloudflare",
model,
async generate(question, context, opts) {

@@ -93,0 +94,0 @@ const messages = buildMessages(question, context, opts);

@@ -7,2 +7,3 @@ import { EmbeddingPlugin, GenerationPlugin } from 'ragpipe';

model: string;
dimensions?: number;
}

@@ -14,3 +15,3 @@ declare function cloudflareEmbedding(options: CloudflareEmbeddingOptions): EmbeddingPlugin;

apiToken: string;
model?: string;
model: string;
systemPrompt?: string;

@@ -17,0 +18,0 @@ }

@@ -7,2 +7,3 @@ import { EmbeddingPlugin, GenerationPlugin } from 'ragpipe';

model: string;
dimensions?: number;
}

@@ -14,3 +15,3 @@ declare function cloudflareEmbedding(options: CloudflareEmbeddingOptions): EmbeddingPlugin;

apiToken: string;
model?: string;
model: string;
systemPrompt?: string;

@@ -17,0 +18,0 @@ }

@@ -27,3 +27,4 @@ // src/embedding.ts

name: "cloudflare",
dimensions: 768,
dimensions: options.dimensions ?? 768,
model,
async embed(text) {

@@ -40,5 +41,4 @@ const vectors = await callApi([text]);

// src/generation.ts
var DEFAULT_MODEL = "@cf/meta/llama-3.1-8b-instruct";
function cloudflareGeneration(options) {
const model = options.model ?? DEFAULT_MODEL;
const { model } = options;
const baseUrl = `https://api.cloudflare.com/client/v4/accounts/${options.accountId}/ai/run/${model}`;

@@ -64,2 +64,3 @@ function buildMessages(question, context, opts) {

name: "cloudflare",
model,
async generate(question, context, opts) {

@@ -66,0 +67,0 @@ const messages = buildMessages(question, context, opts);

{
"name": "@ragpipe/plugin-cloudflare",
"version": "0.1.0-alpha.1",
"description": "Cloudflare Workers AI embedding and generation plugin for ragpipe",
"type": "module",
"license": "MIT",
"author": {
"name": "yungblud",
"url": "https://github.com/yungblud"
},
"repository": {
"type": "git",
"url": "https://github.com/yungblud/ragpipe",
"directory": "packages/plugin-cloudflare"
},
"bugs": {
"url": "https://github.com/yungblud/ragpipe/issues"
},
"homepage": "https://github.com/yungblud/ragpipe#readme",
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"access": "public"
},
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs"
}
},
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": ["dist", "README.md"],
"scripts": {
"build": "tsup",
"dev": "tsup --watch",
"typecheck": "tsc --noEmit",
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest run --coverage"
},
"keywords": [
"ragpipe",
"rag",
"cloudflare",
"workers-ai",
"embedding",
"generation",
"plugin"
],
"peerDependencies": {
"ragpipe": ">=0.1.0"
},
"devDependencies": {
"ragpipe": "workspace:*",
"tsup": "^8.4.0",
"typescript": "^5.8.3",
"vitest": "^3.1.1"
}
}
"name": "@ragpipe/plugin-cloudflare",
"version": "0.1.0",
"description": "Cloudflare Workers AI embedding and generation plugin for ragpipe",
"type": "module",
"license": "MIT",
"author": {
"name": "yungblud",
"url": "https://github.com/yungblud"
},
"repository": {
"type": "git",
"url": "https://github.com/yungblud/ragpipe",
"directory": "packages/plugin-cloudflare"
},
"bugs": {
"url": "https://github.com/yungblud/ragpipe/issues"
},
"homepage": "https://github.com/yungblud/ragpipe#readme",
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"access": "public"
},
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs"
}
},
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist",
"README.md"
],
"keywords": [
"ragpipe",
"rag",
"cloudflare",
"workers-ai",
"embedding",
"generation",
"plugin"
],
"peerDependencies": {
"ragpipe": ">=0.2.0"
},
"devDependencies": {
"tsup": "^8.4.0",
"typescript": "^5.8.3",
"vitest": "^3.1.1",
"ragpipe": "0.2.0"
},
"scripts": {
"build": "tsup",
"dev": "tsup --watch",
"typecheck": "tsc --noEmit",
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest run --coverage"
}
}