@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,100 +1,100 @@
1
- import type { IAgenticaEventJson } from "@agentica/core";
2
-
3
- /**
4
- * RPC interface of Micro agent listener.
5
- *
6
- * `IMicroAgenticaRpcListener` 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 MicroAgenticaEvent}
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 `IMicroAgenticaRpcListener` 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 {
23
- * IMicroAgenticaRpcListener,
24
- * IAgenticaRpcService
25
- * } from "@agentica/core";
26
- * import { Driver, WebSocketConnector } from "tgrid";
27
- *
28
- * const connector: WebSocketConnector<
29
- * null,
30
- * IMicroAgenticaRpcListener,
31
- * IAgenticaRpcService
32
- * > = new WebSocketConnector(null, {
33
- * text: async (evt) => {
34
- * console.log(evt.role, evt.text);
35
- * },
36
- * describe: async (evt) => {
37
- * console.log("describer", evt.text);
38
- * },
39
- * });
40
- * await connector.connect("ws://localhost:3001");
41
- *
42
- * const driver: Driver<IAgenticaRpcService> = connector.getDriver();
43
- * await driver.conversate("Hello, what you can do?");
44
- * ```
45
- *
46
- * @author Samchon
47
- */
48
- export interface IMicroAgenticaRpcListener {
49
- /**
50
- * Describe the function executions' results.
51
- *
52
- * Inform description message of the function execution's results from
53
- * the AI agent server to client.
54
- *
55
- * @param evt Event of a description of function execution results
56
- */
57
- describe: (evt: IAgenticaEventJson.IDescribe) => Promise<void>;
58
-
59
- /**
60
- * Assistant conversation message.
61
- *
62
- * @param evt Event of assistant conversation
63
- */
64
- assistantMessage: (evt: IAgenticaEventJson.IAssistantMessage) => Promise<void>;
65
-
66
- /**
67
- * User conversation message.
68
- *
69
- * @param evt Event of user conversation
70
- */
71
- userMessage?: (evt: IAgenticaEventJson.IUserMessage) => Promise<void>;
72
-
73
- /**
74
- * Call a function.
75
- *
76
- * Informs a function calling from the AI agent server to client.
77
- *
78
- * This event comes before the function execution, so that if you return
79
- * a different value from the original {@link IAgenticaEventJson.ICall.arguments},
80
- * you can modify the arguments of the function calling.
81
- *
82
- * Otherwise you do not return anything (`undefined`) or `null` value, the
83
- * arguments of the function calling would not be modified. Also, if you are
84
- * not interested in the function calling event, you can skit its
85
- * implementation.
86
- *
87
- * @param evt Event of a function calling
88
- * @return New arguments if you want to modify, otherwise null or undefined
89
- */
90
- call?: (evt: IAgenticaEventJson.ICall) => Promise<object | null | void | undefined>;
91
-
92
- /**
93
- * Executition of a function.
94
- *
95
- * Informs a function execution from the AI agent server to client.
96
- *
97
- * @param evt Event of a function execution
98
- */
99
- execute?: (evt: IAgenticaEventJson.IExecute) => Promise<void>;
100
- }
1
+ import type { IAgenticaEventJson } from "@agentica/core";
2
+
3
+ /**
4
+ * RPC interface of Micro agent listener.
5
+ *
6
+ * `IMicroAgenticaRpcListener` 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 MicroAgenticaEvent}
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 `IMicroAgenticaRpcListener` 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 {
23
+ * IMicroAgenticaRpcListener,
24
+ * IAgenticaRpcService
25
+ * } from "@agentica/core";
26
+ * import { Driver, WebSocketConnector } from "tgrid";
27
+ *
28
+ * const connector: WebSocketConnector<
29
+ * null,
30
+ * IMicroAgenticaRpcListener,
31
+ * IAgenticaRpcService
32
+ * > = new WebSocketConnector(null, {
33
+ * text: async (evt) => {
34
+ * console.log(evt.role, evt.text);
35
+ * },
36
+ * describe: async (evt) => {
37
+ * console.log("describer", evt.text);
38
+ * },
39
+ * });
40
+ * await connector.connect("ws://localhost:3001");
41
+ *
42
+ * const driver: Driver<IAgenticaRpcService> = connector.getDriver();
43
+ * await driver.conversate("Hello, what you can do?");
44
+ * ```
45
+ *
46
+ * @author Samchon
47
+ */
48
+ export interface IMicroAgenticaRpcListener {
49
+ /**
50
+ * Describe the function executions' results.
51
+ *
52
+ * Inform description message of the function execution's results from
53
+ * the AI agent server to client.
54
+ *
55
+ * @param evt Event of a description of function execution results
56
+ */
57
+ describe: (evt: IAgenticaEventJson.IDescribe) => Promise<void>;
58
+
59
+ /**
60
+ * Assistant conversation message.
61
+ *
62
+ * @param evt Event of assistant conversation
63
+ */
64
+ assistantMessage: (evt: IAgenticaEventJson.IAssistantMessage) => Promise<void>;
65
+
66
+ /**
67
+ * User conversation message.
68
+ *
69
+ * @param evt Event of user conversation
70
+ */
71
+ userMessage?: (evt: IAgenticaEventJson.IUserMessage) => Promise<void>;
72
+
73
+ /**
74
+ * Call a function.
75
+ *
76
+ * Informs a function calling from the AI agent server to client.
77
+ *
78
+ * This event comes before the function execution, so that if you return
79
+ * a different value from the original {@link IAgenticaEventJson.ICall.arguments},
80
+ * you can modify the arguments of the function calling.
81
+ *
82
+ * Otherwise you do not return anything (`undefined`) or `null` value, the
83
+ * arguments of the function calling would not be modified. Also, if you are
84
+ * not interested in the function calling event, you can skit its
85
+ * implementation.
86
+ *
87
+ * @param evt Event of a function calling
88
+ * @return New arguments if you want to modify, otherwise null or undefined
89
+ */
90
+ call?: (evt: IAgenticaEventJson.ICall) => Promise<object | null | void | undefined>;
91
+
92
+ /**
93
+ * Executition of a function.
94
+ *
95
+ * Informs a function execution from the AI agent server to client.
96
+ *
97
+ * @param evt Event of a function execution
98
+ */
99
+ execute?: (evt: IAgenticaEventJson.IExecute) => Promise<void>;
100
+ }
@@ -1,5 +1,5 @@
1
- // import type { IMicroAgenticaRpcListener } from "./IMicroAgenticaRpcListener";
2
-
3
- // export class McpAgenticaRpcListener {
4
- // public constructor(private readonly driver: IMicroAgenticaRpcListener) {}
5
- // }
1
+ // import type { IMicroAgenticaRpcListener } from "./IMicroAgenticaRpcListener";
2
+
3
+ // export class McpAgenticaRpcListener {
4
+ // public constructor(private readonly driver: IMicroAgenticaRpcListener) {}
5
+ // }
@@ -1,115 +1,115 @@
1
- import type { IAgenticaController, MicroAgentica } from "@agentica/core";
2
-
3
- import type { IAgenticaRpcService } from "./IAgenticaRpcService";
4
- import type { IMicroAgenticaRpcListener } from "./IMicroAgenticaRpcListener";
5
-
6
- /**
7
- * RPC service for the {@link MicroAgentica}.
8
- *
9
- * `MicroAgenticaRpcService` 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 `MicroAgenticaRpcService` 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 IMicroAgenticaRpcListener} type to the
18
- * server, so that `MicroAgenticaRpcService` will remotely call the
19
- * {@link IMicroAgenticaRpcListener listener}'s functions internally.
20
- *
21
- * You can open the WebSocket server of the AI agent like below:
22
- *
23
- * ```typescript
24
- * import {
25
- * IMicroAgenticaRpcListener,
26
- * IAgenticaRpcService,
27
- * Agentica,
28
- * MicroAgenticaRpcService,
29
- * } from "@agentica/core";
30
- * import { WebSocketServer } from "tgrid";
31
- *
32
- * const server: WebSocketServer<
33
- * null,
34
- * IAgenticaRpcService,
35
- * IMicroAgenticaRpcListener
36
- * > = new WebSocketServer();
37
- * await server.open(3001, async (acceptor) => {
38
- * await acceptor.accept(
39
- * new MicroAgenticaRpcService({
40
- * agent: new MicroAgentica({ ... }),
41
- * listener: acceptor.getDriver(),
42
- * }),
43
- * );
44
- * });
45
- * ```
46
- *
47
- * @author Samchon
48
- */
49
- export class MicroAgenticaRpcService
50
- implements IAgenticaRpcService {
51
- /**
52
- * Initializer Constructor.
53
- *
54
- * @param props Properties to construct the RPC service
55
- */
56
- public constructor(private readonly props: MicroAgenticaRpcService.IProps) {
57
- const { agent, listener } = props;
58
-
59
- // ESSENTIAL LISTENERS
60
- agent.on("userMessage", async (evt) => {
61
- listener.userMessage!(evt.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("call", async (evt) => {
74
- const args: object | null | undefined | void = await listener.call!(
75
- evt.toJSON(),
76
- );
77
- if (args != null) {
78
- evt.arguments = args;
79
- }
80
- });
81
- agent.on("execute", async (evt) => {
82
- listener.execute!(evt.toJSON()).catch(() => {});
83
- });
84
- }
85
-
86
- /**
87
- * @inheritDoc
88
- */
89
- public async conversate(content: string | Parameters<typeof MicroAgentica.prototype.conversate>[0]): Promise<void> {
90
- await this.props.agent.conversate(content);
91
- }
92
-
93
- /**
94
- * @inheritDoc
95
- */
96
- public async getControllers(): Promise<IAgenticaController[]> {
97
- return this.props.agent.getControllers() as IAgenticaController[];
98
- }
99
- }
100
- export namespace MicroAgenticaRpcService {
101
- /**
102
- * Properties to construct the RPC service.
103
- */
104
- export interface IProps {
105
- /**
106
- * AI agent to be controlled.
107
- */
108
- agent: MicroAgentica;
109
-
110
- /**
111
- * Listener to be notified.
112
- */
113
- listener: IMicroAgenticaRpcListener;
114
- }
115
- }
1
+ import type { IAgenticaController, MicroAgentica } from "@agentica/core";
2
+
3
+ import type { IAgenticaRpcService } from "./IAgenticaRpcService";
4
+ import type { IMicroAgenticaRpcListener } from "./IMicroAgenticaRpcListener";
5
+
6
+ /**
7
+ * RPC service for the {@link MicroAgentica}.
8
+ *
9
+ * `MicroAgenticaRpcService` 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 `MicroAgenticaRpcService` 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 IMicroAgenticaRpcListener} type to the
18
+ * server, so that `MicroAgenticaRpcService` will remotely call the
19
+ * {@link IMicroAgenticaRpcListener listener}'s functions internally.
20
+ *
21
+ * You can open the WebSocket server of the AI agent like below:
22
+ *
23
+ * ```typescript
24
+ * import {
25
+ * IMicroAgenticaRpcListener,
26
+ * IAgenticaRpcService,
27
+ * Agentica,
28
+ * MicroAgenticaRpcService,
29
+ * } from "@agentica/core";
30
+ * import { WebSocketServer } from "tgrid";
31
+ *
32
+ * const server: WebSocketServer<
33
+ * null,
34
+ * IAgenticaRpcService,
35
+ * IMicroAgenticaRpcListener
36
+ * > = new WebSocketServer();
37
+ * await server.open(3001, async (acceptor) => {
38
+ * await acceptor.accept(
39
+ * new MicroAgenticaRpcService({
40
+ * agent: new MicroAgentica({ ... }),
41
+ * listener: acceptor.getDriver(),
42
+ * }),
43
+ * );
44
+ * });
45
+ * ```
46
+ *
47
+ * @author Samchon
48
+ */
49
+ export class MicroAgenticaRpcService
50
+ implements IAgenticaRpcService {
51
+ /**
52
+ * Initializer Constructor.
53
+ *
54
+ * @param props Properties to construct the RPC service
55
+ */
56
+ public constructor(private readonly props: MicroAgenticaRpcService.IProps) {
57
+ const { agent, listener } = props;
58
+
59
+ // ESSENTIAL LISTENERS
60
+ agent.on("userMessage", async (evt) => {
61
+ listener.userMessage!(evt.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("call", async (evt) => {
74
+ const args: object | null | undefined | void = await listener.call!(
75
+ evt.toJSON(),
76
+ );
77
+ if (args != null) {
78
+ evt.arguments = args;
79
+ }
80
+ });
81
+ agent.on("execute", async (evt) => {
82
+ listener.execute!(evt.toJSON()).catch(() => {});
83
+ });
84
+ }
85
+
86
+ /**
87
+ * @inheritDoc
88
+ */
89
+ public async conversate(content: string | Parameters<typeof MicroAgentica.prototype.conversate>[0]): Promise<void> {
90
+ await this.props.agent.conversate(content);
91
+ }
92
+
93
+ /**
94
+ * @inheritDoc
95
+ */
96
+ public async getControllers(): Promise<IAgenticaController[]> {
97
+ return this.props.agent.getControllers() as IAgenticaController[];
98
+ }
99
+ }
100
+ export namespace MicroAgenticaRpcService {
101
+ /**
102
+ * Properties to construct the RPC service.
103
+ */
104
+ export interface IProps {
105
+ /**
106
+ * AI agent to be controlled.
107
+ */
108
+ agent: MicroAgentica;
109
+
110
+ /**
111
+ * Listener to be notified.
112
+ */
113
+ listener: IMicroAgenticaRpcListener;
114
+ }
115
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
- export * from "./AgenticaRpcService";
2
- export * from "./IAgenticaRpcListener";
3
- export * from "./IAgenticaRpcService";
4
- export * from "./IMicroAgenticaRpcListener";
5
- export * from "./MicroAgenticaRpcService";
1
+ export * from "./AgenticaRpcService";
2
+ export * from "./IAgenticaRpcListener";
3
+ export * from "./IAgenticaRpcService";
4
+ export * from "./IMicroAgenticaRpcListener";
5
+ export * from "./MicroAgenticaRpcService";
@@ -1,6 +1,6 @@
1
- export interface IAgenticaAssistantMessageEventProgress {
2
- type: "assistantMessagePiece";
3
- sequence: number;
4
- text: string;
5
- done: boolean;
6
- }
1
+ export interface IAgenticaAssistantMessageEventProgress {
2
+ type: "assistantMessagePiece";
3
+ sequence: number;
4
+ text: string;
5
+ done: boolean;
6
+ }
@@ -1,6 +1,6 @@
1
- export interface IAgenticaDescribeEventProgress {
2
- type: "describeMessageProgress";
3
- sequence: number;
4
- text: string;
5
- done: boolean;
6
- }
1
+ export interface IAgenticaDescribeEventProgress {
2
+ type: "describeMessageProgress";
3
+ sequence: number;
4
+ text: string;
5
+ done: boolean;
6
+ }
@@ -1,6 +1,6 @@
1
- import type { IAgenticaHistoryJson } from "@agentica/core";
2
-
3
- export interface IAgenticaDescribeEventStart {
4
- type: "describeMessageStart";
5
- executes: IAgenticaHistoryJson.IExecute[];
6
- }
1
+ import type { IAgenticaHistoryJson } from "@agentica/core";
2
+
3
+ export interface IAgenticaDescribeEventStart {
4
+ type: "describeMessageStart";
5
+ executes: IAgenticaHistoryJson.IExecute[];
6
+ }