Welcome to the interactive guide for gascity.ts! This guide provides hands-on examples and visual walkthroughs.
# Install the SDK
bun add @gascity/client @gascity/sdk
# Or clone the repository
git clone https://github.com/gascity-extra/gascity.ts
cd gascity.ts
bun installimport { GasCityClient } from '@gascity/client';
import { slingTask } from '@gascity/sdk';
const client = new GasCityClient({
baseUrl: 'https://api.gascity.com',
token: 'your-api-token'
});
const result = await slingTask({
client,
agent: 'my-agent',
city: 'my-city',
task: 'Analyze this data'
});
console.log('Task completed:', result);The Gas City Console provides a modern interface for managing all your Gas City resources.
The homepage gives you quick access to all major features:
- Cities - Manage your Gas City instances
- Agents - View and configure AI agents
- Tasks - Track task progress and results
- Sessions - Interactive agent conversations
Manage your Gas City instances with the Cities page:
- View all configured cities
- Create new cities
- Monitor city status
- Access city settings
The Agents page provides:
- List of all available agents
- Agent capabilities and configuration
- Performance metrics
- Agent deployment status
Track your tasks with the Tasks page:
- View all active and completed tasks
- Monitor task progress in real-time
- Access task results and outputs
- Filter and search tasks
Manage interactive sessions:
- Start new conversations with agents
- View session history
- Monitor active sessions
- Access session transcripts
Quick navigation menu for easy access to all features.
import { initCity, startCity, stopCity } from '@gascity/sdk';
// Initialize a new city
const city = await initCity({
client,
cityName: 'my-city',
config: {
description: 'My development city',
region: 'us-east-1'
}
});
// Start the city
await startCity({
client,
cityName: 'my-city'
});
// Stop the city
await stopCity({
client,
cityName: 'my-city'
});import { slingTask, getTaskStatus, waitForTaskCompletion } from '@gascity/sdk';
// Submit a task
const bead = await slingTask({
client,
agent: 'my-agent',
city: 'my-city',
task: 'Analyze the sales data for Q4',
metadata: {
priority: 'high',
department: 'sales'
}
});
// Check status
const status = await getTaskStatus({
client,
city: 'my-city',
beadId: bead.beadId
});
// Wait for completion
const result = await waitForTaskCompletion({
client,
city: 'my-city',
beadId: bead.beadId,
timeout: 300000 // 5 minutes
});import { createSession, interactSession } from '@gascity/sdk';
// Create a session
const session = await createSession({
client,
city: 'my-city',
agent: 'my-agent',
initialMessage: 'Help me analyze this data'
});
// Interact with the session
const response = await interactSession({
client,
city: 'my-city',
agent: 'my-agent',
sessionId: session.sessionId,
message: 'What are the key trends?'
});import { streamEvents } from '@gascity/sdk';
// Stream events from a city
const eventStream = await streamEvents({
client,
city: 'my-city'
});
console.log('Listening for events...');
for await (const event of eventStream) {
console.log('Event:', event.type, event.data);
// Handle specific event types
switch (event.type) {
case 'task.created':
console.log('New task created:', event.data.beadId);
break;
case 'task.completed':
console.log('Task completed:', event.data.beadId);
break;
case 'agent.status':
console.log('Agent status:', event.data.status);
break;
}
}The main client for interacting with the Gas City API.
import { GasCityClient } from '@gascity/client';
const client = new GasCityClient({
baseUrl: string, // API base URL
token?: string, // Authentication token
timeout?: number, // Request timeout (ms)
headers?: Record<string, string> // Additional headers
});High-level workflows for common operations:
| Workflow | Description |
|---|---|
initCity |
Initialize a new city |
startCity |
Start a city |
stopCity |
Stop a city |
slingTask |
Submit a task to an agent |
getTaskStatus |
Get task status |
waitForTaskCompletion |
Wait for task to complete |
createSession |
Create an interactive session |
interactSession |
Send message to session |
streamEvents |
Stream events from a city |
import { GasCityError, isGasCityError } from '@gascity/sdk';
try {
const result = await slingTask({ /* ... */ });
} catch (error) {
if (isGasCityError(error)) {
console.error(`Gas City Error: ${error.message}`);
console.error(`Code: ${error.code}`);
// Handle specific error codes
switch (error.code) {
case 'CITY_NOT_FOUND':
// Handle city not found
break;
case 'AGENT_UNAVAILABLE':
// Handle agent unavailable
break;
default:
// Handle other errors
}
}
}import { withRetry } from '@gascity/sdk';
const result = await withRetry(
async () => client.someMethod(),
{
maxRetries: 3,
delay: 1000,
backoff: 'exponential'
}
);import { generateCorrelationId } from '@gascity/sdk';
const correlationId = generateCorrelationId();
console.log(`Starting operation: ${correlationId}`);
try {
const result = await slingTask({
client,
agent: 'my-agent',
city: 'my-city',
task: 'Analyze data',
metadata: {
correlationId
}
});
console.log(`Operation completed: ${correlationId}`);
} catch (error) {
console.error(`Operation failed: ${correlationId}`, error);
}// ✅ Good
try {
const result = await slingTask({ /* ... */ });
} catch (error) {
console.error('Task failed:', error);
}
// ❌ Bad
const result = await slingTask({ /* ... */ }); // No error handling// ✅ Good
const result = await waitForTaskCompletion({
client,
city: 'my-city',
beadId: bead.beadId,
timeout: 300000 // 5 minutes
});
// ❌ Bad
const result = await waitForTaskCompletion({
client,
city: 'my-city',
beadId: bead.beadId
// No timeout - could hang forever
});// ✅ Good
if (!cityName || !agentName) {
throw new Error('City name and agent name are required');
}
const result = await slingTask({
client,
agent: agentName,
city: cityName,
task: taskText
});
// ❌ Bad
const result = await slingTask({
client,
agent: undefined, // Could fail
city: undefined, // Could fail
task: taskText
});// ✅ Good
const correlationId = generateCorrelationId();
const result = await slingTask({
client,
agent: 'my-agent',
city: 'my-city',
task: 'Analyze data',
metadata: { correlationId }
});
// ❌ Bad
const result = await slingTask({
client,
agent: 'my-agent',
city: 'my-city',
task: 'Analyze data'
// No correlation ID - hard to track
});- 📖 Full Documentation
- 🐛 Issues
- 💬 Discussions
- 📧 Support
- Explore the API Reference
- Learn about SDK Workflows
- Check out the Console UI
- Read the Contributing Guide





