New:Microsoft Teams Notifications Are Now Available in Socket.Learn more
Get Started

@aibind/cloudflare

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aibind/cloudflare

Cloudflare Workers adapters for @aibind — D1 (StreamStore) and KV (ConversationStore)

latest
Source
npmnpm
Version
0.4.0
Version published
Maintainers
1
Created
Source

@aibind/cloudflare

Cloudflare Workers adapters for @aibind — wraps D1 as a SqliteClient (for use with @aibind/sqlite) and provides a KV-backed ConversationStore.

Install

npm install @aibind/cloudflare @aibind/sqlite

Usage

import { wrapD1, KVConversationStore } from "@aibind/cloudflare";
import { SqliteStreamStore } from "@aibind/sqlite";

export default {
  async fetch(request: Request, env: Env) {
    // D1 for durable streams (ordered chunks, resumable)
    const streamStore = new SqliteStreamStore(wrapD1(env.DB));

    // KV for conversation history (global low-latency, auto-expiry)
    const conversationStore = new KVConversationStore(env.CONVERSATIONS);
  },
} satisfies ExportedHandler<Env>;

Required D1 schema

You must create these tables yourself before using SqliteStreamStore:

CREATE TABLE aibind_stream_chunks (
  id   TEXT    NOT NULL,
  seq  INTEGER NOT NULL,
  data TEXT    NOT NULL,
  PRIMARY KEY (id, seq)
);

CREATE TABLE aibind_stream_status (
  id           TEXT    PRIMARY KEY,
  state        TEXT    NOT NULL DEFAULT 'active',
  error        TEXT,
  total_chunks INTEGER NOT NULL DEFAULT 0,
  expires_at   INTEGER NOT NULL
);

-- Only needed if using SqliteConversationStore with D1
CREATE TABLE aibind_conversations (
  session_id TEXT    PRIMARY KEY,
  data       TEXT    NOT NULL,
  expires_at INTEGER NOT NULL
);

Apply with wrangler: wrangler d1 execute MY_DB --file=./schema.sql

KVConversationStore requires no schema — KV is a simple key-value store.

wrangler.toml

[[d1_databases]]
binding = "DB"
database_name = "my-db"
database_id = "..."

[[kv_namespaces]]
binding = "CONVERSATIONS"
id = "..."

Documentation

Full docs →

Keywords

cloudflare

FAQs

Package last updated on 06 Mar 2026

Related posts