Integrations
SDK
TypeScript/JavaScript SDKの使い方
インストール
npm install @jinba-toolbox/sdkクライアントの作成
import { createClient } from "@jinba-toolbox/sdk";
const client = createClient({
apiKey: "jtb_xxxxx",
organizationId: "org-id", // デフォルトの組織ID(省略可)
});設定オプション
| パラメータ | 型 | デフォルト | 説明 |
|---|---|---|---|
apiKey | string | (必須) | APIキー |
organizationId | string | - | デフォルトの組織ID |
baseUrl | string | https://toolbox-api.jinba.dev | 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 orgs = await client.listOrganizations();
// 組織の詳細
const org = await client.getOrganization("org-id");ToolSet
// 一覧
const toolSets = await client.listToolSets();
// 詳細(Tool一覧を含む)
const toolSet = await client.getToolSet("my-toolset");
// 作成
const newToolSet = await client.createToolSet({
slug: "my-toolset",
name: { default: "My ToolSet" },
description: { default: "Description" },
sandbox: {
provider: "e2b",
language: "python",
packages: [{ name: "requests" }],
resources: { timeout: 30 },
},
});
// 更新
await client.updateToolSet("my-toolset", {
name: { default: "Updated Name" },
mcpEnabled: true,
});
// 削除
await client.deleteToolSet("my-toolset");Tool
// 一覧
const tools = await client.listTools("my-toolset");
// 詳細
const tool = await client.getTool("my-toolset", "my-tool");
// 作成
const newTool = await client.createTool("my-toolset", {
slug: "my-tool",
name: { default: "My Tool" },
description: { default: "Description" },
inputSchema: { type: "object", properties: { name: { type: "string" } } },
outputSchema: { type: "object", properties: { message: { type: "string" } } },
code: `def run(input): return {"message": f"Hello, {input['name']}!"}`,
});
// 更新
await client.updateTool("my-toolset", "my-tool", {
code: "updated code...",
});
// 削除
await client.deleteTool("my-toolset", "my-tool");バージョン
// 一覧
const versions = await client.listVersions("my-toolset");
// 新バージョンの発行
const version = await client.publishVersion("my-toolset", {
version: "1.0.0",
releaseNotes: "Initial release",
});実行ログ
// 一覧
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のエラーはJinbaTBErrorとしてスローされます。
import { JinbaTBError } from "@jinba-toolbox/sdk";
try {
await client.run("my-toolset", "my-tool", { name: "World" });
} catch (err) {
if (err instanceof JinbaTBError) {
console.error(err.message); // エラーメッセージ
console.error(err.statusCode); // HTTPステータスコード
console.error(err.details); // 追加詳細情報
}
}よくあるエラー
| statusCode | 原因 |
|---|---|
400 | 入力パラメータが不正 |
401 | APIキーが無効 |
402 | クレジット不足 |
404 | リソースが見つからない |
408 | リクエストタイムアウト |