+
Skip to content

coder/blink

Repository files navigation

MIT License discord NPM Version

Blink is a way to build and deploy chat agents with the AI SDK.

import { Agent } from "blink";
import { sendMessages } from "ai";

const agent = new Agent();

agent.on("chat", ({ messages }) => {
  return sendMessages({
    model: "anthropic/claude-sonnet-4.5",
    messages: convertToModelMessages(messages),
  });
});

agent.serve();

To chat with the agent, run blink dev to enter a terminal interface.

  • Leverages the familiar AI SDK at it's core.
  • SDKs for making Slack and GitHub bots.
  • Run your agent locally without ever deploying to the cloud.

Get Started

Install Blink:

npm i -g blink

Create your first agent:

# creates the agent source code in your current directory
blink init

# starts a hot-reloading terminal interface to chat with your agent
blink dev

Create a Slack bot in under a minute:

Getting.Started.mp4

Note

You provide LLM API keys. blink init guides you through this, or add them to .env.local later.

Deploy

If you wish to deploy your agent to the cloud, run:

blink deploy

Important

Cloud is not required to build Blink agents. We guarantee that Blink agents will always be local-first.

User Guide

Developing an Agent

Blink has two modes: run and edit (toggle with ctrl+t, or /run and /edit). Run mode is blue, edit mode is orange. Run mode allows you to chat with your agent. Edit mode allows you to take context from run mode, and edit the agent.

Chat in run mode, switch to edit mode and provide feedback, then go back to run mode and continue chatting. Agents hot-reload as you develop, so changes are reflected instantly.

Note

Run mode cannot see edit mode messages.

Edit.and.Run.Modes.mp4

Chats

Blink allows you to start new chats from web requests:

import blink from "blink";

const agent = blink.agent();

agent.on("request", async (request, context) => {
  // Check if this is a request you'd like to start a chat for.
  // e.g. if this is a webhook from Slack, start a chat for that thread.

  // Specify a unique key for the chat so that on subsequent requests, the same chat is used.
  const chat = await blink.chat.upsert(`slack-${request.body.thread_ts}`);

  await blink.chat.message(
    chat.id,
    {
      role: "user",
      parts: [
        {
          type: "text",
          text: "Hello, how can I help you today?",
        },
      ],
    },
    {
      // Blink manages chat state for you. Interrupt, enqueue, or append messages.
      behavior: "interrupt",
    }
  );

  // This would trigger the chat event handler in your agent.
});

// ... agent.on("chat", ...) ...

agent.serve();

Locally, all chats are stored in ./.blink/chats/<key>.json relative to where your agent is running.

In the cloud, chats keys are namespaced per-agent.

Storage

Blink has a persistent key-value store for your agent:

import { convertToModelMessages, streamText, tool } from "ai";
import blink from "blink";
import { z } from "zod";

const agent = blink.agent();

agent.on("chat", async ({ messages }) => {
  return streamText({
    model: "anthropic/claude-sonnet-4",
    system: "You are a helpful assistant.",
    messages: convertToModelMessages(messages),

    tools: {
      set_memory: tool({
        description: "Set a value to remember later.",
        inputSchema: z.object({
          key: z.string(),
          value: z.string(),
        }),
        execute: async ({ key, value }) => {
          await blink.storage.set(key, value);
          return "Saved memory!";
        },
      }),
      get_memory: tool({
        description: "Get a value from your memory.",
        inputSchema: z.object({
          key: z.string(),
        }),
        execute: async ({ key }) => {
          const value = await blink.storage.get(key);
          return `The value for ${key} is ${value}`;
        },
      }),
      delete_memory: tool({
        description: "Delete a value from your memory.",
        inputSchema: z.object({
          key: z.string(),
        }),
        execute: async ({ key }) => {
          await blink.storage.delete(key);
          return `Deleted memory for ${key}`;
        },
      }),
    },
  });
});

agent.serve();

Locally, all storage is in ./.blink/storage.json relative to where your agent is running.

In the cloud, storage is namespaced per-agent.

Tools

Blink has helpers for tool approvals, and commonly used tools.

Manual Approval

Some tools you'd prefer to approve manually, particularly if they're destructive.

import { convertToModelMessages, streamText, tool } from "ai";
import blink from "blink";
import { z } from "zod";

const agent = blink.agent();

agent.on("chat", async ({ messages }) => {
  return streamText({
    model: "anthropic/claude-sonnet-4",
    system: "You are a helpful assistant.",
    messages: convertToModelMessages(messages),

    tools: {
      harmless_tool: tool({
        description: "A harmless tool.",
        inputSchema: z.object({
          name: z.string(),
        }),
        execute: async ({ name }) => {
          return `Hello, ${name}!`;
        },
      }),
      ...blink.tools.withApproval({
        messages,
        tools: {
          destructive_tool: tool({
            description: "A destructive tool.",
            inputSchema: z.object({
              name: z.string(),
            }),
            execute: async ({ name }) => {
              return `Destructive tool executed!`;
            },
          }),
        },
      }),
    },
  });
});

agent.serve();

Blink will require explicit approval by the user before destructive_tool is executed - displaying a UI to the user to approve or reject the tool call.

Toolsets

Blink has SDK packages for common tools, like Slack, GitHub, and Search:

import github from "@blink-sdk/github";
import { convertToModelMessages, streamText } from "ai";
import blink from "blink";

const agent = blink.agent();

agent.on("chat", async ({ messages }) => {
  return streamText({
    model: "anthropic/claude-sonnet-4",
    system: "You are a helpful assistant.",
    messages: convertToModelMessages(messages),

    tools: {
      ...github.tools,
    },
  });
});

agent.serve();

By default, GitHub tools will not have authentication. Provide context to tools:

import blink from "blink";

blink.tools.withContext(github.tools, {
  accessToken: process.env.GITHUB_TOKEN,
  // optionally, specify app auth, or your own Octokit instance
});

Customizing Tools

You can override any descriptions to customize behavior:

import github from "@blink-sdk/github";
import { convertToModelMessages, streamText } from "ai";
import blink from "blink";

const agent = blink.agent();

agent.on("chat", async ({ messages }) => {
  return streamText({
    model: "anthropic/claude-sonnet-4",
    system: "You are a helpful assistant.",
    messages: convertToModelMessages(messages),

    tools: {
      ...github.tools,
      // Override the default tool with your own description.
      create_issue: {
        ...github.tools.create_issue,
        description: "Create a GitHub issue. *Never* tag users.",
      },
    },
  });
});

agent.serve();

Custom Models

You do not need to use the AI SDK with Blink. Return a Response in sendMessages using withResponseFormat:

import * as blink from "blink";
import OpenAI from "openai";

const client = new OpenAI();
const agent = blink.agent();

agent.on("chat", async ({ messages }) => {
  const stream = await client.chat.completions
    .create({
      model: "gpt-4o",
      messages: messages.map((m) => ({
        role: m.role,
        content: m.parts
          .map((p) => {
            if (p.type === "text") {
              return p.text;
            }
          })
          .join("\n"),
      })),
      stream: true,
    })
    .withResponse();
  return blink.withResponseFormat(stream.response, "openai-chat");
});

agent.serve();

Custom Bundling

Create a blink.config.ts file in your project root (next to package.json):

import { defineConfig, buildWithEsbuild } from "blink/build";

export default defineConfig({
  entry: "src/agent.ts",
  outdir: "dist",
  build: buildWithEsbuild({
    // ... esbuild options ...
  }),
});

By default, Blink uses esbuild to bundle your agent.

The build function can be customized to use a different bundler if you wish.

Blink Documentation

For a closer look at Blink, visit docs.blink.so.

About

Blink is a tool for building and sharing AI agents.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Contributors 4

  •  
  •  
  •  
  •  

Languages

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载