1.9.0 • Published 11 months ago

@airops/js_sdk v1.9.0

Weekly downloads
-
License
MIT
Repository
-
Last release
11 months ago

@airops/sdk

⚠️ Deprecated Package

This package is no longer maintained and is deprecated. Please use the new package @airops/airops-js, which provides enhanced features and improvements.

🔄 Migration Guide

To migrate to the new package just install @airops/airops-js by running the following command:

npm install @airops/airops-js

Getting Started

  1. Server configuration

    To authenticate with our API using the SDK, you'll need three pieces of information: your workspace id, user id, and API key. First, use the API key to hash your user id on your back-end server. This will result in a hashed user id that is unique to your API key and user id combination. Workspace id and API key can be found in your workspace settings. Below is an example nodejs configuration.

    const crypto = require('crypto');
    
    const userIdHash = () => {
      const apiKey = "YOUR_API_KEY";
      const userId = "YOUR_USER_ID";
    
      // Convert your api key to a buffer
      const key = Buffer.from(apiKey, 'utf-8');
    
      // Hash the message using HMAC-SHA256 and the key
      const hash = crypto.createHmac('sha256', key)
        .update(userId)
        .digest('hex');
    
      return hash;
    }
  2. Install the client SDK

     npm i @airops/js_sdk
  3. Identify the user

    const airopsInstance = AirOps.identify({
      userId: 'YOUR_USER_ID',
      workspaceId: 'YOUR_WORKSPACE_ID',
      hashedUserId: 'YOUR_USER_ID_HASH'
    })
  4. Use it to execute an app

    Once you have successfully initialized the SDK, you can begin using the methods available to interact with our API. Note that the methods will return promises.

    // Execute an app
    const response = await airopsInstance.apps.execute({
      appId: 1,
      version: 1,
      payload: {
        "inputs": {
          "name": "XXXXYYYYZZZZ"
        }
      }
    });
    
    // Wait for result
    const result = await response.result();
    // Do something with result.output
    
    // Cancel execution
    await response.cancel();
  5. Example response

    The response from the execute method will contain the execution id that can be used to retrieve results later along with two methods to wait for results or cancel the execution:

    interface ExecuteResponse {
      executionId: number;
      result: () => Promise<AppExecution>;
      cancel: () => Promise<void>;
    }
    
    interface AppExecution {
      airops_app_id: number;
      id: number;
      status: string;
      output: string;
      stream_channel_id: string;
    }
  6. Execute an app with streaming

    In order to stream the app results you will need to enable stream and pass a callback function to the execute method. Optionally you can pass an extra callback function to get a notification when the app is finished.

    const response = await airopsInstance.apps.execute({
      appId: 1,
      version: 1,
      payload: {
        inputs: {
          name: "XXXXYYYYZZZZ",
        },
      },
      stream: true,
      streamCallback: (data: { content: string }) => {
        // Do something with the data
      },
      streamCompletedCallback: (data: { content: string }) => {
        // Do something with the data
      },
    });
  7. Pull results async

    You can implement your own pulling logic using the getResults method.

    const result = await airopsInstance.apps.getResults({
      appId: 1,
      executionId: response.executionId,
    });
  8. Error handling

    try {
      await airopsInstance.apps.execute({
        appId: 1,
        version: 4,
        payload: {
          inputs: { name: "XXXXYYYYZZZZ" },
        },
      });
    } catch (e) {
      // Do something with error.message
    }
  9. Chat assistant

    const response = await airopsInstance.apps.chatStream({
      appId: 2,
      message,
      streamCallback: (data: { token: string; }) => {
        // do something with data.token
      },
      streamCompletedCallback: (data: { result: string }) => {
        // do something with data.result
      },
      ...(sessionId && { sessionId }), // optionally pass sessionId to continue chat.
    });
    // Wait for result
    const result = await response.result;
    // Do something with result.result
    
    // Use session id to continue chat
    response.sessionId;
  10. Example response

    The response from the chatStream method will contain the sessionId and a result method to wait for the response. In order to continue with the chat pass the sessionId along with the message.

    export interface ChatStreamResponse {
      sessionId: string;
      result: Promise<{ result: string }>; // result is a promise that resolves when the execution is completed.
    }
1.9.0

11 months ago

0.58.0-beta.0

12 months ago

1.0.0

12 months ago

1.9.0-0

11 months ago

0.57.0-beta.0

12 months ago

1.2.0-beta.0

12 months ago

0.32.0

12 months ago

1.1.0-beta.0

12 months ago

0.64.0-beta.0

12 months ago

0.61.0-beta.0

12 months ago

0.55.0-beta.0

12 months ago

1.7.0-0

11 months ago

0.62.0-beta.0

12 months ago

1.4.0-0

11 months ago

0.54.0-beta.0

12 months ago

1.8.0-0

11 months ago

0.63.0-beta.0

12 months ago

1.6.0-beta.0

11 months ago

0.59.0-beta.0

12 months ago

1.3.0-beta.0

11 months ago

0.56.0-beta.0

12 months ago

1.5.0-0

11 months ago

0.53.0-beta.0

12 months ago

0.52.0-beta.0

12 months ago

0.51.0-beta.0

12 months ago

0.50.0-beta.0

12 months ago

0.49.0-beta.0

12 months ago

0.48.0-beta.0

12 months ago

0.46.0-beta.0

12 months ago

0.45.0-beta.0

12 months ago

0.44.0-beta.0

12 months ago

0.43.0-beta.0

12 months ago

0.42.0-beta.0

12 months ago

0.41.0-beta.0

12 months ago

0.40.0-beta.0

12 months ago

0.39.0-beta.0

12 months ago

0.38.0-beta.0

12 months ago

0.37.0-beta.0

12 months ago

0.36.0-beta.0

12 months ago

0.35.0-beta.0

12 months ago

0.31.0

12 months ago

0.30.0

12 months ago

0.29.0

12 months ago

0.29.0-beta.0

12 months ago

0.28.0-beta.0

12 months ago

0.27.0-beta.0

12 months ago

0.26.0-beta.0

12 months ago

0.25.0-beta.0

12 months ago

0.24.0-beta.0

12 months ago

0.23.0-beta.0

1 year ago

0.22.0-beta.0

1 year ago

0.21.0-beta.0

1 year ago

0.20.0-beta.0

1 year ago

0.19.0

1 year ago

0.19.0-beta.0

1 year ago

0.18.0-beta.0

1 year ago

0.17.0-beta.0

1 year ago

0.16.0-beta.0

1 year ago

0.15.0-beta.0

1 year ago

0.14.0-beta.0

1 year ago

0.13.0-beta.0

1 year ago

0.12.0-beta.0

1 year ago

0.11.0-beta.0

1 year ago

0.10.0-beta.0

1 year ago

0.9.0-beta.0

1 year ago

0.8.0-beta.0

1 year ago

0.7.0-beta.0

1 year ago

0.6.0-beta.0

1 year ago

0.5.0

1 year ago

0.5.0-rc.0

1 year ago

0.5.0-alpha.0

1 year ago

0.4.0

1 year ago

0.4.0-alpha.0

1 year ago

0.3.0-alpha.0

1 year ago

0.2.0-alpha.0

1 year ago

0.1.0-alpha.0

1 year ago

0.0.0

1 year ago