@juggernautlabs/cloud
Official Node.js and browser SDK for the Juggernaut Cloud Platform. Execute AI processes, manage cloud database schemas, search cloud resources, run plugins locally, and handle file assets with full TypeScript support.

Installation
npm install @juggernautlabs/cloud
For the browser via CDN:
<script src="https://cdn.jsdelivr.net/npm/@juggernautlabs/cloud/build/browser.js"></script>
<script>
JuggernautCloud.init('your-client-id', 'your-api-key');
</script>
Quick Start
import { init, runProcess, getProcessJobEvents, DatabaseSchema } from '@juggernautlabs/cloud';
// Initialize once per application lifecycle
init('your-client-id', 'your-api-key');
// Run a process
const { referenceId, jobId } = await runProcess({
processId: 'process_123',
inputs: { topic: 'AI Trends' },
metadata: { source: 'dashboard' }
});
// Poll for completion and get results in one call
const final = await getProcessJobEvents({
referenceId,
polling: { intervalMs: 2000, durationMs: 120000 },
onProgress: (tick) => console.log('status tick', tick.data.length)
});
console.log(final.results);
Table of Contents
- Initialization
- Process Execution
- Run a Process
- Run a Process and Wait for Completion
- Get Process Inputs
- Upload / Ingest a Process
- Schedule a Process
- Job Events & Polling
- Get Job Results
- Retrieve Job Files
- Resource Search
- Model Listings
- Local Plugin Initialization
- Database Operations
- Browser Usage
- Error Handling
- TypeScript Types
- Contributing
- License
Initialization
import { init } from '@juggernautlabs/cloud';
init(clientId?: string, apiKey?: string);
Call once at application startup to set global authentication credentials. All subsequent API calls use these credentials unless you pass clientId/apiKey per request.
You can also provide credentials via environment variables:
JUGGERNAUT_CLIENT_ID
JUGGERNAUT_API_KEY
JUGGERNAUT_BASE_URL (optional, defaults to https://core.juggernautlabs.ai)
Credentials are resolved in the following order of precedence:
- Per-request
clientId / apiKey
- Explicit values passed to
init(...)
- Environment variables
import { init, runProcess } from '@juggernautlabs/cloud';
// Use env vars only
init();
// Override env vars / per-request
init('your-client-id', 'your-api-key');
// Override init/env credentials for a single call
await runProcess({
processId: 'process_123',
inputs: { topic: 'AI Trends' },
clientId: 'other-client',
apiKey: 'other-key'
});
Process Execution
Run a Process
import { runProcess } from '@juggernautlabs/cloud';
const job = await runProcess({
processId: 'your-process-id',
inputs: {
market: 'US_EQUITY',
symbol: 'AAPL'
},
metadata: {
userId: 'user_123',
traceId: 'trace_456'
}
// Optional: accessPoint: 'your-access-point-id'
});
ProcessExecutionOptions
| Property |
Type |
Required |
Description |
processId |
string |
✅ |
The process definition ID to execute |
inputs |
Record<string, any> |
✅ |
Input payload passed to the process |
metadata |
Record<string, any> |
❌ |
Arbitrary metadata attached to the job |
accessPoint |
string |
❌ |
Public access point for white-label deployments |
clientId |
string |
❌ |
Override global client ID |
apiKey |
string |
❌ |
Override global API key |
Get Process Inputs
Retrieve the declared input schema for a process.
import { getProcessInputs } from '@juggernautlabs/cloud';
const inputs = await getProcessInputs('process_123');
console.log(inputs); // [{ name: 'symbol', type: 'string', required: true }, ...]
Upload / Ingest a Process
Ingest a raw process definition using the /api/process/upload endpoint. This is useful when you have a process description matching the InputProcess schema (pipelines, steps, messages, plugins, etc.) and want the server to normalize and store it.
import { ingestProcess } from '@juggernautlabs/cloud';
const result = await ingestProcess({
process: {
name: 'My Ingested Process',
defaultModel: 'gpt-4',
store: {},
pipelines: [
{
type: 'standard',
next: null,
steps: [
{
name: 'Generate summary',
outputName: 'summary',
iterations: 1,
type: 'standard',
executionType: 'standard',
taskType: 'LLM',
messages: [
{
type: 'system',
content: 'Summarize the following: {{topic}}',
variables: [{ topic: 'AI' }],
isTemplate: true
}
],
options: {
outputFormat: 'text'
}
}
]
}
]
}
});
Schedule a Process
import { scheduleProcess } from '@juggernautlabs/cloud';
const schedule = await scheduleProcess({
processId: 'your-process-id',
name: 'Daily report',
intervals: 'daily',
inputs: { /* ... */ },
metadata: { /* ... */ }
});
Job Events & Polling
Fetch events manually or use the built-in poller.
Manual Event Fetch
import { getProcessJobEvents } from '@juggernautlabs/cloud';
const events = await getProcessJobEvents({
referenceId: 'ref_abc123'
});
Automatic Polling (Recommended)
const result = await getProcessJobEvents({
referenceId: 'ref_abc123',
polling: {
intervalMs: 2000, // Poll every 2 seconds
durationMs: 300000, // Optional: stop polling after 5 minutes
maxIntervalMs: 30000 // Optional: back off to 30s for long-running jobs
},
onProgress: (tick) => {
console.log('Events:', tick.data.length, 'done:', tick.done);
}
});
console.log('Final results:', result.results);
Polling Response (PollResultResponse)
| Property |
Type |
Description |
data |
any[] |
Latest batch of events |
done |
boolean |
true when the job reaches a terminal status |
results |
any \| null |
Final job output (populated once done === true) |
error |
string |
Error message if the job failed or results could not be fetched |
Terminal Statuses: job-end, job-error, job-completed, process-completed, process-ended
The poller deduplicates overlapping ticks, caches results after the first successful fetch, runs event detection and result fetching concurrently, and supports optional exponential backoff via maxIntervalMs for long-running jobs.
Run a Process and Wait for Completion
For CLI agents and other long-running callers, use runProcessAndWait to start a process and block until it completes in a single call:
import { runProcessAndWait } from '@juggernautlabs/cloud';
const result = await runProcessAndWait({
processId: 'process_123',
inputs: { topic: 'AI Trends' },
metadata: { source: 'cli' },
polling: {
intervalMs: 2000, // Poll every 2 seconds initially
maxIntervalMs: 30000 // Back off to 30 seconds for multi-minute jobs
},
onProgress: (tick) => {
console.log('Events so far:', tick.data.length, 'done:', tick.done);
}
});
if (result.error) {
console.error('Job failed:', result.error);
} else {
console.log('Final results:', result.results);
}
Get Job Results
import { getJobResults } from '@juggernautlabs/cloud';
const results = await getJobResults('jobId_123');
Usually unnecessary when using the polling helper above.
Retrieve Job Files
import { getJobFile } from '@juggernautlabs/cloud';
// Link format from job results: file(image):64f8a1b2c3d4e5f6a7b8c9d0
const stream = await getJobFile('jobId_123', 'file(image):64f8a1b2c3d4e5f6a7b8c9d0');
Supported File Types: image, audio, text
Resource Search
Search processes, prompts, plugins, and process jobs.
import {
searchListings,
getRecentSearches,
searchProcessJobs,
getListingsByIds
} from '@juggernautlabs/cloud';
// Search any supported resource type
const listings = await searchListings({
searchType: 'process',
name: 'report',
pageNumber: 1,
rowsPerPage: 12,
orderBy: { createdAt: 'desc' }
});
// Recent searches
const recent = await getRecentSearches('process');
// Jobs for a specific process
const jobs = await searchProcessJobs({
processId: 'process_123',
fields: { status: { $in: ['completed', 'failed'] } }
});
// Batch fetch by IDs
const byIds = await getListingsByIds({
listingType: 'prompt',
ids: ['id1', 'id2']
});
Model Listings
List the AI models available in the Juggernaut platform.
import { listModels } from '@juggernautlabs/cloud';
const allModels = await listModels();
Local Plugin Initialization
Fetch plugin metadata and JavaScript content, then execute the plugin locally in a Node VM context.
import { getPlugin, getPluginContent, initializePlugin } from '@juggernautlabs/cloud';
// Just metadata or source
const details = await getPlugin('plugin_123');
const source = await getPluginContent('plugin_123');
// Full local initialization
const plugin = await initializePlugin('plugin_123', { execute: true });
// Callers provide their own auth tokens
const instance = plugin.exports.create(
{ /* authSettings */ },
{ /* settings */ }
);
In browser environments initializePlugin returns { details, content } without executing the script.
Database Operations
The SDK includes a fluent DatabaseSchema class for Juggernaut Cloud Database resources.
import { DatabaseSchema } from '@juggernautlabs/cloud';
const users = new DatabaseSchema('schema_users_123', 'Users');
// CREATE
const newRecord = await users.insert({ email: 'ken@juggernautlabs.ai', role: 'admin' });
// READ
const record = await users.getRecord('64f8a1b2c3d4e5f6a7b8c9d0');
// UPDATE
await users.update('64f8a1b2c3d4e5f6a7b8c9d0', { role: 'superadmin' });
// DELETE
await users.delete('64f8a1b2c3d4e5f6a7b8c9d0');
// QUERY
const results = await users.query('SELECT * FROM Users WHERE role = ?', { role: 'admin' });
Provide an accessPoint as the third constructor argument to route through the public API layer.
Browser Usage
Load the IIFE bundle and use the global JuggernautCloud object:
<script src="https://cdn.jsdelivr.net/npm/@juggernautlabs/cloud/build/browser.js"></script>
<script>
JuggernautCloud.init('your-client-id', 'your-api-key');
JuggernautCloud.runProcess({
processId: 'process_123',
inputs: { topic: 'AI Trends' }
}).then(job => console.log(job));
</script>
Plugin VM execution is not available in the browser bundle; use getPlugin and getPluginContent and execute the script with your own loader.
Error Handling
Network errors from the Juggernaut API bubble up as standard Error objects with the status and message returned by the API.
Validation errors thrown by the SDK itself include:
| Method |
Throws When |
DatabaseSchema.getRecord() |
id is falsy |
DatabaseSchema.query() |
queryString is falsy |
DatabaseSchema.insert() |
record is not an object |
getJobFile() |
link does not match file(type):id pattern |
TypeScript Types
All public types are exported from the package entry point:
import type {
ProcessExecutionOptions,
ProcessRunAndWaitOptions,
ProcessScheduleOptions,
ProcessIngestOptions,
InputProcess,
InputPipeline,
InputPipelineStep,
InputPipelineMessage,
ProcessJobEventsRequest,
PollResultResponse,
PollingOptions,
SearchListingsRequest,
ProcessJobSearchRequest,
ListingsByIdsRequest,
ModelDefinition,
ListModelsRequest,
ListModelsResponse,
PluginInitializationOptions,
PluginInstance,
BrowserCommand,
ContextMappingOptions,
ContextLoopOptions
} from '@juggernautlabs/cloud';
Contributing
Issues and pull requests are welcome in the GitHub repository.
License
MIT © Juggernaut Labs