@agient/chatbot 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +79 -2
- package/assets/hi.gif +0 -0
- package/dist/index.d.ts +90 -0
- package/dist/index.js +10537 -0
- package/package.json +5 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Agient.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,9 +1,86 @@
|
|
|
1
1
|
<p align="center">
|
|
2
2
|
<a href="#">
|
|
3
|
-
<img src="
|
|
3
|
+
<img src="assets/hi.gif" width="150" height="150" />
|
|
4
4
|
</a>
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
7
|
# @agient/chatbot
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
<div align="center">
|
|
10
|
+
|
|
11
|
+
**Create AI chatbot assistants with minimal setup. Implement tools that will allow your chatbots to perform actions and fetch data from your website.**
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
## 📦 Installation
|
|
16
|
+
|
|
17
|
+
**using [npm](https://npmjs.com)**
|
|
18
|
+
|
|
19
|
+
```shell
|
|
20
|
+
npm i @agient/chatbot
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**using [yarn](https://yarnpkg.com)**
|
|
24
|
+
|
|
25
|
+
```shell
|
|
26
|
+
yarn add @agient/chatbot
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**using [pnpm](https://pnpm.io)**
|
|
30
|
+
|
|
31
|
+
```shell
|
|
32
|
+
pnpm add @agient/chatbot
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**using [bun](https://bun.sh)**
|
|
36
|
+
|
|
37
|
+
```shell
|
|
38
|
+
bun i @agient/chatbot
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## 🚀 Quick Start
|
|
42
|
+
|
|
43
|
+
Heading to [agient.dev](https://agient.dev) and create your own chatbot project. Once you've created your project, you'll receive an API key that you'll need to initialize the chatbot in your application.
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { createAgient } from '@agient/chatbot';
|
|
47
|
+
|
|
48
|
+
// Initialize the chatbot with your API key
|
|
49
|
+
const agient = createAgient('your-api-key');
|
|
50
|
+
|
|
51
|
+
agient.on('getWeather', async args => {
|
|
52
|
+
return 'The weather is currently sunny and 75°F';
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## ⚙️ Configuration Options
|
|
57
|
+
|
|
58
|
+
The `createAgient` function accepts the following options:
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
interface AgientOptions {
|
|
62
|
+
/**
|
|
63
|
+
* Whether to automatically start the chat widget when initialized.
|
|
64
|
+
* If false, the widget will need to be manually started.
|
|
65
|
+
* @default true
|
|
66
|
+
*/
|
|
67
|
+
autoStart?: boolean;
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 🔨 Tool Handling
|
|
72
|
+
|
|
73
|
+
The chatbot supports custom tools that can be implemented to perform specific actions.
|
|
74
|
+
Tools must first be registered inside your chatbot at https://agient.dev. Then you can implement them by their names.
|
|
75
|
+
Here's how to implement a tool:
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
import { createAgient } from '@agient/chatbot';
|
|
79
|
+
|
|
80
|
+
const agient = createAgient('your-api-key');
|
|
81
|
+
|
|
82
|
+
agient.on('incrementCounter', async ({ by }) => {
|
|
83
|
+
const newCount = await incrementCounter(by);
|
|
84
|
+
return `The counter is now ${newCount}`;
|
|
85
|
+
});
|
|
86
|
+
```
|
package/assets/hi.gif
ADDED
|
Binary file
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The main instance interface returned by {@link createAgient}.
|
|
3
|
+
* Provides methods to interact with the chat widget.
|
|
4
|
+
*
|
|
5
|
+
* @template Tools - The type of tools available to the chatbot
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const agient = createAgient('api-key');
|
|
10
|
+
*
|
|
11
|
+
* // Register a handler for the 'incrementCounter' tool
|
|
12
|
+
* agient.on('incrementCounter', async ({ by }) => {
|
|
13
|
+
* const newCount = await incrementCounter(by);
|
|
14
|
+
* return `The counter is now ${newCount}`;
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare type AgientInstance<Tools extends ToolsMap> = {
|
|
19
|
+
/**
|
|
20
|
+
* Registers a handler for a specific tool.
|
|
21
|
+
* @param event - The name of the tool to handle
|
|
22
|
+
* @param fn - The handler function that processes the tool's arguments and returns a response
|
|
23
|
+
*/
|
|
24
|
+
on: <Tool extends ToolKeys<Tools>>(event: Tool, fn: (args: Tools[Tool]) => string | Promise<string>) => void;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Configuration options for the Agient chat widget.
|
|
29
|
+
*/
|
|
30
|
+
export declare interface AgientOptions {
|
|
31
|
+
/**
|
|
32
|
+
* Whether to automatically start the chat widget when initialized.
|
|
33
|
+
* If false, the widget will need to be manually started.
|
|
34
|
+
* @default true
|
|
35
|
+
*/
|
|
36
|
+
autoStart?: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new Agient instance for embedding the chat widget into your application.
|
|
41
|
+
*
|
|
42
|
+
* @param apiKey - Your Agient API key for authentication
|
|
43
|
+
* @param options - Configuration options for the widget instance. See {@link AgientOptions} for available options.
|
|
44
|
+
* @returns An {@link AgientInstance} that provides methods to interact with the widget.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const agient = createAgient('your-api-key', {
|
|
49
|
+
* autoStart: true
|
|
50
|
+
* });
|
|
51
|
+
*
|
|
52
|
+
* agient.on('message', async (args) => {
|
|
53
|
+
* // Handle incoming messages
|
|
54
|
+
* return 'Response message';
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare const createAgient: <Tools extends ToolsMap = DefaultToolsMap>(apiKey: string, options?: AgientOptions) => AgientInstance<Tools>;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Default tools map that allows any argument types.
|
|
62
|
+
* Used when no specific tool types are provided.
|
|
63
|
+
*/
|
|
64
|
+
export declare type DefaultToolsMap = {
|
|
65
|
+
[key: string]: Record<string, any>;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Represents a valid argument type that can be passed to or returned from a tool.
|
|
70
|
+
* This includes primitive types, arrays, and objects.
|
|
71
|
+
*/
|
|
72
|
+
export declare type ToolAgrument = string | number | boolean | null | Array<ToolAgrument> | {
|
|
73
|
+
[key: string]: ToolAgrument;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Extracts the available tool names from a {@link ToolsMap}.
|
|
78
|
+
* @template Tools - The tools map type to extract keys from
|
|
79
|
+
*/
|
|
80
|
+
export declare type ToolKeys<Tools extends ToolsMap> = keyof Tools & (string | symbol);
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Maps tool names to their argument types.
|
|
84
|
+
* Each tool is defined as a record of string keys to {@link ToolAgrument} values.
|
|
85
|
+
*/
|
|
86
|
+
export declare type ToolsMap = {
|
|
87
|
+
[key: string]: Record<string, ToolAgrument>;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export { }
|