Skip to main content

TypeScript SDK

Introduction

The Pieces SDK is a powerful code engine package designed for writing applications on top of Pieces OS. It facilitates communication with a locally hosted server to enable features such as copilot chats, asset saving, and more.

Requirements

The Pieces SDK has the following system requirements:

Installation

To get started with the Pieces SDK, follow these steps:

  1. Download Pieces OS: Pieces OS serves as the primary backend service, providing essential functionality for the SDK. Download the appropriate version for your operating system:

  2. Install the SDK: Install the Pieces SDK using your preferred package manager:

    npm install @pieces.app/pieces-os-client

Getting Started

info

It's important to note that the localhost port for Pieces OS is different based on the operating system.

For Linux, you should use localhost:5323.

For macOS and Windows, you should use localhost:1000.

Create a main.ts file and add the following code:

main.ts
import * as Pieces from '@pieces.app/pieces-os-client'
import os from 'os';

const platform = os.platform();
let port = 1000;

// Defining the port based on the operating system. For Linux, the port is 5323, and for macOS/Windows, the port is 1000.
if (platform === 'linux') {
port = 5323;
} else {
port = 1000;
}

// The `basePath` defaults to http://localhost:1000, however we need to change it to the correct port based on the operating system.
const configuration = new Pieces.Configuration({
basePath: `http://localhost:${port}`
})
// Create an instance of the WellKnownApi class
const apiInstance = new Pieces.WellKnownApi(configuration)

apiInstance.getWellKnownHealth().then((data: string) => {
console.log(data) // ok
}).catch((error: unknown) => console.error(error))

Run the following command to execute the script:

ts-node main.ts

Next Steps

If you've made it this far, that means you've successfully connected to your local Pieces OS server using our TypeScript SDK! You can now explore the various endpoints available in the SDK to build your application on top of Pieces OS.

Click the Next → button below to dive deeper into the TypeScript SDK documentation.