@agentica/rpc 0.43.2 → 0.44.0-dev.20260313

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.
@@ -1,7 +1,7 @@
1
- // export class AgenticaRpcListener {
2
- // public constructor() {}
3
-
4
- // public on() {}
5
-
6
- // public off() {}
7
- // }
1
+ // export class AgenticaRpcListener {
2
+ // public constructor() {}
3
+
4
+ // public on() {}
5
+
6
+ // public off() {}
7
+ // }
@@ -1,124 +1,124 @@
1
- import type { Agentica, IAgenticaController } from "@agentica/core";
2
-
3
- import type { IAgenticaRpcListener } from "./IAgenticaRpcListener";
4
- import type { IAgenticaRpcService } from "./IAgenticaRpcService";
5
-
6
- /**
7
- * RPC service for the {@link Agentica}.
8
- *
9
- * `AgenticaRpcService` is class defining an AI agent service
10
- * provided from the server to clients through the RPC (Remote Procedure Call)
11
- * paradigm in the websocket protocol.
12
- *
13
- * Client connecting to the `AgenticaRpcService` providing websocket server
14
- * will call the {@link conversate} function remotely through its basic
15
- * interface type {@link IAgenticaRpcService} with the RPC paradigm.
16
- *
17
- * Also, the client provides the {@link IAgenticaRpcListener} type to the
18
- * server, so that `AgenticaRpcService` will remotely call the
19
- * {@link IAgenticaRpcListener listener}'s functions internally.
20
- *
21
- * You can open the WebSocket server of the AI agent like below:
22
- *
23
- * ```typescript
24
- * import {
25
- * IAgenticaRpcListener,
26
- * IAgenticaRpcService,
27
- * Agentica,
28
- * AgenticaRpcService,
29
- * } from "@agentica/core";
30
- * import { WebSocketServer } from "tgrid";
31
- *
32
- * const server: WebSocketServer<
33
- * null,
34
- * IAgenticaRpcService,
35
- * IAgenticaRpcListener
36
- * > = new WebSocketServer();
37
- * await server.open(3001, async (acceptor) => {
38
- * await acceptor.accept(
39
- * new AgenticaRpcService({
40
- * agent: new Agentica({ ... }),
41
- * listener: acceptor.getDriver(),
42
- * }),
43
- * );
44
- * });
45
- * ```
46
- *
47
- * @author Samchon
48
- */
49
- export class AgenticaRpcService
50
- 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("userMessage", async (event) => {
61
- listener.userMessage!(event.toJSON()).catch(() => {});
62
- });
63
- agent.on("assistantMessage", async (evt) => {
64
- await evt.join();
65
- listener.assistantMessage(evt.toJSON()).catch(() => {});
66
- });
67
- agent.on("describe", async (evt) => {
68
- await evt.join();
69
- listener.describe(evt.toJSON()).catch(() => {});
70
- });
71
-
72
- // OPTIONAL LISTENERS
73
- agent.on("initialize", async (evt) => {
74
- listener.initialize!(evt.toJSON()).catch(() => {});
75
- });
76
- agent.on("select", async (evt) => {
77
- listener.select!(evt.toJSON()).catch(() => {});
78
- });
79
- agent.on("cancel", async (evt) => {
80
- listener.cancel!(evt.toJSON()).catch(() => {});
81
- });
82
- agent.on("call", async (evt) => {
83
- const args: object | null | undefined | void = await listener.call!(
84
- evt.toJSON(),
85
- );
86
- if (args != null) {
87
- evt.arguments = args;
88
- }
89
- });
90
- agent.on("execute", async (evt) => {
91
- listener.execute!(evt.toJSON()).catch(() => {});
92
- });
93
- }
94
-
95
- /**
96
- * @inheritDoc
97
- */
98
- public async conversate(content: string | Parameters<typeof Agentica.prototype.conversate>[0]): Promise<void> {
99
- await this.props.agent.conversate(content);
100
- }
101
-
102
- /**
103
- * @inheritDoc
104
- */
105
- public async getControllers(): Promise<IAgenticaController[]> {
106
- return this.props.agent.getControllers() as IAgenticaController[];
107
- }
108
- }
109
- export namespace AgenticaRpcService {
110
- /**
111
- * Properties of the {@link AgenticaRpcService}.
112
- */
113
- export interface IProps {
114
- /**
115
- * Target agent to provide as RPC service.
116
- */
117
- agent: Agentica;
118
-
119
- /**
120
- * Listener to be binded on the agent.
121
- */
122
- listener: IAgenticaRpcListener;
123
- }
124
- }
1
+ import type { Agentica, IAgenticaController } from "@agentica/core";
2
+
3
+ import type { IAgenticaRpcListener } from "./IAgenticaRpcListener";
4
+ import type { IAgenticaRpcService } from "./IAgenticaRpcService";
5
+
6
+ /**
7
+ * RPC service for the {@link Agentica}.
8
+ *
9
+ * `AgenticaRpcService` is class defining an AI agent service
10
+ * provided from the server to clients through the RPC (Remote Procedure Call)
11
+ * paradigm in the websocket protocol.
12
+ *
13
+ * Client connecting to the `AgenticaRpcService` providing websocket server
14
+ * will call the {@link conversate} function remotely through its basic
15
+ * interface type {@link IAgenticaRpcService} with the RPC paradigm.
16
+ *
17
+ * Also, the client provides the {@link IAgenticaRpcListener} type to the
18
+ * server, so that `AgenticaRpcService` will remotely call the
19
+ * {@link IAgenticaRpcListener listener}'s functions internally.
20
+ *
21
+ * You can open the WebSocket server of the AI agent like below:
22
+ *
23
+ * ```typescript
24
+ * import {
25
+ * IAgenticaRpcListener,
26
+ * IAgenticaRpcService,
27
+ * Agentica,
28
+ * AgenticaRpcService,
29
+ * } from "@agentica/core";
30
+ * import { WebSocketServer } from "tgrid";
31
+ *
32
+ * const server: WebSocketServer<
33
+ * null,
34
+ * IAgenticaRpcService,
35
+ * IAgenticaRpcListener
36
+ * > = new WebSocketServer();
37
+ * await server.open(3001, async (acceptor) => {
38
+ * await acceptor.accept(
39
+ * new AgenticaRpcService({
40
+ * agent: new Agentica({ ... }),
41
+ * listener: acceptor.getDriver(),
42
+ * }),
43
+ * );
44
+ * });
45
+ * ```
46
+ *
47
+ * @author Samchon
48
+ */
49
+ export class AgenticaRpcService
50
+ 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("userMessage", async (event) => {
61
+ listener.userMessage!(event.toJSON()).catch(() => {});
62
+ });
63
+ agent.on("assistantMessage", async (evt) => {
64
+ await evt.join();
65
+ listener.assistantMessage(evt.toJSON()).catch(() => {});
66
+ });
67
+ agent.on("describe", async (evt) => {
68
+ await evt.join();
69
+ listener.describe(evt.toJSON()).catch(() => {});
70
+ });
71
+
72
+ // OPTIONAL LISTENERS
73
+ agent.on("initialize", async (evt) => {
74
+ listener.initialize!(evt.toJSON()).catch(() => {});
75
+ });
76
+ agent.on("select", async (evt) => {
77
+ listener.select!(evt.toJSON()).catch(() => {});
78
+ });
79
+ agent.on("cancel", async (evt) => {
80
+ listener.cancel!(evt.toJSON()).catch(() => {});
81
+ });
82
+ agent.on("call", async (evt) => {
83
+ const args: object | null | undefined | void = await listener.call!(
84
+ evt.toJSON(),
85
+ );
86
+ if (args != null) {
87
+ evt.arguments = args;
88
+ }
89
+ });
90
+ agent.on("execute", async (evt) => {
91
+ listener.execute!(evt.toJSON()).catch(() => {});
92
+ });
93
+ }
94
+
95
+ /**
96
+ * @inheritDoc
97
+ */
98
+ public async conversate(content: string | Parameters<typeof Agentica.prototype.conversate>[0]): Promise<void> {
99
+ await this.props.agent.conversate(content);
100
+ }
101
+
102
+ /**
103
+ * @inheritDoc
104
+ */
105
+ public async getControllers(): Promise<IAgenticaController[]> {
106
+ return this.props.agent.getControllers() as IAgenticaController[];
107
+ }
108
+ }
109
+ export namespace AgenticaRpcService {
110
+ /**
111
+ * Properties of the {@link AgenticaRpcService}.
112
+ */
113
+ export interface IProps {
114
+ /**
115
+ * Target agent to provide as RPC service.
116
+ */
117
+ agent: Agentica;
118
+
119
+ /**
120
+ * Listener to be binded on the agent.
121
+ */
122
+ listener: IAgenticaRpcListener;
123
+ }
124
+ }
@@ -1,125 +1,125 @@
1
- import type { IAgenticaEventJson } from "@agentica/core";
2
-
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 AgenticaEvent}
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: IAgenticaEventJson.IDescribe) => Promise<void>;
55
-
56
- /**
57
- * Assistant conversation message.
58
- *
59
- * @param evt Event of assistant conversation
60
- */
61
- assistantMessage: (evt: IAgenticaEventJson.IAssistantMessage) => Promise<void>;
62
-
63
- /**
64
- * User conversation message.
65
- *
66
- * @param evt Event of user conversation
67
- */
68
- userMessage?: (evt: IAgenticaEventJson.IUserMessage) => Promise<void>;
69
-
70
- /**
71
- * Initialize the AI agent.
72
- *
73
- * Informs an initialization of controller functions from
74
- * the AI agent server to client.
75
- *
76
- * @param evt Event of initialization
77
- */
78
- initialize?: (evt: IAgenticaEventJson.IInitialize) => Promise<void>;
79
-
80
- /**
81
- * Select a function to call.
82
- *
83
- * Informs a selected function to call from the AI agent server to client.
84
- *
85
- * @param evt Event of selecting a function to call
86
- */
87
- select?: (evt: IAgenticaEventJson.ISelect) => Promise<void>;
88
-
89
- /**
90
- * Cancel a function to call.
91
- *
92
- * Informs a canceling function to call from the AI agent server to client.
93
- *
94
- * @param evt Event of canceling a function to call
95
- */
96
- cancel?: (evt: IAgenticaEventJson.ICancel) => Promise<void>;
97
-
98
- /**
99
- * Call a function.
100
- *
101
- * Informs a function calling from the AI agent server to client.
102
- *
103
- * This event comes before the function execution, so that if you return
104
- * a different value from the original {@link IAgenticaEventJson.ICall.arguments},
105
- * you can modify the arguments of the function calling.
106
- *
107
- * Otherwise you do not return anything (`undefined`) or `null` value, the
108
- * arguments of the function calling would not be modified. Also, if you are
109
- * not interested in the function calling event, you can skit its
110
- * implementation.
111
- *
112
- * @param evt Event of a function calling
113
- * @return New arguments if you want to modify, otherwise null or undefined
114
- */
115
- call?: (evt: IAgenticaEventJson.ICall) => Promise<object | null | void | undefined>;
116
-
117
- /**
118
- * Executition of a function.
119
- *
120
- * Informs a function execution from the AI agent server to client.
121
- *
122
- * @param evt Event of a function execution
123
- */
124
- execute?: (evt: IAgenticaEventJson.IExecute) => Promise<void>;
125
- }
1
+ import type { IAgenticaEventJson } from "@agentica/core";
2
+
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 AgenticaEvent}
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: IAgenticaEventJson.IDescribe) => Promise<void>;
55
+
56
+ /**
57
+ * Assistant conversation message.
58
+ *
59
+ * @param evt Event of assistant conversation
60
+ */
61
+ assistantMessage: (evt: IAgenticaEventJson.IAssistantMessage) => Promise<void>;
62
+
63
+ /**
64
+ * User conversation message.
65
+ *
66
+ * @param evt Event of user conversation
67
+ */
68
+ userMessage?: (evt: IAgenticaEventJson.IUserMessage) => Promise<void>;
69
+
70
+ /**
71
+ * Initialize the AI agent.
72
+ *
73
+ * Informs an initialization of controller functions from
74
+ * the AI agent server to client.
75
+ *
76
+ * @param evt Event of initialization
77
+ */
78
+ initialize?: (evt: IAgenticaEventJson.IInitialize) => Promise<void>;
79
+
80
+ /**
81
+ * Select a function to call.
82
+ *
83
+ * Informs a selected function to call from the AI agent server to client.
84
+ *
85
+ * @param evt Event of selecting a function to call
86
+ */
87
+ select?: (evt: IAgenticaEventJson.ISelect) => Promise<void>;
88
+
89
+ /**
90
+ * Cancel a function to call.
91
+ *
92
+ * Informs a canceling function to call from the AI agent server to client.
93
+ *
94
+ * @param evt Event of canceling a function to call
95
+ */
96
+ cancel?: (evt: IAgenticaEventJson.ICancel) => Promise<void>;
97
+
98
+ /**
99
+ * Call a function.
100
+ *
101
+ * Informs a function calling from the AI agent server to client.
102
+ *
103
+ * This event comes before the function execution, so that if you return
104
+ * a different value from the original {@link IAgenticaEventJson.ICall.arguments},
105
+ * you can modify the arguments of the function calling.
106
+ *
107
+ * Otherwise you do not return anything (`undefined`) or `null` value, the
108
+ * arguments of the function calling would not be modified. Also, if you are
109
+ * not interested in the function calling event, you can skit its
110
+ * implementation.
111
+ *
112
+ * @param evt Event of a function calling
113
+ * @return New arguments if you want to modify, otherwise null or undefined
114
+ */
115
+ call?: (evt: IAgenticaEventJson.ICall) => Promise<object | null | void | undefined>;
116
+
117
+ /**
118
+ * Executition of a function.
119
+ *
120
+ * Informs a function execution from the AI agent server to client.
121
+ *
122
+ * @param evt Event of a function execution
123
+ */
124
+ execute?: (evt: IAgenticaEventJson.IExecute) => Promise<void>;
125
+ }
@@ -1,44 +1,44 @@
1
- import type { AgenticaUserMessageContent, IAgenticaController } from "@agentica/core";
2
-
3
- /**
4
- * RPC interface of AI agent service.
5
- *
6
- * `IAgenticaRpcService` is an interface defining an AI agent service
7
- * provided from the server to client through the RPC (Remote Procedure Call)
8
- * paradigm in the websocket protocol.
9
- *
10
- * The client will call the {@link conversate} function remotely, and the
11
- * server responses to the client by calling the client's
12
- * {@link IAgenticaRpcListener} functions remotely too.
13
- *
14
- * @author Samchon
15
- */
16
- export interface IAgenticaRpcService {
17
- /**
18
- * Conversate with the AI agent.
19
- *
20
- * User talks to the AI agent with the content.
21
- *
22
- * When AI agent responds some actions like conversating or executing
23
- * LLM (Large Language Model) function calling, the functions defined in the
24
- * {@link IAgenticaRpcListener} would be called through the RPC
25
- * (Remote Procedure Call) paradigm.
26
- *
27
- * @param content The content to talk
28
- * @returns Returned when the conversation process is completely done
29
- */
30
- conversate: (
31
- content:
32
- | string
33
- | AgenticaUserMessageContent
34
- | Array<AgenticaUserMessageContent>,
35
- ) => Promise<void>;
36
-
37
- /**
38
- * Get controllers.
39
- *
40
- * Get controllers, collection of functions that would be
41
- * called by the AI chatbot.
42
- */
43
- getControllers: () => Promise<IAgenticaController[]>;
44
- }
1
+ import type { AgenticaUserMessageContent, IAgenticaController } from "@agentica/core";
2
+
3
+ /**
4
+ * RPC interface of AI agent service.
5
+ *
6
+ * `IAgenticaRpcService` is an interface defining an AI agent service
7
+ * provided from the server to client through the RPC (Remote Procedure Call)
8
+ * paradigm in the websocket protocol.
9
+ *
10
+ * The client will call the {@link conversate} function remotely, and the
11
+ * server responses to the client by calling the client's
12
+ * {@link IAgenticaRpcListener} functions remotely too.
13
+ *
14
+ * @author Samchon
15
+ */
16
+ export interface IAgenticaRpcService {
17
+ /**
18
+ * Conversate with the AI agent.
19
+ *
20
+ * User talks to the AI agent with the content.
21
+ *
22
+ * When AI agent responds some actions like conversating or executing
23
+ * LLM (Large Language Model) function calling, the functions defined in the
24
+ * {@link IAgenticaRpcListener} would be called through the RPC
25
+ * (Remote Procedure Call) paradigm.
26
+ *
27
+ * @param content The content to talk
28
+ * @returns Returned when the conversation process is completely done
29
+ */
30
+ conversate: (
31
+ content:
32
+ | string
33
+ | AgenticaUserMessageContent
34
+ | Array<AgenticaUserMessageContent>,
35
+ ) => Promise<void>;
36
+
37
+ /**
38
+ * Get controllers.
39
+ *
40
+ * Get controllers, collection of functions that would be
41
+ * called by the AI chatbot.
42
+ */
43
+ getControllers: () => Promise<IAgenticaController[]>;
44
+ }