@gftdcojp/actor-sdk-ui

Actor APIと連携したReact UIコンポーネントライブラリ。api.gftd.ai/actors APIを使用してActorの管理、実行、監視を行うための完全なTypeScriptサポート付きコンポーネント群です。
主な機能
🎭 Actor Management
- Actor一覧表示: 利用可能なActorの一覧を表示
- Actor作成: 新しいActorの作成と設定
- Actor編集・削除: 既存Actorの更新と削除
- ステータス管理: Active、Inactive、Running、Stoppedの状態管理
⚡ Actor Execution
- リアルタイム実行: ActorをWebUIから直接実行
- パラメータ設定: JSON形式での入力パラメータ設定
- 実行履歴: 過去の実行結果とログの確認
- 実行制御: 実行中のActorの停止と管理
📊 Monitoring & Analytics
- ダッシュボード: Actorの状態と実行状況を可視化
- フィルタリング: ステータス、タイプ別でのActor絞り込み
- ログ表示: 実行ログとエラー情報の詳細表示
- 使用量統計: メモリ、CPU、ネットワーク使用量の追跡
💬 Session Management (OpenAI Agent SDK inspired)
- セッション作成: actor_idを指定した新しいセッション開始
- セッション継続: 既存セッションでの会話継続
- セッション復元: セッションIDによる過去セッションの復元
- ストリーミング: リアルタイムメッセージ配信
- メッセージ履歴: セッション内メッセージの完全な履歴管理
- セッション一覧: アクター別セッション管理と検索
技術スタック
- Frontend: Next.js 15.2.4 + React 19
- Styling: Tailwind CSS + Shadcn/ui
- API: Actor API (api.gftd.ai)
- 状態管理: React Hooks
- TypeScript: 完全型安全
インストール
npm install @gftdcojp/actor-sdk-ui
yarn add @gftdcojp/actor-sdk-ui
pnpm add @gftdcojp/actor-sdk-ui
基本的な使用方法
1. スタイルのインポート
import '@gftdcojp/actor-sdk-ui/styles'
@import '@gftdcojp/actor-sdk-ui/styles';
🔍 Embedding & Vector Search
Actor SDK UIは、LangChainJS + HuggingFaceTransformersEmbeddings + usearch による高速なembeddingとvector searchをサポートしています。
Embedding SDK の使用例
import { EmbeddingSDK } from '@gftdcojp/actor-sdk-ui';
import { Document } from '@langchain/core/documents';
const embeddingSDK = new EmbeddingSDK({
modelName: 'Xenova/all-MiniLM-L6-v2',
cacheDir: './cache',
});
await embeddingSDK.initialize();
const documents = [
new Document({
pageContent: 'This is a sample document about machine learning.',
metadata: { source: 'sample1.txt', category: 'tech' },
}),
new Document({
pageContent: 'Natural language processing is a subfield of AI.',
metadata: { source: 'sample2.txt', category: 'tech' },
}),
];
const documentIds = await embeddingSDK.addDocuments(documents);
const results = await embeddingSDK.search('machine learning', 5);
console.log(results);
await embeddingSDK.saveIndex('my_index.bin');
await embeddingSDK.cleanup();
Vector Store の直接使用
import { VectorStore } from '@gftdcojp/actor-sdk-ui';
import { Document } from '@langchain/core/documents';
import LightningFS from '@isomorphic-git/lightning-fs';
const fs = new LightningFS('my-vector-store');
const vectorStore = new VectorStore(fs, 384);
await vectorStore.initialize();
const vector = [0.1, 0.2, 0.3, ];
const document = new Document({
pageContent: 'Sample document',
metadata: { source: 'test.txt' },
});
const id = await vectorStore.add(vector, document);
const results = await vectorStore.search(vector, 5);
console.log(results);
await vectorStore.cleanup();
特徴
- 高速検索: usearchによる高速なベクトル検索
- 軽量モデル: Xenova/all-MiniLM-L6-v2(384次元)
- ブラウザ対応: Transformers.jsによるクライアントサイド実行
- 永続化: LightningFSによるin-memoryファイルシステム
- TypeScript: 完全なTypeScriptサポート
🦊 GitLab統合
Actor SDK UIは、GitLab APIとisomorphic-gitを使用したGit統合をサポートしています。
🎯 統一概念
- user_org_id = gitlab organization_id: GitLab組織IDと統一
- actor_id = repository_name (uuid): UUIDを含むリポジトリ名(例:
chat-assistant-abc123
)
- new session -> new_branch: セッション作成時に新しいGitブランチ作成
🏗️ アーキテクチャ
- Actor = GitLabプロジェクト: 新しいActorが新しいGitLabプロジェクト
- Session = Gitブランチ: 新しいSessionが新しいブランチ
- ファイルシステム = Git: isomorphic-gitによるGit操作
- ベクトルストア = Git管理: ベクトルデータのGit保存・読み込み
GitLab統合の使用例
import { ActorGitManager } from '@gftdcojp/actor-sdk-ui';
import { Document } from '@langchain/core/documents';
const gitManager = new ActorGitManager({
gitlab: {
url: 'https://gitlab-gftd-ai.fly.dev/',
token: 'glpat-',
defaultVisibility: 'private',
},
embedding: {
modelName: 'Xenova/all-MiniLM-L6-v2',
dimensions: 384,
},
author: {
name: 'GFTD Actor SDK',
email: 'actor-sdk@gftd.ai',
},
});
const actor = await gitManager.createActor({
name: 'my-actor',
description: 'My intelligent actor',
visibility: 'private',
});
const embeddingSDK = await gitManager.createActorSession(
actor.id,
'session-001',
'main'
);
const documents = [
new Document({
pageContent: 'Sample document content',
metadata: { source: 'sample.txt' },
}),
];
await gitManager.addDocumentsToActor(actor.id, documents, 'session-001');
const results = await gitManager.searchInActor(
actor.id,
'search query',
5,
'session-001'
);
await gitManager.saveFileToActor(
actor.id,
'config.json',
JSON.stringify({ setting: 'value' }),
'Add configuration',
'session-001'
);
await gitManager.switchActorSession(actor.id, 'session-002');
Git操作の詳細
import { GitEmbeddingSDK } from '@gftdcojp/actor-sdk-ui';
const gitEmbeddingSDK = new GitEmbeddingSDK({
git: {
url: 'https://gitlab-gftd-ai.fly.dev/user/project.git',
token: 'your-gitlab-token',
author: {
name: 'Your Name',
email: 'your@email.com',
},
branch: 'main',
},
modelName: 'Xenova/all-MiniLM-L6-v2',
dimensions: 384,
});
await gitEmbeddingSDK.initialize();
await gitEmbeddingSDK.createSession('new-session');
await gitEmbeddingSDK.saveFile('data.txt', 'content');
const content = await gitEmbeddingSDK.loadFile('data.txt');
await gitEmbeddingSDK.push();
await gitEmbeddingSDK.pull();
const history = await gitEmbeddingSDK.getCommitHistory();
Git統合の特徴
- 完全なバージョン管理: すべてのベクトルデータと設定がGitで管理
- ブランチベースのセッション: 並行開発とA/Bテストが可能
- GitLab API統合: プロジェクト、ブランチの自動管理
- isomorphic-git: ブラウザ環境でのGit操作
- 自動同期: 変更の自動コミット・プッシュ
- コラボレーション: チームでのベクトルデータ共有
Git統合の環境設定
GITLAB_URL=https://gitlab-gftd-ai.fly.dev/
GITLAB_PAT=your-gitlab-personal-access-token
AUTHOR_NAME=Your Name
AUTHOR_EMAIL=your@email.com
###実行例
node dist/lib/git/example.js
2. コンポーネントの使用
import { ActorDashboard, useActors } from '@gftdcojp/actor-sdk-ui'
function MyApp() {
return (
<div className="min-h-screen bg-background">
<ActorDashboard />
</div>
)
}
export default MyApp
3. API クライアントの使用
import { actorApi, Actor } from '@gftdcojp/actor-sdk-ui'
async function fetchActors() {
const response = await actorApi.getActors()
if (response.success) {
console.log('Actors:', response.data?.actors)
}
}
4. React Hooks の使用
import { useActors, useActorMutations } from '@gftdcojp/actor-sdk-ui'
function ActorList() {
const { actors, loading, error } = useActors()
const { runActor } = useActorMutations()
const handleRunActor = async (actorId: string) => {
const result = await runActor(actorId, {
input: { message: "Hello, World!" }
})
console.log('Run result:', result)
}
if (loading) return <div>Loading...</div>
if (error) return <div>Error: {error}</div>
return (
<div>
{actors.map(actor => (
<div key={actor.id}>
<h3>{actor.name}</h3>
<button onClick={() => handleRunActor(actor.id)}>
Run Actor
</button>
</div>
))}
</div>
)
}
セッション管理の使用方法
1. シンプルなセッション管理
import { createActorSession, continueActorSession } from '@gftdcojp/actor-sdk-ui'
const session = await createActorSession(
"actor-123",
"Hello, I need help with data analysis"
)
if (session) {
console.log("Session ID:", session.session.id)
const response = await continueActorSession(
session.session.id,
"Can you analyze this dataset for me?"
)
if (response) {
console.log("Actor response:", response.message.content)
}
}
2. クラス形式API(OpenAI Agent SDK スタイル)
import { ActorSDK } from '@gftdcojp/actor-sdk-ui'
const sdk = new ActorSDK({ baseUrl: "/api" })
const session = await sdk.createSession({
actorId: "actor-456",
message: "I want to create a web scraper",
config: {
timeout_seconds: 300,
max_messages: 50
}
})
const response = await sdk.continueSession({
sessionId: session.session.id,
message: "The target website is example.com"
})
3. React Hooks でのセッション管理
import { useActorSession } from '@gftdcojp/actor-sdk-ui'
function ChatComponent() {
const {
session,
messages,
loading,
createSession,
continueSession,
resetSession
} = useActorSession()
const handleStartChat = async () => {
await createSession("actor-123", "Hello!")
}
const handleSendMessage = async (message: string) => {
await continueSession(message)
}
return (
<div>
{!session ? (
<button onClick={handleStartChat}>Start Chat</button>
) : (
<div>
<div>Session: {session.id}</div>
<div>Messages: {messages.length}</div>
<button onClick={() => handleSendMessage("Tell me more")}>
Send Message
</button>
<button onClick={resetSession}>New Session</button>
</div>
)}
</div>
)
}
4. ストリーミングセッション
import { createStreamingActorSession } from '@gftdcojp/actor-sdk-ui'
const stream = await createStreamingActorSession(
"actor-789",
"Generate a detailed report",
{ stream: true }
)
for await (const event of stream) {
switch (event.event.type) {
case "message_delta":
process.stdout.write(event.event.data.content)
break
case "done":
console.log("\nCompleted!")
break
}
}
環境変数の設定
.env.local
ファイルを作成し、以下の環境変数を設定してください:
ACTOR_API_BASE_URL=http://api.gftd.ai
ACTOR_API_KEY=your_api_key_here
サンプルアプリケーション
examples/
ディレクトリには、パッケージの使用方法を示すサンプルアプリケーションが含まれています。
📱 Next.js Sample Application
完全なNext.jsアプリケーションのサンプル:
cd examples/nextjs-sample
pnpm install
pnpm dev
含まれる機能:
- 🎭 Actor Dashboard
- 💬 Session Management (OpenAI Agent SDK inspired)
- 🛠 API Client Demo
- ⚛️ React Hooks Examples
詳細は examples/README.md
を参照してください。
開発者向けセットアップ
1. 依存関係のインストール
pnpm install
2. ライブラリのビルド
pnpm build
pnpm dev:lib
3. 開発サーバーの起動
pnpm dev
API連携
Actor API エンドポイント
1. Actor管理
GET /api/actors
- Actor一覧取得
POST /api/actors
- 新しいActor作成
GET /api/actors/[id]
- 特定Actor詳細取得
PUT /api/actors/[id]
- Actor情報更新
DELETE /api/actors/[id]
- Actor削除
2. Actor実行
POST /api/actors/[id]/run
- Actor実行
GET /api/actors/[id]/run
- 実行履歴取得
GET /api/runs/[runId]
- 特定実行の詳細取得
DELETE /api/runs/[runId]
- 実行停止
PATCH /api/runs/[runId]
- 実行設定更新
データ型定義
interface Actor {
id: string
name: string
description: string
type: string
status: "active" | "inactive" | "running" | "stopped"
version: string
created_at: string
updated_at: string
metadata?: Record<string, any>
config?: ActorConfig
}
interface ActorRunRequest {
input: Record<string, any>
config?: {
memory_mb?: number
timeout_seconds?: number
webhook_url?: string
priority?: "low" | "normal" | "high"
}
}
ファイル構成
actor-sdk-ui/
├── app/ # Next.js App Router
│ ├── api/ # APIルート
│ │ ├── actors/ # Actor管理API
│ │ └── runs/ # 実行管理API
│ ├── globals.css # グローバルスタイル
│ ├── layout.tsx # ルートレイアウト
│ └── page.tsx # メインページ
├── components/ # UIコンポーネント
│ ├── actor-dashboard.tsx # Actorダッシュボード
│ ├── workbench.tsx # メインワークベンチ
│ └── ui/ # 基本UIコンポーネント
├── hooks/ # React Hooks
│ └── use-actors.ts # Actor API連携フック
├── lib/ # ユーティリティ
│ ├── api/ # APIクライアント
│ │ └── actor-client.ts
│ ├── types/ # 型定義
│ │ └── actor.ts
│ └── utils.ts # ヘルパー関数
└── README.md
使用方法
1. Actorダッシュボード
メインページの「Actors」タブから、Actor管理ダッシュボードにアクセスできます。
2. Actor作成
「Create Actor」ボタンから新しいActorを作成できます:
- Name: Actorの名前
- Type: Web Scraper, Data Processor, API Client等
- Description: Actorの説明
3. Actor実行
各ActorカードのRunボタンから実行できます:
- JSON形式でパラメータを入力
- 実行後は実行IDが返却される
- 実行状況はリアルタイムで更新
4. 実行履歴の確認
各Actorの実行履歴タブから、過去の実行結果を確認できます。
開発・カスタマイズ
API Client の拡張
新しいAPIエンドポイントを追加する場合:
lib/types/actor.ts
に型定義を追加
lib/api/actor-client.ts
にメソッドを追加
hooks/use-actors.ts
にHookを追加
- UIコンポーネントでHookを使用
UI コンポーネントの追加
Shadcn/uiベースのコンポーネントを使用してUIを拡張できます:
pnpm dlx shadcn-ui@latest add [component-name]
トラブルシューティング
IndexedDB エラー
サーバーサイドでIndexedDBが参照されるエラーが発生した場合、クライアントサイドでのみ実行されるように修正済みです。
API接続エラー
- 環境変数
ACTOR_API_BASE_URL
と ACTOR_API_KEY
が正しく設定されているか確認
- ネットワーク接続とCORS設定を確認
TypeScript エラー
React 19の型定義との互換性問題が発生する場合がありますが、機能的には問題ありません。
利用可能なコンポーネント
🎭 メインコンポーネント
ActorDashboard
- Actor管理ダッシュボード
actorApi
- APIクライアント
useActors
- Actor一覧管理Hook
useActor
- 単一Actor管理Hook
useActorMutations
- CRUD操作Hook
useActorRuns
- 実行履歴管理Hook
useRun
- 単一実行管理Hook
🧩 UIコンポーネント
Button
, Card
, Badge
Input
, Textarea
, Select
Dialog
, Label
, Alert
Tabs
, ScrollArea
, Skeleton
Toaster
, useToast
📝 型定義
Actor
, ActorConfig
ActorRunRequest
, ActorRunResponse
ActorListResponse
, ActorRunListResponse
ActorCreateRequest
, ActorUpdateRequest
ApiResponse
, ApiError
パッケージ公開
1. ビルド
pnpm build
2. 公開準備
npm pack
3. npm 公開
npm publish
npm version patch
npm publish
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
)
- Commit your changes (
git commit -m 'Add some amazing feature'
)
- Push to the branch (
git push origin feature/amazing-feature
)
- Open a Pull Request
ライセンス
MIT License