@agentica/core 0.24.0 → 0.25.0
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/lib/Agentica.d.ts +2 -2
- package/lib/Agentica.js +4 -4
- package/lib/Agentica.js.map +1 -1
- package/lib/MicroAgentica.d.ts +2 -2
- package/lib/MicroAgentica.js +4 -4
- package/lib/MicroAgentica.js.map +1 -1
- package/lib/context/AgenticaContext.d.ts +2 -2
- package/lib/context/MicroAgenticaContext.d.ts +2 -2
- package/lib/context/index.d.ts +5 -0
- package/lib/{structures/mcp → context}/index.js +5 -1
- package/lib/context/index.js.map +1 -0
- package/lib/events/AgenticaAssistantMessageEvent.d.ts +9 -0
- package/lib/{histories/AgenticaUserInputHistory.js → events/AgenticaAssistantMessageEvent.js} +1 -1
- package/lib/events/AgenticaAssistantMessageEvent.js.map +1 -0
- package/lib/events/AgenticaEvent.d.ts +9 -9
- package/lib/events/AgenticaUserMessageEvent.d.ts +9 -0
- package/lib/events/{AgenticaUserInputEvent.js → AgenticaUserMessageEvent.js} +1 -1
- package/lib/events/AgenticaUserMessageEvent.js.map +1 -0
- package/lib/events/MicroAgenticaEvent.d.ts +6 -6
- package/lib/events/index.d.ts +14 -0
- package/lib/events/index.js +31 -0
- package/lib/events/index.js.map +1 -0
- package/lib/factory/events.d.ts +8 -8
- package/lib/factory/events.js +23 -38
- package/lib/factory/events.js.map +1 -1
- package/lib/factory/histories.d.ts +1 -36
- package/lib/factory/histories.js +77 -24
- package/lib/factory/histories.js.map +1 -1
- package/lib/functional/assertHttpController.js +6 -6
- package/lib/functional/assertHttpLlmApplication.js +6 -6
- package/lib/functional/assertMcpController.d.ts +1 -2
- package/lib/functional/assertMcpController.js +6 -6
- package/lib/functional/assertMcpController.js.map +1 -1
- package/lib/functional/index.d.ts +6 -0
- package/lib/functional/index.js +23 -0
- package/lib/functional/index.js.map +1 -0
- package/lib/functional/validateHttpController.js +5 -5
- package/lib/functional/validateHttpLlmApplication.js +5 -5
- package/lib/functional/validateMcpController.d.ts +1 -2
- package/lib/functional/validateMcpController.js +11 -11
- package/lib/functional/validateMcpController.js.map +1 -1
- package/lib/histories/{AgenticaTextHistory.d.ts → AgenticaAssistantMessageHistory.d.ts} +1 -2
- package/lib/histories/AgenticaAssistantMessageHistory.js +3 -0
- package/lib/histories/AgenticaAssistantMessageHistory.js.map +1 -0
- package/lib/histories/AgenticaHistory.d.ts +7 -7
- package/lib/histories/AgenticaUserMessageHistory.d.ts +6 -0
- package/lib/{events/AgenticaTextEvent.js → histories/AgenticaUserMessageHistory.js} +1 -1
- package/lib/histories/AgenticaUserMessageHistory.js.map +1 -0
- package/lib/histories/MicroAgenticaHistory.d.ts +5 -4
- package/lib/histories/contents/AgenticaUserMessageAudioContent.d.ts +19 -0
- package/lib/histories/contents/AgenticaUserMessageAudioContent.js +3 -0
- package/lib/histories/contents/AgenticaUserMessageAudioContent.js.map +1 -0
- package/lib/histories/contents/AgenticaUserMessageContent.d.ts +14 -0
- package/lib/histories/{AgenticaTextHistory.js → contents/AgenticaUserMessageContent.js} +1 -1
- package/lib/histories/contents/AgenticaUserMessageContent.js.map +1 -0
- package/lib/histories/contents/AgenticaUserMessageContentBase.d.ts +6 -0
- package/lib/histories/contents/AgenticaUserMessageContentBase.js +3 -0
- package/lib/histories/contents/AgenticaUserMessageContentBase.js.map +1 -0
- package/lib/histories/contents/AgenticaUserMessageFileContent.d.ts +26 -0
- package/lib/histories/contents/AgenticaUserMessageFileContent.js +3 -0
- package/lib/histories/contents/AgenticaUserMessageFileContent.js.map +1 -0
- package/lib/histories/contents/AgenticaUserMessageImageContent.d.ts +20 -0
- package/lib/histories/contents/AgenticaUserMessageImageContent.js +3 -0
- package/lib/histories/contents/AgenticaUserMessageImageContent.js.map +1 -0
- package/lib/histories/contents/AgenticaUserMessageTextContent.d.ts +14 -0
- package/lib/histories/contents/AgenticaUserMessageTextContent.js +3 -0
- package/lib/histories/contents/AgenticaUserMessageTextContent.js.map +1 -0
- package/lib/histories/contents/index.d.ts +5 -0
- package/lib/histories/contents/index.js +22 -0
- package/lib/histories/contents/index.js.map +1 -0
- package/lib/histories/index.d.ts +9 -0
- package/lib/histories/index.js +26 -0
- package/lib/histories/index.js.map +1 -0
- package/lib/index.d.ts +6 -45
- package/lib/index.js +6 -46
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +148 -133
- package/lib/index.mjs.map +1 -1
- package/lib/json/IAgenticaEventJson.d.ts +29 -23
- package/lib/json/IAgenticaHistoryJson.d.ts +24 -19
- package/lib/json/IMicroAgenticaEventJson.d.ts +1 -1
- package/lib/json/IMicroAgenticaHistoryJson.d.ts +1 -1
- package/lib/json/index.d.ts +7 -0
- package/lib/json/index.js +24 -0
- package/lib/json/index.js.map +1 -0
- package/lib/orchestrate/call.js +4 -4
- package/lib/orchestrate/call.js.map +1 -1
- package/lib/orchestrate/cancel.js +1 -1
- package/lib/orchestrate/cancel.js.map +1 -1
- package/lib/orchestrate/initialize.js +4 -4
- package/lib/orchestrate/initialize.js.map +1 -1
- package/lib/orchestrate/select.js +3 -3
- package/lib/orchestrate/select.js.map +1 -1
- package/lib/structures/IAgenticaController.d.ts +1 -2
- package/lib/structures/index.d.ts +10 -0
- package/lib/structures/index.js +27 -0
- package/lib/structures/index.js.map +1 -0
- package/lib/transformers/transformEvent.d.ts +1 -0
- package/lib/transformers/{AgenticaEventTransformer.js → transformEvent.js} +74 -31
- package/lib/transformers/transformEvent.js.map +1 -0
- package/lib/transformers/transformHistory.d.ts +1 -0
- package/lib/transformers/{AgenticaHistoryTransformer.js → transformHistory.js} +24 -23
- package/lib/transformers/transformHistory.js.map +1 -0
- package/lib/utils/ChatGptCompletionMessageUtil.js +2 -2
- package/package.json +5 -6
- package/src/Agentica.ts +10 -9
- package/src/MicroAgentica.ts +12 -9
- package/src/context/AgenticaContext.ts +2 -2
- package/src/context/MicroAgenticaContext.ts +2 -2
- package/src/context/index.ts +5 -0
- package/src/events/AgenticaAssistantMessageEvent.ts +12 -0
- package/src/events/AgenticaEvent.ts +15 -15
- package/src/events/AgenticaUserMessageEvent.ts +12 -0
- package/src/events/MicroAgenticaEvent.ts +9 -9
- package/src/events/index.ts +14 -0
- package/src/factory/events.ts +29 -34
- package/src/factory/histories.ts +81 -32
- package/src/functional/assertMcpController.ts +4 -2
- package/src/functional/index.ts +7 -0
- package/src/functional/validateMcpController.ts +4 -2
- package/src/histories/{AgenticaTextHistory.ts → AgenticaAssistantMessageHistory.ts} +4 -2
- package/src/histories/AgenticaHistory.ts +8 -8
- package/src/histories/AgenticaUserMessageHistory.ts +11 -0
- package/src/histories/MicroAgenticaHistory.ts +6 -5
- package/src/histories/contents/AgenticaUserMessageAudioContent.ts +21 -0
- package/src/histories/contents/AgenticaUserMessageContent.ts +19 -0
- package/src/histories/contents/AgenticaUserMessageContentBase.ts +6 -0
- package/src/histories/contents/AgenticaUserMessageFileContent.ts +27 -0
- package/src/histories/contents/AgenticaUserMessageImageContent.ts +23 -0
- package/src/histories/contents/AgenticaUserMessageTextContent.ts +15 -0
- package/src/histories/contents/index.ts +5 -0
- package/src/histories/index.ts +9 -0
- package/src/index.ts +6 -54
- package/src/json/IAgenticaEventJson.ts +36 -28
- package/src/json/IAgenticaHistoryJson.ts +28 -22
- package/src/json/IMicroAgenticaEventJson.ts +2 -1
- package/src/json/IMicroAgenticaHistoryJson.ts +2 -1
- package/src/json/index.ts +7 -0
- package/src/orchestrate/call.ts +8 -8
- package/src/orchestrate/cancel.ts +2 -2
- package/src/orchestrate/initialize.ts +5 -5
- package/src/orchestrate/select.ts +5 -5
- package/src/structures/IAgenticaController.ts +4 -2
- package/src/structures/index.ts +10 -0
- package/src/transformers/{AgenticaEventTransformer.ts → transformEvent.ts} +94 -42
- package/src/transformers/{AgenticaHistoryTransformer.ts → transformHistory.ts} +30 -26
- package/lib/events/AgenticaTextEvent.d.ts +0 -10
- package/lib/events/AgenticaTextEvent.js.map +0 -1
- package/lib/events/AgenticaUserInputEvent.d.ts +0 -10
- package/lib/events/AgenticaUserInputEvent.js.map +0 -1
- package/lib/histories/AgenticaTextHistory.js.map +0 -1
- package/lib/histories/AgenticaUserInputHistory.d.ts +0 -86
- package/lib/histories/AgenticaUserInputHistory.js.map +0 -1
- package/lib/structures/mcp/IMcpLlmTransportProps.d.ts +0 -11
- package/lib/structures/mcp/IMcpLlmTransportProps.js +0 -3
- package/lib/structures/mcp/IMcpLlmTransportProps.js.map +0 -1
- package/lib/structures/mcp/index.d.ts +0 -1
- package/lib/structures/mcp/index.js.map +0 -1
- package/lib/transformers/AgenticaEventTransformer.d.ts +0 -63
- package/lib/transformers/AgenticaEventTransformer.js.map +0 -1
- package/lib/transformers/AgenticaHistoryTransformer.d.ts +0 -41
- package/lib/transformers/AgenticaHistoryTransformer.js.map +0 -1
- package/src/events/AgenticaTextEvent.ts +0 -12
- package/src/events/AgenticaUserInputEvent.ts +0 -12
- package/src/histories/AgenticaUserInputHistory.ts +0 -94
- package/src/structures/mcp/IMcpLlmTransportProps.ts +0 -13
- package/src/structures/mcp/index.ts +0 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type OpenAI from "openai";
|
|
2
|
+
import type { IValidation } from "typia";
|
|
2
3
|
|
|
3
4
|
import type { AgenticaEventSource } from "../events/AgenticaEventSource";
|
|
4
|
-
import type {
|
|
5
|
+
import type { AgenticaUserMessageContent } from "../histories";
|
|
5
6
|
|
|
6
7
|
import type { IAgenticaHistoryJson } from "./IAgenticaHistoryJson";
|
|
7
8
|
import type { IAgenticaOperationJson } from "./IAgenticaOperationJson";
|
|
@@ -25,26 +26,38 @@ export type IAgenticaEventJson =
|
|
|
25
26
|
| IAgenticaEventJson.IInitialize
|
|
26
27
|
| IAgenticaEventJson.IRequest
|
|
27
28
|
| IAgenticaEventJson.ISelect
|
|
28
|
-
| IAgenticaEventJson.
|
|
29
|
-
| IAgenticaEventJson.
|
|
29
|
+
| IAgenticaEventJson.IValidate
|
|
30
|
+
| IAgenticaEventJson.IAssistantMessage
|
|
31
|
+
| IAgenticaEventJson.IUserMessage;
|
|
30
32
|
export namespace IAgenticaEventJson {
|
|
31
33
|
export type Type = IAgenticaEventJson["type"];
|
|
32
34
|
export interface Mapper {
|
|
35
|
+
userMessage: IUserMessage;
|
|
36
|
+
assistantMessage: IAssistantMessage;
|
|
33
37
|
initialize: IInitialize;
|
|
34
38
|
select: ISelect;
|
|
35
39
|
cancel: ICancel;
|
|
36
40
|
call: ICall;
|
|
37
41
|
execute: IExecute;
|
|
38
42
|
describe: IDescribe;
|
|
39
|
-
text: IText;
|
|
40
43
|
request: IRequest;
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
/**
|
|
44
|
-
* Event of
|
|
47
|
+
* Event of assistant message.
|
|
45
48
|
*/
|
|
46
|
-
export interface
|
|
47
|
-
|
|
49
|
+
export interface IAssistantMessage extends IBase<"assistantMessage"> {
|
|
50
|
+
/**
|
|
51
|
+
* Conversation text.
|
|
52
|
+
*/
|
|
53
|
+
text: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Event of user message.
|
|
58
|
+
*/
|
|
59
|
+
export interface IUserMessage extends IBase<"userMessage"> {
|
|
60
|
+
contents: Array<AgenticaUserMessageContent>;
|
|
48
61
|
}
|
|
49
62
|
|
|
50
63
|
/**
|
|
@@ -90,7 +103,22 @@ export namespace IAgenticaEventJson {
|
|
|
90
103
|
arguments: Record<string, any>;
|
|
91
104
|
}
|
|
92
105
|
|
|
93
|
-
export interface IValidate extends IBase<"validate"> {
|
|
106
|
+
export interface IValidate extends IBase<"validate"> {
|
|
107
|
+
/**
|
|
108
|
+
* ID of the tool calling.
|
|
109
|
+
*/
|
|
110
|
+
id: string;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Target operation to call.
|
|
114
|
+
*/
|
|
115
|
+
operation: IAgenticaOperationJson;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Validation result as a failure.
|
|
119
|
+
*/
|
|
120
|
+
result: IValidation.IFailure;
|
|
121
|
+
}
|
|
94
122
|
|
|
95
123
|
/**
|
|
96
124
|
* Event of function calling execution.
|
|
@@ -141,26 +169,6 @@ export namespace IAgenticaEventJson {
|
|
|
141
169
|
done: boolean;
|
|
142
170
|
}
|
|
143
171
|
|
|
144
|
-
/**
|
|
145
|
-
* Event of text message.
|
|
146
|
-
*/
|
|
147
|
-
export interface IText extends IBase<"text"> {
|
|
148
|
-
/**
|
|
149
|
-
* Role of the orator.
|
|
150
|
-
*/
|
|
151
|
-
role: "assistant";
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Conversation text.
|
|
155
|
-
*/
|
|
156
|
-
text: string;
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Whether the streaming is completed or not.
|
|
160
|
-
*/
|
|
161
|
-
done: boolean;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
172
|
/**
|
|
165
173
|
* Request event of LLM vendor API.
|
|
166
174
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AgenticaUserMessageContent } from "../histories";
|
|
2
2
|
|
|
3
3
|
import type { IAgenticaOperationJson } from "./IAgenticaOperationJson";
|
|
4
4
|
import type { IAgenticaOperationSelectionJson } from "./IAgenticaOperationSelectionJson";
|
|
@@ -20,24 +20,45 @@ import type { IAgenticaOperationSelectionJson } from "./IAgenticaOperationSelect
|
|
|
20
20
|
* @author Samchon
|
|
21
21
|
*/
|
|
22
22
|
export type IAgenticaHistoryJson =
|
|
23
|
-
| IAgenticaHistoryJson.
|
|
24
|
-
| IAgenticaHistoryJson.
|
|
23
|
+
| IAgenticaHistoryJson.IUserMessage
|
|
24
|
+
| IAgenticaHistoryJson.IAssistantMessage
|
|
25
25
|
| IAgenticaHistoryJson.ISelect
|
|
26
26
|
| IAgenticaHistoryJson.ICancel
|
|
27
27
|
| IAgenticaHistoryJson.IExecute
|
|
28
28
|
| IAgenticaHistoryJson.IDescribe;
|
|
29
29
|
export namespace IAgenticaHistoryJson {
|
|
30
|
+
export type Type = IAgenticaHistoryJson["type"];
|
|
31
|
+
export interface Mapper {
|
|
32
|
+
userMessage: IUserMessage;
|
|
33
|
+
assistantMessage: IAssistantMessage;
|
|
34
|
+
select: ISelect;
|
|
35
|
+
cancel: ICancel;
|
|
36
|
+
execute: IExecute;
|
|
37
|
+
describe: IDescribe;
|
|
38
|
+
}
|
|
39
|
+
|
|
30
40
|
/**
|
|
31
|
-
* User
|
|
41
|
+
* User prompt.
|
|
32
42
|
*
|
|
33
|
-
* User
|
|
43
|
+
* User prompt about the user's input.
|
|
34
44
|
*/
|
|
35
|
-
export interface
|
|
45
|
+
export interface IUserMessage extends IBase<"userMessage"> {
|
|
36
46
|
/**
|
|
37
47
|
* User input.
|
|
38
48
|
*/
|
|
39
|
-
contents: Array<
|
|
49
|
+
contents: Array<AgenticaUserMessageContent>;
|
|
40
50
|
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Assistant prompt.
|
|
54
|
+
*/
|
|
55
|
+
export interface IAssistantMessage extends IBase<"assistantMessage"> {
|
|
56
|
+
/**
|
|
57
|
+
* The text content.
|
|
58
|
+
*/
|
|
59
|
+
text: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
41
62
|
/**
|
|
42
63
|
* Select prompt.
|
|
43
64
|
*
|
|
@@ -118,21 +139,6 @@ export namespace IAgenticaHistoryJson {
|
|
|
118
139
|
text: string;
|
|
119
140
|
}
|
|
120
141
|
|
|
121
|
-
/**
|
|
122
|
-
* Text prompt.
|
|
123
|
-
*/
|
|
124
|
-
export interface IText extends IBase<"text"> {
|
|
125
|
-
/**
|
|
126
|
-
* Role of the orator.
|
|
127
|
-
*/
|
|
128
|
-
role: "assistant";
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* The text content.
|
|
132
|
-
*/
|
|
133
|
-
text: string;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
142
|
interface IBase<Type extends string> {
|
|
137
143
|
/**
|
|
138
144
|
* Discriminator type.
|
|
@@ -12,10 +12,11 @@ import type { IAgenticaEventJson } from "./IAgenticaEventJson";
|
|
|
12
12
|
* @author Samchon
|
|
13
13
|
*/
|
|
14
14
|
export type IMicroAgenticaEventJson =
|
|
15
|
+
| IAgenticaEventJson.IUserMessage
|
|
16
|
+
| IAgenticaEventJson.IAssistantMessage
|
|
15
17
|
| IAgenticaEventJson.ICall
|
|
16
18
|
| IAgenticaEventJson.IDescribe
|
|
17
19
|
| IAgenticaEventJson.IExecute
|
|
18
20
|
| IAgenticaEventJson.IInitialize
|
|
19
21
|
| IAgenticaEventJson.IRequest
|
|
20
|
-
| IAgenticaEventJson.IText
|
|
21
22
|
| IAgenticaEventJson.IValidate;
|
|
@@ -18,6 +18,7 @@ import type { IAgenticaHistoryJson } from "./IAgenticaHistoryJson";
|
|
|
18
18
|
* @author Samchon
|
|
19
19
|
*/
|
|
20
20
|
export type IMicroAgenticaHistoryJson =
|
|
21
|
-
| IAgenticaHistoryJson.
|
|
21
|
+
| IAgenticaHistoryJson.IUserMessage
|
|
22
|
+
| IAgenticaHistoryJson.IAssistantMessage
|
|
22
23
|
| IAgenticaHistoryJson.IExecute
|
|
23
24
|
| IAgenticaHistoryJson.IDescribe;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./IAgenticaEventJson";
|
|
2
|
+
export * from "./IAgenticaHistoryJson";
|
|
3
|
+
export * from "./IAgenticaOperationJson";
|
|
4
|
+
export * from "./IAgenticaOperationSelectionJson";
|
|
5
|
+
export * from "./IAgenticaTokenUsageJson";
|
|
6
|
+
export * from "./IMicroAgenticaEventJson";
|
|
7
|
+
export * from "./IMicroAgenticaHistoryJson";
|
package/src/orchestrate/call.ts
CHANGED
|
@@ -17,18 +17,18 @@ import type { AgenticaContext } from "../context/AgenticaContext";
|
|
|
17
17
|
import type { AgenticaOperation } from "../context/AgenticaOperation";
|
|
18
18
|
import type { MicroAgenticaContext } from "../context/MicroAgenticaContext";
|
|
19
19
|
import type { AgenticaCallEvent } from "../events/AgenticaCallEvent";
|
|
20
|
+
import type { AgenticaAssistantMessageHistory } from "../histories/AgenticaAssistantMessageHistory";
|
|
20
21
|
import type { AgenticaCancelHistory } from "../histories/AgenticaCancelHistory";
|
|
21
22
|
import type { AgenticaExecuteHistory } from "../histories/AgenticaExecuteHistory";
|
|
22
23
|
import type { AgenticaHistory } from "../histories/AgenticaHistory";
|
|
23
|
-
import type { AgenticaTextHistory } from "../histories/AgenticaTextHistory";
|
|
24
24
|
import type { MicroAgenticaHistory } from "../histories/MicroAgenticaHistory";
|
|
25
25
|
|
|
26
26
|
import { AgenticaConstant } from "../constants/AgenticaConstant";
|
|
27
27
|
import { AgenticaDefaultPrompt } from "../constants/AgenticaDefaultPrompt";
|
|
28
28
|
import { AgenticaSystemPrompt } from "../constants/AgenticaSystemPrompt";
|
|
29
29
|
import { isAgenticaContext } from "../context/internal/isAgenticaContext";
|
|
30
|
-
import { createCallEvent, createExecuteEvent,
|
|
31
|
-
import { createCancelHistory, createExecuteHistory,
|
|
30
|
+
import { creatAssistantEvent, createCallEvent, createExecuteEvent, createValidateEvent } from "../factory/events";
|
|
31
|
+
import { createAssistantMessageHistory, createCancelHistory, createExecuteHistory, decodeHistory, decodeUserMessageContent } from "../factory/histories";
|
|
32
32
|
import { createOperationSelection } from "../factory/operations";
|
|
33
33
|
import { ChatGptCompletionMessageUtil } from "../utils/ChatGptCompletionMessageUtil";
|
|
34
34
|
import { StreamUtil, toAsyncGenerator } from "../utils/StreamUtil";
|
|
@@ -54,7 +54,7 @@ export async function call<Model extends ILlmSchema.Model>(
|
|
|
54
54
|
// USER INPUT
|
|
55
55
|
{
|
|
56
56
|
role: "user",
|
|
57
|
-
content: ctx.prompt.contents,
|
|
57
|
+
content: ctx.prompt.contents.map(decodeUserMessageContent),
|
|
58
58
|
},
|
|
59
59
|
// SYSTEM PROMPT
|
|
60
60
|
...(ctx.config?.systemPrompt?.execute === null
|
|
@@ -104,7 +104,7 @@ export async function call<Model extends ILlmSchema.Model>(
|
|
|
104
104
|
Array<
|
|
105
105
|
| AgenticaExecuteHistory<Model>
|
|
106
106
|
| AgenticaCancelHistory<Model>
|
|
107
|
-
|
|
|
107
|
+
| AgenticaAssistantMessageHistory
|
|
108
108
|
>
|
|
109
109
|
>
|
|
110
110
|
> = [];
|
|
@@ -181,11 +181,11 @@ export async function call<Model extends ILlmSchema.Model>(
|
|
|
181
181
|
&& choice.message.content.length !== 0
|
|
182
182
|
) {
|
|
183
183
|
closures.push(async () => {
|
|
184
|
-
const value:
|
|
184
|
+
const value: AgenticaAssistantMessageHistory = createAssistantMessageHistory(
|
|
185
185
|
{ text: choice.message.content! },
|
|
186
186
|
);
|
|
187
187
|
ctx.dispatch(
|
|
188
|
-
|
|
188
|
+
creatAssistantEvent({
|
|
189
189
|
get: () => value.text,
|
|
190
190
|
done: () => true,
|
|
191
191
|
stream: toAsyncGenerator(value.text),
|
|
@@ -471,7 +471,7 @@ async function correct<Model extends ILlmSchema.Model>(
|
|
|
471
471
|
// USER INPUT
|
|
472
472
|
{
|
|
473
473
|
role: "user",
|
|
474
|
-
content: ctx.prompt.contents,
|
|
474
|
+
content: ctx.prompt.contents.map(decodeUserMessageContent),
|
|
475
475
|
},
|
|
476
476
|
// TYPE CORRECTION
|
|
477
477
|
...(ctx.config?.systemPrompt?.execute === null
|
|
@@ -16,7 +16,7 @@ import type { AgenticaCancelHistory } from "../histories/AgenticaCancelHistory";
|
|
|
16
16
|
import { AgenticaConstant } from "../constants/AgenticaConstant";
|
|
17
17
|
import { AgenticaDefaultPrompt } from "../constants/AgenticaDefaultPrompt";
|
|
18
18
|
import { AgenticaSystemPrompt } from "../constants/AgenticaSystemPrompt";
|
|
19
|
-
import { createCancelHistory, decodeHistory } from "../factory/histories";
|
|
19
|
+
import { createCancelHistory, decodeHistory, decodeUserMessageContent } from "../factory/histories";
|
|
20
20
|
import { ChatGptCompletionMessageUtil } from "../utils/ChatGptCompletionMessageUtil";
|
|
21
21
|
import { StreamUtil } from "../utils/StreamUtil";
|
|
22
22
|
|
|
@@ -141,7 +141,7 @@ async function step<Model extends ILlmSchema.Model>(ctx: AgenticaContext<Model>,
|
|
|
141
141
|
// USER INPUT
|
|
142
142
|
{
|
|
143
143
|
role: "user",
|
|
144
|
-
content: ctx.prompt.contents,
|
|
144
|
+
content: ctx.prompt.contents.map(decodeUserMessageContent),
|
|
145
145
|
},
|
|
146
146
|
// SYSTEM PROMPT
|
|
147
147
|
{
|
|
@@ -9,8 +9,8 @@ import type { AgenticaHistory } from "../histories/AgenticaHistory";
|
|
|
9
9
|
|
|
10
10
|
import { AgenticaDefaultPrompt } from "../constants/AgenticaDefaultPrompt";
|
|
11
11
|
import { AgenticaSystemPrompt } from "../constants/AgenticaSystemPrompt";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
12
|
+
import { creatAssistantEvent } from "../factory/events";
|
|
13
|
+
import { createAssistantMessageHistory, decodeHistory, decodeUserMessageContent } from "../factory/histories";
|
|
14
14
|
import { ChatGptCompletionMessageUtil } from "../utils/ChatGptCompletionMessageUtil";
|
|
15
15
|
import { MPSC } from "../utils/MPSC";
|
|
16
16
|
import { streamDefaultReaderToAsyncGenerator, StreamUtil } from "../utils/StreamUtil";
|
|
@@ -36,7 +36,7 @@ export async function initialize<Model extends ILlmSchema.Model>(ctx: AgenticaCo
|
|
|
36
36
|
// USER INPUT
|
|
37
37
|
{
|
|
38
38
|
role: "user",
|
|
39
|
-
content: ctx.prompt.contents,
|
|
39
|
+
content: ctx.prompt.contents.map(decodeUserMessageContent),
|
|
40
40
|
},
|
|
41
41
|
{
|
|
42
42
|
// SYSTEM PROMPT
|
|
@@ -107,7 +107,7 @@ export async function initialize<Model extends ILlmSchema.Model>(ctx: AgenticaCo
|
|
|
107
107
|
mpsc.produce(choice.delta.content);
|
|
108
108
|
|
|
109
109
|
ctx.dispatch(
|
|
110
|
-
|
|
110
|
+
creatAssistantEvent({
|
|
111
111
|
stream: streamDefaultReaderToAsyncGenerator(mpsc.consumer.getReader()),
|
|
112
112
|
done: () => mpsc.done(),
|
|
113
113
|
get: () => textContext[choice.index]!.content,
|
|
@@ -144,7 +144,7 @@ export async function initialize<Model extends ILlmSchema.Model>(ctx: AgenticaCo
|
|
|
144
144
|
&& choice.message.content.length !== 0
|
|
145
145
|
) {
|
|
146
146
|
prompts.push(
|
|
147
|
-
|
|
147
|
+
createAssistantMessageHistory({ text: choice.message.content }),
|
|
148
148
|
);
|
|
149
149
|
}
|
|
150
150
|
}
|
|
@@ -17,8 +17,8 @@ import type { AgenticaSelectHistory } from "../histories/AgenticaSelectHistory";
|
|
|
17
17
|
import { AgenticaConstant } from "../constants/AgenticaConstant";
|
|
18
18
|
import { AgenticaDefaultPrompt } from "../constants/AgenticaDefaultPrompt";
|
|
19
19
|
import { AgenticaSystemPrompt } from "../constants/AgenticaSystemPrompt";
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
20
|
+
import { creatAssistantEvent } from "../factory/events";
|
|
21
|
+
import { createAssistantMessageHistory, createSelectHistory, decodeHistory, decodeUserMessageContent } from "../factory/histories";
|
|
22
22
|
import { createOperationSelection } from "../factory/operations";
|
|
23
23
|
import { ChatGptCompletionMessageUtil } from "../utils/ChatGptCompletionMessageUtil";
|
|
24
24
|
import { StreamUtil, toAsyncGenerator } from "../utils/StreamUtil";
|
|
@@ -144,7 +144,7 @@ async function step<Model extends ILlmSchema.Model>(ctx: AgenticaContext<Model>,
|
|
|
144
144
|
// USER INPUT
|
|
145
145
|
{
|
|
146
146
|
role: "user",
|
|
147
|
-
content: ctx.prompt.contents,
|
|
147
|
+
content: ctx.prompt.contents.map(decodeUserMessageContent),
|
|
148
148
|
},
|
|
149
149
|
// SYSTEM PROMPT
|
|
150
150
|
{
|
|
@@ -259,11 +259,11 @@ async function step<Model extends ILlmSchema.Model>(ctx: AgenticaContext<Model>,
|
|
|
259
259
|
&& choice.message.content != null
|
|
260
260
|
&& choice.message.content.length !== 0
|
|
261
261
|
) {
|
|
262
|
-
const text =
|
|
262
|
+
const text = createAssistantMessageHistory({ text: choice.message.content });
|
|
263
263
|
prompts.push(text);
|
|
264
264
|
|
|
265
265
|
ctx.dispatch(
|
|
266
|
-
|
|
266
|
+
creatAssistantEvent({
|
|
267
267
|
stream: toAsyncGenerator(text.text),
|
|
268
268
|
join: async () => Promise.resolve(text.text),
|
|
269
269
|
done: () => true,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Client } from "@modelcontextprotocol/sdk/client/index.d.ts";
|
|
2
1
|
import type {
|
|
3
2
|
IHttpConnection,
|
|
4
3
|
IHttpLlmApplication,
|
|
@@ -126,7 +125,10 @@ export namespace IAgenticaController {
|
|
|
126
125
|
/**
|
|
127
126
|
* MCP client for connection.
|
|
128
127
|
*/
|
|
129
|
-
|
|
128
|
+
// @ts-ignore Type checking only when `@modelcontextprotocol/sdk` is installed.
|
|
129
|
+
// This strategy is useful for someone who does not need MCP,
|
|
130
|
+
// for someone who has not installed `@modelcontextprotocol/sdk`.
|
|
131
|
+
client: import("@modelcontextprotocol/sdk/client/index.d.ts").Client;
|
|
130
132
|
}
|
|
131
133
|
|
|
132
134
|
interface IBase<Protocol, Application> {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./IAgenticaConfig";
|
|
2
|
+
export * from "./IAgenticaController";
|
|
3
|
+
export * from "./IAgenticaExecutor";
|
|
4
|
+
export * from "./IAgenticaProps";
|
|
5
|
+
export * from "./IAgenticaSystemPrompt";
|
|
6
|
+
export * from "./IAgenticaVendor";
|
|
7
|
+
export * from "./IMicroAgenticaConfig";
|
|
8
|
+
export * from "./IMicroAgenticaExecutor";
|
|
9
|
+
export * from "./IMicroAgenticaProps";
|
|
10
|
+
export * from "./IMicroAgenticaSystemPrompt";
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
3
|
import type { AgenticaOperation } from "../context/AgenticaOperation";
|
|
4
|
+
import type { AgenticaUserMessageEvent, AgenticaValidateEvent } from "../events";
|
|
5
|
+
import type { AgenticaAssistantMessageEvent } from "../events/AgenticaAssistantMessageEvent";
|
|
4
6
|
import type { AgenticaCallEvent } from "../events/AgenticaCallEvent";
|
|
5
7
|
import type { AgenticaCancelEvent } from "../events/AgenticaCancelEvent";
|
|
6
8
|
import type { AgenticaDescribeEvent } from "../events/AgenticaDescribeEvent";
|
|
@@ -9,32 +11,16 @@ import type { AgenticaExecuteEvent } from "../events/AgenticaExecuteEvent";
|
|
|
9
11
|
import type { AgenticaInitializeEvent } from "../events/AgenticaInitializeEvent";
|
|
10
12
|
import type { AgenticaRequestEvent } from "../events/AgenticaRequestEvent";
|
|
11
13
|
import type { AgenticaSelectEvent } from "../events/AgenticaSelectEvent";
|
|
12
|
-
import type { AgenticaTextEvent } from "../events/AgenticaTextEvent";
|
|
13
14
|
import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
14
15
|
|
|
15
|
-
import { createCallEvent, createCancelEvent, createDescribeEvent, createExecuteEvent, createInitializeEvent, createRequestEvent, createSelectEvent,
|
|
16
|
+
import { creatAssistantEvent, createCallEvent, createCancelEvent, createDescribeEvent, createExecuteEvent, createInitializeEvent, createRequestEvent, createSelectEvent, createUserMessageEvent, createValidateEvent } from "../factory/events";
|
|
16
17
|
import { createOperationSelection } from "../factory/operations";
|
|
17
18
|
import { toAsyncGenerator } from "../utils/StreamUtil";
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
function: string;
|
|
24
|
-
};
|
|
25
|
-
}): AgenticaOperation<Model> {
|
|
26
|
-
const found: AgenticaOperation<Model> | undefined = props.operations
|
|
27
|
-
.get(props.input.controller)
|
|
28
|
-
?.get(props.input.function);
|
|
29
|
-
if (found === undefined) {
|
|
30
|
-
throw new Error(
|
|
31
|
-
`No operation found: (controller: ${props.input.controller}, function: ${props.input.function})`,
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
return found;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function transform<Model extends ILlmSchema.Model>(props: {
|
|
20
|
+
/**
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export function transformEvent<Model extends ILlmSchema.Model>(props: {
|
|
38
24
|
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
39
25
|
event: IAgenticaEventJson;
|
|
40
26
|
}): AgenticaEvent<Model> {
|
|
@@ -76,15 +62,26 @@ function transform<Model extends ILlmSchema.Model>(props: {
|
|
|
76
62
|
event: props.event,
|
|
77
63
|
});
|
|
78
64
|
}
|
|
79
|
-
else if (props.event.type === "
|
|
80
|
-
return
|
|
65
|
+
else if (props.event.type === "assistantMessage") {
|
|
66
|
+
return transformAssistantMessage({
|
|
67
|
+
event: props.event,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
else if (props.event.type === "userMessage") {
|
|
71
|
+
return transformUserMessage({
|
|
81
72
|
event: props.event,
|
|
82
73
|
});
|
|
83
74
|
}
|
|
84
|
-
|
|
75
|
+
return transformValidateEvent({
|
|
76
|
+
operations: props.operations,
|
|
77
|
+
event: props.event,
|
|
78
|
+
});
|
|
85
79
|
}
|
|
86
80
|
|
|
87
|
-
|
|
81
|
+
/**
|
|
82
|
+
* @internal
|
|
83
|
+
*/
|
|
84
|
+
export function transformCall<Model extends ILlmSchema.Model>(props: {
|
|
88
85
|
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
89
86
|
event: IAgenticaEventJson.ICall;
|
|
90
87
|
}): AgenticaCallEvent<Model> {
|
|
@@ -98,7 +95,10 @@ function transformCall<Model extends ILlmSchema.Model>(props: {
|
|
|
98
95
|
});
|
|
99
96
|
}
|
|
100
97
|
|
|
101
|
-
|
|
98
|
+
/**
|
|
99
|
+
* @internal
|
|
100
|
+
*/
|
|
101
|
+
function transformCancel<Model extends ILlmSchema.Model>(props: {
|
|
102
102
|
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
103
103
|
event: IAgenticaEventJson.ICancel;
|
|
104
104
|
}): AgenticaCancelEvent<Model> {
|
|
@@ -113,6 +113,9 @@ export function transformCancel<Model extends ILlmSchema.Model>(props: {
|
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
+
/**
|
|
117
|
+
* @internal
|
|
118
|
+
*/
|
|
116
119
|
function transformDescribe<Model extends ILlmSchema.Model>(props: {
|
|
117
120
|
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
118
121
|
event: IAgenticaEventJson.IDescribe;
|
|
@@ -131,6 +134,9 @@ function transformDescribe<Model extends ILlmSchema.Model>(props: {
|
|
|
131
134
|
});
|
|
132
135
|
}
|
|
133
136
|
|
|
137
|
+
/**
|
|
138
|
+
* @internal
|
|
139
|
+
*/
|
|
134
140
|
function transformExecute<Model extends ILlmSchema.Model>(props: {
|
|
135
141
|
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
136
142
|
event: IAgenticaEventJson.IExecute;
|
|
@@ -146,16 +152,25 @@ function transformExecute<Model extends ILlmSchema.Model>(props: {
|
|
|
146
152
|
});
|
|
147
153
|
}
|
|
148
154
|
|
|
155
|
+
/**
|
|
156
|
+
* @internal
|
|
157
|
+
*/
|
|
149
158
|
function transformInitialize(): AgenticaInitializeEvent {
|
|
150
159
|
return createInitializeEvent();
|
|
151
160
|
}
|
|
152
161
|
|
|
162
|
+
/**
|
|
163
|
+
* @internal
|
|
164
|
+
*/
|
|
153
165
|
function transformRequest(props: {
|
|
154
166
|
event: IAgenticaEventJson.IRequest;
|
|
155
167
|
}): AgenticaRequestEvent {
|
|
156
168
|
return createRequestEvent(props.event);
|
|
157
169
|
}
|
|
158
170
|
|
|
171
|
+
/**
|
|
172
|
+
* @internal
|
|
173
|
+
*/
|
|
159
174
|
function transformSelect<Model extends ILlmSchema.Model>(props: {
|
|
160
175
|
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
161
176
|
event: IAgenticaEventJson.ISelect;
|
|
@@ -171,10 +186,13 @@ function transformSelect<Model extends ILlmSchema.Model>(props: {
|
|
|
171
186
|
});
|
|
172
187
|
}
|
|
173
188
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
189
|
+
/**
|
|
190
|
+
* @internal
|
|
191
|
+
*/
|
|
192
|
+
function transformAssistantMessage(props: {
|
|
193
|
+
event: IAgenticaEventJson.IAssistantMessage;
|
|
194
|
+
}): AgenticaAssistantMessageEvent {
|
|
195
|
+
return creatAssistantEvent({
|
|
178
196
|
stream: toAsyncGenerator(props.event.text),
|
|
179
197
|
done: () => true,
|
|
180
198
|
get: () => props.event.text,
|
|
@@ -182,15 +200,49 @@ function transformText(props: {
|
|
|
182
200
|
});
|
|
183
201
|
}
|
|
184
202
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
203
|
+
/**
|
|
204
|
+
* @internal
|
|
205
|
+
*/
|
|
206
|
+
function transformUserMessage(props: {
|
|
207
|
+
event: IAgenticaEventJson.IUserMessage;
|
|
208
|
+
}): AgenticaUserMessageEvent {
|
|
209
|
+
return createUserMessageEvent(props.event);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* @internal
|
|
214
|
+
*/
|
|
215
|
+
function transformValidateEvent<Model extends ILlmSchema.Model>(props: {
|
|
216
|
+
event: IAgenticaEventJson.IValidate;
|
|
217
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
218
|
+
}): AgenticaValidateEvent<Model> {
|
|
219
|
+
return createValidateEvent({
|
|
220
|
+
id: props.event.id,
|
|
221
|
+
operation: findOperation({
|
|
222
|
+
operations: props.operations,
|
|
223
|
+
input: props.event.operation,
|
|
224
|
+
}),
|
|
225
|
+
result: props.event.result,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* @internal
|
|
231
|
+
*/
|
|
232
|
+
function findOperation<Model extends ILlmSchema.Model>(props: {
|
|
233
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
234
|
+
input: {
|
|
235
|
+
controller: string;
|
|
236
|
+
function: string;
|
|
237
|
+
};
|
|
238
|
+
}): AgenticaOperation<Model> {
|
|
239
|
+
const found: AgenticaOperation<Model> | undefined = props.operations
|
|
240
|
+
.get(props.input.controller)
|
|
241
|
+
?.get(props.input.function);
|
|
242
|
+
if (found === undefined) {
|
|
243
|
+
throw new Error(
|
|
244
|
+
`No operation found: (controller: ${props.input.controller}, function: ${props.input.function})`,
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
return found;
|
|
248
|
+
}
|