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 는 애플리케이션 사용자 등록, 비밀번호 세션, 새로 고침 순환, 사용자 조회, 비밀번호 복구 및 업스트림 공급자 PKCE에 프로젝트 게시 가능 키를 사용합니다. flow.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);