Vana SDK - v2.2.2
    Preparing search index...

    Class ServerController

    Manages personal server interactions for secure data processing.

    Handles communication with personal servers for computation requests and identity retrieval. Personal servers process user data with cryptographic verification, ensuring privacy and permission compliance.

    Architecture: Servers use deterministic key derivation from user addresses. Identity cached for offline retrieval. Operations authenticated via wallet signatures and permission verification.

    Method Selection:

    • getIdentity() - Retrieve server public key for encryption
    • createOperation() - Submit computation with permission ID
    • getOperation() - Check status and retrieve results
    • waitForOperation() - Poll until completion or timeout
    • cancelOperation() - Stop running operations

    Typical Workflow:

    1. Get server identity for encryption key
    2. Create operation with permission ID
    3. Poll for completion
    4. Retrieve results
    // Get server identity for encryption
    const identity = await vana.server.getIdentity({
    userAddress: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36"
    });
    console.log(`Server key: ${identity.publicKey}`);

    // Submit computation request
    const operation = await vana.server.createOperation({
    permissionId: 123
    });

    // Wait for results
    const result = await vana.server.waitForOperation(operation.id);
    console.log("Processing complete:", result.result);

    For conceptual overview, visit https://docs.vana.org/docs/personal-servers

    Hierarchy

    • BaseController
      • ServerController
    Index

    Methods

    • Retrieves cryptographic identity for a personal server.

      Parameters

      • request: InitPersonalServerParams

        Identity request parameters

        Defines parameters for initializing personal server connections.

        • userAddress: string

          Identifies the user whose personal server to connect to. Must be a valid Ethereum address in hex format.

          '0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36'
          

      Returns Promise<PersonalServerIdentity>

      Server identity with public key and metadata

      Fetches public key and metadata required for data encryption. Identity cached by infrastructure for offline retrieval. Each user address maps to deterministic server identity.

      Identity service unavailable. Check network connection and server URL configuration.

      Identity retrieval failed. Verify user address and server registration.

      const identity = await vana.server.getIdentity({
      userAddress: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36"
      });

      console.log(`Server: ${identity.name}`);
      console.log(`Address: ${identity.address}`);
      console.log(`Public Key: ${identity.publicKey}`);

      // Use for encryption before data sharing
      const encrypted = await encryptWithPublicKey(
      data,
      identity.publicKey
      );
    • Creates a server operation and returns its details from the OpenAPI schema.

      Parameters

      • params: CreateOperationParams

        The operation request parameters

        Defines parameters for creating server-side operations.

        • permissionId: number

          References the permission scope for this operation. Determines what data and actions are allowed.

          If permission scope is inadequate.

      Returns Promise<{ kind: "OperationCreated"; id: string; created_at: string }>

      Server response with operation ID

      This method submits a computation request to the personal server and returns the server's CreateOperationResponse. The response contains the operation ID which can be used with waitForOperation() to poll for completion.

      When the server request fails or parameters are invalid

      When personal server API communication fails

      const response = await vana.server.createOperation({
      permissionId: 123
      });
      console.log(`Operation ID: ${response.id}`);

      // Wait for completion
      const result = await vana.server.waitForOperation(response.id);
      console.log("Result:", result.result);
    • Retrieves the current status and result of a server operation.

      Parameters

      • operationId: string

        The ID of the operation to query

      Returns Promise<
          {
              kind: "OperationStatus";
              id: string;
              status: "starting"
              | "processing"
              | "succeeded"
              | "failed"
              | "canceled";
              started_at?: string | null;
              finished_at?: string | null;
              result?: { [key: string]: unknown } | null;
          },
      >

      The operation status response from the server

      Common status values: starting, processing, succeeded, failed, canceled. When status is succeeded, the result field contains the operation output. Returns the server response directly from the OpenAPI schema.

      When the API request fails or returns invalid data

      const operation = await vana.server.getOperation(operationId);
      if (operation.status === 'succeeded') {
      console.log('Result:', operation.result);
      console.log('Started at:', operation.started_at);
      console.log('Finished at:', operation.finished_at);
      }
    • Waits for an operation to complete and returns the final result.

      Parameters

      • opOrId:
            | string
            | {
                kind: "OperationStatus";
                id: string;
                status: "starting"
                | "processing"
                | "succeeded"
                | "failed"
                | "canceled";
                started_at?: string | null;
                finished_at?: string | null;
                result?: { [key: string]: unknown } | null;
            }

        Either an Operation object or operation ID string

        • string
        • {
              kind: "OperationStatus";
              id: string;
              status: "starting" | "processing" | "succeeded" | "failed" | "canceled";
              started_at?: string | null;
              finished_at?: string | null;
              result?: { [key: string]: unknown } | null;
          }
          • kind: "OperationStatus"

            Kind

            Resource type identifier for response routing

            OperationStatus
            
            OperationStatus
            
          • id: string

            Id

            Unique operation identifier

            cm4xp9qkw0001qj0g8xqg8xqg
            
          • status: "starting" | "processing" | "succeeded" | "failed" | "canceled"

            Status

            Current operation status. Transitions: starting → processing → (succeeded|failed|canceled)

            processing
            @enum {string}
          • Optionalstarted_at?: string | null

            Started At

            ISO 8601 timestamp when operation began processing

            2024-01-01T00:00:01Z
            
          • Optionalfinished_at?: string | null

            Finished At

            ISO 8601 timestamp when operation completed (succeeded, failed, or canceled)

            2024-01-01T00:00:05Z
            
          • Optionalresult?: { [key: string]: unknown } | null

            Result

            Operation result data as a dictionary. Format depends on operation type. For LLM inference: {'output': 'generated text'} or parsed JSON object. For JSON mode: parsed JSON object structure.

            {
            * "output": "The analysis of your data indicates positive trends in engagement metrics..."
            * }
      • Optionaloptions: PollingOptions

        Optional polling configuration

      Returns Promise<
          {
              kind: "OperationStatus";
              id: string;
              status: "starting"
              | "processing"
              | "succeeded"
              | "failed"
              | "canceled";
              started_at?: string | null;
              finished_at?: string | null;
              result?: { [key: string]: unknown } | null;
          },
      >

      The completed operation with result and timestamp data

      This method polls the operation status at regular intervals until it reaches a terminal state (succeeded, failed, or canceled). Supports ergonomic overloads to accept either an Operation object or just the ID. Returns the server response directly from the OpenAPI schema.

      When the operation fails or times out

      // Using operation object
      const operation = await vana.server.createOperation({ permissionId: 123 });
      const completed = await vana.server.waitForOperation(operation);

      // Using just the ID
      const completed = await vana.server.waitForOperation("op_abc123");

      // With custom timeout
      const completed = await vana.server.waitForOperation(operation, {
      timeout: 60000,
      pollingInterval: 1000
      });

      // Access server-provided timestamps
      console.log('Started:', completed.started_at);
      console.log('Finished:', completed.finished_at);
    • Downloads an artifact generated by a server operation.

      Parameters

      • params: DownloadArtifactParams

        The download parameters

        Parameters for downloading an artifact from a server operation.

        • operationId: string

          The operation ID that generated the artifact.

        • artifactPath: string

          The path to the artifact file to download.

      Returns Promise<Blob>

      A Blob containing the artifact data

      Artifacts are files generated during operations like Gemini agent analysis. The download requires authentication using the application's signature. This method returns the artifact as a Blob that can be saved or processed.

      Simplified Signature Scheme: The signature is generated over the operation ID only, allowing a single signature to be reused for listing and downloading multiple artifacts from the same operation. This simplifies client implementation while maintaining security - access to the operation ID grants access to all artifacts.

      When the artifact cannot be downloaded or doesn't exist

      When unable to reach the personal server API

      When unable to create the required signature

      // Download an artifact after a Gemini operation
      const blob = await vana.server.downloadArtifact({
      operationId: 'op_123',
      artifactPath: 'analysis_report.pdf'
      });

      // Save to file in Node.js
      const buffer = await blob.arrayBuffer();
      fs.writeFileSync('report.pdf', Buffer.from(buffer));

      // Or create download link in browser
      const url = URL.createObjectURL(blob);
      const a = document.createElement('a');
      a.href = url;
      a.download = 'report.pdf';
      a.click();
    • Lists all artifacts generated by a server operation.

      Parameters

      • operationId: string

        The operation ID that generated the artifacts

      Returns Promise<{ path: string; size: number; content_type: string }[]>

      Promise resolving to array of artifact metadata objects

      Retrieves metadata for all artifact files produced by an operation, including file paths, sizes, and content types. This provides visibility into available outputs without downloading them.

      Simplified Signature Scheme: Uses the same signature as downloadArtifact - signs only operation_id. This allows reusing the same signature for listing and downloading.

      When artifacts cannot be listed

      When unable to reach the personal server API

      When unable to create the required signature

      // List artifacts from a Gemini operation
      const artifacts = await vana.server.listArtifacts('op_123');

      console.log(`Found ${artifacts.length} artifacts:`);
      artifacts.forEach(artifact => {
      console.log(`- ${artifact.path} (${artifact.size} bytes)`);
      });

      // Download a specific artifact
      const blob = await vana.server.downloadArtifact({
      operationId: 'op_123',
      artifactPath: artifacts[0].path
      });
    • Cancels a running operation on the personal server.

      Parameters

      • operationId: string

        The unique identifier of the operation to cancel, obtained from createOperation() response

      Returns Promise<void>

      Promise that resolves when the cancellation request is accepted

      This method attempts to cancel an operation that is currently processing on the personal server. The operation must be in a cancellable state (typically starting or processing). Not all operations support cancellation, and cancellation may not be immediate. The server will attempt to stop the operation and update its status to canceled.

      Cancellation Behavior:

      • Operations in succeeded or failed states cannot be canceled
      • Some long-running operations may take time to respond to cancellation
      • Always verify cancellation by polling the operation status afterward

      When the operation cannot be canceled or doesn't exist. Check operation status - it may already be completed or failed.

      When unable to reach the personal server API. Verify server URL and network connectivity.

      // Start a long-running operation
      const operation = await vana.server.createOperation({
      permissionId: 123
      });

      // Cancel if needed
      try {
      await vana.server.cancelOperation(operation.id);
      console.log("Cancellation requested");

      // Verify cancellation
      const status = await vana.server.getOperation(operation.id);
      if (status.status === "canceled") {
      console.log("Operation successfully canceled");
      }
      } catch (error) {
      console.error("Failed to cancel:", error);
      }