MCP HubMCP Hub
スキル一覧に戻る

times-square-integration

lsst-sqre
更新日 Today
48 閲覧
2
1
2
GitHubで表示
メタapidata

について

このスキルは、Times Squareノートブック実行システムを操作するための統合パターンを提供します。SSE更新の実装、URLパラメータの処理、GitHub PRプレビューの設定、あるいはTimes Square APIを操作する際にご利用ください。これには、ノートブックの表示と実行のためのコンテキストプロバイダ、データ取得フック、モックAPIエンドポイント、およびページルーティングパターンが含まれます。

クイックインストール

Claude Code

推奨
プラグインコマンド推奨
/plugin add https://github.com/lsst-sqre/squareone
Git クローン代替
git clone https://github.com/lsst-sqre/squareone.git ~/.claude/skills/times-square-integration

このコマンドをClaude Codeにコピー&ペーストしてスキルをインストールします

ドキュメント

Times Square Integration

Times Square is a notebook execution system integrated into the squareone app for displaying computational notebooks.

Core Concepts

  • Pages: Notebooks that can be executed and displayed
  • Parameters: URL-based parameters for notebook execution
  • SSE (Server-Sent Events): Real-time updates during execution
  • GitHub PR Previews: Preview notebooks from pull requests

Context Providers

TimesSquareUrlParametersContext

Manages URL-based state for Times Square pages.

import { TimesSquareUrlParametersContext } from '../contexts/TimesSquareUrlParametersContext';

// Provider setup (usually in page)
<TimesSquareUrlParametersContext.Provider value={urlParams}>
  <TimesSquarePage />
</TimesSquareUrlParametersContext.Provider>

// Usage in components
const { getParameter, setParameter } = useContext(TimesSquareUrlParametersContext);

const value = getParameter('myParam');
setParameter('myParam', 'newValue');

TimesSquareHtmlEventsContext

Manages real-time SSE (Server-Sent Events) updates.

import { TimesSquareHtmlEventsContext } from '../contexts/TimesSquareHtmlEventsContext';

// Provider setup
<TimesSquareHtmlEventsContext.Provider value={eventSource}>
  <TimesSquarePage />
</TimesSquareHtmlEventsContext.Provider>

// Usage
const events = useContext(TimesSquareHtmlEventsContext);
// events provides real-time updates from notebook execution

Data Fetching Hooks

useTimesSquarePage

Custom hook for fetching Times Square page data.

import { useTimesSquarePage } from '../hooks/useTimesSquarePage';

function MyComponent({ pageSlug }) {
  const { data, error, isLoading } = useTimesSquarePage(pageSlug);

  if (isLoading) return <div>Loading...</div>;
  if (error) return <div>Error: {error.message}</div>;

  return <div>{data.displayName}</div>;
}

Pattern uses SWR for caching and revalidation.

Routing Patterns

Regular Pages

/times-square/{page-slug}

GitHub PR Previews

/times-square/github-pr/{owner}/{repo}/{commit}

Example:

/times-square/github-pr/lsst-sqre/times-square-demo/abc123

API Routes

Mock API endpoints in development (/pages/api/dev/times-square/):

  • GET /times-square/api/v1/pages - List pages
  • GET /times-square/api/v1/pages/:page - Page metadata
  • GET /times-square/api/v1/pages/:page/html - Rendered HTML
  • GET /times-square/api/v1/pages/:page/htmlstatus - Execution status
  • GET /times-square/api/v1/pages/:page/htmlevents - SSE endpoint

Mock API Endpoints

For local development without Times Square backend:

// pages/api/dev/times-square/v1/pages/[page]/html.ts
import type { NextApiRequest, NextApiResponse } from 'next';

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse
) {
  const { page } = req.query;

  // Return mock HTML
  res.status(200).json({
    html: '<div>Mock Times Square page</div>',
    parameters: {},
  });
}

Page Component Pattern

import { GetServerSideProps } from 'next';
import { useTimesSquarePage } from '../hooks/useTimesSquarePage';
import { TimesSquareUrlParametersContext } from '../contexts/TimesSquareUrlParametersContext';
import { loadAppConfig } from '../lib/config/loader';

type Props = {
  pageSlug: string;
};

export default function TimesSquarePage({ pageSlug }: Props) {
  const { data, error, isLoading } = useTimesSquarePage(pageSlug);

  if (isLoading) return <div>Loading notebook...</div>;
  if (error) return <div>Error loading notebook</div>;

  return (
    <div>
      <h1>{data.displayName}</h1>
      <div dangerouslySetInnerHTML={{ __html: data.html }} />
    </div>
  );
}

export const getServerSideProps: GetServerSideProps<Props> = async (context) => {
  const appConfig = await loadAppConfig();
  const pageSlug = context.params?.page as string;

  return {
    props: {
      appConfig,
      pageSlug,
    },
  };
};

SSE Integration

function TimesSquareLivePage({ pageSlug }) {
  const [eventSource, setEventSource] = useState(null);

  useEffect(() => {
    const es = new EventSource(
      `/times-square/api/v1/pages/${pageSlug}/htmlevents`
    );

    es.onmessage = (event) => {
      const data = JSON.parse(event.data);
      // Handle real-time updates
      console.log('New data:', data);
    };

    setEventSource(es);

    return () => es.close();
  }, [pageSlug]);

  return (
    <TimesSquareHtmlEventsContext.Provider value={eventSource}>
      {/* Page content */}
    </TimesSquareHtmlEventsContext.Provider>
  );
}

Configuration

Times Square URL configured in AppConfig:

# squareone.config.yaml
timesSquareUrl: 'http://localhost:3000/times-square/api'  # Dev
# timesSquareUrl: 'https://data.lsst.cloud/times-square/api'  # Prod

Access in components:

import { useAppConfig } from '../contexts/AppConfigContext';

const config = useAppConfig();
const timesSquareUrl = config.timesSquareUrl;

Best Practices

  1. Use context providers for shared state
  2. Cache with SWR for performance
  3. Mock APIs for development
  4. Handle loading states gracefully
  5. Clean up SSE connections on unmount
  6. Validate parameters before execution
  7. Show execution progress with SSE
  8. Handle errors appropriately

GitHub リポジトリ

lsst-sqre/squareone
パス: .claude/skills/times-square-integration
nextjsrubin-science-platform

関連スキル

content-collections

メタ

This skill provides a production-tested setup for Content Collections, a TypeScript-first tool that transforms Markdown/MDX files into type-safe data collections with Zod validation. Use it when building blogs, documentation sites, or content-heavy Vite + React applications to ensure type safety and automatic content validation. It covers everything from Vite plugin configuration and MDX compilation to deployment optimization and schema validation.

スキルを見る

creating-opencode-plugins

メタ

This skill provides the structure and API specifications for creating OpenCode plugins that hook into 25+ event types like commands, files, and LSP operations. It offers implementation patterns for JavaScript/TypeScript modules that intercept and extend the AI assistant's lifecycle. Use it when you need to build event-driven plugins for monitoring, custom handling, or extending OpenCode's capabilities.

スキルを見る

evaluating-llms-harness

テスト

This Claude Skill runs the lm-evaluation-harness to benchmark LLMs across 60+ standardized academic tasks like MMLU and GSM8K. It's designed for developers to compare model quality, track training progress, or report academic results. The tool supports various backends including HuggingFace and vLLM models.

スキルを見る

polymarket

メタ

This skill enables developers to build applications with the Polymarket prediction markets platform, including API integration for trading and market data. It also provides real-time data streaming via WebSocket to monitor live trades and market activity. Use it for implementing trading strategies or creating tools that process live market updates.

スキルを見る