Token导航 LogoToken导航TokenDH.com
开发需要联网github未标认证来源可访问许可证需确认审计提醒

ably-realtime巧妙地实时

Agent Skill

ably-realtime 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

376

周安装

16

GitHub Stars

公开资料未说明

下载量

132
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:ably-realtime(巧妙地实时)
来源仓库:https://github.com/itzaks/ably-realtime-skill
仓库路径:skills/ably-realtime
安装命令:
npx skills add https://github.com/itzaks/ably-realtime-skill --skill ably-realtime
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/itzaks/ably-realtime-skill --skill ably-realtime

简介

ably-realtime 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息。

  • 适合在 Codex、Claude、Cursor、Gemini CLI 中围绕仓库状态或代码变更进行整理。
  • 通过 npx 命令从 GitHub 安装,需确认权限范围和是否触发文件读写操作。
  • 建议结合原始 README 核验具体用法,并关注维护状态与联网行为。
  • 使用前请评估是否会执行命令或修改文件,避免意外影响项目结构。

SKILL.md

Ably Realtime for React/TypeScript

Ably Realtime is a platform for building scalable real-time applications with pub-sub messaging, presence tracking, collaborative features, chat, and database synchronization.

When to Use Each Feature

Ably provides different abstractions for different real-time use cases:

  • Channels (Core Pub-Sub): Custom real-time messaging, notifications, live updates, event broadcasting
  • Spaces: Participant state in collaborative UIs (live cursors, avatar stacks, user locations, component locking)
  • LiveObjects: Application state synchronization (counters, voting, shared configurations, game state) with conflict-free updates
  • Chat SDK: Complete messaging apps (1:1 chat, group conversations, livestream chat, support tickets)
  • LiveSync: Database-to-client synchronization (broadcasting Postgres changes, outbox pattern, transactional consistency)

Installation

# Core Ably (required)
npm install ably

# Additional packages (install as needed)
npm install @ably/spaces           # For Spaces
npm install @ably/chat             # For Chat SDK
npm install @ably-labs/models      # For LiveSync Models SDK

Basic Setup

All Ably features require a Realtime client. Create the client outside React components to prevent reconnections on re-renders:

// main.tsx or app.tsx
import * as Ably from 'ably';
import { AblyProvider } from 'ably/react';

// Create client OUTSIDE components
const realtimeClient = new Ably.Realtime({
  key: import.meta.env.VITE_ABLY_API_KEY,
  clientId: 'unique-user-id', // Required for Spaces and Chat
});

function Root() {
  return (
    <AblyProvider client={realtimeClient}>
      <App />
    </AblyProvider>
  );
}

For production applications, use token authentication instead of API keys. See references/auth-security.md.

Quick Start: Channels (Core Pub-Sub)

Basic real-time messaging with channels:

import { ChannelProvider, useChannel } from 'ably/react';

// Wrap with ChannelProvider
<ChannelProvider channelName="notifications">
  <NotificationComponent />
</ChannelProvider>

// Use in component
function NotificationComponent() {
  const { publish } = useChannel('notifications', (message) => {
    console.log('Received:', message.data);
    // Update local state with message
  });

  const sendNotification = () => {
    publish('alert', { text: 'New update!', timestamp: Date.now() });
  };

  return <button onClick={sendNotification}>Send</button>;
}

For detailed channel operations, presence tracking, and history, see references/channels/.

Quick Start: Spaces (Collaborative UI)

Track participant state for collaborative features:

import Spaces from '@ably/spaces';
import { SpacesProvider, SpaceProvider, useMembers, useCursors } from '@ably/spaces/react';

// Setup (in root)
const spaces = new Spaces(realtimeClient);

<SpacesProvider client={spaces}>
  <SpaceProvider name="my-collaborative-space">
    <CollaborativeEditor />
  </SpaceProvider>
</SpacesProvider>

// Avatar stack
function AvatarStack() {
  const { self, others } = useMembers();

  return (
    <div>
      <Avatar user={self} />
      {others.map(member => (
        <Avatar key={member.connectionId} user={member} />
      ))}
    </div>
  );
}

// Live cursors
function CursorTracking() {
  const { set } = useCursors((update) => {
    // Render other users' cursors
    renderCursor(update.connectionId, update.position);
  });

  useEffect(() => {
    const handleMove = (e: MouseEvent) => {
      set({ position: { x: e.clientX, y: e.clientY } });
    };
    window.addEventListener('mousemove', handleMove);
    return () => window.removeEventListener('mousemove', handleMove);
  }, [set]);

  return <canvas id="cursor-layer" />;
}

For locations, component locking, and advanced patterns, see references/spaces/.

Quick Start: LiveObjects (Shared State)

⚠️ Public Preview: LiveObjects API may change before general availability.

Conflict-free shared state synchronization:

import { LiveCounter, LiveMap } from "ably/liveobjects";

async function setupSharedState() {
  const channel = realtimeClient.channels.get("game:lobby-1");
  const gameState = await channel.object.get();

  // Create shared counter
  await gameState.set("score", LiveCounter.create(0));

  // Create shared map
  await gameState.set(
    "players",
    LiveMap.create({
      player1: { name: "Alice", ready: false },
      player2: { name: "Bob", ready: false },
    }),
  );

  // Subscribe to changes
  gameState.get("score").subscribe(() => {
    console.log("Score:", gameState.get("score").value());
  });

  // Update values
  await gameState.get("score").increment(10);
  await gameState.get("players").set("player1", { name: "Alice", ready: true });
}

React integration:

function GameLobby() {
  const [score, setScore] = useState(0);
  const [players, setPlayers] = useState({});

  useEffect(() => {
    let gameState: any;

    async function init() {
      const channel = realtimeClient.channels.get('game:lobby-1');
      gameState = await channel.object.get();

      // Subscribe to updates
      gameState.get('score').subscribe(() => {
        setScore(gameState.get('score').value());
      });

      gameState.get('players').subscribe(() => {
        setPlayers(gameState.get('players').value());
      });
    }

    init();

    return () => {
      // Cleanup subscriptions
    };
  }, []);

  return (
    <div>
      <h2>Score: {score}</h2>
      {Object.entries(players).map(([id, player]: [string, any]) => (
        <div key={id}>{player.name} - {player.ready ? '✓' : '...'}</div>
      ))}
    </div>
  );
}

For LiveMap batch operations, composability, and detailed API, see references/liveobjects/.

Quick Start: Chat SDK

Purpose-built chat with rooms, messages, typing indicators, and reactions:

import { ChatClient } from '@ably/chat';
import { ChatClientProvider, ChatRoomProvider, useMessages, useTyping } from '@ably/chat/react';

// Setup (in root)
const chatClient = new ChatClient(realtimeClient);

<ChatClientProvider client={chatClient}>
  <ChatRoomProvider name="support:ticket-123">
    <ChatRoom />
  </ChatRoomProvider>
</ChatClientProvider>

// Chat component
function ChatRoom() {
  const [messages, setMessages] = useState<Message[]>([]);
  const { currentlyTyping, keystroke } = useTyping();

  const { send, getPreviousMessages } = useMessages({
    listener: (event) => {
      if (event.type === 'created') {
        setMessages(prev => [...prev, event.message]);
      }
    }
  });

  useEffect(() => {
    // Load history
    getPreviousMessages({ limit: 50 }).then(result => {
      setMessages(result.items.reverse());
    });
  }, []);

  const handleSend = (text: string) => {
    send({ text });
  };

  const handleTyping = () => {
    keystroke(); // Triggers typing indicator
  };

  return (
    <div>
      <MessageList messages={messages} />
      {currentlyTyping.length > 0 && (
        <TypingIndicator users={currentlyTyping} />
      )}
      <MessageInput onSend={handleSend} onKeyPress={handleTyping} />
    </div>
  );
}

For message updates/deletes, reactions, presence, and room lifecycle, see references/chat/.

Quick Start: LiveSync (Database Sync)

Broadcast database changes from PostgreSQL/Neon to clients:

Backend (Database + Outbox):

-- Outbox table for change events
CREATE TABLE outbox (
  sequence_id serial PRIMARY KEY,
  mutation_id TEXT NOT NULL,
  channel TEXT NOT NULL,
  name TEXT NOT NULL,
  data JSONB,
  processed BOOLEAN DEFAULT false
);

-- Trigger to notify on changes
CREATE FUNCTION outbox_notify() RETURNS trigger AS $$
BEGIN
  PERFORM pg_notify('ably_adbc', '');
  RETURN NULL;
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER outbox_trigger
  AFTER INSERT ON outbox
  FOR EACH STATEMENT
  EXECUTE PROCEDURE outbox_notify();
// API route - transactional write
export async function POST(req: Request) {
  const { documentId, content } = await req.json();

  await db.transaction(async (trx) => {
    // Update application data
    await trx("documents")
      .where({ id: documentId })
      .update({ content, updated_at: new Date() });

    // Insert change event
    await trx("outbox").insert({
      mutation_id: crypto.randomUUID(),
      channel: `document:${documentId}`,
      name: "document.updated",
      data: { id: documentId, content },
    });
  });

  return Response.json({ success: true });
}

Frontend (Subscribe to Changes):

function DocumentEditor({ documentId }: { documentId: string }) {
  const [content, setContent] = useState('');

  const { channel } = useChannel(`document:${documentId}`, (message) => {
    if (message.name === 'document.updated') {
      setContent(message.data.content);
    }
  });

  useEffect(() => {
    // Load initial state
    fetch(`/api/documents/${documentId}`)
      .then(r => r.json())
      .then(doc => setContent(doc.content));
  }, [documentId]);

  return <textarea value={content} onChange={(e) => setContent(e.target.value)} />;
}

For Models SDK with optimistic updates, integration setup, and advanced patterns, see references/livesync/.

Common Patterns

Pattern: Load History Before Subscribing

function ChatWithHistory() {
  const [messages, setMessages] = useState<any[]>([]);

  const { channel } = useChannel('chat', (message) => {
    setMessages(prev => [...prev, message]);
  });

  useEffect(() => {
    async function loadHistory() {
      const history = await channel.history({ limit: 50 });
      setMessages(history.items.reverse());
    }
    loadHistory();
  }, [channel]);

  return <MessageList messages={messages} />;
}

Pattern: Optimistic Updates with Confirmation

function OptimisticComment({ postId }: { postId: string }) {
  const [comments, setComments] = useState<Comment[]>([]);
  const pendingMutations = useRef(new Map());

  useChannel(`post:${postId}`, (message) => {
    const mutationId = message.data.mutation_id;

    // Remove optimistic entry, add confirmed
    if (pendingMutations.current.has(mutationId)) {
      setComments(prev => {
        const withoutOptimistic = prev.filter(c => c.id !== mutationId);
        return [...withoutOptimistic, message.data];
      });
      pendingMutations.current.delete(mutationId);
    } else {
      setComments(prev => [...prev, message.data]);
    }
  });

  const addComment = async (text: string) => {
    const mutationId = crypto.randomUUID();
    const optimistic = { id: mutationId, text, pending: true };

    // Add optimistically
    setComments(prev => [...prev, optimistic]);
    pendingMutations.current.set(mutationId, optimistic);

    // Send to backend
    await fetch('/api/comments', {
      method: 'POST',
      body: JSON.stringify({ mutationId, postId, text })
    });
  };

  return <CommentList comments={comments} onAdd={addComment} />;
}

Pattern: Presence with Profile Data

import { usePresence, usePresenceListener } from 'ably/react';

function OnlineUsers() {
  usePresence('room', {
    username: 'Alice',
    avatar: '/avatars/alice.jpg',
    status: 'active'
  });

  const { presenceData } = usePresenceListener('room');

  return (
    <div>
      <h3>Online ({presenceData.length})</h3>
      {presenceData.map(member => (
        <div key={member.connectionId}>
          <img src={member.data?.avatar} alt={member.data?.username} />
          <span>{member.data?.username}</span>
          <span>{member.data?.status}</span>
        </div>
      ))}
    </div>
  );
}

Pattern: Connection State Monitoring

import { useConnectionStateListener, useAbly } from 'ably/react';

function ConnectionStatus() {
  const ably = useAbly();
  const [state, setState] = useState(ably.connection.state);
  const [error, setError] = useState<string | null>(null);

  useConnectionStateListener((stateChange) => {
    setState(stateChange.current);

    if (stateChange.current === 'failed' || stateChange.current === 'suspended') {
      setError(stateChange.reason?.message || 'Connection issue');
    } else {
      setError(null);
    }
  });

  return (
    <div className={`status-${state}`}>
      {state === 'connected' ? '🟢' : '🔴'} {state}
      {error && <span>{error}</span>}
    </div>
  );
}

TypeScript Types

Ably provides comprehensive TypeScript definitions. Import types as needed:

import type * as Ably from "ably";
import type { Message } from "@ably/chat";
import type { SpaceMember, CursorUpdate } from "@ably/spaces";

const handleMessage = (msg: Ably.Message) => {
  console.log(msg.name, msg.data, msg.timestamp);
};

const handleCursor = (update: CursorUpdate) => {
  const position: { x: number; y: number } = update.position;
};

Progressive References

For detailed documentation on specific features:

  • Core Channels - Channel operations, presence, history, connection management
  • Spaces - Setup, React hooks (useMembers, useCursors, useLocations, useLocks), patterns
  • LiveObjects - Overview, API reference (LiveCounter, LiveMap), composability, batch operations
  • Chat SDK - Setup, React hooks (useMessages, useTyping, useRoomReactions), message CRUD, features
  • LiveSync - Outbox pattern, integration setup, Models SDK, optimistic updates, React patterns
  • Auth & Security - Token authentication, clientId, capabilities, production best practices

Troubleshooting

Connection limit exceeded

Each Realtime client instance creates a connection. Create the client once outside React components:

// ❌ Wrong - creates new connection on every render
function App() {
  const client = new Ably.Realtime({ key });
  return <AblyProvider client={client}>...</AblyProvider>;
}

// ✅ Correct - single connection
const client = new Ably.Realtime({ key });
function App() {
  return <AblyProvider client={client}>...</AblyProvider>;
}

Provider nesting issues

Ensure correct provider hierarchy:

// For Spaces
<AblyProvider client={realtimeClient}>
  <SpacesProvider client={spacesClient}>
    <SpaceProvider name="space-name">
      {/* Your components */}
    </SpaceProvider>
  </SpacesProvider>
</AblyProvider>

// For Chat
<AblyProvider client={realtimeClient}>
  <ChatClientProvider client={chatClient}>
    <ChatRoomProvider name="room-name">
      {/* Your components */}
    </ChatRoomProvider>
  </ChatClientProvider>
</AblyProvider>

Channel not receiving messages

  1. Check channel name matches exactly (case-sensitive)
  2. Verify API key has required capabilities
  3. Ensure clientId is set when using presence or Chat
  4. Check connection state with useConnectionStateListener

LiveObjects not syncing

  1. Verify LiveObjects is enabled in your Ably app (Dashboard → Settings)
  2. Check channel is attached: channel.state === 'attached'
  3. Ensure proper await on async operations
  4. LiveObjects requires Ably protocol version 2 (set automatically)

Chat messages not persisting

Chat messages persist for 30 days by default. Check:

  1. Ably app has Chat enabled
  2. Room is properly attached before sending
  3. Message has required fields (text or metadata)
  4. API key has publish capability

Best Practices

  1. Single Realtime Client: Create one client instance per application, share across components
  2. ClientId for Identity: Always set clientId when using Spaces or Chat for user identification
  3. Channel Naming: Use hierarchical names for organization: post:123, room:lobby:1, user:alice:notifications
  4. Presence Data: Keep presence data small (under 1KB) for efficiency
  5. History Limits: Load only necessary history to reduce bandwidth and latency
  6. Error Handling: Monitor connection state and handle disconnections gracefully
  7. Token Auth in Production: Never expose API keys in client code, use token authentication
  8. Cleanup: Unsubscribe from channels and detach when components unmount (hooks handle this automatically)
  9. LiveObjects Conflicts: Design for eventual consistency, use LiveCounter for numeric aggregations
  10. LiveSync Transactions: Always write to outbox within same transaction as application data

Additional Resources

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

32.77%
按下载量换算43

Claude

28.83%
按下载量换算38

Cursor

19.94%
按下载量换算26

Gemini CLI

9.76%
按下载量换算13

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

可疑

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills