@mps-electrolab/ai-commerce-client
v0.3.1
Published
Dependency-free Node.js SDK for MPS local agents. It sends an installation credential to the AI Commerce Gateway; it never accepts or forwards an OpenAI API key and does not import Galaxy, RTPC, or portal code.
Downloads
298
Readme
AI Commerce Client
Dependency-free Node.js SDK for MPS local agents. It sends an installation credential to the AI Commerce Gateway; it never accepts or forwards an OpenAI API key and does not import Galaxy, RTPC, or portal code.
import { createAiCommerceClient, readAiCommerceClientConfig } from '@mps-electrolab/ai-commerce-client'
const client = createAiCommerceClient(readAiCommerceClientConfig(process.env))
const response = await client.createResponse({
capability: 'general-assistant',
input: [{ role: 'user', content: 'Summarize this work order.' }],
})
console.log(response.output_text)
console.log(response.functionCalls)
console.log(await client.getAccountCredits())Required local-agent environment variables:
AI_GATEWAY_URL=https://ai-commerce-gateway.vercel.app
AI_GATEWAY_CREDENTIAL=installation-credential-issued-by-site-adminThe client retries transient 429, 502, 503, and 504 responses with the
same idempotency key. Callers should retain response.idempotencyKey when they
need to retry across process restarts.
AiCommerceInsufficientCreditsError identifies a 402 insufficient_credits
response. Agents should stop dispatching new model requests, show the operator
the portal top-up path, and call getAccountCredits() before clearing their
local exhausted-credit latch.
Function tools and continuations
The gateway enforces the installation capability's tool policy. Pass only function tools that the assigned capability allows. Responses expose parsed function calls, and a follow-up response can reference the prior response ID.
const first = await client.createResponse({
capability: 'rtpc-ai-advisor',
input: [{ role: 'user', content: 'Prepare a change proposal.' }],
tools: [{ type: 'function', name: 'propose_rtpc_data_changes', parameters: { type: 'object' } }],
})
const call = first.functionCalls[0]
if (call) {
await client.createResponse({
capability: 'rtpc-ai-advisor',
previousResponseId: first.id,
input: [{ type: 'function_call_output', call_id: call.callId, output: '{"status":"pending_review"}' }],
})
}Publishing
Build and test the package from this directory, then publish the resulting
private scoped package to the selected registry. Consumers should pin a released
version, for example @mps-electrolab/[email protected]; they must not
import source code from Galaxy or RTPC.
