Kobolds

Client Installation#

Once you've finished installing the client for your application, be sure to check out the Codex repository for more helpful examples on how to use the clients.

NodeJS/Typescript#

Installing the Nodejs client is fairly straight forward but requires a few modifications.

Prerequisites

  • KOBOLDS_TOKEN - see broker for more information.
  • nodejs v24+
  • access to the libkobolds nodejs package for your architecture

1. Configure the .npmrc file#

Since the libkobolds and @kobolds/kobolds-ts packages are hosted on GitLab, we must configure the .npmrc file to pull them from there properly. This portion of the process assumes you've already obtained a KOBOLDS_TOKEN which is a token with permissions to pull from the GitLab package registry. To ensure you've configured it correctly, you can type echo $KOBOLDS_TOKEN in a terminal and you should see it output.

cat >> .npmrc <<'EOF'
@kobolds:registry=https://gitlab.com/api/v4/projects/77463884/packages/npm/
//gitlab.com/api/v4/projects/77463884/packages/npm/:_authToken=${KOBOLDS_TOKEN}
EOF

2. Add the packages to your package.json file#

# Install all the types (skip this if you already have them)
npm install --save-dev typescript @types/node tsx

# Install the kobolds-ts package. The version may be incorrect, so check to ensure you have the latest.
npm install --save @kobolds/kobolds-ts@0.1.1

# Install the libkobolds package. The version may be incorrect, so check to ensure you have the latest. NOTE: there is only a linux based x86_64 version of libkobolds available.
npm install --save-optional @kobolds/libkobolds-x86_64-linux-gnu@0.1.1

4. Setup your package.json#

We are going to assume that your package.json looks something like this after installing all dependencies.

{
    "name": "testclient",
    "version": "0.0.0",
    "description": "",
    "license": "ISC",
    "author": "",
    "type": "module",
    "main": "main.ts",
    "scripts": {
        "main": "tsx main.ts"
    },
    "devDependencies": {
        "@types/node": "^26.6.4",
        "tsx": "^4.23.15",
        "typescript": "^7.0.2"
    },
    "dependencies": {
        "@kobolds/kobolds-ts": "^0.1.1"
    },
    "optionalDependencies": {
        "@kobolds/libkobolds-x86_64-linux-gnu": "^0.1.1"
    }
}

3. Import kobolds-ts into your project#

Below is a basic example of how to use the kobolds client to connect to the broker. This assumes that you have the broker listening on the default port over TCP. Please reference broker for more information on gettting the broker configured.

import Client, { Libkobolds, defer, type ClientConfig } from "@kobolds/kobolds-ts";

const main = async (): Promise<void> => {
import Client, {
  Libkobolds,
  defer,
  type ClientConfig,
} from "@kobolds/kobolds-ts";

const main = async (): Promise<void> => {
  // create a config for the client. This may look scary but it contains all the necessesary information to run the client.
  const config: ClientConfig = {
    connection_string: "tcp://127.0.0.1:7331",
    authentication_config: {
      method: Libkobolds.Method.pre_shared_key,
      algorithm: Libkobolds.Algorithm.hmac256,
      secret: "kobolds",
    },
    chunk_pool_capacity: 1_000,
    control_message_encoding: Libkobolds.Encoding.cbor,
    max_connections: 1,
    client_id: BigInt(1),
  };

  // instantiate a client
  const client = new Client(config);

  // connect to the already running broker. see [broker](installation_broker.md);
  await client
    .connect(5_000)
    .then(() => console.info("successfully connected to the broker"));

  // this is clean up code that will run (in reverse order) to drain and close the client
  using _close = defer(() => client.close());
  using _drain = defer(async () => await client.drain());

  // FIX: add the rest of your code here....
};

main().catch((err) => {
  console.error("error running this example", err);
  process.exitCode = 1;
});