Integrations
SDK
TypeScript/JavaScript SDKの使い方
インストール
npm install @jinba-tool-registry/sdk初期化
import { createClient } from "@jinba-tool-registry/sdk";
const client = createClient({
apiKey: "jtr_xxxxx",
organizationId: "org-id", // デフォルトの組織ID(省略可)
});オプション
| パラメータ | 型 | デフォルト | 説明 |
|---|---|---|---|
apiKey | string | (必須) | APIキー |
organizationId | string | - | デフォルトの組織ID |
baseUrl | string | https://tool-registry-api.jinba.io | APIのベースURL |
timeout | number | 30000 | リクエストタイムアウト(ms) |
ツール実行
実行(Publish済み)
const result = await client.run("my-toolset", "my-tool", {
name: "World",
});
console.log(result.success); // true
console.log(result.output); // { message: "Hello, World!" }バージョン指定:
const result = await client.run("my-toolset", "my-tool", { name: "World" }, {
version: "1.0.0",
});テスト実行(ドラフト)
Publishせずにドラフトのコードをテストできます。
const result = await client.test("my-toolset", "my-tool", {
name: "World",
});
console.log(result.output); // { message: "Hello, World!" }
console.log(result.logs); // { stdout: [...], stderr: [...] }実行ログ
実行ログ一覧
const runs = await client.listRuns();実行ログ詳細
const run = await client.getRun("run_xxx");型定義
RunResult
interface RunResult {
runId: string;
success: boolean;
output?: Record<string, unknown>;
error?: RunError;
logs?: RunLogs;
durationMs?: number;
}
interface RunError {
name: string;
message: string;
traceback?: string;
}
interface RunLogs {
stdout: string[];
stderr: string[];
}Run
interface Run {
id: string;
toolSetId: string;
toolSetVersion: string;
toolId: string;
toolSlug: string;
userId: string;
input: Record<string, unknown>;
output?: Record<string, unknown> | null;
status: "pending" | "running" | "success" | "failed" | "timeout";
error?: RunError | null;
logs?: RunLogs | null;
startedAt?: string | null;
completedAt?: string | null;
durationMs?: number | null;
createdAt: string;
}エラーハンドリング
SDKのエラーはJinbaTRErrorとしてスローされます。
import { JinbaTRError } from "@jinba-tool-registry/sdk";
try {
await client.run("my-toolset", "my-tool", { name: "World" });
} catch (err) {
if (err instanceof JinbaTRError) {
console.error(err.message); // エラーメッセージ
console.error(err.statusCode); // HTTPステータスコード
console.error(err.details); // 追加詳細情報
}
}よくあるエラー
| statusCode | 原因 |
|---|---|
400 | 入力パラメータが不正 |
401 | APIキーが無効 |
402 | クレジット不足 |
404 | リソースが見つからない |
408 | リクエストタイムアウト |