Node.js SDK は、明示的なメモリ ヘルパー、レガシー ルーター ヘッダー、信頼できる JavaScript および TypeScript ランタイム用の x402 支払いユーティリティ。
#インストール
npm install agihalo-node-sdk ethers#認証と OAuth
import {
HaloAuthClient,
HaloOAuthClient,
} from "agihalo-node-sdk";
// OEM or application user Authentication.
const auth = new HaloAuthClient({
publishableKey: HALO_PROJECT_PUBLISHABLE_KEY,
});
const session = await auth.signInWithPassword(
"user@example.com",
"Secret123!"
);
const refreshed = await auth.refreshSession(session.refresh_token);
const user = await auth.getUser(refreshed.access_token);
// Service-side OAuth App client.
const oauth = new HaloOAuthClient({
clientId: "halo_client_...",
clientSecret: HALO_OAUTH_CLIENT_SECRET,
});
const tokens = await oauth.exchangeCode(
callbackCode,
"https://service.example.com/callback"
);HaloAuthClient は、アプリケーション ユーザーのサインアップ、パスワード セッション、更新ローテーション、ユーザー検索、パスワード回復などにプロジェクト公開可能キーを使用します。HaloOAuthClient は、OAuth アプリとして登録されたサービス用です。返されたトークンは保存されません。
#メモリ クライアント
import { HaloMemoryClient } from "agihalo-node-sdk";
const memory = new HaloMemoryClient({
apiKey: process.env.HALO_API_KEY!,
projectKey: "customer-product",
});
const declaration = memory.functionDeclaration();
const result = await memory.executeRetrieveFunction({
endUserKey: "user_123",
sessionData: {
messages: [
{ role: "user", content: "What are my report preferences?" },
],
},
limit: 5,
});
// Feed result.functionResponse to your model, then capture the final answer.
await memory.capture({
endUserKey: "user_123",
sessionData: {
messages: [
{ role: "user", content: "What are my report preferences?" },
],
},
response: {
role: "assistant",
content: "You prefer concise reports in the morning.",
},
});#メモリの削除
await memory.deleteTopic({
endUserKey: "user_123",
topicKey: "report_preferences",
includeRaw: false,
});
await memory.deleteRawEntry({
endUserKey: "user_123",
rawEntryId: "raw_entry_id",
});#接続されているアカウント
await memory.registerOAuthProvider({
providerKey: "google",
clientId: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_CLIENT_SECRET,
redirectUri:
"https://connect.example.com/api/v1/memory/oauth/callback/google",
});
const result = await memory.startOAuth({
scopeId: "memory-scope-uuid",
connectorId: "google.calendar",
completionMode: "mobile_deep_link",
returnUri: "example-app://oauth/complete",
});#支払いヘルパー
使用 haloSystem 自動 402 再試行ラッパーの場合、またはエージェントが明示的に決定して署名する必要がある場合のHaloPaymentTools 。
import { HaloPaymentTools } from "agihalo-node-sdk";
const tools = new HaloPaymentTools({
privateKey: secureWalletPrivateKey,
apiKey: HALO_API_KEY,
haloUrl: "https://api.agihalo.com",
});
const decision = await tools.consultJudge(context, "1.00 USDC");
const signature = await tools.signPayment(paymentRequirement);