Skip to main content

SDK Resources

For advanced use cases, you can access API resources directly without React hooks.

Important

Prefer using hooks whenever possible. Direct resource access:

  • Does NOT handle caching
  • Does NOT invalidate queries automatically
  • Requires manual error handling

Available Resources

import {
projects,
chat,
agents,
auth,
tenants,
workspaces,
deployments,
ai,
marketplace,
mcpServers,
git,
documents,
// ... 39 total resources
} from "@dgidgi/sdk";

Projects Resource

import { projects } from "@dgidgi/sdk";

// List projects
const { data, total } = await projects.list({ page: 1, limit: 20 });

// Get single project
const project = await projects.get("proj-123");

// Create project
const newProject = await projects.create({
name: "My Project",
description: "A new project",
language: "TypeScript",
});

// Update project
const updated = await projects.update("proj-123", {
name: "Updated Name",
});

// Delete project
await projects.delete("proj-123");

// Nested resources
const files = await projects.files.list("proj-123");
const repos = await projects.repositories.list("proj-123");
const docs = await projects.documents.list("proj-123");

// Version management
const versions = await projects.versions.list("proj-123");
const version = await projects.versions.get("proj-123", "version-456");

// Create a new version
const newVersion = await projects.versions.create("proj-123", {
version: "1.0.0",
releaseNotes: "Initial release",
});

// Release a version
await projects.versions.release("proj-123", "version-456");

// Set current version
await projects.versions.setCurrent("proj-123", "version-456");

// Link blueprint to version
await projects.versions.linkBlueprint("proj-123", "version-456", {
blueprintId: "blueprint-789",
});

// Get documents for a specific version
const versionDocs = await projects.versions.documents("proj-123", "version-456");

Chat Resource

import { chat } from "@dgidgi/sdk";

// Sessions
const sessions = await chat.sessions.list({ projectId: "proj-123" });
const session = await chat.sessions.get("session-456");
const newSession = await chat.sessions.create({
projectId: "proj-123",
title: "New Chat",
});
await chat.sessions.delete("session-456");

// Messages
const messages = await chat.messages.list("session-456");
await chat.messages.send("session-456", {
content: "Hello!",
role: "user",
});

// Completion (non-streaming)
const response = await chat.complete({
sessionId: "session-456",
message: "How do I deploy?",
});

Agents Resource

import { agents } from "@dgidgi/sdk";

// CRUD
const agentList = await agents.list();
const agent = await agents.get("agent-123");
const newAgent = await agents.create({
name: "Code Agent",
systemPrompt: "You are a helpful coding assistant",
config: { autonomyLevel: "medium" },
});
await agents.update("agent-123", { name: "Updated" });
await agents.delete("agent-123");

// Permissions
await agents.permissions.set("agent-123", {
canWriteFiles: true,
canExecuteCommands: false,
});

// Memory
const memories = await agents.memory.list("agent-123");
await agents.memory.add("agent-123", {
content: "User prefers TypeScript",
type: "preference",
});

// MCP Servers
await agents.mcpServers.attach("agent-123", "mcp-server-456");
await agents.mcpServers.detach("agent-123", "mcp-server-456");

AI Resource

import { ai } from "@dgidgi/sdk";

// Generate content
const generated = await ai.generate({
prompt: "Write a function to sort an array",
model: "gpt-4o",
temperature: 0.7,
});

// Chat completion
const completion = await ai.chat({
messages: [
{ role: "system", content: "You are a helpful assistant" },
{ role: "user", content: "Explain recursion" },
],
model: "claude-3-sonnet",
});

// Refine prompt
const refined = await ai.refinePrompt({
prompt: "make a website",
context: "React project",
});

// Embeddings
const embeddings = await ai.embeddings({
input: "Some text to embed",
model: "text-embedding-3-small",
});

Tenants Resource

import { tenants } from "@dgidgi/sdk";

// CRUD
const tenantList = await tenants.list();
const tenant = await tenants.get("tenant-123");
const newTenant = await tenants.create({
name: "My Organization",
slug: "my-org",
});
await tenants.update("tenant-123", { name: "Updated" });

// Team
const members = await tenants.members.list("tenant-123");
await tenants.members.invite("tenant-123", {
email: "user@example.com",
role: "member",
});
await tenants.members.remove("tenant-123", "user-456");

// Settings
const settings = await tenants.settings.get("tenant-123");
await tenants.settings.update("tenant-123", {
llmSource: "platform",
costOptimization: "balanced",
});

Deployments Resource

import { deployments } from "@dgidgi/sdk";

// CRUD
const deploymentList = await deployments.list({ projectId: "proj-123" });
const deployment = await deployments.get("deploy-456");

// Deploy
await deployments.deploy("deploy-456");

// Rollback
await deployments.rollback("deploy-456", { version: "v1.2.3" });

// Logs
const logs = await deployments.logs("deploy-456", { tail: 100 });

// Status
const status = await deployments.status("deploy-456");

MCP Servers Resource

import { mcpServers } from "@dgidgi/sdk";

// List available servers
const servers = await mcpServers.list();

// Get server details
const server = await mcpServers.get("mcp-123");

// Configure server
await mcpServers.configure("mcp-123", {
enabled: true,
config: { apiKey: "..." },
});

// Get tools from server
const tools = await mcpServers.tools("mcp-123");

Direct Client Access

For custom endpoints not covered by resources:

import { getClient } from "@dgidgi/sdk";

const client = getClient();

// GET request
const data = await client.get<MyType>("/custom/endpoint");

// POST request
const result = await client.post<ResultType>("/custom/endpoint", {
body: { key: "value" },
});

// PUT request
await client.put("/custom/endpoint", { data: "..." });

// PATCH request
await client.patch("/custom/endpoint", { partial: "update" });

// DELETE request
await client.delete("/custom/endpoint");

// Streaming
for await (const { event, data } of client.stream("/stream/endpoint")) {
console.log(event, data);
}

Error Handling

import { projects, SDKError } from "@dgidgi/sdk";

try {
await projects.create({ name: "Test" });
} catch (error) {
if (error instanceof SDKError) {
console.error(`API Error [${error.code}]: ${error.message}`);
console.error(`Status: ${error.status}`);
console.error(`Request ID: ${error.requestId}`);
console.error(`Details:`, error.details);
} else {
console.error("Unexpected error:", error);
}
}

Pagination

Resources that return lists support pagination:

// Standard pagination
const page1 = await projects.list({ page: 1, limit: 20 });
console.log(page1.data); // Project[]
console.log(page1.total); // Total count
console.log(page1.page); // Current page
console.log(page1.pageSize);// Items per page

// Cursor-based pagination (some resources)
const results = await chat.messages.list(sessionId, {
cursor: "msg-123",
limit: 50,
});

When to Use Resources Directly

ScenarioUse HooksUse Resources
React componentsYes
Server-side scriptsYes
Background jobsYes
One-off operationsYes
Cached dataYes
Real-time updatesYes
Complex queriesYes