@agentica/core 0.34.2 → 0.35.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 +9 -10
- package/lib/Agentica.js.map +1 -1
- package/lib/MicroAgentica.d.ts +9 -10
- package/lib/MicroAgentica.js.map +1 -1
- package/lib/constants/AgenticaDefaultPrompt.d.ts +1 -2
- package/lib/constants/AgenticaDefaultPrompt.js.map +1 -1
- package/lib/context/AgenticaContext.d.ts +6 -7
- package/lib/context/AgenticaOperation.d.ts +5 -5
- package/lib/context/AgenticaOperationCollection.d.ts +5 -6
- package/lib/context/AgenticaOperationSelection.d.ts +2 -3
- package/lib/context/MicroAgenticaContext.d.ts +5 -6
- package/lib/context/internal/AgenticaOperationComposer.js.map +1 -1
- package/lib/context/internal/AgenticaOperationComposer.spec.js +41 -9
- package/lib/context/internal/AgenticaOperationComposer.spec.js.map +1 -1
- package/lib/context/internal/__IChatInitialApplication.d.ts +1 -1
- package/lib/context/internal/isAgenticaContext.js.map +1 -1
- package/lib/events/AgenticaCallEvent.d.ts +2 -3
- package/lib/events/AgenticaCancelEvent.d.ts +2 -3
- package/lib/events/AgenticaDescribeEvent.d.ts +3 -4
- package/lib/events/AgenticaEvent.d.ts +10 -11
- package/lib/events/AgenticaExecuteEvent.d.ts +5 -5
- package/lib/events/AgenticaJsonParseErrorEvent.d.ts +2 -3
- package/lib/events/AgenticaSelectEvent.d.ts +3 -4
- package/lib/events/AgenticaValidateEvent.d.ts +2 -3
- package/lib/events/MicroAgenticaEvent.d.ts +8 -9
- package/lib/factory/events.d.ts +22 -22
- package/lib/factory/events.js.map +1 -1
- package/lib/factory/histories.js.map +1 -1
- package/lib/factory/operations.d.ts +3 -4
- package/lib/factory/operations.js.map +1 -1
- package/lib/functional/assertHttpController.d.ts +6 -10
- package/lib/functional/assertHttpController.js +775 -91
- package/lib/functional/assertHttpController.js.map +1 -1
- package/lib/functional/assertHttpLlmApplication.d.ts +4 -8
- package/lib/functional/assertHttpLlmApplication.js +775 -91
- package/lib/functional/assertHttpLlmApplication.js.map +1 -1
- package/lib/functional/assertMcpController.d.ts +5 -6
- package/lib/functional/assertMcpController.js +201 -32
- package/lib/functional/assertMcpController.js.map +1 -1
- package/lib/functional/validateHttpController.d.ts +6 -10
- package/lib/functional/validateHttpController.js +636 -89
- package/lib/functional/validateHttpController.js.map +1 -1
- package/lib/functional/validateHttpLlmApplication.d.ts +4 -8
- package/lib/functional/validateHttpLlmApplication.js +636 -89
- package/lib/functional/validateHttpLlmApplication.js.map +1 -1
- package/lib/functional/validateMcpController.d.ts +5 -6
- package/lib/functional/validateMcpController.js +366 -61
- package/lib/functional/validateMcpController.js.map +1 -1
- package/lib/histories/AgenticaCancelHistory.d.ts +2 -3
- package/lib/histories/AgenticaDescribeHistory.d.ts +2 -3
- package/lib/histories/AgenticaExecuteHistory.d.ts +5 -5
- package/lib/histories/AgenticaHistory.d.ts +7 -8
- package/lib/histories/AgenticaSelectHistory.d.ts +2 -3
- package/lib/histories/MicroAgenticaHistory.d.ts +5 -6
- package/lib/index.mjs +3964 -849
- package/lib/index.mjs.map +1 -1
- package/lib/orchestrate/call.d.ts +1 -2
- package/lib/orchestrate/call.js.map +1 -1
- package/lib/orchestrate/cancel.d.ts +1 -2
- package/lib/orchestrate/cancel.js +4 -4
- package/lib/orchestrate/cancel.js.map +1 -1
- package/lib/orchestrate/describe.d.ts +1 -2
- package/lib/orchestrate/describe.js.map +1 -1
- package/lib/orchestrate/execute.d.ts +1 -2
- package/lib/orchestrate/execute.js.map +1 -1
- package/lib/orchestrate/initialize.d.ts +1 -2
- package/lib/orchestrate/initialize.js +262 -83
- package/lib/orchestrate/initialize.js.map +1 -1
- package/lib/orchestrate/internal/cancelFunctionFromContext.js.map +1 -1
- package/lib/orchestrate/internal/selectFunctionFromContext.js.map +1 -1
- package/lib/orchestrate/select.d.ts +1 -2
- package/lib/orchestrate/select.js +4 -4
- package/lib/orchestrate/select.js.map +1 -1
- package/lib/structures/IAgenticaConfig.d.ts +3 -4
- package/lib/structures/IAgenticaController.d.ts +11 -14
- package/lib/structures/IAgenticaExecutor.d.ts +6 -7
- package/lib/structures/IAgenticaProps.d.ts +3 -8
- package/lib/structures/IAgenticaSystemPrompt.d.ts +9 -10
- package/lib/structures/IMicroAgenticaConfig.d.ts +3 -4
- package/lib/structures/IMicroAgenticaExecutor.d.ts +3 -4
- package/lib/structures/IMicroAgenticaProps.d.ts +3 -8
- package/lib/structures/IMicroAgenticaSystemPrompt.d.ts +6 -7
- package/lib/transformers/transformHistory.js.map +1 -1
- package/lib/utils/ChatGptCompletionStreamingUtil.spec.js +2 -2
- package/lib/utils/ChatGptCompletionStreamingUtil.spec.js.map +1 -1
- package/lib/utils/request.d.ts +2 -3
- package/lib/utils/request.js.map +1 -1
- package/package.json +8 -8
- package/src/Agentica.ts +24 -26
- package/src/MicroAgentica.ts +27 -29
- package/src/constants/AgenticaDefaultPrompt.ts +2 -4
- package/src/context/AgenticaContext.ts +6 -7
- package/src/context/AgenticaOperation.ts +14 -14
- package/src/context/AgenticaOperationCollection.ts +5 -8
- package/src/context/AgenticaOperationSelection.ts +2 -4
- package/src/context/MicroAgenticaContext.ts +5 -6
- package/src/context/internal/AgenticaOperationComposer.spec.ts +50 -18
- package/src/context/internal/AgenticaOperationComposer.ts +21 -23
- package/src/context/internal/__IChatInitialApplication.ts +1 -1
- package/src/context/internal/isAgenticaContext.ts +4 -6
- package/src/events/AgenticaCallEvent.ts +2 -5
- package/src/events/AgenticaCancelEvent.ts +2 -6
- package/src/events/AgenticaDescribeEvent.ts +3 -7
- package/src/events/AgenticaEvent.ts +17 -19
- package/src/events/AgenticaEvent.type.ts +1 -1
- package/src/events/AgenticaExecuteEvent.ts +12 -12
- package/src/events/AgenticaJsonParseErrorEvent.ts +2 -4
- package/src/events/AgenticaSelectEvent.ts +3 -7
- package/src/events/AgenticaValidateEvent.ts +2 -5
- package/src/events/MicroAgenticaEvent.ts +13 -15
- package/src/factory/events.ts +24 -24
- package/src/factory/histories.ts +15 -17
- package/src/factory/operations.ts +3 -5
- package/src/functional/assertHttpController.ts +7 -15
- package/src/functional/assertHttpLlmApplication.ts +4 -13
- package/src/functional/assertMcpController.ts +6 -8
- package/src/functional/validateHttpController.ts +7 -15
- package/src/functional/validateHttpLlmApplication.ts +4 -13
- package/src/functional/validateMcpController.ts +6 -11
- package/src/histories/AgenticaCancelHistory.ts +2 -6
- package/src/histories/AgenticaDescribeHistory.ts +2 -6
- package/src/histories/AgenticaExecuteHistory.ts +7 -9
- package/src/histories/AgenticaHistory.ts +11 -13
- package/src/histories/AgenticaSelectHistory.ts +2 -6
- package/src/histories/MicroAgenticaHistory.ts +7 -9
- package/src/orchestrate/call.ts +55 -56
- package/src/orchestrate/cancel.ts +11 -12
- package/src/orchestrate/describe.ts +4 -5
- package/src/orchestrate/execute.ts +3 -5
- package/src/orchestrate/initialize.ts +4 -5
- package/src/orchestrate/internal/cancelFunctionFromContext.ts +4 -6
- package/src/orchestrate/internal/selectFunctionFromContext.ts +5 -9
- package/src/orchestrate/select.ts +11 -12
- package/src/structures/IAgenticaConfig.ts +4 -6
- package/src/structures/IAgenticaController.ts +11 -14
- package/src/structures/IAgenticaExecutor.ts +9 -11
- package/src/structures/IAgenticaProps.ts +3 -10
- package/src/structures/IAgenticaSystemPrompt.ts +9 -11
- package/src/structures/IMicroAgenticaConfig.ts +3 -5
- package/src/structures/IMicroAgenticaExecutor.ts +4 -6
- package/src/structures/IMicroAgenticaProps.ts +3 -10
- package/src/structures/IMicroAgenticaSystemPrompt.ts +6 -8
- package/src/transformers/transformHistory.ts +19 -21
- package/src/utils/ChatGptCompletionStreamingUtil.spec.ts +4 -5
- package/src/utils/request.ts +2 -3
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
|
|
3
1
|
import type { AgenticaOperation } from "./AgenticaOperation";
|
|
4
2
|
|
|
5
3
|
/**
|
|
@@ -11,12 +9,11 @@ import type { AgenticaOperation } from "./AgenticaOperation";
|
|
|
11
9
|
*
|
|
12
10
|
* @author Samchon
|
|
13
11
|
*/
|
|
14
|
-
export interface AgenticaOperationCollection
|
|
12
|
+
export interface AgenticaOperationCollection {
|
|
15
13
|
/**
|
|
16
14
|
* List of every operations.
|
|
17
15
|
*/
|
|
18
|
-
array: AgenticaOperation
|
|
19
|
-
|
|
16
|
+
array: AgenticaOperation[];
|
|
20
17
|
/**
|
|
21
18
|
* Divided operations.
|
|
22
19
|
*
|
|
@@ -32,14 +29,14 @@ export interface AgenticaOperationCollection<Model extends ILlmSchema.Model> {
|
|
|
32
29
|
* Otherwise, if the {@link IAgenticaConfig.capacity} has not been
|
|
33
30
|
* configured, this `divided` property would be the `undefined` value.
|
|
34
31
|
*/
|
|
35
|
-
divided?: AgenticaOperation
|
|
32
|
+
divided?: AgenticaOperation[][] | undefined;
|
|
36
33
|
|
|
37
34
|
/**
|
|
38
35
|
* Flat dictionary of operations.
|
|
39
36
|
*
|
|
40
37
|
* Dictionary of operations with their {@link IAgenticaOperation.name}.
|
|
41
38
|
*/
|
|
42
|
-
flat: Map<string, AgenticaOperation
|
|
39
|
+
flat: Map<string, AgenticaOperation>;
|
|
43
40
|
|
|
44
41
|
/**
|
|
45
42
|
* Group dictionary of operations.
|
|
@@ -48,5 +45,5 @@ export interface AgenticaOperationCollection<Model extends ILlmSchema.Model> {
|
|
|
48
45
|
* {@link IAgenticaOperation.controller.name} and
|
|
49
46
|
* {@link IAgenticaOperation.function.name}.
|
|
50
47
|
*/
|
|
51
|
-
group: Map<string, Map<string, AgenticaOperation
|
|
48
|
+
group: Map<string, Map<string, AgenticaOperation>>;
|
|
52
49
|
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
|
|
3
1
|
import type { IAgenticaOperationSelectionJson } from "../json/IAgenticaOperationSelectionJson";
|
|
4
2
|
|
|
5
3
|
import type { AgenticaOperation } from "./AgenticaOperation";
|
|
6
4
|
|
|
7
|
-
export interface AgenticaOperationSelection
|
|
8
|
-
operation: AgenticaOperation
|
|
5
|
+
export interface AgenticaOperationSelection {
|
|
6
|
+
operation: AgenticaOperation;
|
|
9
7
|
reason: string;
|
|
10
8
|
toJSON: () => IAgenticaOperationSelectionJson;
|
|
11
9
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
1
|
import type OpenAI from "openai";
|
|
3
2
|
|
|
4
3
|
import type { MicroAgenticaEvent } from "../events/MicroAgenticaEvent";
|
|
@@ -29,7 +28,7 @@ import type { AgenticaOperationCollection } from "./AgenticaOperationCollection"
|
|
|
29
28
|
*
|
|
30
29
|
* @author Samchon
|
|
31
30
|
*/
|
|
32
|
-
export interface MicroAgenticaContext
|
|
31
|
+
export interface MicroAgenticaContext {
|
|
33
32
|
// ----
|
|
34
33
|
// APPLICATION
|
|
35
34
|
// ----
|
|
@@ -40,7 +39,7 @@ export interface MicroAgenticaContext<Model extends ILlmSchema.Model> {
|
|
|
40
39
|
* groups composed by the divide and conquer rule for the
|
|
41
40
|
* efficient operation selection if configured.
|
|
42
41
|
*/
|
|
43
|
-
operations: AgenticaOperationCollection
|
|
42
|
+
operations: AgenticaOperationCollection;
|
|
44
43
|
|
|
45
44
|
/**
|
|
46
45
|
* Configuration of the agent.
|
|
@@ -50,7 +49,7 @@ export interface MicroAgenticaContext<Model extends ILlmSchema.Model> {
|
|
|
50
49
|
*
|
|
51
50
|
* @todo Write detaily after supporting the agent customization feature
|
|
52
51
|
*/
|
|
53
|
-
config: IMicroAgenticaConfig
|
|
52
|
+
config: IMicroAgenticaConfig | undefined;
|
|
54
53
|
|
|
55
54
|
// ----
|
|
56
55
|
// STATES
|
|
@@ -58,7 +57,7 @@ export interface MicroAgenticaContext<Model extends ILlmSchema.Model> {
|
|
|
58
57
|
/**
|
|
59
58
|
* Prompt histories.
|
|
60
59
|
*/
|
|
61
|
-
histories: MicroAgenticaHistory
|
|
60
|
+
histories: MicroAgenticaHistory[];
|
|
62
61
|
|
|
63
62
|
/**
|
|
64
63
|
* Text prompt of the user.
|
|
@@ -83,7 +82,7 @@ export interface MicroAgenticaContext<Model extends ILlmSchema.Model> {
|
|
|
83
82
|
*
|
|
84
83
|
* @param event Event to deliver
|
|
85
84
|
*/
|
|
86
|
-
dispatch: (event: MicroAgenticaEvent
|
|
85
|
+
dispatch: (event: MicroAgenticaEvent) => Promise<void>;
|
|
87
86
|
|
|
88
87
|
/**
|
|
89
88
|
* Request to the OpenAI server.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IHttpLlmFunction, ILlmFunction, ILlmSchema, IMcpLlmFunction, IValidation } from "@samchon/openapi";
|
|
2
2
|
|
|
3
3
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
4
4
|
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory";
|
|
@@ -17,7 +17,7 @@ const client = new Client({
|
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
// test helper functions
|
|
20
|
-
function createMockHttpFunction(name: string, method: "get" | "post" | "patch" | "put" | "delete", path: string): IHttpLlmFunction
|
|
20
|
+
function createMockHttpFunction(name: string, method: "get" | "post" | "patch" | "put" | "delete", path: string): IHttpLlmFunction {
|
|
21
21
|
return {
|
|
22
22
|
name,
|
|
23
23
|
method,
|
|
@@ -38,41 +38,55 @@ function createMockHttpFunction(name: string, method: "get" | "post" | "patch" |
|
|
|
38
38
|
comment: () => "OK",
|
|
39
39
|
operation: () => ({}),
|
|
40
40
|
}),
|
|
41
|
-
parameters: {
|
|
41
|
+
parameters: {
|
|
42
|
+
type: "object",
|
|
43
|
+
properties: {},
|
|
44
|
+
additionalProperties: false,
|
|
45
|
+
required: [],
|
|
46
|
+
$defs: {},
|
|
47
|
+
} satisfies ILlmSchema.IParameters,
|
|
42
48
|
output: {},
|
|
43
49
|
};
|
|
44
50
|
}
|
|
45
51
|
|
|
46
|
-
function createMockHttpController(name: string, functions: IHttpLlmFunction
|
|
52
|
+
function createMockHttpController(name: string, functions: IHttpLlmFunction[]): IAgenticaController.IHttp {
|
|
47
53
|
return {
|
|
48
54
|
name,
|
|
49
55
|
protocol: "http",
|
|
50
56
|
connection: { host: "https://example.com" },
|
|
51
57
|
application: {
|
|
52
|
-
model: "chatgpt",
|
|
53
|
-
options: {},
|
|
54
58
|
functions,
|
|
59
|
+
config: {
|
|
60
|
+
reference: true,
|
|
61
|
+
strict: false,
|
|
62
|
+
separate: null,
|
|
63
|
+
maxLength: 64,
|
|
64
|
+
equals: false,
|
|
65
|
+
},
|
|
55
66
|
errors: [],
|
|
56
67
|
},
|
|
57
68
|
};
|
|
58
69
|
}
|
|
59
70
|
|
|
60
|
-
function createMockClassController(name: string, functions: ILlmFunction
|
|
71
|
+
function createMockClassController(name: string, functions: ILlmFunction[]): IAgenticaController.IClass {
|
|
61
72
|
return {
|
|
62
73
|
name,
|
|
63
74
|
protocol: "class",
|
|
64
75
|
application: {
|
|
65
|
-
model: "chatgpt",
|
|
66
|
-
options: {},
|
|
67
76
|
functions,
|
|
77
|
+
config: {
|
|
78
|
+
reference: true,
|
|
79
|
+
strict: false,
|
|
80
|
+
separate: null,
|
|
81
|
+
validate: null,
|
|
82
|
+
},
|
|
68
83
|
},
|
|
69
84
|
execute: {},
|
|
70
85
|
};
|
|
71
86
|
}
|
|
72
87
|
|
|
73
|
-
async function createMockMcpController(name: string, functions: IMcpLlmFunction
|
|
88
|
+
async function createMockMcpController(name: string, functions: IMcpLlmFunction[]): Promise<IAgenticaController.IMcp> {
|
|
74
89
|
const controller = await assertMcpController({
|
|
75
|
-
model: "chatgpt",
|
|
76
90
|
name,
|
|
77
91
|
client,
|
|
78
92
|
});
|
|
@@ -112,7 +126,13 @@ describe("a AgenticaOperationComposer", () => {
|
|
|
112
126
|
{
|
|
113
127
|
name: "function3",
|
|
114
128
|
validate: () => ({ success: true, data: {} } as IValidation<unknown>),
|
|
115
|
-
parameters: {
|
|
129
|
+
parameters: {
|
|
130
|
+
type: "object",
|
|
131
|
+
properties: {},
|
|
132
|
+
additionalProperties: false,
|
|
133
|
+
required: [],
|
|
134
|
+
$defs: {},
|
|
135
|
+
} satisfies ILlmSchema.IParameters,
|
|
116
136
|
output: {},
|
|
117
137
|
},
|
|
118
138
|
]);
|
|
@@ -126,7 +146,7 @@ describe("a AgenticaOperationComposer", () => {
|
|
|
126
146
|
additionalProperties: false,
|
|
127
147
|
required: [],
|
|
128
148
|
$defs: {},
|
|
129
|
-
} satisfies
|
|
149
|
+
} satisfies ILlmSchema.IParameters,
|
|
130
150
|
validate: (data: unknown) => ({
|
|
131
151
|
success: true,
|
|
132
152
|
data,
|
|
@@ -154,7 +174,7 @@ describe("a AgenticaOperationComposer", () => {
|
|
|
154
174
|
createMockHttpFunction("function5", "patch", "/api/function5"),
|
|
155
175
|
]);
|
|
156
176
|
|
|
157
|
-
const config: IAgenticaConfig
|
|
177
|
+
const config: IAgenticaConfig = {
|
|
158
178
|
capacity: 2,
|
|
159
179
|
};
|
|
160
180
|
|
|
@@ -186,7 +206,13 @@ describe("a AgenticaOperationComposer", () => {
|
|
|
186
206
|
{
|
|
187
207
|
name: "function1",
|
|
188
208
|
validate: () => ({ success: true, data: {} } as IValidation<unknown>),
|
|
189
|
-
parameters: {
|
|
209
|
+
parameters: {
|
|
210
|
+
type: "object",
|
|
211
|
+
properties: {},
|
|
212
|
+
additionalProperties: false,
|
|
213
|
+
required: [],
|
|
214
|
+
$defs: {},
|
|
215
|
+
} satisfies ILlmSchema.IParameters,
|
|
190
216
|
output: {},
|
|
191
217
|
},
|
|
192
218
|
]);
|
|
@@ -224,11 +250,11 @@ describe("a AgenticaOperationComposer", () => {
|
|
|
224
250
|
});
|
|
225
251
|
|
|
226
252
|
it("should throw error for unsupported protocol", () => {
|
|
227
|
-
const mockController: IAgenticaController.IHttp
|
|
253
|
+
const mockController: IAgenticaController.IHttp = {
|
|
228
254
|
name: "unsupportedController",
|
|
229
255
|
protocol: "unsupported" as unknown as "http",
|
|
230
256
|
connection: { host: "https://example.com" },
|
|
231
|
-
application: { } as unknown as IAgenticaController.IHttp
|
|
257
|
+
application: { } as unknown as IAgenticaController.IHttp["application"],
|
|
232
258
|
};
|
|
233
259
|
|
|
234
260
|
expect(() => getOperations({ controllers: [mockController], naming: (func, idx) => `_${idx}_${func}` })).toThrow("Unsupported protocol: unsupported");
|
|
@@ -257,7 +283,13 @@ describe("a AgenticaOperationComposer", () => {
|
|
|
257
283
|
{
|
|
258
284
|
name: "function1",
|
|
259
285
|
validate: () => ({ success: true, data: {} } as IValidation<unknown>),
|
|
260
|
-
parameters: {
|
|
286
|
+
parameters: {
|
|
287
|
+
type: "object",
|
|
288
|
+
properties: {},
|
|
289
|
+
additionalProperties: false,
|
|
290
|
+
required: [],
|
|
291
|
+
$defs: {},
|
|
292
|
+
} satisfies ILlmSchema.IParameters,
|
|
261
293
|
output: {},
|
|
262
294
|
},
|
|
263
295
|
]);
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
|
|
3
1
|
import type { IAgenticaConfig } from "../../structures/IAgenticaConfig";
|
|
4
2
|
import type { IAgenticaController } from "../../structures/IAgenticaController";
|
|
5
3
|
import type { IMicroAgenticaConfig } from "../../structures/IMicroAgenticaConfig";
|
|
@@ -16,10 +14,10 @@ import { __map_take } from "../../utils/__map_take";
|
|
|
16
14
|
*
|
|
17
15
|
* @internal
|
|
18
16
|
*/
|
|
19
|
-
export function compose
|
|
20
|
-
controllers: IAgenticaController
|
|
21
|
-
config?: IAgenticaConfig
|
|
22
|
-
}): AgenticaOperationCollection
|
|
17
|
+
export function compose(props: {
|
|
18
|
+
controllers: IAgenticaController[];
|
|
19
|
+
config?: IAgenticaConfig | IMicroAgenticaConfig | undefined;
|
|
20
|
+
}): AgenticaOperationCollection {
|
|
23
21
|
const unique: boolean = (props.controllers.length === 1 || (() => {
|
|
24
22
|
const names = props.controllers.map(
|
|
25
23
|
|
|
@@ -28,12 +26,12 @@ export function compose<Model extends ILlmSchema.Model>(props: {
|
|
|
28
26
|
return new Set(names).size === names.length;
|
|
29
27
|
})());
|
|
30
28
|
|
|
31
|
-
const array: AgenticaOperation
|
|
29
|
+
const array: AgenticaOperation[] = getOperations({
|
|
32
30
|
controllers: props.controllers,
|
|
33
31
|
naming: (func: string, controllerIndex: number) => unique ? func : `_${controllerIndex}_${func}`,
|
|
34
32
|
});
|
|
35
|
-
const capacity: number | undefined = (props.config as IAgenticaConfig
|
|
36
|
-
const divided: AgenticaOperation
|
|
33
|
+
const capacity: number | undefined = (props.config as IAgenticaConfig)?.capacity;
|
|
34
|
+
const divided: AgenticaOperation[][] | undefined
|
|
37
35
|
= capacity !== undefined && array.length > capacity
|
|
38
36
|
? divide({
|
|
39
37
|
array,
|
|
@@ -41,8 +39,8 @@ export function compose<Model extends ILlmSchema.Model>(props: {
|
|
|
41
39
|
})
|
|
42
40
|
: undefined;
|
|
43
41
|
|
|
44
|
-
const flat: Map<string, AgenticaOperation
|
|
45
|
-
const group: Map<string, Map<string, AgenticaOperation
|
|
42
|
+
const flat: Map<string, AgenticaOperation> = new Map();
|
|
43
|
+
const group: Map<string, Map<string, AgenticaOperation>> = new Map();
|
|
46
44
|
for (const item of array) {
|
|
47
45
|
flat.set(item.name, item);
|
|
48
46
|
__map_take(group, item.controller.name, () => new Map()).set(
|
|
@@ -61,10 +59,10 @@ export function compose<Model extends ILlmSchema.Model>(props: {
|
|
|
61
59
|
/**
|
|
62
60
|
* @internal
|
|
63
61
|
*/
|
|
64
|
-
export function getOperations
|
|
65
|
-
controllers: IAgenticaController
|
|
62
|
+
export function getOperations(props: {
|
|
63
|
+
controllers: IAgenticaController[];
|
|
66
64
|
naming: (func: string, controllerIndex: number) => string;
|
|
67
|
-
}): AgenticaOperation
|
|
65
|
+
}): AgenticaOperation[] {
|
|
68
66
|
return props.controllers.flatMap((controller, idx) => {
|
|
69
67
|
switch (controller.protocol) {
|
|
70
68
|
case "http":{
|
|
@@ -84,11 +82,11 @@ export function getOperations<Model extends ILlmSchema.Model>(props: {
|
|
|
84
82
|
/**
|
|
85
83
|
* @internal
|
|
86
84
|
*/
|
|
87
|
-
export function toHttpOperations
|
|
88
|
-
controller: IAgenticaController.IHttp
|
|
85
|
+
export function toHttpOperations(props: {
|
|
86
|
+
controller: IAgenticaController.IHttp;
|
|
89
87
|
index: number;
|
|
90
88
|
naming: (func: string, controllerIndex: number) => string;
|
|
91
|
-
}): AgenticaOperation
|
|
89
|
+
}): AgenticaOperation[] {
|
|
92
90
|
return props.controller.application.functions.map(func => ({
|
|
93
91
|
protocol: "http",
|
|
94
92
|
controller: props.controller,
|
|
@@ -106,11 +104,11 @@ export function toHttpOperations<Model extends ILlmSchema.Model>(props: {
|
|
|
106
104
|
/**
|
|
107
105
|
* @internal
|
|
108
106
|
*/
|
|
109
|
-
export function toClassOperations
|
|
110
|
-
controller: IAgenticaController.IClass
|
|
107
|
+
export function toClassOperations(props: {
|
|
108
|
+
controller: IAgenticaController.IClass;
|
|
111
109
|
index: number;
|
|
112
110
|
naming: (func: string, controllerIndex: number) => string;
|
|
113
|
-
}): AgenticaOperation
|
|
111
|
+
}): AgenticaOperation[] {
|
|
114
112
|
return props.controller.application.functions.map(func => ({
|
|
115
113
|
protocol: "class",
|
|
116
114
|
controller: props.controller,
|
|
@@ -128,11 +126,11 @@ export function toClassOperations<Model extends ILlmSchema.Model>(props: {
|
|
|
128
126
|
/**
|
|
129
127
|
* @internal
|
|
130
128
|
*/
|
|
131
|
-
export function toMcpOperations
|
|
132
|
-
controller: IAgenticaController.IMcp
|
|
129
|
+
export function toMcpOperations(props: {
|
|
130
|
+
controller: IAgenticaController.IMcp;
|
|
133
131
|
index: number;
|
|
134
132
|
naming: (func: string, controllerIndex: number) => string;
|
|
135
|
-
}): AgenticaOperation
|
|
133
|
+
}): AgenticaOperation[] {
|
|
136
134
|
return props.controller.application.functions.map(func => ({
|
|
137
135
|
protocol: "mcp",
|
|
138
136
|
controller: props.controller,
|
|
@@ -11,5 +11,5 @@ export interface __IChatInitialApplication {
|
|
|
11
11
|
* Also, user just wants to list up every remote API functions that can be
|
|
12
12
|
* called from the backend server, utilize this function too.
|
|
13
13
|
*/
|
|
14
|
-
getApiFunctions: (props: object) => Promise<Array<IHttpLlmFunction
|
|
14
|
+
getApiFunctions: (props: object) => Promise<Array<IHttpLlmFunction>>;
|
|
15
15
|
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
|
|
3
1
|
import type { AgenticaContext } from "../AgenticaContext";
|
|
4
2
|
import type { MicroAgenticaContext } from "../MicroAgenticaContext";
|
|
5
3
|
|
|
6
4
|
/**
|
|
7
5
|
* @internal
|
|
8
6
|
*/
|
|
9
|
-
export function isAgenticaContext
|
|
10
|
-
ctx: AgenticaContext
|
|
11
|
-
): ctx is AgenticaContext
|
|
12
|
-
return typeof (ctx as AgenticaContext
|
|
7
|
+
export function isAgenticaContext(
|
|
8
|
+
ctx: AgenticaContext | MicroAgenticaContext,
|
|
9
|
+
): ctx is AgenticaContext {
|
|
10
|
+
return typeof (ctx as AgenticaContext).initialize === "function";
|
|
13
11
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
|
|
3
1
|
import type { AgenticaOperation } from "../context/AgenticaOperation";
|
|
4
2
|
import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
5
3
|
|
|
@@ -10,12 +8,11 @@ import type { AgenticaEventBase } from "./AgenticaEventBase";
|
|
|
10
8
|
*
|
|
11
9
|
* @author Samchon
|
|
12
10
|
*/
|
|
13
|
-
export interface AgenticaCallEvent
|
|
14
|
-
extends AgenticaEventBase<"call"> {
|
|
11
|
+
export interface AgenticaCallEvent extends AgenticaEventBase<"call"> {
|
|
15
12
|
/**
|
|
16
13
|
* Target operation to call.
|
|
17
14
|
*/
|
|
18
|
-
operation: AgenticaOperation
|
|
15
|
+
operation: AgenticaOperation;
|
|
19
16
|
|
|
20
17
|
/**
|
|
21
18
|
* Arguments of the function calling.
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
|
|
3
1
|
import type { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
|
|
4
2
|
import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
5
3
|
|
|
6
4
|
import type { AgenticaEventBase } from "./AgenticaEventBase";
|
|
7
5
|
|
|
8
|
-
export interface AgenticaCancelEvent<
|
|
9
|
-
|
|
10
|
-
> extends AgenticaEventBase<"cancel"> {
|
|
11
|
-
selection: AgenticaOperationSelection<Model>;
|
|
6
|
+
export interface AgenticaCancelEvent extends AgenticaEventBase<"cancel"> {
|
|
7
|
+
selection: AgenticaOperationSelection;
|
|
12
8
|
toJSON: () => IAgenticaEventJson.ICancel;
|
|
13
9
|
}
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
|
|
3
1
|
import type { AgenticaDescribeHistory } from "../histories/AgenticaDescribeHistory";
|
|
4
2
|
import type { AgenticaExecuteHistory } from "../histories/AgenticaExecuteHistory";
|
|
5
3
|
import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
6
4
|
|
|
7
5
|
import type { AgenticaEventBase } from "./AgenticaEventBase";
|
|
8
6
|
|
|
9
|
-
export interface AgenticaDescribeEvent<
|
|
10
|
-
|
|
11
|
-
> extends AgenticaEventBase<"describe"> {
|
|
12
|
-
executes: AgenticaExecuteHistory<Model>[];
|
|
7
|
+
export interface AgenticaDescribeEvent extends AgenticaEventBase<"describe"> {
|
|
8
|
+
executes: AgenticaExecuteHistory[];
|
|
13
9
|
stream: AsyncGenerator<string, undefined, undefined>;
|
|
14
10
|
|
|
15
11
|
join: () => Promise<string>;
|
|
16
12
|
toJSON: () => IAgenticaEventJson.IDescribe;
|
|
17
|
-
toHistory: () => AgenticaDescribeHistory
|
|
13
|
+
toHistory: () => AgenticaDescribeHistory;
|
|
18
14
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
|
|
3
1
|
import type { AgenticaAssistantMessageEvent } from "./AgenticaAssistantMessageEvent";
|
|
4
2
|
import type { AgenticaCallEvent } from "./AgenticaCallEvent";
|
|
5
3
|
import type { AgenticaCancelEvent } from "./AgenticaCancelEvent";
|
|
@@ -23,32 +21,32 @@ import type { AgenticaValidateEvent } from "./AgenticaValidateEvent";
|
|
|
23
21
|
*
|
|
24
22
|
* @author Samchon
|
|
25
23
|
*/
|
|
26
|
-
export type AgenticaEvent
|
|
24
|
+
export type AgenticaEvent =
|
|
27
25
|
| AgenticaUserMessageEvent
|
|
28
26
|
| AgenticaAssistantMessageEvent
|
|
29
27
|
| AgenticaInitializeEvent
|
|
30
|
-
| AgenticaSelectEvent
|
|
31
|
-
| AgenticaCallEvent
|
|
32
|
-
| AgenticaCancelEvent
|
|
33
|
-
| AgenticaExecuteEvent
|
|
34
|
-
| AgenticaDescribeEvent
|
|
35
|
-
| AgenticaValidateEvent
|
|
36
|
-
| AgenticaJsonParseErrorEvent
|
|
28
|
+
| AgenticaSelectEvent
|
|
29
|
+
| AgenticaCallEvent
|
|
30
|
+
| AgenticaCancelEvent
|
|
31
|
+
| AgenticaExecuteEvent
|
|
32
|
+
| AgenticaDescribeEvent
|
|
33
|
+
| AgenticaValidateEvent
|
|
34
|
+
| AgenticaJsonParseErrorEvent
|
|
37
35
|
| AgenticaRequestEvent
|
|
38
36
|
| AgenticaResponseEvent;
|
|
39
37
|
export namespace AgenticaEvent {
|
|
40
|
-
export type Type = AgenticaEvent
|
|
41
|
-
export interface Mapper
|
|
38
|
+
export type Type = AgenticaEvent["type"];
|
|
39
|
+
export interface Mapper {
|
|
42
40
|
userMessage: AgenticaUserMessageEvent;
|
|
43
41
|
assistantMessage: AgenticaAssistantMessageEvent;
|
|
44
|
-
select: AgenticaSelectEvent
|
|
42
|
+
select: AgenticaSelectEvent;
|
|
45
43
|
initialize: AgenticaInitializeEvent;
|
|
46
|
-
call: AgenticaCallEvent
|
|
47
|
-
cancel: AgenticaCancelEvent
|
|
48
|
-
execute: AgenticaExecuteEvent
|
|
49
|
-
describe: AgenticaDescribeEvent
|
|
50
|
-
validate: AgenticaValidateEvent
|
|
51
|
-
jsonParseError: AgenticaJsonParseErrorEvent
|
|
44
|
+
call: AgenticaCallEvent;
|
|
45
|
+
cancel: AgenticaCancelEvent;
|
|
46
|
+
execute: AgenticaExecuteEvent;
|
|
47
|
+
describe: AgenticaDescribeEvent;
|
|
48
|
+
validate: AgenticaValidateEvent;
|
|
49
|
+
jsonParseError: AgenticaJsonParseErrorEvent;
|
|
52
50
|
request: AgenticaRequestEvent;
|
|
53
51
|
response: AgenticaResponseEvent;
|
|
54
52
|
}
|
|
@@ -12,7 +12,7 @@ checks([
|
|
|
12
12
|
Pass
|
|
13
13
|
>(),
|
|
14
14
|
check<
|
|
15
|
-
Exclude<AgenticaHistory.Type, "systemMessage"> extends keyof AgenticaEvent.Mapper
|
|
15
|
+
Exclude<AgenticaHistory.Type, "systemMessage"> extends keyof AgenticaEvent.Mapper ? true : false,
|
|
16
16
|
true,
|
|
17
17
|
Pass
|
|
18
18
|
>(),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IHttpResponse
|
|
1
|
+
import type { IHttpResponse } from "@samchon/openapi";
|
|
2
2
|
|
|
3
3
|
import type { AgenticaOperation } from "../context/AgenticaOperation";
|
|
4
4
|
import type { AgenticaExecuteHistory } from "../histories/AgenticaExecuteHistory";
|
|
@@ -6,30 +6,30 @@ import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
|
6
6
|
|
|
7
7
|
import type { AgenticaEventBase } from "./AgenticaEventBase";
|
|
8
8
|
|
|
9
|
-
export type AgenticaExecuteEvent
|
|
10
|
-
| AgenticaExecuteEvent.Class
|
|
11
|
-
| AgenticaExecuteEvent.Protocol
|
|
9
|
+
export type AgenticaExecuteEvent =
|
|
10
|
+
| AgenticaExecuteEvent.Class
|
|
11
|
+
| AgenticaExecuteEvent.Protocol;
|
|
12
12
|
export namespace AgenticaExecuteEvent {
|
|
13
|
-
export interface Class
|
|
13
|
+
export interface Class
|
|
14
14
|
extends Base<
|
|
15
15
|
"class",
|
|
16
|
-
AgenticaOperation.Class
|
|
17
|
-
AgenticaExecuteHistory.Class
|
|
16
|
+
AgenticaOperation.Class,
|
|
17
|
+
AgenticaExecuteHistory.Class,
|
|
18
18
|
unknown
|
|
19
19
|
> {}
|
|
20
20
|
|
|
21
|
-
export interface Protocol
|
|
21
|
+
export interface Protocol
|
|
22
22
|
extends Base<
|
|
23
23
|
"http",
|
|
24
|
-
AgenticaOperation.Http
|
|
25
|
-
AgenticaExecuteHistory.Http
|
|
24
|
+
AgenticaOperation.Http,
|
|
25
|
+
AgenticaExecuteHistory.Http,
|
|
26
26
|
IHttpResponse
|
|
27
27
|
> {}
|
|
28
28
|
|
|
29
29
|
interface Base<
|
|
30
30
|
Protocol extends "http" | "class",
|
|
31
|
-
Operation extends AgenticaOperation
|
|
32
|
-
History extends AgenticaExecuteHistory
|
|
31
|
+
Operation extends AgenticaOperation,
|
|
32
|
+
History extends AgenticaExecuteHistory,
|
|
33
33
|
Value,
|
|
34
34
|
> extends AgenticaEventBase<"execute"> {
|
|
35
35
|
protocol: Protocol;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
|
|
3
1
|
import type { AgenticaOperation } from "../context/AgenticaOperation";
|
|
4
2
|
|
|
5
3
|
import type { AgenticaEventBase } from "./AgenticaEventBase";
|
|
6
4
|
|
|
7
|
-
export interface AgenticaJsonParseErrorEvent
|
|
5
|
+
export interface AgenticaJsonParseErrorEvent
|
|
8
6
|
extends AgenticaEventBase<"jsonParseError"> {
|
|
9
7
|
/**
|
|
10
8
|
* ID of the tool calling.
|
|
11
9
|
*/
|
|
12
10
|
call_id: string;
|
|
13
|
-
operation: AgenticaOperation
|
|
11
|
+
operation: AgenticaOperation;
|
|
14
12
|
arguments: string;
|
|
15
13
|
errorMessage: string;
|
|
16
14
|
life: number;
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
|
|
3
1
|
import type { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
|
|
4
2
|
import type { AgenticaSelectHistory } from "../histories/AgenticaSelectHistory";
|
|
5
3
|
import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
6
4
|
|
|
7
5
|
import type { AgenticaEventBase } from "./AgenticaEventBase";
|
|
8
6
|
|
|
9
|
-
export interface AgenticaSelectEvent<
|
|
10
|
-
|
|
11
|
-
> extends AgenticaEventBase<"select"> {
|
|
12
|
-
selection: AgenticaOperationSelection<Model>;
|
|
7
|
+
export interface AgenticaSelectEvent extends AgenticaEventBase<"select"> {
|
|
8
|
+
selection: AgenticaOperationSelection;
|
|
13
9
|
toJSON: () => IAgenticaEventJson.ISelect;
|
|
14
|
-
toHistory: () => AgenticaSelectHistory
|
|
10
|
+
toHistory: () => AgenticaSelectHistory;
|
|
15
11
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
1
|
import type { IValidation } from "typia";
|
|
3
2
|
|
|
4
3
|
import type { AgenticaOperation } from "../context/AgenticaOperation";
|
|
@@ -11,9 +10,7 @@ import type { AgenticaEventBase } from "./AgenticaEventBase";
|
|
|
11
10
|
*
|
|
12
11
|
* @author Samchon
|
|
13
12
|
*/
|
|
14
|
-
export interface AgenticaValidateEvent<
|
|
15
|
-
Model extends ILlmSchema.Model,
|
|
16
|
-
> extends AgenticaEventBase<"validate"> {
|
|
13
|
+
export interface AgenticaValidateEvent extends AgenticaEventBase<"validate"> {
|
|
17
14
|
/**
|
|
18
15
|
* ID of the tool calling.
|
|
19
16
|
*/
|
|
@@ -22,7 +19,7 @@ export interface AgenticaValidateEvent<
|
|
|
22
19
|
/**
|
|
23
20
|
* Target operation to call.
|
|
24
21
|
*/
|
|
25
|
-
operation: AgenticaOperation
|
|
22
|
+
operation: AgenticaOperation;
|
|
26
23
|
|
|
27
24
|
/**
|
|
28
25
|
* Validation result as a failure.
|