# DZapAI SDK and CLI

This repository exposes:
- A reusable SDK for TypeScript and JavaScript apps.
- A `dzap` CLI for command-line workflows.
- An optional Express server wrapper.

## Build

```bash
npm run build
```

## Private Tester Distribution (No Repo Access)

Create a distributable package that includes only compiled artifacts:

```bash
npm run pack:tester
```

This generates `dzapai-<version>.tgz`.

Tester install commands:

```bash
# CLI (global)
npm install -g ./dzapai-<version>.tgz
dzap

# SDK (inside tester project)
npm install ./dzapai-<version>.tgz
```

Note: API keys should be provided via environment variables in tester machines.

## SDK Usage

```ts
import { DZapSDK } from "dzapai";

const sdk = new DZapSDK();
await sdk.initialize({
  startupPassword: "alohomora",
  initializeRetrieval: true,
  syncProviders: false
});

const result = await sdk.ask({
  userQuery: "Show my balances",
  metadata: {
    accountInfo: [
      { blockchain: "evm", chain: "1", user_account: "0xabc..." }
    ]
  }
});

console.log(result.finalText);
```

You can also set `DZAP_STARTUP_PASSWORD=alohomora` and omit `startupPassword` in `initialize(...)`.

## SDK Tool Access

```ts
const tools = sdk.listTools();
console.log(tools.map((tool) => tool.name));

const priceTool = sdk.getTool("PriceTool");
const priceResult = await priceTool.execute({
  tokenAddresses: "0xA0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
  chainId: 1
});

console.log(priceResult);
```

## CLI Usage

```bash
DzapAI
```

On startup it first asks for a password (`alohomora`), then runs the profile phase (wallet/chain/blockchain), saves the profile, and opens the interactive shell.
Use normal text for AI prompts and slash commands for actions:

```text
>> what are top pools on chain 1?
>> /tools
>> /tool PriceTool {"tokenAddresses":"0xA0...","chainId":1}
>> /set wallet 0xabc...
>> /set chain 1
>> /session history
>> /exit
```

## Server Usage

```bash
npm run dev
npm start
```
Set `DZAP_STARTUP_PASSWORD=alohomora` in your environment (or `.env`) before starting the server.

Server entrypoint: `src/server/index.ts`.
