# carter-js

> A utility module for easy integration with Carter

Latest version **4.2.0** (published 2023-07-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install carter-js
pnpm add carter-js
yarn add carter-js
bun add carter-js
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.2.0 |
| Published | 2023-07-26 |
| First published | 2022-10-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 64.5 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | LazyLyrics |
| Maintainers | lazylyrics |
| Keywords | carter, ai, speech, assistant |

## Links

- npm: https://www.npmjs.com/package/carter-js
- npm.io page: https://npm.io/package/carter-js

## Dependencies (7)

- [uuid](https://npm.io/package/uuid.md) ^9.0.0
- [luxon](https://npm.io/package/luxon.md) ^3.1.0
- [typedoc](https://npm.io/package/typedoc.md) ^0.23.19
- [node-fetch](https://npm.io/package/node-fetch.md) ^3.3.1
- [@types/node](https://npm.io/package/@types/node.md) ^18.15.11
- [performance-now](https://npm.io/package/performance-now.md) ^2.1.0
- [typedoc-plugin-missing-exports](https://npm.io/package/typedoc-plugin-missing-exports.md) ^1.0.0

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 4.2.0 (latest) — 2023-07-26
- 4.0.1 — 2023-06-25
- 4.0.0 — 2023-06-08
- 3.0.0 — 2023-05-10
- 2.2.0 — 2023-04-28
- 2.1.0 — 2023-04-20
- 2.0.2 — 2023-04-13
- 2.0.1 — 2023-04-10
- 2.0.0 — 2023-04-10
- 1.6.2 — 2022-12-31
- 1.6.1 — 2022-12-31
- 1.5.1 — 2022-11-30
- 1.5.0 — 2022-11-05
- 1.4.1 — 2022-11-02
- 1.4.0 — 2022-11-02
- … 7 more at https://npm.io/package/carter-js/versions

## README

# Carter JS

**[TypeDocs](https://lazylyrics.github.io/carter-js/) |
[Changelog](https://github.com/LazyLyrics/carter-js/blob/main/changelog.md) | [Full Documentation](https://lazylyrics.gitbook.io/carter-js-v4/)**

*`carter-js` documentation is a work in progress. Objects described here and in the full documentation can be found in the TypeDoc documentation if you need more details. That documentation is fully updated at all times, though the annotations and descriptions are also a work in progress.*

`carter-js` provides a set of utility functions for interacting with your [Carter](https://www.carterapi.com/) agent. In order for `carter-js` to work you'll need to create a [Carter](https://www.carterapi.com/) agent.

**Please note:** carter-js is in its infancy and errors are likely. If you experience any issues please feel free to open a [GitHub](https://github.com/LazyLyrics/carter-js) issue or contact me through the [Carter](https://www.carterapi.com/) Discord server in order to help carter-js improve.

For support and general chit chat, join the [discord](https://discord.gg/4w2Hs9QU)!

## Installation

```shellscript
  npm install carter-js
```

## Basic Usage

```js
  import { Carter } from 'carter-js'

  // Create a Carter object
  // make sure to use the new keyword
  // in order to create a Carter instance
  const carter = new Carter(apiKey, userLogger, speak)
```

A Carter object contains all the necessary methods for interacting with your Carter agent. You'll need to provide your API key to create this. Make sure you keep this key secret while developing, as this key will allow anyone access to your agent. You can provide your logger object to take advantage of the built-in logging functionality. If you don't provide a logger object, `carter-js` will not log anything. Any logger with `debug`. `info`, `warn`, and `error` methods will work, but this feature is in beta.

`speak` is a boolean value which determines whether or not an audio url is returned from the API. Response times are faster with `speak` set to `false`, but you won't be able to access the `audio_url`. You can set the default `speak` value on the class constructor as above, or on a per-interaction basis. If you don't provide a default to the constructor, `speak` will default to `false`.

### Send a message to your Carter agent

```js
  // Send a message to your Carter agent
  const interaction = await carter.say("Hello", 'your_player_id')
  const outputText = interaction.outputText
```

`Carter.say()` sends a fetch request, extracts the useful elements of the response and returns a `CarterInteraction` object.

### Take advantage of context

```js
  // Send a message to your Carter agent with some extra context
  const interaction = await carter.say("Hello", 'your_player_id', 'User is very confused')
  const outputText = interaction.outputText
```

## Conversation History

Your Carter object keeps a history of interactions with your carter agent. You can access this through `carter.history`. `carter.history` is an array containing `CarterInteraction` objects.

This entire array is accessible in full, and is ordered with the most recent interaction at the front of the array. For convenience, you can also invoke `Carter.latest()` which will return the most recent interaction.

For more information and full documentation on `carter-js` - including audio input, the context endpoint, and more see the [GitBook Docs](https://lazylyrics.gitbook.io/carter-js-v3/).

---
_Source: https://npm.io/package/carter-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
