@agentica/rpc 0.10.1 → 0.10.3
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/README.md +111 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -38,17 +38,21 @@ await driver.conversate("Hello, what you can do?");
|
|
|
38
38
|
## How to use
|
|
39
39
|
### Setup
|
|
40
40
|
```bash
|
|
41
|
-
|
|
41
|
+
# SERVER APPLICATION
|
|
42
|
+
npm install @agentica/core @agentica/rpc @samchon/openapi tgrid typia
|
|
42
43
|
npx typia setup
|
|
44
|
+
|
|
45
|
+
# CLIENT APPLICATION
|
|
46
|
+
npm install @agentica/core @agentica/rpc @samchon/openapi tgrid
|
|
43
47
|
```
|
|
44
48
|
|
|
45
49
|
Install `@agentica/rpc` with its dependent libraries.
|
|
46
50
|
|
|
47
|
-
Note that, you have to install not only `@agentica/core` and `@agentica/rpc`, but also [`@samchon/openapi`](https://github.com/samchon/openapi)
|
|
51
|
+
Note that, you have to install not only `@agentica/core` and `@agentica/rpc`, but also [`@samchon/openapi`](https://github.com/samchon/openapi) and [`tgrid`](https://github.com/samchon/tgrid) too. If you're developing server application, you have to install `typia` too.
|
|
48
52
|
|
|
49
53
|
`@samchon/openapi` is an OpenAPI specification library which can convert Swagger/OpenAPI document to LLM function calling schema. And `typia` is a transformer (compiler) library which can compose LLM function calling schema from a TypeScript class type. And then `tgrid` is an RPC (REmote Procedure Call) framework supporting the websocket protocol.
|
|
50
54
|
|
|
51
|
-
By the way, as `typia` is a transformer library analyzing TypeScript source code in the compilation level, it needs additional setup command `npx typia setup
|
|
55
|
+
By the way, as `typia` is a transformer library analyzing TypeScript source code in the compilation level, it needs additional setup command `npx typia setup` when developing server application. Also, if your client (frontend) application is not using the standard TypeScript compiler (not `tsc`), you have to setup [`@ryoppippi/unplugin-typia`](https://typia.io/docs/setup/#unplugin-typia) too.
|
|
52
56
|
|
|
53
57
|
### Server Application
|
|
54
58
|
```typescript
|
|
@@ -111,6 +115,110 @@ And then call the backend server's function `IAgenticaRpcService.conversate()` r
|
|
|
111
115
|
|
|
112
116
|
|
|
113
117
|
|
|
118
|
+
## NestJS Application
|
|
119
|
+
### Bootstrap
|
|
120
|
+
```bash
|
|
121
|
+
npx nestia start <directory>
|
|
122
|
+
cd <directory>
|
|
123
|
+
npm install @agentica/core @agentica/rpc @samchon/openapi tgrid
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
You can integrate `@agentica` with [NestJS Framework](https://nestjs.com) utilizing [Nestia](https://nestia.io).
|
|
127
|
+
|
|
128
|
+
At first, create a boilerplate project of NestJS combined with Nestia by running `npx nesta start` command. And then install `@agentica/rpc` with its dependency packages.
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
import { WebSocketAdaptor } from "@nestia/core";
|
|
132
|
+
import { INestApplication } from "@nestjs/common";
|
|
133
|
+
import { NestFactory } from "@nestjs/core";
|
|
134
|
+
|
|
135
|
+
import { MyConfiguration } from "./MyConfiguration";
|
|
136
|
+
import { MyModule } from "./MyModule";
|
|
137
|
+
|
|
138
|
+
export class MyBackend {
|
|
139
|
+
private application_?: INestApplication;
|
|
140
|
+
|
|
141
|
+
public async open(): Promise<void> {
|
|
142
|
+
//----
|
|
143
|
+
// OPEN THE BACKEND SERVER
|
|
144
|
+
//----
|
|
145
|
+
// MOUNT CONTROLLERS
|
|
146
|
+
this.application_ = await NestFactory.create(MyModule, { logger: false });
|
|
147
|
+
WebSocketAdaptor.upgrade(this.application_);
|
|
148
|
+
...
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
After setup, update `src/MyBackend.ts` file to call `WebSocketAdaptor.upgrade()` function to the NestJS application instance. The function `WebSocketAdaptor.upgrade()` will make the NestJS backend server to compatible with WebSocket protocol.
|
|
154
|
+
|
|
155
|
+
### API Controller
|
|
156
|
+
```typescript
|
|
157
|
+
import { AgenticaRpcService, IAgenticaRpcListener } from "@agentica/rpc";
|
|
158
|
+
import { WebSocketRoute } from "@nestia/core";
|
|
159
|
+
import { Controller } from "@nestjs/common";
|
|
160
|
+
import { WebSocketAcceptor } from "tgrid";
|
|
161
|
+
|
|
162
|
+
@Controller("chat")
|
|
163
|
+
export class ChatController {
|
|
164
|
+
@WebSocketRoute()
|
|
165
|
+
public async start(
|
|
166
|
+
// @WebSocketRoute.Param("id") id: string,
|
|
167
|
+
@WebSocketRoute.Acceptor()
|
|
168
|
+
acceptor: WebSocketAcceptor<
|
|
169
|
+
null, // header
|
|
170
|
+
AgenticaRpcService,
|
|
171
|
+
IAgenticaRpcListener
|
|
172
|
+
>,
|
|
173
|
+
): Promise<void> {
|
|
174
|
+
await acceptor.accept(
|
|
175
|
+
new AgenticaRpcService({
|
|
176
|
+
agent: new Agentica({ ... }),
|
|
177
|
+
listener: acceptor.getDriver(),
|
|
178
|
+
}),
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Make a new NestJS controller class like above.
|
|
185
|
+
|
|
186
|
+
When a client connects to the server with `ws://localhost:3001/chat` URL, Agentica made chatbot would be started in the WebSocket protocol.
|
|
187
|
+
|
|
188
|
+
If you need path or query parameters, utilize `@WebSocketRoute.Path()` or `@WebSocketRoute.Query()` decorator functions.
|
|
189
|
+
|
|
190
|
+
### Software Development Kit
|
|
191
|
+
```bash
|
|
192
|
+
npx nestia sdk
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
When backend server development has been completed, you can generate SDK (Software Development Kit) library for client developers by running `npx nestia sdk` command.
|
|
196
|
+
|
|
197
|
+
Client developers can utilize the SDK library like below.
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
import { IAgenticaRpcListener } from "@agentica/rpc";
|
|
201
|
+
import api from "@ORGANIZATION/PROJECT-api";
|
|
202
|
+
|
|
203
|
+
const { connector, driver } = await api.functional.chat.start(
|
|
204
|
+
{
|
|
205
|
+
host: "http://localhost:3000",
|
|
206
|
+
} satisfies api.IConnection,
|
|
207
|
+
{
|
|
208
|
+
text: async (evt) => {
|
|
209
|
+
console.log(evt.role, evt.text);
|
|
210
|
+
},
|
|
211
|
+
describe: async (evt) => {
|
|
212
|
+
console.log("describer", evt.text);
|
|
213
|
+
},
|
|
214
|
+
} satisfies IAgenticaRpcListener,
|
|
215
|
+
);
|
|
216
|
+
await driver.conversate("Hello, what you can do?");s
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
114
222
|
## Principles
|
|
115
223
|
### Remote Procedure Call
|
|
116
224
|
```mermaid
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentica/rpc",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.3",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"description": "Agentic AI Library specialized in LLM Function Calling",
|
|
6
6
|
"scripts": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"src"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@agentica/core": "^0.10.
|
|
40
|
+
"@agentica/core": "^0.10.3",
|
|
41
41
|
"@samchon/openapi": "^3.0.0",
|
|
42
42
|
"@samchon/shopping-api": "^0.15.0",
|
|
43
43
|
"chalk": "4.1.2",
|