🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

treza-sdk

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

treza-sdk

TypeScript SDK for the Treza Execution API - enables AI agents to submit tasks for execution in secure enclave environments

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

Treza SDK

TypeScript/JavaScript SDK for the Treza Execution API. This SDK enables AI agents to submit tasks for execution in secure enclave environments, retrieve results, and verify execution integrity through cryptographic attestations.

Installation

npm install treza-sdk

Quick Start

import { TrezaClient } from 'treza-sdk';

// Initialize the client
const client = new TrezaClient({
  apiKey: 'your-api-key-here'
});

// Submit a task
const response = await client.submitTask({
  agent_id: 'my-agent-001',
  task_code: 'console.log("Hello from enclave!");',
  payload: { message: 'Hello World' }
});

console.log('Task submitted:', response.task_id);

// Get task result
const result = await client.getTaskStatus(response.task_id);
console.log('Task result:', result);

Configuration

The TrezaClient accepts the following configuration options:

const client = new TrezaClient({
  apiKey: 'your-api-key',           // Required: Your Treza API key
  baseUrl: 'https://api.treza.xyz', // Optional: API base URL (default shown)
  timeout: 30000                    // Optional: Request timeout in ms (default: 30000)
});

API Reference

submitTask(request: TaskRequest): Promise<TaskResponse>

Submit a task for execution in the enclave.

Parameters:

  • request.agent_id (string, required): Unique identifier for the submitting agent
  • request.task_code (string, required): The code or logic to be executed inside the enclave
  • request.payload (object, optional): Input parameters to pass to the enclave task
  • request.metadata (object, optional): Task metadata (e.g., labels, tags)

Returns: Promise resolving to a TaskResponse with task ID and status.

getTaskStatus(taskId: string): Promise<TaskResult>

Get the status or result of a submitted task.

Parameters:

  • taskId (string, required): The ID of the task to check

Returns: Promise resolving to a TaskResult with execution details.

waitForTaskCompletion(taskId: string, options?): Promise<TaskResult>

Poll a task until it completes or fails.

Parameters:

  • taskId (string, required): The ID of the task to wait for
  • options.pollInterval (number, optional): Polling interval in ms (default: 1000)
  • options.maxWaitTime (number, optional): Maximum wait time in ms (default: 300000)

Returns: Promise resolving to the completed TaskResult.

submitAndWait(request: TaskRequest, waitOptions?): Promise<TaskResult>

Submit a task and wait for its completion in one call.

Parameters:

  • request: Same as submitTask
  • waitOptions: Same as waitForTaskCompletion

Returns: Promise resolving to the completed TaskResult.

Usage Examples

Basic Task Execution

import { TrezaClient } from 'treza-sdk';

const client = new TrezaClient({
  apiKey: process.env.TREZA_API_KEY!
});

async function runTask() {
  try {
    const result = await client.submitAndWait({
      agent_id: 'data-processor-v1',
      task_code: `
        // Your enclave code here
        const data = payload.numbers;
        const sum = data.reduce((a, b) => a + b, 0);
        return { sum, count: data.length, average: sum / data.length };
      `,
      payload: {
        numbers: [1, 2, 3, 4, 5]
      },
      metadata: {
        label: 'data-processing',
        version: '1.0'
      }
    });

    console.log('Execution completed:', result.output);
    
    if (result.attestation) {
      console.log('Attestation received:', result.attestation);
    }
  } catch (error) {
    console.error('Task failed:', error);
  }
}

runTask();

Manual Status Polling

async function manualPolling() {
  // Submit task
  const response = await client.submitTask({
    agent_id: 'my-agent',
    task_code: 'return { result: "computed value" };'
  });

  console.log(`Task ${response.task_id} submitted with status: ${response.status}`);

  // Poll for completion
  let result;
  do {
    await new Promise(resolve => setTimeout(resolve, 2000)); // Wait 2 seconds
    result = await client.getTaskStatus(response.task_id);
    console.log(`Task status: ${result.status}`);
  } while (result.status === 'queued' || result.status === 'running');

  if (result.status === 'completed') {
    console.log('Task completed successfully:', result.output);
  } else {
    console.error('Task failed:', result.logs);
  }
}

Error Handling

import { TrezaSdkError } from 'treza-sdk';

async function handleErrors() {
  try {
    const result = await client.submitTask({
      agent_id: 'test-agent',
      task_code: 'invalid code here'
    });
  } catch (error) {
    if (error instanceof TrezaSdkError) {
      console.error('Treza SDK Error:', {
        message: error.message,
        code: error.code,
        statusCode: error.statusCode,
        details: error.details
      });
    } else {
      console.error('Unexpected error:', error);
    }
  }
}

Types

The SDK exports TypeScript types for all API entities:

import {
  TrezaConfig,
  TaskRequest,
  TaskResponse,
  TaskResult,
  TaskAttestation,
  TaskStatus,
  TrezaSdkError
} from 'treza-sdk';

Development

Building

npm run build

Testing

npm test

Linting

npm run lint
npm run lint:fix

License

MIT

Support

For issues and questions, please visit the GitHub repository or contact support.

Keywords

treza

FAQs

Package last updated on 19 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts