@agentica/core 0.24.0 → 0.26.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/README.md +56 -17
- 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/context/internal/AgenticaOperationComposer.spec.js +13 -5
- package/lib/context/internal/AgenticaOperationComposer.spec.js.map +1 -1
- package/lib/events/AgenticaAssistantMessageEvent.d.ts +9 -0
- package/lib/events/AgenticaAssistantMessageEvent.js +3 -0
- package/lib/events/AgenticaAssistantMessageEvent.js.map +1 -0
- package/lib/events/AgenticaEvent.d.ts +9 -9
- package/lib/events/AgenticaEvent.type.d.ts +1 -0
- package/lib/events/AgenticaEvent.type.js +8 -0
- package/lib/events/AgenticaEvent.type.js.map +1 -0
- 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 +103 -22
- 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/AgenticaAssistantMessageHistory.d.ts +5 -0
- package/lib/histories/AgenticaAssistantMessageHistory.js +3 -0
- package/lib/histories/AgenticaAssistantMessageHistory.js.map +1 -0
- package/lib/histories/AgenticaHistory.d.ts +9 -7
- package/lib/histories/{AgenticaTextHistory.d.ts → AgenticaSystemMessageHistory.d.ts} +1 -2
- package/lib/histories/{AgenticaUserInputHistory.js → AgenticaSystemMessageHistory.js} +1 -1
- package/lib/histories/AgenticaSystemMessageHistory.js.map +1 -0
- 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 +10 -0
- package/lib/histories/index.js +27 -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 +182 -131
- package/lib/index.mjs.map +1 -1
- package/lib/json/IAgenticaEventJson.d.ts +44 -19
- package/lib/json/IAgenticaEventJson.type.d.ts +1 -0
- package/lib/json/IAgenticaEventJson.type.js +8 -0
- package/lib/json/IAgenticaEventJson.type.js.map +1 -0
- package/lib/json/IAgenticaHistoryJson.d.ts +34 -19
- package/lib/json/IAgenticaHistoryJson.type.d.ts +1 -0
- package/lib/json/IAgenticaHistoryJson.type.js +8 -0
- package/lib/json/IAgenticaHistoryJson.type.js.map +1 -0
- 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/transformHistory.d.ts +1 -0
- package/lib/transformers/{AgenticaHistoryTransformer.js → transformHistory.js} +33 -23
- package/lib/transformers/transformHistory.js.map +1 -0
- package/lib/utils/ChatGptCompletionMessageUtil.js +2 -2
- package/lib/utils/types.d.ts +33 -0
- package/lib/utils/types.js +29 -0
- package/lib/utils/types.js.map +1 -0
- package/package.json +7 -7
- 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/context/internal/AgenticaOperationComposer.spec.ts +15 -5
- package/src/events/AgenticaAssistantMessageEvent.ts +12 -0
- package/src/events/AgenticaEvent.ts +15 -15
- package/src/events/AgenticaEvent.type.ts +19 -0
- 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 +120 -29
- package/src/functional/assertMcpController.ts +4 -2
- package/src/functional/index.ts +7 -0
- package/src/functional/validateMcpController.ts +4 -2
- package/src/histories/AgenticaAssistantMessageHistory.ts +10 -0
- package/src/histories/AgenticaHistory.ts +11 -8
- package/src/histories/{AgenticaTextHistory.ts → AgenticaSystemMessageHistory.ts} +4 -2
- 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 +10 -0
- package/src/index.ts +6 -54
- package/src/json/IAgenticaEventJson.ts +53 -21
- package/src/json/IAgenticaEventJson.type.ts +19 -0
- package/src/json/IAgenticaHistoryJson.ts +41 -23
- package/src/json/IAgenticaHistoryJson.type.ts +19 -0
- 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/{AgenticaHistoryTransformer.ts → transformHistory.ts} +43 -26
- package/src/utils/types.ts +50 -0
- 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 +0 -155
- 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
- package/src/transformers/AgenticaEventTransformer.ts +0 -196
package/src/factory/events.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { v4 } from "uuid";
|
|
|
5
5
|
|
|
6
6
|
import type { AgenticaOperation } from "../context/AgenticaOperation";
|
|
7
7
|
import type { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
|
|
8
|
+
import type { AgenticaAssistantMessageEvent } from "../events/AgenticaAssistantMessageEvent";
|
|
8
9
|
import type { AgenticaCallEvent } from "../events/AgenticaCallEvent";
|
|
9
10
|
import type { AgenticaCancelEvent } from "../events/AgenticaCancelEvent";
|
|
10
11
|
import type { AgenticaDescribeEvent } from "../events/AgenticaDescribeEvent";
|
|
@@ -14,14 +15,13 @@ import type { AgenticaInitializeEvent } from "../events/AgenticaInitializeEvent"
|
|
|
14
15
|
import type { AgenticaRequestEvent } from "../events/AgenticaRequestEvent";
|
|
15
16
|
import type { AgenticaResponseEvent } from "../events/AgenticaResponseEvent";
|
|
16
17
|
import type { AgenticaSelectEvent } from "../events/AgenticaSelectEvent";
|
|
17
|
-
import type {
|
|
18
|
-
import type { AgenticaUserInputEvent } from "../events/AgenticaUserInputEvent";
|
|
18
|
+
import type { AgenticaUserMessageEvent } from "../events/AgenticaUserMessageEvent";
|
|
19
19
|
import type { AgenticaValidateEvent } from "../events/AgenticaValidateEvent";
|
|
20
|
+
import type { AgenticaUserMessageContent } from "../histories";
|
|
20
21
|
import type { AgenticaExecuteHistory } from "../histories/AgenticaExecuteHistory";
|
|
21
|
-
import type { AgenticaUserInputHistory } from "../histories/AgenticaUserInputHistory";
|
|
22
22
|
import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
23
23
|
|
|
24
|
-
import { createExecuteHistory, createSelectHistory,
|
|
24
|
+
import { createExecuteHistory, createSelectHistory, createUserMessageHistory } from "./histories";
|
|
25
25
|
|
|
26
26
|
/* -----------------------------------------------------------
|
|
27
27
|
FUNCTION SELECTS
|
|
@@ -36,23 +36,6 @@ export function createInitializeEvent(): AgenticaInitializeEvent {
|
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export function createUserInputEvent(props: {
|
|
40
|
-
contents: Array<AgenticaUserInputHistory.Contents>;
|
|
41
|
-
}): AgenticaUserInputEvent {
|
|
42
|
-
return {
|
|
43
|
-
type: "user_input",
|
|
44
|
-
role: "user",
|
|
45
|
-
contents: props.contents,
|
|
46
|
-
join: async () => props.contents,
|
|
47
|
-
toJSON: () => ({
|
|
48
|
-
type: "user_input",
|
|
49
|
-
contents: props.contents,
|
|
50
|
-
}),
|
|
51
|
-
toHistory: () => createUserInputHistory({
|
|
52
|
-
contents: props.contents,
|
|
53
|
-
}),
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
39
|
export function createSelectEvent<Model extends ILlmSchema.Model>(props: {
|
|
57
40
|
selection: AgenticaOperationSelection<Model>;
|
|
58
41
|
}): AgenticaSelectEvent<Model> {
|
|
@@ -151,32 +134,44 @@ export function createExecuteEvent<Model extends ILlmSchema.Model>(props: {
|
|
|
151
134
|
}
|
|
152
135
|
|
|
153
136
|
/* -----------------------------------------------------------
|
|
154
|
-
|
|
137
|
+
CONTENTS
|
|
155
138
|
----------------------------------------------------------- */
|
|
156
|
-
export function
|
|
139
|
+
export function createUserMessageEvent(props: {
|
|
140
|
+
contents: Array<AgenticaUserMessageContent>;
|
|
141
|
+
}): AgenticaUserMessageEvent {
|
|
142
|
+
return {
|
|
143
|
+
type: "userMessage",
|
|
144
|
+
contents: props.contents,
|
|
145
|
+
toJSON: () => ({
|
|
146
|
+
type: "userMessage",
|
|
147
|
+
contents: props.contents,
|
|
148
|
+
}),
|
|
149
|
+
toHistory: () => createUserMessageHistory({
|
|
150
|
+
contents: props.contents,
|
|
151
|
+
}),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function creatAssistantEvent(props: {
|
|
157
156
|
stream: AsyncGenerator<string, undefined, undefined>;
|
|
158
157
|
done: () => boolean;
|
|
159
158
|
get: () => string;
|
|
160
159
|
join: () => Promise<string>;
|
|
161
|
-
}):
|
|
160
|
+
}): AgenticaAssistantMessageEvent {
|
|
162
161
|
return {
|
|
163
|
-
type: "
|
|
164
|
-
role: "assistant",
|
|
162
|
+
type: "assistantMessage",
|
|
165
163
|
stream: props.stream,
|
|
166
164
|
join: props.join,
|
|
167
165
|
toJSON: () => ({
|
|
168
|
-
type: "
|
|
169
|
-
role: "assistant",
|
|
166
|
+
type: "assistantMessage",
|
|
170
167
|
done: props.done(),
|
|
171
168
|
text: props.get(),
|
|
172
169
|
}),
|
|
173
170
|
toHistory: () => ({
|
|
174
|
-
type: "
|
|
175
|
-
role: "assistant",
|
|
171
|
+
type: "assistantMessage",
|
|
176
172
|
text: props.get(),
|
|
177
173
|
toJSON: () => ({
|
|
178
|
-
type: "
|
|
179
|
-
role: "assistant",
|
|
174
|
+
type: "assistantMessage",
|
|
180
175
|
text: props.get(),
|
|
181
176
|
}),
|
|
182
177
|
}),
|
|
@@ -215,8 +210,8 @@ export function createDescribeEvent<Model extends ILlmSchema.Model>(props: {
|
|
|
215
210
|
}
|
|
216
211
|
|
|
217
212
|
/* -----------------------------------------------------------
|
|
218
|
-
|
|
219
|
-
|
|
213
|
+
API REQUESTS
|
|
214
|
+
----------------------------------------------------------- */
|
|
220
215
|
export function createRequestEvent(props: {
|
|
221
216
|
source: AgenticaEventSource;
|
|
222
217
|
body: OpenAI.ChatCompletionCreateParamsStreaming;
|
package/src/factory/histories.ts
CHANGED
|
@@ -3,31 +3,26 @@ import type OpenAI from "openai";
|
|
|
3
3
|
|
|
4
4
|
import type { AgenticaOperation } from "../context/AgenticaOperation";
|
|
5
5
|
import type { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
|
|
6
|
+
import type { AgenticaUserMessageContent } from "../histories";
|
|
7
|
+
import type { AgenticaAssistantMessageHistory } from "../histories/AgenticaAssistantMessageHistory";
|
|
6
8
|
import type { AgenticaCancelHistory } from "../histories/AgenticaCancelHistory";
|
|
7
9
|
import type { AgenticaDescribeHistory } from "../histories/AgenticaDescribeHistory";
|
|
8
10
|
import type { AgenticaExecuteHistory } from "../histories/AgenticaExecuteHistory";
|
|
9
11
|
import type { AgenticaHistory } from "../histories/AgenticaHistory";
|
|
10
12
|
import type { AgenticaSelectHistory } from "../histories/AgenticaSelectHistory";
|
|
11
|
-
import type {
|
|
12
|
-
import type {
|
|
13
|
+
import type { AgenticaSystemMessageHistory } from "../histories/AgenticaSystemMessageHistory";
|
|
14
|
+
import type { AgenticaUserMessageHistory } from "../histories/AgenticaUserMessageHistory";
|
|
13
15
|
import type { IAgenticaHistoryJson } from "../json/IAgenticaHistoryJson";
|
|
14
16
|
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
15
20
|
export function decodeHistory<Model extends ILlmSchema.Model>(history: AgenticaHistory<Model>): OpenAI.ChatCompletionMessageParam[] {
|
|
16
21
|
// NO NEED TO DECODE DESCRIBE
|
|
17
22
|
if (history.type === "describe") {
|
|
18
23
|
return [];
|
|
19
24
|
}
|
|
20
|
-
|
|
21
|
-
if (history.type === "text") {
|
|
22
|
-
return [
|
|
23
|
-
{
|
|
24
|
-
role: history.role,
|
|
25
|
-
content: history.text,
|
|
26
|
-
},
|
|
27
|
-
];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (history.type === "select" || history.type === "cancel") {
|
|
25
|
+
else if (history.type === "select" || history.type === "cancel") {
|
|
31
26
|
return [
|
|
32
27
|
{
|
|
33
28
|
role: "assistant",
|
|
@@ -54,8 +49,7 @@ export function decodeHistory<Model extends ILlmSchema.Model>(history: AgenticaH
|
|
|
54
49
|
},
|
|
55
50
|
];
|
|
56
51
|
}
|
|
57
|
-
|
|
58
|
-
if (history.type === "execute") {
|
|
52
|
+
else if (history.type === "execute") {
|
|
59
53
|
return [
|
|
60
54
|
{
|
|
61
55
|
role: "assistant",
|
|
@@ -99,31 +93,98 @@ export function decodeHistory<Model extends ILlmSchema.Model>(history: AgenticaH
|
|
|
99
93
|
];
|
|
100
94
|
}
|
|
101
95
|
|
|
102
|
-
if (history.type === "
|
|
96
|
+
if (history.type === "assistantMessage") {
|
|
97
|
+
return [
|
|
98
|
+
{
|
|
99
|
+
role: "assistant",
|
|
100
|
+
content: history.text,
|
|
101
|
+
},
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (history.type === "systemMessage") {
|
|
106
|
+
return [
|
|
107
|
+
{
|
|
108
|
+
role: "system",
|
|
109
|
+
content: history.text,
|
|
110
|
+
},
|
|
111
|
+
];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (history.type === "userMessage") {
|
|
115
|
+
const contents = history.contents;
|
|
103
116
|
return [
|
|
104
117
|
{
|
|
105
118
|
role: "user",
|
|
106
|
-
content:
|
|
119
|
+
content: contents.map(decodeUserMessageContent),
|
|
107
120
|
},
|
|
108
121
|
];
|
|
109
122
|
}
|
|
110
123
|
|
|
111
124
|
history satisfies never;
|
|
112
|
-
throw new Error(
|
|
125
|
+
throw new Error(`Unsupported history type, value: ${JSON.stringify(history)}`);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @internal
|
|
130
|
+
*/
|
|
131
|
+
export function decodeUserMessageContent(content: AgenticaUserMessageContent): OpenAI.ChatCompletionContentPart {
|
|
132
|
+
if (content.type === "text") {
|
|
133
|
+
return content;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (content.type === "audio") {
|
|
137
|
+
return {
|
|
138
|
+
type: "input_audio",
|
|
139
|
+
input_audio: {
|
|
140
|
+
data: content.data,
|
|
141
|
+
format: content.format,
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (content.type === "file") {
|
|
147
|
+
return {
|
|
148
|
+
type: "file",
|
|
149
|
+
file: content.file.type === "data"
|
|
150
|
+
? {
|
|
151
|
+
file_data: content.file.data,
|
|
152
|
+
filename: content.file.name,
|
|
153
|
+
}
|
|
154
|
+
: {
|
|
155
|
+
file_id: content.file.id,
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (content.type === "image") {
|
|
161
|
+
return {
|
|
162
|
+
type: "image_url",
|
|
163
|
+
image_url: {
|
|
164
|
+
url: content.url,
|
|
165
|
+
detail: content.detail,
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
content satisfies never;
|
|
171
|
+
throw new Error(`Unsupported user message content type, value: ${JSON.stringify(content)}`);
|
|
113
172
|
}
|
|
114
173
|
|
|
115
174
|
/* -----------------------------------------------------------
|
|
116
175
|
USER INPUT PROMPTS
|
|
117
176
|
----------------------------------------------------------- */
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
177
|
+
/**
|
|
178
|
+
* @internal
|
|
179
|
+
*/
|
|
180
|
+
export function createUserMessageHistory(props: {
|
|
181
|
+
contents: Array<AgenticaUserMessageContent>;
|
|
182
|
+
}): AgenticaUserMessageHistory {
|
|
121
183
|
return {
|
|
122
|
-
type: "
|
|
123
|
-
role: "user",
|
|
184
|
+
type: "userMessage",
|
|
124
185
|
contents: props.contents,
|
|
125
186
|
toJSON: () => ({
|
|
126
|
-
type: "
|
|
187
|
+
type: "userMessage",
|
|
127
188
|
contents: props.contents,
|
|
128
189
|
}),
|
|
129
190
|
};
|
|
@@ -132,12 +193,30 @@ export function createUserInputHistory(props: {
|
|
|
132
193
|
/* -----------------------------------------------------------
|
|
133
194
|
TEXT PROMPTS
|
|
134
195
|
----------------------------------------------------------- */
|
|
135
|
-
|
|
196
|
+
/**
|
|
197
|
+
* @internal
|
|
198
|
+
*/
|
|
199
|
+
export function createAssistantMessageHistory(props: {
|
|
200
|
+
text: string;
|
|
201
|
+
}): AgenticaAssistantMessageHistory {
|
|
202
|
+
const prompt: IAgenticaHistoryJson.IAssistantMessage = {
|
|
203
|
+
type: "assistantMessage",
|
|
204
|
+
text: props.text,
|
|
205
|
+
};
|
|
206
|
+
return {
|
|
207
|
+
...prompt,
|
|
208
|
+
toJSON: () => prompt,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* @internal
|
|
214
|
+
*/
|
|
215
|
+
export function createSystemMessageHistory(props: {
|
|
136
216
|
text: string;
|
|
137
|
-
}):
|
|
138
|
-
const prompt: IAgenticaHistoryJson.
|
|
139
|
-
type: "
|
|
140
|
-
role: "assistant",
|
|
217
|
+
}): AgenticaSystemMessageHistory {
|
|
218
|
+
const prompt: IAgenticaHistoryJson.ISystemMessage = {
|
|
219
|
+
type: "systemMessage",
|
|
141
220
|
text: props.text,
|
|
142
221
|
};
|
|
143
222
|
return {
|
|
@@ -146,6 +225,9 @@ export function createTextHistory(props: {
|
|
|
146
225
|
};
|
|
147
226
|
}
|
|
148
227
|
|
|
228
|
+
/**
|
|
229
|
+
* @internal
|
|
230
|
+
*/
|
|
149
231
|
export function createDescribeHistory<Model extends ILlmSchema.Model>(props: {
|
|
150
232
|
executes: AgenticaExecuteHistory<Model>[];
|
|
151
233
|
text: string;
|
|
@@ -165,6 +247,9 @@ export function createDescribeHistory<Model extends ILlmSchema.Model>(props: {
|
|
|
165
247
|
/* -----------------------------------------------------------
|
|
166
248
|
FUNCTION CALLING PROMPTS
|
|
167
249
|
----------------------------------------------------------- */
|
|
250
|
+
/**
|
|
251
|
+
* @internal
|
|
252
|
+
*/
|
|
168
253
|
export function createSelectHistory<Model extends ILlmSchema.Model>(props: {
|
|
169
254
|
id: string;
|
|
170
255
|
selections: AgenticaOperationSelection<Model>[];
|
|
@@ -181,6 +266,9 @@ export function createSelectHistory<Model extends ILlmSchema.Model>(props: {
|
|
|
181
266
|
};
|
|
182
267
|
}
|
|
183
268
|
|
|
269
|
+
/**
|
|
270
|
+
* @internal
|
|
271
|
+
*/
|
|
184
272
|
export function createCancelHistory<Model extends ILlmSchema.Model>(props: {
|
|
185
273
|
id: string;
|
|
186
274
|
selections: AgenticaOperationSelection<Model>[];
|
|
@@ -197,6 +285,9 @@ export function createCancelHistory<Model extends ILlmSchema.Model>(props: {
|
|
|
197
285
|
};
|
|
198
286
|
}
|
|
199
287
|
|
|
288
|
+
/**
|
|
289
|
+
* @internal
|
|
290
|
+
*/
|
|
200
291
|
export function createExecuteHistory<
|
|
201
292
|
Model extends ILlmSchema.Model,
|
|
202
293
|
>(props: {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Client } from "@modelcontextprotocol/sdk/client/index.d.ts";
|
|
2
1
|
import type { ILlmSchema, IMcpLlmApplication, IMcpTool } from "@samchon/openapi";
|
|
3
2
|
|
|
4
3
|
import { McpLlm } from "@samchon/openapi";
|
|
@@ -23,8 +22,11 @@ import type { IAgenticaController } from "../structures/IAgenticaController";
|
|
|
23
22
|
*/
|
|
24
23
|
export async function assertMcpController<Model extends ILlmSchema.Model>(props: {
|
|
25
24
|
name: string;
|
|
26
|
-
client: Client;
|
|
27
25
|
model: Model;
|
|
26
|
+
// @ts-ignore Type checking only when `@modelcontextprotocol/sdk` is installed.
|
|
27
|
+
// This strategy is useful for someone who does not need MCP,
|
|
28
|
+
// for someone who has not installed `@modelcontextprotocol/sdk`.
|
|
29
|
+
client: import("@modelcontextprotocol/sdk/client/index.d.ts").Client;
|
|
28
30
|
options?: Partial<IMcpLlmApplication.IOptions<Model>>;
|
|
29
31
|
}): Promise<IAgenticaController.IMcp<Model>> {
|
|
30
32
|
// for peerDependencies
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./assertHttpController";
|
|
2
|
+
export * from "./assertHttpLlmApplication"; // deprecated
|
|
3
|
+
export * from "./assertMcpController";
|
|
4
|
+
export * from "./validateHttpController"; // deprecated
|
|
5
|
+
|
|
6
|
+
export * from "./validateHttpLlmApplication";
|
|
7
|
+
export * from "./validateMcpController";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Client } from "@modelcontextprotocol/sdk/client/index.d.ts";
|
|
2
1
|
import type { ILlmSchema, IMcpLlmApplication, IMcpTool, IValidation } from "@samchon/openapi";
|
|
3
2
|
|
|
4
3
|
import { McpLlm } from "@samchon/openapi";
|
|
@@ -25,7 +24,10 @@ export async function validateMcpController<
|
|
|
25
24
|
Model extends ILlmSchema.Model,
|
|
26
25
|
>(props: {
|
|
27
26
|
name: string;
|
|
28
|
-
|
|
27
|
+
// @ts-ignore Type checking only when `@modelcontextprotocol/sdk` is installed.
|
|
28
|
+
// This strategy is useful for someone who does not need MCP,
|
|
29
|
+
// for someone who has not installed `@modelcontextprotocol/sdk`.
|
|
30
|
+
client: import("@modelcontextprotocol/sdk/client/index.d.ts").Client;
|
|
29
31
|
model: Model;
|
|
30
32
|
options?: Partial<IMcpLlmApplication.IOptions<Model>>;
|
|
31
33
|
}): Promise<IValidation<IAgenticaController.IMcp<Model>>> {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IAgenticaHistoryJson } from "../json/IAgenticaHistoryJson";
|
|
2
|
+
|
|
3
|
+
import type { AgenticaHistoryBase } from "./AgenticaHistoryBase";
|
|
4
|
+
|
|
5
|
+
export interface AgenticaAssistantMessageHistory extends AgenticaHistoryBase<
|
|
6
|
+
"assistantMessage",
|
|
7
|
+
IAgenticaHistoryJson.IAssistantMessage
|
|
8
|
+
> {
|
|
9
|
+
text: string;
|
|
10
|
+
}
|
|
@@ -1,27 +1,30 @@
|
|
|
1
1
|
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
+
import type { AgenticaAssistantMessageHistory } from "./AgenticaAssistantMessageHistory";
|
|
3
4
|
import type { AgenticaCancelHistory } from "./AgenticaCancelHistory";
|
|
4
5
|
import type { AgenticaDescribeHistory } from "./AgenticaDescribeHistory";
|
|
5
6
|
import type { AgenticaExecuteHistory } from "./AgenticaExecuteHistory";
|
|
6
7
|
import type { AgenticaSelectHistory } from "./AgenticaSelectHistory";
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
8
|
+
import type { AgenticaSystemMessageHistory } from "./AgenticaSystemMessageHistory";
|
|
9
|
+
import type { AgenticaUserMessageHistory } from "./AgenticaUserMessageHistory";
|
|
9
10
|
|
|
10
11
|
export type AgenticaHistory<Model extends ILlmSchema.Model> =
|
|
11
12
|
| AgenticaCancelHistory<Model>
|
|
12
13
|
| AgenticaDescribeHistory<Model>
|
|
13
14
|
| AgenticaExecuteHistory<Model>
|
|
14
15
|
| AgenticaSelectHistory<Model>
|
|
15
|
-
|
|
|
16
|
-
|
|
|
16
|
+
| AgenticaAssistantMessageHistory
|
|
17
|
+
| AgenticaUserMessageHistory
|
|
18
|
+
| AgenticaSystemMessageHistory;
|
|
17
19
|
export namespace AgenticaHistory {
|
|
18
20
|
export type Type = AgenticaHistory<any>["type"];
|
|
19
21
|
export interface Mapper<Model extends ILlmSchema.Model> {
|
|
22
|
+
select: AgenticaSelectHistory<Model>;
|
|
20
23
|
cancel: AgenticaCancelHistory<Model>;
|
|
21
|
-
describe: AgenticaDescribeHistory<Model>;
|
|
22
24
|
execute: AgenticaExecuteHistory<Model>;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
describe: AgenticaDescribeHistory<Model>;
|
|
26
|
+
assistantMessage: AgenticaAssistantMessageHistory;
|
|
27
|
+
systemMessage: AgenticaSystemMessageHistory;
|
|
28
|
+
userMessage: AgenticaUserMessageHistory;
|
|
26
29
|
}
|
|
27
30
|
}
|
|
@@ -2,7 +2,9 @@ import type { IAgenticaHistoryJson } from "../json/IAgenticaHistoryJson";
|
|
|
2
2
|
|
|
3
3
|
import type { AgenticaHistoryBase } from "./AgenticaHistoryBase";
|
|
4
4
|
|
|
5
|
-
export interface
|
|
6
|
-
|
|
5
|
+
export interface AgenticaSystemMessageHistory extends AgenticaHistoryBase<
|
|
6
|
+
"systemMessage",
|
|
7
|
+
IAgenticaHistoryJson.ISystemMessage
|
|
8
|
+
> {
|
|
7
9
|
text: string;
|
|
8
10
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IAgenticaHistoryJson } from "../json/IAgenticaHistoryJson";
|
|
2
|
+
|
|
3
|
+
import type { AgenticaHistoryBase } from "./AgenticaHistoryBase";
|
|
4
|
+
import type { AgenticaUserMessageContent } from "./contents/AgenticaUserMessageContent";
|
|
5
|
+
|
|
6
|
+
export interface AgenticaUserMessageHistory extends AgenticaHistoryBase<
|
|
7
|
+
"userMessage",
|
|
8
|
+
IAgenticaHistoryJson.IUserMessage
|
|
9
|
+
> {
|
|
10
|
+
contents: AgenticaUserMessageContent[];
|
|
11
|
+
}
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
+
import type { AgenticaAssistantMessageHistory } from "./AgenticaAssistantMessageHistory";
|
|
3
4
|
import type { AgenticaDescribeHistory } from "./AgenticaDescribeHistory";
|
|
4
5
|
import type { AgenticaExecuteHistory } from "./AgenticaExecuteHistory";
|
|
5
|
-
import type {
|
|
6
|
-
import type { AgenticaUserInputHistory } from "./AgenticaUserInputHistory";
|
|
6
|
+
import type { AgenticaUserMessageHistory } from "./AgenticaUserMessageHistory";
|
|
7
7
|
|
|
8
8
|
export type MicroAgenticaHistory<Model extends ILlmSchema.Model> =
|
|
9
9
|
| AgenticaDescribeHistory<Model>
|
|
10
10
|
| AgenticaExecuteHistory<Model>
|
|
11
|
-
|
|
|
12
|
-
|
|
|
11
|
+
| AgenticaAssistantMessageHistory
|
|
12
|
+
| AgenticaUserMessageHistory;
|
|
13
13
|
export namespace MicroAgenticaHistory {
|
|
14
14
|
export type Type = MicroAgenticaHistory<any>["type"];
|
|
15
15
|
export interface Mapper<Model extends ILlmSchema.Model> {
|
|
16
16
|
describe: AgenticaDescribeHistory<Model>;
|
|
17
17
|
execute: AgenticaExecuteHistory<Model>;
|
|
18
|
-
|
|
18
|
+
userMessage: AgenticaUserMessageHistory;
|
|
19
|
+
assistantMessage: AgenticaAssistantMessageHistory;
|
|
19
20
|
}
|
|
20
21
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AgenticaUserMessageContentBase } from "./AgenticaUserMessageContentBase";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Audio content by user.
|
|
5
|
+
*
|
|
6
|
+
* @reference https://platform.openai.com/docs/guides/audio
|
|
7
|
+
* @warning We not recommend it because audio data only support base64
|
|
8
|
+
* so it's too big data
|
|
9
|
+
* @author SunRabbit
|
|
10
|
+
*/
|
|
11
|
+
export interface AgenticaUserMessageAudioContent extends AgenticaUserMessageContentBase<"audio"> {
|
|
12
|
+
/**
|
|
13
|
+
* Base64 encoded audio data.
|
|
14
|
+
*/
|
|
15
|
+
data: string;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The format of the encoded audio data. Currently supports "wav" and "mp3".
|
|
19
|
+
*/
|
|
20
|
+
format: "wav" | "mp3";
|
|
21
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AgenticaUserMessageAudioContent } from "./AgenticaUserMessageAudioContent";
|
|
2
|
+
import type { AgenticaUserMessageFileContent } from "./AgenticaUserMessageFileContent";
|
|
3
|
+
import type { AgenticaUserMessageImageContent } from "./AgenticaUserMessageImageContent";
|
|
4
|
+
import type { AgenticaUserMessageTextContent } from "./AgenticaUserMessageTextContent";
|
|
5
|
+
|
|
6
|
+
export type AgenticaUserMessageContent =
|
|
7
|
+
| AgenticaUserMessageAudioContent
|
|
8
|
+
| AgenticaUserMessageFileContent
|
|
9
|
+
| AgenticaUserMessageImageContent
|
|
10
|
+
| AgenticaUserMessageTextContent;
|
|
11
|
+
export namespace AgenticaUserMessageContent {
|
|
12
|
+
export type Type = AgenticaUserMessageContent["type"];
|
|
13
|
+
export interface Mapper {
|
|
14
|
+
audio: AgenticaUserMessageAudioContent;
|
|
15
|
+
file: AgenticaUserMessageFileContent;
|
|
16
|
+
image: AgenticaUserMessageImageContent;
|
|
17
|
+
text: AgenticaUserMessageTextContent;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AgenticaUserMessageContentBase } from "./AgenticaUserMessageContentBase";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* File content by user.
|
|
5
|
+
*
|
|
6
|
+
* @reference https://platform.openai.com/docs/api-reference/uploads/create
|
|
7
|
+
* @author SunRabbit
|
|
8
|
+
*/
|
|
9
|
+
export interface AgenticaUserMessageFileContent extends AgenticaUserMessageContentBase<"file"> {
|
|
10
|
+
/**
|
|
11
|
+
* Reference to the pre-uploaded file or the data itself.
|
|
12
|
+
*
|
|
13
|
+
* @todo Properly define independent interface
|
|
14
|
+
*/
|
|
15
|
+
file: AgenticaUserMessageFileContent.IReference | AgenticaUserMessageFileContent.IData;
|
|
16
|
+
}
|
|
17
|
+
export namespace AgenticaUserMessageFileContent {
|
|
18
|
+
export interface IReference {
|
|
19
|
+
type: "reference";
|
|
20
|
+
id: string;
|
|
21
|
+
}
|
|
22
|
+
export interface IData {
|
|
23
|
+
type: "data";
|
|
24
|
+
name: string;
|
|
25
|
+
data: string;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { tags } from "typia";
|
|
2
|
+
|
|
3
|
+
import type { AgenticaUserMessageContentBase } from "./AgenticaUserMessageContentBase";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Image content by user.
|
|
7
|
+
*
|
|
8
|
+
* @reference https://platform.openai.com/docs/guides/vision
|
|
9
|
+
* @author SunRabbit
|
|
10
|
+
*/
|
|
11
|
+
export interface AgenticaUserMessageImageContent extends AgenticaUserMessageContentBase<"image"> {
|
|
12
|
+
/**
|
|
13
|
+
* Image URL.
|
|
14
|
+
*/
|
|
15
|
+
url: string & tags.Format<"url">;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Specifies the detail level of the image.
|
|
19
|
+
*
|
|
20
|
+
* @reference https://platform.openai.com/docs/guides/vision#low-or-high-fidelity-image-understanding
|
|
21
|
+
*/
|
|
22
|
+
detail?: "auto" | "high" | "low" | undefined;
|
|
23
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AgenticaUserMessageContentBase } from "./AgenticaUserMessageContentBase";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Text content by user.
|
|
5
|
+
*
|
|
6
|
+
* @reference https://platform.openai.com/docs/guides/text-generation
|
|
7
|
+
* @author Samchon
|
|
8
|
+
* @author SunRabbit
|
|
9
|
+
*/
|
|
10
|
+
export interface AgenticaUserMessageTextContent extends AgenticaUserMessageContentBase<"text"> {
|
|
11
|
+
/**
|
|
12
|
+
* The text content.
|
|
13
|
+
*/
|
|
14
|
+
text: string;
|
|
15
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./AgenticaAssistantMessageHistory";
|
|
2
|
+
export * from "./AgenticaCancelHistory";
|
|
3
|
+
export * from "./AgenticaDescribeHistory";
|
|
4
|
+
export * from "./AgenticaExecuteHistory";
|
|
5
|
+
export * from "./AgenticaHistory";
|
|
6
|
+
export * from "./AgenticaSelectHistory";
|
|
7
|
+
export * from "./AgenticaSystemMessageHistory";
|
|
8
|
+
export * from "./AgenticaUserMessageHistory";
|
|
9
|
+
export * from "./contents";
|
|
10
|
+
export * from "./MicroAgenticaHistory";
|