@agentica/rpc 0.7.0-dev.20250224

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Wrtn Technologies
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.
@@ -0,0 +1,74 @@
1
+ import { Agentica } from "@agentica/core";
2
+ import { IAgenticaRpcListener } from "./IAgenticaRpcListener";
3
+ import { IAgenticaRpcService } from "./IAgenticaRpcService";
4
+ /**
5
+ * RPC service for the {@link Agentica}.
6
+ *
7
+ * `AgenticaRpcService` is class defining an AI agent service
8
+ * provided from the server to clients through the RPC (Remote Procedure Call)
9
+ * paradigm in the websocket protocol.
10
+ *
11
+ * Client connecting to the `AgenticaRpcService` providing websocket server
12
+ * will call the {@link conversate} function remotely through its basic
13
+ * interface type {@link IAgenticaRpcService} with the RPC paradigm.
14
+ *
15
+ * Also, the client provides the {@link IAgenticaRpcListener} type to the
16
+ * server, so that `AgenticaRpcService` will remotely call the
17
+ * {@link IAgenticaRpcListener listener}'s functions internally.
18
+ *
19
+ * You can open the WebSocket server of the AI agent like below:
20
+ *
21
+ * ```typescript
22
+ * import {
23
+ * IAgenticaRpcListener,
24
+ * IAgenticaRpcService,
25
+ * Agentica,
26
+ * AgenticaRpcService,
27
+ * } from "@agentica/core";
28
+ * import { WebSocketServer } from "tgrid";
29
+ *
30
+ * const server: WebSocketServer<
31
+ * null,
32
+ * IAgenticaRpcService,
33
+ * IAgenticaRpcListener
34
+ * > = new WebSocketServer();
35
+ * await server.open(3001, async (acceptor) => {
36
+ * await acceptor.accept(
37
+ * new AgenticaRpcService({
38
+ * agent: new Agentica({ ... }),
39
+ * listener: acceptor.getDriver(),
40
+ * }),
41
+ * );
42
+ * });
43
+ * ```
44
+ *
45
+ * @author Samchon
46
+ */
47
+ export declare class AgenticaRpcService implements IAgenticaRpcService {
48
+ private readonly props;
49
+ /**
50
+ * Initializer Constructor.
51
+ *
52
+ * @param props Properties to construct the RPC service
53
+ */
54
+ constructor(props: AgenticaRpcService.IProps);
55
+ /**
56
+ * @inheritDoc
57
+ */
58
+ conversate(content: string): Promise<void>;
59
+ }
60
+ export declare namespace AgenticaRpcService {
61
+ /**
62
+ * Properties of the {@link AgenticaRpcService}.
63
+ */
64
+ interface IProps {
65
+ /**
66
+ * Target agent to provide as RPC service.
67
+ */
68
+ agent: Agentica;
69
+ /**
70
+ * Listener to be binded on the agent.
71
+ */
72
+ listener: IAgenticaRpcListener;
73
+ }
74
+ }
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.AgenticaRpcService = void 0;
13
+ /**
14
+ * RPC service for the {@link Agentica}.
15
+ *
16
+ * `AgenticaRpcService` is class defining an AI agent service
17
+ * provided from the server to clients through the RPC (Remote Procedure Call)
18
+ * paradigm in the websocket protocol.
19
+ *
20
+ * Client connecting to the `AgenticaRpcService` providing websocket server
21
+ * will call the {@link conversate} function remotely through its basic
22
+ * interface type {@link IAgenticaRpcService} with the RPC paradigm.
23
+ *
24
+ * Also, the client provides the {@link IAgenticaRpcListener} type to the
25
+ * server, so that `AgenticaRpcService` will remotely call the
26
+ * {@link IAgenticaRpcListener listener}'s functions internally.
27
+ *
28
+ * You can open the WebSocket server of the AI agent like below:
29
+ *
30
+ * ```typescript
31
+ * import {
32
+ * IAgenticaRpcListener,
33
+ * IAgenticaRpcService,
34
+ * Agentica,
35
+ * AgenticaRpcService,
36
+ * } from "@agentica/core";
37
+ * import { WebSocketServer } from "tgrid";
38
+ *
39
+ * const server: WebSocketServer<
40
+ * null,
41
+ * IAgenticaRpcService,
42
+ * IAgenticaRpcListener
43
+ * > = new WebSocketServer();
44
+ * await server.open(3001, async (acceptor) => {
45
+ * await acceptor.accept(
46
+ * new AgenticaRpcService({
47
+ * agent: new Agentica({ ... }),
48
+ * listener: acceptor.getDriver(),
49
+ * }),
50
+ * );
51
+ * });
52
+ * ```
53
+ *
54
+ * @author Samchon
55
+ */
56
+ class AgenticaRpcService {
57
+ /**
58
+ * Initializer Constructor.
59
+ *
60
+ * @param props Properties to construct the RPC service
61
+ */
62
+ constructor(props) {
63
+ this.props = props;
64
+ const { agent, listener } = props;
65
+ // ESSENTIAL LISTENERS
66
+ agent.on("text", (evt) => listener.text(primitive(evt)));
67
+ agent.on("describe", (evt) => listener.describe(primitive(evt)));
68
+ // OPTIONAL LISTENERS
69
+ agent.on("initialize", (evt) => listener.initialize(primitive(evt)));
70
+ agent.on("select", (evt) => listener.select(primitive(evt)));
71
+ agent.on("cancel", (evt) => listener.cancel(primitive(evt)));
72
+ agent.on("call", (evt) => __awaiter(this, void 0, void 0, function* () {
73
+ const args = yield listener.call(primitive(evt));
74
+ if (!!args)
75
+ evt.arguments = args;
76
+ }));
77
+ agent.on("execute", (evt) => listener.execute(primitive(evt)));
78
+ }
79
+ /**
80
+ * @inheritDoc
81
+ */
82
+ conversate(content) {
83
+ return __awaiter(this, void 0, void 0, function* () {
84
+ yield this.props.agent.conversate(content);
85
+ });
86
+ }
87
+ }
88
+ exports.AgenticaRpcService = AgenticaRpcService;
89
+ /**
90
+ * @internal
91
+ */
92
+ const primitive = (obj) => JSON.parse(JSON.stringify(obj));
93
+ //# sourceMappingURL=AgenticaRpcService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgenticaRpcService.js","sourceRoot":"","sources":["../src/AgenticaRpcService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,MAAa,kBAAkB;IAC7B;;;;OAIG;IACH,YAAoC,KAAgC;QAAhC,UAAK,GAAL,KAAK,CAA2B;QAClE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;QAElC,sBAAsB;QACtB,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACzD,KAAK,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAEjE,qBAAqB;QACrB,KAAK,CAAC,EAAE,CAAC,YAAY,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAW,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACtE,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC9D,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC9D,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAO,GAAG,EAAE,EAAE;YAC7B,MAAM,IAAI,GAA8B,MAAM,QAAQ,CAAC,IAAK,CAC1D,SAAS,CAAC,GAAG,CAAC,CACf,CAAC;YACF,IAAI,CAAC,CAAC,IAAI;gBAAE,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC;QACnC,CAAC,CAAA,CAAC,CAAC;QACH,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAClE,CAAC;IAED;;OAEG;IACU,UAAU,CAAC,OAAe;;YACrC,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAC7C,CAAC;KAAA;CACF;AAhCD,gDAgCC;AAkBD;;GAEG;AACH,MAAM,SAAS,GAAG,CAAI,GAAM,EAAgB,EAAE,CAC5C,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAiB,CAAC"}
@@ -0,0 +1,112 @@
1
+ import { IAgenticaEvent } from "@agentica/core";
2
+ import { Primitive } from "typia";
3
+ /**
4
+ * RPC interface of AI agent listener.
5
+ *
6
+ * `IAgenticaRpcListener` is an interface defining an AI agent listener
7
+ * provided from the client to server through the RPC (Remote Procedure Call)
8
+ * paradigm in the websocket protocol.
9
+ *
10
+ * It has defined the event listener functions of {@link IAgenticaEvent}
11
+ * types. If you skip some event typed functions' implementations,
12
+ * the skipped event would be ignored.
13
+ *
14
+ * Also, the event like listener functions of `IAgenticaRpcListener` type
15
+ * are remotely called when a client calls the
16
+ * {@link IAgenticaRpcService.conversate} function remotely, so that the
17
+ * server responses to the client by the event listener functions.
18
+ *
19
+ * You can connect to the WebSocket server of the AI agent like below:
20
+ *
21
+ * ```typescript
22
+ * import { IAgenticaRpcListener, IAgenticaRpcService } from "@agentica/core";
23
+ * import { Driver, WebSocketConnector } from "tgrid";
24
+ *
25
+ * const connector: WebSocketConnector<
26
+ * null,
27
+ * IAgenticaRpcListener,
28
+ * IAgenticaRpcService
29
+ * > = new WebSocketConnector(null, {
30
+ * text: async (evt) => {
31
+ * console.log(evt.role, evt.text);
32
+ * },
33
+ * describe: async (evt) => {
34
+ * console.log("describer", evt.text);
35
+ * },
36
+ * });
37
+ * await connector.connect("ws://localhost:3001");
38
+ *
39
+ * const driver: Driver<IAgenticaRpcService> = connector.getDriver();
40
+ * await driver.conversate("Hello, what you can do?");
41
+ * ```
42
+ *
43
+ * @author Samchon
44
+ */
45
+ export interface IAgenticaRpcListener {
46
+ /**
47
+ * Describe the function executions' results.
48
+ *
49
+ * Inform description message of the function execution's results from
50
+ * the AI agent server to client.
51
+ *
52
+ * @param evt Event of a description of function execution results
53
+ */
54
+ describe(evt: Primitive<IAgenticaEvent.IDescribe>): Promise<void>;
55
+ /**
56
+ * Text conversation message.
57
+ *
58
+ * @param evt Event of a text conversation message
59
+ */
60
+ text(evt: Primitive<IAgenticaEvent.IText>): Promise<void>;
61
+ /**
62
+ * Initialize the AI agent.
63
+ *
64
+ * Informs an initialization of controller functions from
65
+ * the AI agent server to client.
66
+ *
67
+ * @param evt Event of initialization
68
+ */
69
+ initialize?(evt: Primitive<IAgenticaEvent.IInitialize>): Promise<void>;
70
+ /**
71
+ * Select a function to call.
72
+ *
73
+ * Informs a selected function to call from the AI agent server to client.
74
+ *
75
+ * @param evt Event of selecting a function to call
76
+ */
77
+ select?(evt: Primitive<IAgenticaEvent.ISelect>): Promise<void>;
78
+ /**
79
+ * Cancel a function to call.
80
+ *
81
+ * Informs a canceling function to call from the AI agent server to client.
82
+ *
83
+ * @param evt Event of canceling a function to call
84
+ */
85
+ cancel?(evt: Primitive<IAgenticaEvent.ICancel>): Promise<void>;
86
+ /**
87
+ * Call a function.
88
+ *
89
+ * Informs a function calling from the AI agent server to client.
90
+ *
91
+ * This event comes before the function execution, so that if you return
92
+ * a different value from the original {@link IAgenticaEvent.ICall.arguments},
93
+ * you can modify the arguments of the function calling.
94
+ *
95
+ * Otherwise you do not return anything (`undefined`) or `null` value, the
96
+ * arguments of the function calling would not be modified. Also, if you are
97
+ * not interested in the function calling event, you can skit its
98
+ * implementation.
99
+ *
100
+ * @param evt Event of a function calling
101
+ * @return New arguments if you want to modify, otherwise null or undefined
102
+ */
103
+ call?(evt: Primitive<IAgenticaEvent.ICall>): Promise<object | null | undefined>;
104
+ /**
105
+ * Executition of a function.
106
+ *
107
+ * Informs a function execution from the AI agent server to client.
108
+ *
109
+ * @param evt Event of a function execution
110
+ */
111
+ execute?(evt: Primitive<IAgenticaEvent.IExecute>): Promise<void>;
112
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IAgenticaRpcListener.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IAgenticaRpcListener.js","sourceRoot":"","sources":["../src/IAgenticaRpcListener.ts"],"names":[],"mappings":""}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * RPC interface of AI agent service.
3
+ *
4
+ * `IAgenticaRpcService` is an interface defining an AI agent service
5
+ * provided from the server to client through the RPC (Remote Procedure Call)
6
+ * paradigm in the websocket protocol.
7
+ *
8
+ * The client will call the {@link conversate} function remotely, and the
9
+ * server responses to the client by calling the client's
10
+ * {@link IAgenticaRpcListener} functions remotely too.
11
+ *
12
+ * @author Samchon
13
+ */
14
+ export interface IAgenticaRpcService {
15
+ /**
16
+ * Conversate with the AI agent.
17
+ *
18
+ * User talks to the AI agent with the content.
19
+ *
20
+ * When AI agent responds some actions like conversating or executing
21
+ * LLM (Large Language Model) function calling, the functions defined in the
22
+ * {@link IAgenticaRpcListener} would be called through the RPC
23
+ * (Remote Procedure Call) paradigm.
24
+ *
25
+ * @param content The content to talk
26
+ * @returns Returned when the conversation process is completely done
27
+ */
28
+ conversate(content: string): Promise<void>;
29
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IAgenticaRpcService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IAgenticaRpcService.js","sourceRoot":"","sources":["../src/IAgenticaRpcService.ts"],"names":[],"mappings":""}
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./IAgenticaRpcListener";
2
+ export * from "./IAgenticaRpcService";
3
+ export * from "./AgenticaRpcService";
package/lib/index.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./IAgenticaRpcListener"), exports);
18
+ __exportStar(require("./IAgenticaRpcService"), exports);
19
+ __exportStar(require("./AgenticaRpcService"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAuC;AACvC,wDAAsC;AACtC,uDAAqC"}
package/lib/index.mjs ADDED
@@ -0,0 +1,24 @@
1
+ class AgenticaRpcService {
2
+ constructor(props) {
3
+ this.props = props;
4
+ const {agent, listener} = props;
5
+ agent.on("text", (evt => listener.text(primitive(evt))));
6
+ agent.on("describe", (evt => listener.describe(primitive(evt))));
7
+ agent.on("initialize", (evt => listener.initialize(primitive(evt))));
8
+ agent.on("select", (evt => listener.select(primitive(evt))));
9
+ agent.on("cancel", (evt => listener.cancel(primitive(evt))));
10
+ agent.on("call", (async evt => {
11
+ const args = await listener.call(primitive(evt));
12
+ if (!!args) evt.arguments = args;
13
+ }));
14
+ agent.on("execute", (evt => listener.execute(primitive(evt))));
15
+ }
16
+ async conversate(content) {
17
+ await this.props.agent.conversate(content);
18
+ }
19
+ }
20
+
21
+ const primitive = obj => JSON.parse(JSON.stringify(obj));
22
+
23
+ export { AgenticaRpcService };
24
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../src/AgenticaRpcService.ts"],"sourcesContent":[null],"names":["AgenticaRpcService","constructor","props","this","agent","listener","on","evt","text","primitive","describe","initialize","select","cancel","async","args","call","arguments","execute","conversate","content","obj","JSON","parse","stringify"],"mappings":"MAiDaA;IAMX,WAAAC,CAAoCC;QAAAC,KAAKD,QAALA;QAClC,OAAME,OAAOC,YAAeH;QAG5BE,MAAME,GAAG,SAASC,OAAQF,SAASG,KAAKC,UAAUF;QAClDH,MAAME,GAAG,aAAaC,OAAQF,SAASK,SAASD,UAAUF;QAG1DH,MAAME,GAAG,eAAeC,OAAQF,SAASM,WAAYF,UAAUF;QAC/DH,MAAME,GAAG,WAAWC,OAAQF,SAASO,OAAQH,UAAUF;QACvDH,MAAME,GAAG,WAAWC,OAAQF,SAASQ,OAAQJ,UAAUF;QACvDH,MAAME,GAAG,SAAQQ,MAAOP;YACtB,MAAMQ,aAAwCV,SAASW,KACrDP,UAAUF;YAEZ,MAAMQ,MAAMR,IAAIU,YAAYF;AAAI;QAElCX,MAAME,GAAG,YAAYC,OAAQF,SAASa,QAAST,UAAUF;;IAMpD,gBAAMY,CAAWC;cAChBjB,KAAKD,MAAME,MAAMe,WAAWC;;;;AAuBtC,MAAMX,YAAgBY,OACpBC,KAAKC,MAAMD,KAAKE,UAAUH;;"}
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@agentica/rpc",
3
+ "version": "0.7.0-dev.20250224",
4
+ "main": "lib/index.js",
5
+ "description": "Agentic AI Library specialized in LLM Function Calling",
6
+ "scripts": {
7
+ "prepare": "ts-patch install",
8
+ "build": "rimraf lib && tsc && rollup -c",
9
+ "dev": "rimraf lib && tsc --watch"
10
+ },
11
+ "author": "Wrtn Technologies",
12
+ "homepage": "https://wrtnlabs.io/agentica",
13
+ "license": "MIT",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/wrtnlabs/agentica"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/wrtnlabs/agentica/issues"
20
+ },
21
+ "keywords": [
22
+ "openai",
23
+ "chatgpt",
24
+ "anthropic",
25
+ "claude",
26
+ "ai",
27
+ "chatbot",
28
+ "nestia",
29
+ "swagger",
30
+ "openapi"
31
+ ],
32
+ "files": [
33
+ "README.md",
34
+ "LICENSE",
35
+ "package.json",
36
+ "lib",
37
+ "src"
38
+ ],
39
+ "dependencies": {
40
+ "@agentica/core": "^0.7.0-dev.20250224",
41
+ "@samchon/openapi": "^2.4.3",
42
+ "@samchon/shopping-api": "^0.15.0",
43
+ "chalk": "4.1.2",
44
+ "openai": "^4.80.0",
45
+ "tstl": "^3.0.0",
46
+ "typia": "^7.6.4"
47
+ },
48
+ "devDependencies": {
49
+ "@rollup/plugin-terser": "^0.4.4",
50
+ "@rollup/plugin-typescript": "^12.1.2",
51
+ "@types/node": "^22.13.4",
52
+ "rimraf": "^6.0.1",
53
+ "rollup": "^4.34.8",
54
+ "ts-patch": "^3.3.0",
55
+ "typescript": "~5.7.3"
56
+ },
57
+ "module": "lib/index.mjs",
58
+ "typings": "lib/index.d.ts"
59
+ }
@@ -0,0 +1,104 @@
1
+ import { Agentica } from "@agentica/core";
2
+ import { Primitive } from "typia";
3
+
4
+ import { IAgenticaRpcListener } from "./IAgenticaRpcListener";
5
+ import { IAgenticaRpcService } from "./IAgenticaRpcService";
6
+
7
+ /**
8
+ * RPC service for the {@link Agentica}.
9
+ *
10
+ * `AgenticaRpcService` is class defining an AI agent service
11
+ * provided from the server to clients through the RPC (Remote Procedure Call)
12
+ * paradigm in the websocket protocol.
13
+ *
14
+ * Client connecting to the `AgenticaRpcService` providing websocket server
15
+ * will call the {@link conversate} function remotely through its basic
16
+ * interface type {@link IAgenticaRpcService} with the RPC paradigm.
17
+ *
18
+ * Also, the client provides the {@link IAgenticaRpcListener} type to the
19
+ * server, so that `AgenticaRpcService` will remotely call the
20
+ * {@link IAgenticaRpcListener listener}'s functions internally.
21
+ *
22
+ * You can open the WebSocket server of the AI agent like below:
23
+ *
24
+ * ```typescript
25
+ * import {
26
+ * IAgenticaRpcListener,
27
+ * IAgenticaRpcService,
28
+ * Agentica,
29
+ * AgenticaRpcService,
30
+ * } from "@agentica/core";
31
+ * import { WebSocketServer } from "tgrid";
32
+ *
33
+ * const server: WebSocketServer<
34
+ * null,
35
+ * IAgenticaRpcService,
36
+ * IAgenticaRpcListener
37
+ * > = new WebSocketServer();
38
+ * await server.open(3001, async (acceptor) => {
39
+ * await acceptor.accept(
40
+ * new AgenticaRpcService({
41
+ * agent: new Agentica({ ... }),
42
+ * listener: acceptor.getDriver(),
43
+ * }),
44
+ * );
45
+ * });
46
+ * ```
47
+ *
48
+ * @author Samchon
49
+ */
50
+ export class AgenticaRpcService implements IAgenticaRpcService {
51
+ /**
52
+ * Initializer Constructor.
53
+ *
54
+ * @param props Properties to construct the RPC service
55
+ */
56
+ public constructor(private readonly props: AgenticaRpcService.IProps) {
57
+ const { agent, listener } = props;
58
+
59
+ // ESSENTIAL LISTENERS
60
+ agent.on("text", (evt) => listener.text(primitive(evt)));
61
+ agent.on("describe", (evt) => listener.describe(primitive(evt)));
62
+
63
+ // OPTIONAL LISTENERS
64
+ agent.on("initialize", (evt) => listener.initialize!(primitive(evt)));
65
+ agent.on("select", (evt) => listener.select!(primitive(evt)));
66
+ agent.on("cancel", (evt) => listener.cancel!(primitive(evt)));
67
+ agent.on("call", async (evt) => {
68
+ const args: object | null | undefined = await listener.call!(
69
+ primitive(evt),
70
+ );
71
+ if (!!args) evt.arguments = args;
72
+ });
73
+ agent.on("execute", (evt) => listener.execute!(primitive(evt)));
74
+ }
75
+
76
+ /**
77
+ * @inheritDoc
78
+ */
79
+ public async conversate(content: string): Promise<void> {
80
+ await this.props.agent.conversate(content);
81
+ }
82
+ }
83
+ export namespace AgenticaRpcService {
84
+ /**
85
+ * Properties of the {@link AgenticaRpcService}.
86
+ */
87
+ export interface IProps {
88
+ /**
89
+ * Target agent to provide as RPC service.
90
+ */
91
+ agent: Agentica;
92
+
93
+ /**
94
+ * Listener to be binded on the agent.
95
+ */
96
+ listener: IAgenticaRpcListener;
97
+ }
98
+ }
99
+
100
+ /**
101
+ * @internal
102
+ */
103
+ const primitive = <T>(obj: T): Primitive<T> =>
104
+ JSON.parse(JSON.stringify(obj)) as Primitive<T>;
@@ -0,0 +1,121 @@
1
+ import { IAgenticaEvent } from "@agentica/core";
2
+ import { Primitive } from "typia";
3
+
4
+ /**
5
+ * RPC interface of AI agent listener.
6
+ *
7
+ * `IAgenticaRpcListener` is an interface defining an AI agent listener
8
+ * provided from the client to server through the RPC (Remote Procedure Call)
9
+ * paradigm in the websocket protocol.
10
+ *
11
+ * It has defined the event listener functions of {@link IAgenticaEvent}
12
+ * types. If you skip some event typed functions' implementations,
13
+ * the skipped event would be ignored.
14
+ *
15
+ * Also, the event like listener functions of `IAgenticaRpcListener` type
16
+ * are remotely called when a client calls the
17
+ * {@link IAgenticaRpcService.conversate} function remotely, so that the
18
+ * server responses to the client by the event listener functions.
19
+ *
20
+ * You can connect to the WebSocket server of the AI agent like below:
21
+ *
22
+ * ```typescript
23
+ * import { IAgenticaRpcListener, IAgenticaRpcService } from "@agentica/core";
24
+ * import { Driver, WebSocketConnector } from "tgrid";
25
+ *
26
+ * const connector: WebSocketConnector<
27
+ * null,
28
+ * IAgenticaRpcListener,
29
+ * IAgenticaRpcService
30
+ * > = new WebSocketConnector(null, {
31
+ * text: async (evt) => {
32
+ * console.log(evt.role, evt.text);
33
+ * },
34
+ * describe: async (evt) => {
35
+ * console.log("describer", evt.text);
36
+ * },
37
+ * });
38
+ * await connector.connect("ws://localhost:3001");
39
+ *
40
+ * const driver: Driver<IAgenticaRpcService> = connector.getDriver();
41
+ * await driver.conversate("Hello, what you can do?");
42
+ * ```
43
+ *
44
+ * @author Samchon
45
+ */
46
+ export interface IAgenticaRpcListener {
47
+ /**
48
+ * Describe the function executions' results.
49
+ *
50
+ * Inform description message of the function execution's results from
51
+ * the AI agent server to client.
52
+ *
53
+ * @param evt Event of a description of function execution results
54
+ */
55
+ describe(evt: Primitive<IAgenticaEvent.IDescribe>): Promise<void>;
56
+
57
+ /**
58
+ * Text conversation message.
59
+ *
60
+ * @param evt Event of a text conversation message
61
+ */
62
+ text(evt: Primitive<IAgenticaEvent.IText>): Promise<void>;
63
+
64
+ /**
65
+ * Initialize the AI agent.
66
+ *
67
+ * Informs an initialization of controller functions from
68
+ * the AI agent server to client.
69
+ *
70
+ * @param evt Event of initialization
71
+ */
72
+ initialize?(evt: Primitive<IAgenticaEvent.IInitialize>): Promise<void>;
73
+
74
+ /**
75
+ * Select a function to call.
76
+ *
77
+ * Informs a selected function to call from the AI agent server to client.
78
+ *
79
+ * @param evt Event of selecting a function to call
80
+ */
81
+ select?(evt: Primitive<IAgenticaEvent.ISelect>): Promise<void>;
82
+
83
+ /**
84
+ * Cancel a function to call.
85
+ *
86
+ * Informs a canceling function to call from the AI agent server to client.
87
+ *
88
+ * @param evt Event of canceling a function to call
89
+ */
90
+ cancel?(evt: Primitive<IAgenticaEvent.ICancel>): Promise<void>;
91
+
92
+ /**
93
+ * Call a function.
94
+ *
95
+ * Informs a function calling from the AI agent server to client.
96
+ *
97
+ * This event comes before the function execution, so that if you return
98
+ * a different value from the original {@link IAgenticaEvent.ICall.arguments},
99
+ * you can modify the arguments of the function calling.
100
+ *
101
+ * Otherwise you do not return anything (`undefined`) or `null` value, the
102
+ * arguments of the function calling would not be modified. Also, if you are
103
+ * not interested in the function calling event, you can skit its
104
+ * implementation.
105
+ *
106
+ * @param evt Event of a function calling
107
+ * @return New arguments if you want to modify, otherwise null or undefined
108
+ */
109
+ call?(
110
+ evt: Primitive<IAgenticaEvent.ICall>,
111
+ ): Promise<object | null | undefined>;
112
+
113
+ /**
114
+ * Executition of a function.
115
+ *
116
+ * Informs a function execution from the AI agent server to client.
117
+ *
118
+ * @param evt Event of a function execution
119
+ */
120
+ execute?(evt: Primitive<IAgenticaEvent.IExecute>): Promise<void>;
121
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * RPC interface of AI agent service.
3
+ *
4
+ * `IAgenticaRpcService` is an interface defining an AI agent service
5
+ * provided from the server to client through the RPC (Remote Procedure Call)
6
+ * paradigm in the websocket protocol.
7
+ *
8
+ * The client will call the {@link conversate} function remotely, and the
9
+ * server responses to the client by calling the client's
10
+ * {@link IAgenticaRpcListener} functions remotely too.
11
+ *
12
+ * @author Samchon
13
+ */
14
+ export interface IAgenticaRpcService {
15
+ /**
16
+ * Conversate with the AI agent.
17
+ *
18
+ * User talks to the AI agent with the content.
19
+ *
20
+ * When AI agent responds some actions like conversating or executing
21
+ * LLM (Large Language Model) function calling, the functions defined in the
22
+ * {@link IAgenticaRpcListener} would be called through the RPC
23
+ * (Remote Procedure Call) paradigm.
24
+ *
25
+ * @param content The content to talk
26
+ * @returns Returned when the conversation process is completely done
27
+ */
28
+ conversate(content: string): Promise<void>;
29
+ }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./IAgenticaRpcListener";
2
+ export * from "./IAgenticaRpcService";
3
+ export * from "./AgenticaRpcService";