Node.js SDK 提供显式记忆助手、旧版路由器标头、和 x402 支付实用程序,用于受信任的 JavaScript 和 TypeScript 运行时。
#安装
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 使用项目可发布密钥进行应用程序用户注册、密码会话、刷新轮换、用户查找、密码恢复和上游提供商 PKCEHaloOAuthClient 适用于注册为 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);