@agentica/core 0.10.4 → 0.11.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 +14 -14
- package/lib/Agentica.js +54 -31
- package/lib/Agentica.js.map +1 -1
- package/lib/chatgpt/ChatGptAgent.d.ts +3 -3
- package/lib/chatgpt/ChatGptAgent.js +1 -1
- package/lib/chatgpt/ChatGptAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptCallFunctionAgent.d.ts +3 -3
- package/lib/chatgpt/ChatGptCallFunctionAgent.js +61 -63
- package/lib/chatgpt/ChatGptCallFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptCancelFunctionAgent.d.ts +6 -6
- package/lib/chatgpt/ChatGptCancelFunctionAgent.js +28 -30
- package/lib/chatgpt/ChatGptCancelFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptCompletionMessageUtil.d.ts +8 -0
- package/lib/chatgpt/ChatGptCompletionMessageUtil.js +536 -0
- package/lib/chatgpt/ChatGptCompletionMessageUtil.js.map +1 -0
- package/lib/chatgpt/ChatGptDescribeFunctionAgent.d.ts +4 -3
- package/lib/chatgpt/ChatGptDescribeFunctionAgent.js +56 -6
- package/lib/chatgpt/ChatGptDescribeFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptHistoryDecoder.d.ts +2 -2
- package/lib/chatgpt/ChatGptHistoryDecoder.js +8 -8
- package/lib/chatgpt/ChatGptHistoryDecoder.js.map +1 -1
- package/lib/chatgpt/ChatGptInitializeFunctionAgent.d.ts +3 -3
- package/lib/chatgpt/ChatGptInitializeFunctionAgent.js +11 -5
- package/lib/chatgpt/ChatGptInitializeFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptSelectFunctionAgent.d.ts +3 -3
- package/lib/chatgpt/ChatGptSelectFunctionAgent.js +39 -42
- package/lib/chatgpt/ChatGptSelectFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptUsageAggregator.d.ts +6 -0
- package/lib/chatgpt/ChatGptUsageAggregator.js +48 -0
- package/lib/chatgpt/ChatGptUsageAggregator.js.map +1 -0
- package/lib/context/AgenticaCancelPrompt.d.ts +16 -0
- package/lib/context/AgenticaCancelPrompt.js +20 -0
- package/lib/context/AgenticaCancelPrompt.js.map +1 -0
- package/lib/context/AgenticaClassOperation.d.ts +8 -0
- package/lib/context/AgenticaClassOperation.js +11 -0
- package/lib/context/AgenticaClassOperation.js.map +1 -0
- package/lib/{structures/IAgenticaContext.d.ts → context/AgenticaContext.d.ts} +15 -14
- package/lib/{structures/IAgenticaPrompt.js → context/AgenticaContext.js} +1 -1
- package/lib/context/AgenticaContext.js.map +1 -0
- package/lib/context/AgenticaHttpOperation.d.ts +8 -0
- package/lib/context/AgenticaHttpOperation.js +11 -0
- package/lib/context/AgenticaHttpOperation.js.map +1 -0
- package/lib/context/AgenticaOperation.d.ts +46 -0
- package/lib/{structures/IAgenticaContext.js → context/AgenticaOperation.js} +1 -1
- package/lib/context/AgenticaOperation.js.map +1 -0
- package/lib/context/AgenticaOperationBase.d.ts +29 -0
- package/lib/context/AgenticaOperationBase.js +21 -0
- package/lib/context/AgenticaOperationBase.js.map +1 -0
- package/lib/{structures/IAgenticaOperationCollection.d.ts → context/AgenticaOperationCollection.d.ts} +6 -6
- package/lib/{structures/IAgenticaOperationSelection.js → context/AgenticaOperationCollection.js} +1 -1
- package/lib/context/AgenticaOperationCollection.js.map +1 -0
- package/lib/context/AgenticaOperationSelection.d.ts +15 -0
- package/lib/context/AgenticaOperationSelection.js +17 -0
- package/lib/context/AgenticaOperationSelection.js.map +1 -0
- package/lib/context/AgenticaTokenUsage.d.ts +82 -0
- package/lib/context/AgenticaTokenUsage.js +97 -0
- package/lib/context/AgenticaTokenUsage.js.map +1 -0
- package/lib/context/internal/AgenticaTokenUsageAggregator.d.ts +10 -0
- package/lib/{internal → context/internal}/AgenticaTokenUsageAggregator.js +0 -46
- package/lib/context/internal/AgenticaTokenUsageAggregator.js.map +1 -0
- package/lib/context/internal/__IChatCancelFunctionsApplication.js.map +1 -0
- package/lib/context/internal/__IChatFunctionReference.js.map +1 -0
- package/lib/context/internal/__IChatInitialApplication.js.map +1 -0
- package/lib/context/internal/__IChatSelectFunctionsApplication.js.map +1 -0
- package/lib/events/AgenticaCallEvent.d.ts +18 -0
- package/lib/events/AgenticaCallEvent.js +22 -0
- package/lib/events/AgenticaCallEvent.js.map +1 -0
- package/lib/events/AgenticaCancelEvent.d.ts +14 -0
- package/lib/events/AgenticaCancelEvent.js +18 -0
- package/lib/events/AgenticaCancelEvent.js.map +1 -0
- package/lib/events/AgenticaDescribeEvent.d.ts +27 -0
- package/lib/events/AgenticaDescribeEvent.js +40 -0
- package/lib/events/AgenticaDescribeEvent.js.map +1 -0
- package/lib/events/AgenticaEvent.d.ts +25 -0
- package/lib/{structures/IAgenticaEvent.js → events/AgenticaEvent.js} +1 -1
- package/lib/events/AgenticaEvent.js.map +1 -0
- package/lib/events/AgenticaEventBase.d.ts +4 -0
- package/lib/events/AgenticaEventBase.js +10 -0
- package/lib/events/AgenticaEventBase.js.map +1 -0
- package/lib/events/AgenticaEventSource.d.ts +1 -0
- package/lib/events/AgenticaEventSource.js +3 -0
- package/lib/events/AgenticaEventSource.js.map +1 -0
- package/lib/events/AgenticaExecuteEvent.d.ts +22 -0
- package/lib/events/AgenticaExecuteEvent.js +33 -0
- package/lib/events/AgenticaExecuteEvent.js.map +1 -0
- package/lib/events/AgenticaInitializeEvent.d.ts +6 -0
- package/lib/events/AgenticaInitializeEvent.js +16 -0
- package/lib/events/AgenticaInitializeEvent.js.map +1 -0
- package/lib/events/AgenticaRequestEvent.d.ts +27 -0
- package/lib/events/AgenticaRequestEvent.js +22 -0
- package/lib/events/AgenticaRequestEvent.js.map +1 -0
- package/lib/events/AgenticaResponseEvent.d.ts +35 -0
- package/lib/events/AgenticaResponseEvent.js +16 -0
- package/lib/events/AgenticaResponseEvent.js.map +1 -0
- package/lib/events/AgenticaSelectEvent.d.ts +16 -0
- package/lib/events/AgenticaSelectEvent.js +26 -0
- package/lib/events/AgenticaSelectEvent.js.map +1 -0
- package/lib/events/AgenticaTextEvent.d.ts +25 -0
- package/lib/events/AgenticaTextEvent.js +40 -0
- package/lib/events/AgenticaTextEvent.js.map +1 -0
- package/lib/index.d.ts +26 -8
- package/lib/index.js +29 -9
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +1391 -306
- package/lib/index.mjs.map +1 -1
- package/lib/internal/AgenticaOperationComposer.d.ts +2 -2
- package/lib/internal/AgenticaOperationComposer.js +12 -0
- package/lib/internal/AgenticaOperationComposer.js.map +1 -1
- package/lib/internal/ByteArrayUtil.d.ts +3 -0
- package/lib/internal/ByteArrayUtil.js +10 -0
- package/lib/internal/ByteArrayUtil.js.map +1 -0
- package/lib/internal/MPSCUtil.d.ts +21 -0
- package/lib/internal/MPSCUtil.js +84 -0
- package/lib/internal/MPSCUtil.js.map +1 -0
- package/lib/internal/StreamUtil.d.ts +6 -0
- package/lib/internal/StreamUtil.js +65 -0
- package/lib/internal/StreamUtil.js.map +1 -0
- package/lib/json/IAgenticaEventJson.d.ts +149 -0
- package/lib/{structures/IAgenticaOperation.js → json/IAgenticaEventJson.js} +1 -1
- package/lib/json/IAgenticaEventJson.js.map +1 -0
- package/lib/json/IAgenticaOperationJson.d.ts +33 -0
- package/lib/json/IAgenticaOperationJson.js +3 -0
- package/lib/json/IAgenticaOperationJson.js.map +1 -0
- package/lib/json/IAgenticaOperationSelectionJson.d.ts +18 -0
- package/lib/{structures/IAgenticaOperationCollection.js → json/IAgenticaOperationSelectionJson.js} +1 -1
- package/lib/json/IAgenticaOperationSelectionJson.js.map +1 -0
- package/lib/json/IAgenticaPromptJson.d.ts +111 -0
- package/lib/json/IAgenticaPromptJson.js +3 -0
- package/lib/json/IAgenticaPromptJson.js.map +1 -0
- package/lib/{structures/IAgenticaTokenUsage.d.ts → json/IAgenticaTokenUsageJson.d.ts} +10 -10
- package/lib/json/IAgenticaTokenUsageJson.js +3 -0
- package/lib/json/IAgenticaTokenUsageJson.js.map +1 -0
- package/lib/prompts/AgenticaCancelPrompt.d.ts +16 -0
- package/lib/prompts/AgenticaCancelPrompt.js +20 -0
- package/lib/prompts/AgenticaCancelPrompt.js.map +1 -0
- package/lib/prompts/AgenticaDescribePrompt.d.ts +24 -0
- package/lib/prompts/AgenticaDescribePrompt.js +20 -0
- package/lib/prompts/AgenticaDescribePrompt.js.map +1 -0
- package/lib/prompts/AgenticaExecutePrompt.d.ts +20 -0
- package/lib/prompts/AgenticaExecutePrompt.js +24 -0
- package/lib/prompts/AgenticaExecutePrompt.js.map +1 -0
- package/lib/prompts/AgenticaPrompt.d.ts +7 -0
- package/lib/{typings/AgenticaSource.js → prompts/AgenticaPrompt.js} +1 -1
- package/lib/prompts/AgenticaPrompt.js.map +1 -0
- package/lib/prompts/AgenticaPromptBase.d.ts +22 -0
- package/lib/prompts/AgenticaPromptBase.js +22 -0
- package/lib/prompts/AgenticaPromptBase.js.map +1 -0
- package/lib/prompts/AgenticaSelectPrompt.d.ts +16 -0
- package/lib/prompts/AgenticaSelectPrompt.js +20 -0
- package/lib/prompts/AgenticaSelectPrompt.js.map +1 -0
- package/lib/prompts/AgenticaTextPrompt.d.ts +14 -0
- package/lib/prompts/AgenticaTextPrompt.js +20 -0
- package/lib/prompts/AgenticaTextPrompt.js.map +1 -0
- package/lib/structures/IAgenticaConfig.d.ts +3 -3
- package/lib/structures/IAgenticaExecutor.d.ts +12 -11
- package/lib/structures/IAgenticaProps.d.ts +2 -3
- package/lib/structures/IAgenticaSystemPrompt.d.ts +12 -11
- package/lib/transformers/AgenticaEventTransformer.d.ts +45 -0
- package/lib/transformers/AgenticaEventTransformer.js +127 -0
- package/lib/transformers/AgenticaEventTransformer.js.map +1 -0
- package/lib/transformers/AgenticaPromptTransformer.d.ts +34 -0
- package/lib/transformers/AgenticaPromptTransformer.js +90 -0
- package/lib/transformers/AgenticaPromptTransformer.js.map +1 -0
- package/package.json +1 -1
- package/src/Agentica.ts +93 -63
- package/src/chatgpt/ChatGptAgent.ts +8 -7
- package/src/chatgpt/ChatGptCallFunctionAgent.ts +90 -88
- package/src/chatgpt/ChatGptCancelFunctionAgent.ts +51 -58
- package/src/chatgpt/ChatGptCompletionMessageUtil.ts +166 -0
- package/src/chatgpt/ChatGptDescribeFunctionAgent.ts +81 -12
- package/src/chatgpt/ChatGptHistoryDecoder.ts +14 -14
- package/src/chatgpt/ChatGptInitializeFunctionAgent.ts +21 -13
- package/src/chatgpt/ChatGptSelectFunctionAgent.ts +66 -74
- package/src/chatgpt/ChatGptUsageAggregator.ts +62 -0
- package/src/context/AgenticaCancelPrompt.ts +32 -0
- package/src/context/AgenticaClassOperation.ts +23 -0
- package/src/{structures/IAgenticaContext.ts → context/AgenticaContext.ts} +17 -16
- package/src/context/AgenticaHttpOperation.ts +27 -0
- package/src/{structures/IAgenticaOperation.ts → context/AgenticaOperation.ts} +25 -22
- package/src/context/AgenticaOperationBase.ts +57 -0
- package/src/{structures/IAgenticaOperationCollection.ts → context/AgenticaOperationCollection.ts} +6 -6
- package/src/context/AgenticaOperationSelection.ts +27 -0
- package/src/context/AgenticaTokenUsage.ts +170 -0
- package/src/context/internal/AgenticaTokenUsageAggregator.ts +66 -0
- package/src/events/AgenticaCallEvent.ts +36 -0
- package/src/events/AgenticaCancelEvent.ts +28 -0
- package/src/events/AgenticaDescribeEvent.ts +61 -0
- package/src/events/AgenticaEvent.ts +36 -0
- package/src/events/AgenticaEventBase.ts +7 -0
- package/src/{typings/AgenticaSource.ts → events/AgenticaEventSource.ts} +1 -1
- package/src/events/AgenticaExecuteEvent.ts +50 -0
- package/src/events/AgenticaInitializeEvent.ts +14 -0
- package/src/events/AgenticaRequestEvent.ts +45 -0
- package/src/events/AgenticaResponseEvent.ts +48 -0
- package/src/events/AgenticaSelectEvent.ts +37 -0
- package/src/events/AgenticaTextEvent.ts +57 -0
- package/src/index.ts +33 -9
- package/src/internal/AgenticaOperationComposer.ts +24 -15
- package/src/internal/ByteArrayUtil.ts +5 -0
- package/src/internal/MPSCUtil.ts +75 -0
- package/src/internal/StreamUtil.ts +64 -0
- package/src/json/IAgenticaEventJson.ts +178 -0
- package/src/json/IAgenticaOperationJson.ts +36 -0
- package/src/json/IAgenticaOperationSelectionJson.ts +19 -0
- package/src/json/IAgenticaPromptJson.ts +130 -0
- package/src/{structures/IAgenticaTokenUsage.ts → json/IAgenticaTokenUsageJson.ts} +10 -10
- package/src/prompts/AgenticaCancelPrompt.ts +32 -0
- package/src/prompts/AgenticaDescribePrompt.ts +41 -0
- package/src/prompts/AgenticaExecutePrompt.ts +52 -0
- package/src/prompts/AgenticaPrompt.ts +14 -0
- package/src/prompts/AgenticaPromptBase.ts +27 -0
- package/src/prompts/AgenticaSelectPrompt.ts +32 -0
- package/src/prompts/AgenticaTextPrompt.ts +31 -0
- package/src/structures/IAgenticaConfig.ts +3 -3
- package/src/structures/IAgenticaExecutor.ts +14 -13
- package/src/structures/IAgenticaProps.ts +2 -3
- package/src/structures/IAgenticaSystemPrompt.ts +12 -11
- package/src/transformers/AgenticaEventTransformer.ts +165 -0
- package/src/transformers/AgenticaPromptTransformer.ts +134 -0
- package/lib/internal/AgenticaPromptFactory.d.ts +0 -7
- package/lib/internal/AgenticaPromptFactory.js +0 -9
- package/lib/internal/AgenticaPromptFactory.js.map +0 -1
- package/lib/internal/AgenticaPromptTransformer.d.ts +0 -10
- package/lib/internal/AgenticaPromptTransformer.js +0 -58
- package/lib/internal/AgenticaPromptTransformer.js.map +0 -1
- package/lib/internal/AgenticaTokenUsageAggregator.d.ts +0 -11
- package/lib/internal/AgenticaTokenUsageAggregator.js.map +0 -1
- package/lib/structures/IAgenticaContext.js.map +0 -1
- package/lib/structures/IAgenticaEvent.d.ts +0 -192
- package/lib/structures/IAgenticaEvent.js.map +0 -1
- package/lib/structures/IAgenticaOperation.d.ts +0 -47
- package/lib/structures/IAgenticaOperation.js.map +0 -1
- package/lib/structures/IAgenticaOperationCollection.js.map +0 -1
- package/lib/structures/IAgenticaOperationSelection.d.ts +0 -50
- package/lib/structures/IAgenticaOperationSelection.js.map +0 -1
- package/lib/structures/IAgenticaPrompt.d.ts +0 -138
- package/lib/structures/IAgenticaPrompt.js.map +0 -1
- package/lib/structures/IAgenticaTokenUsage.js +0 -3
- package/lib/structures/IAgenticaTokenUsage.js.map +0 -1
- package/lib/structures/internal/__IChatCancelFunctionsApplication.js.map +0 -1
- package/lib/structures/internal/__IChatFunctionReference.js.map +0 -1
- package/lib/structures/internal/__IChatInitialApplication.js.map +0 -1
- package/lib/structures/internal/__IChatSelectFunctionsApplication.js.map +0 -1
- package/lib/typings/AgenticaSource.d.ts +0 -1
- package/lib/typings/AgenticaSource.js.map +0 -1
- package/src/internal/AgenticaPromptFactory.ts +0 -32
- package/src/internal/AgenticaPromptTransformer.ts +0 -86
- package/src/internal/AgenticaTokenUsageAggregator.ts +0 -121
- package/src/structures/IAgenticaEvent.ts +0 -229
- package/src/structures/IAgenticaOperationSelection.ts +0 -68
- package/src/structures/IAgenticaPrompt.ts +0 -182
- /package/lib/{structures → context}/internal/__IChatCancelFunctionsApplication.d.ts +0 -0
- /package/lib/{structures → context}/internal/__IChatCancelFunctionsApplication.js +0 -0
- /package/lib/{structures → context}/internal/__IChatFunctionReference.d.ts +0 -0
- /package/lib/{structures → context}/internal/__IChatFunctionReference.js +0 -0
- /package/lib/{structures → context}/internal/__IChatInitialApplication.d.ts +0 -0
- /package/lib/{structures → context}/internal/__IChatInitialApplication.js +0 -0
- /package/lib/{structures → context}/internal/__IChatSelectFunctionsApplication.d.ts +0 -0
- /package/lib/{structures → context}/internal/__IChatSelectFunctionsApplication.js +0 -0
- /package/src/{structures → context}/internal/__IChatCancelFunctionsApplication.ts +0 -0
- /package/src/{structures → context}/internal/__IChatFunctionReference.ts +0 -0
- /package/src/{structures → context}/internal/__IChatInitialApplication.ts +0 -0
- /package/src/{structures → context}/internal/__IChatSelectFunctionsApplication.ts +0 -0
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
IHttpLlmFunction,
|
|
3
|
-
ILlmApplication,
|
|
4
|
-
ILlmSchema,
|
|
5
|
-
} from "@samchon/openapi";
|
|
1
|
+
import { ILlmApplication, ILlmSchema } from "@samchon/openapi";
|
|
6
2
|
import OpenAI from "openai";
|
|
7
3
|
import typia, { IValidation } from "typia";
|
|
8
4
|
import { v4 } from "uuid";
|
|
9
5
|
|
|
6
|
+
import { AgenticaContext } from "../context/AgenticaContext";
|
|
7
|
+
import { AgenticaOperation } from "../context/AgenticaOperation";
|
|
8
|
+
import { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
|
|
9
|
+
import { __IChatFunctionReference } from "../context/internal/__IChatFunctionReference";
|
|
10
|
+
import { __IChatSelectFunctionsApplication } from "../context/internal/__IChatSelectFunctionsApplication";
|
|
11
|
+
import { AgenticaEvent } from "../events/AgenticaEvent";
|
|
12
|
+
import { AgenticaSelectEvent } from "../events/AgenticaSelectEvent";
|
|
13
|
+
import { AgenticaTextEvent } from "../events/AgenticaTextEvent";
|
|
10
14
|
import { AgenticaConstant } from "../internal/AgenticaConstant";
|
|
11
15
|
import { AgenticaDefaultPrompt } from "../internal/AgenticaDefaultPrompt";
|
|
12
|
-
import { AgenticaPromptFactory } from "../internal/AgenticaPromptFactory";
|
|
13
16
|
import { AgenticaSystemPrompt } from "../internal/AgenticaSystemPrompt";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import { IAgenticaPrompt } from "../structures/IAgenticaPrompt";
|
|
20
|
-
import { __IChatFunctionReference } from "../structures/internal/__IChatFunctionReference";
|
|
21
|
-
import { __IChatSelectFunctionsApplication } from "../structures/internal/__IChatSelectFunctionsApplication";
|
|
17
|
+
import { StreamUtil } from "../internal/StreamUtil";
|
|
18
|
+
import { AgenticaPrompt } from "../prompts/AgenticaPrompt";
|
|
19
|
+
import { AgenticaSelectPrompt } from "../prompts/AgenticaSelectPrompt";
|
|
20
|
+
import { AgenticaTextPrompt } from "../prompts/AgenticaTextPrompt";
|
|
21
|
+
import { ChatGptCompletionMessageUtil } from "./ChatGptCompletionMessageUtil";
|
|
22
22
|
import { ChatGptHistoryDecoder } from "./ChatGptHistoryDecoder";
|
|
23
23
|
|
|
24
24
|
export namespace ChatGptSelectFunctionAgent {
|
|
25
25
|
export const execute = async <Model extends ILlmSchema.Model>(
|
|
26
|
-
ctx:
|
|
27
|
-
): Promise<
|
|
26
|
+
ctx: AgenticaContext<Model>,
|
|
27
|
+
): Promise<AgenticaPrompt<Model>[]> => {
|
|
28
28
|
if (ctx.operations.divided === undefined)
|
|
29
29
|
return step(ctx, ctx.operations.array, 0);
|
|
30
30
|
|
|
31
|
-
const stacks:
|
|
31
|
+
const stacks: AgenticaOperationSelection<Model>[][] =
|
|
32
32
|
ctx.operations.divided.map(() => []);
|
|
33
|
-
const events:
|
|
34
|
-
const prompts:
|
|
33
|
+
const events: AgenticaEvent<Model>[] = [];
|
|
34
|
+
const prompts: AgenticaPrompt<Model>[][] = await Promise.all(
|
|
35
35
|
ctx.operations.divided.map((operations, i) =>
|
|
36
36
|
step(
|
|
37
37
|
{
|
|
@@ -58,48 +58,38 @@ export namespace ChatGptSelectFunctionAgent {
|
|
|
58
58
|
.map(
|
|
59
59
|
(s) =>
|
|
60
60
|
ctx.operations.group
|
|
61
|
-
.get(s.controller.name)!
|
|
62
|
-
.get(s.function.name)!,
|
|
61
|
+
.get(s.operation.controller.name)!
|
|
62
|
+
.get(s.operation.function.name)!,
|
|
63
63
|
),
|
|
64
64
|
0,
|
|
65
65
|
);
|
|
66
66
|
|
|
67
67
|
// RE-COLLECT SELECT FUNCTION EVENTS
|
|
68
|
-
const collection:
|
|
68
|
+
const collection: AgenticaSelectPrompt<Model> = new AgenticaSelectPrompt({
|
|
69
69
|
id: v4(),
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
};
|
|
70
|
+
selections: [],
|
|
71
|
+
});
|
|
73
72
|
for (const e of events)
|
|
74
73
|
if (e.type === "select") {
|
|
75
|
-
collection.
|
|
76
|
-
AgenticaPromptFactory.selection({
|
|
77
|
-
protocol: e.operation.protocol as "http",
|
|
78
|
-
controller: e.operation
|
|
79
|
-
.controller as IAgenticaController.IHttp<Model>,
|
|
80
|
-
function: e.operation.function as IHttpLlmFunction<Model>,
|
|
81
|
-
reason: e.reason,
|
|
82
|
-
name: e.operation.name,
|
|
83
|
-
}),
|
|
84
|
-
);
|
|
74
|
+
collection.selections.push(e.selection);
|
|
85
75
|
await selectFunction(ctx, {
|
|
86
|
-
name: e.operation.name,
|
|
87
|
-
reason: e.reason,
|
|
76
|
+
name: e.selection.operation.name,
|
|
77
|
+
reason: e.selection.reason,
|
|
88
78
|
});
|
|
89
79
|
}
|
|
90
80
|
return [collection];
|
|
91
81
|
};
|
|
92
82
|
|
|
93
83
|
const step = async <Model extends ILlmSchema.Model>(
|
|
94
|
-
ctx:
|
|
95
|
-
operations:
|
|
84
|
+
ctx: AgenticaContext<Model>,
|
|
85
|
+
operations: AgenticaOperation<Model>[],
|
|
96
86
|
retry: number,
|
|
97
87
|
failures?: IFailure[],
|
|
98
|
-
): Promise<
|
|
88
|
+
): Promise<AgenticaPrompt<Model>[]> => {
|
|
99
89
|
//----
|
|
100
90
|
// EXECUTE CHATGPT API
|
|
101
91
|
//----
|
|
102
|
-
const
|
|
92
|
+
const completionStream = await ctx.request("select", {
|
|
103
93
|
messages: [
|
|
104
94
|
// COMMON SYSTEM PROMPT
|
|
105
95
|
{
|
|
@@ -170,6 +160,8 @@ export namespace ChatGptSelectFunctionAgent {
|
|
|
170
160
|
parallel_tool_calls: false,
|
|
171
161
|
});
|
|
172
162
|
|
|
163
|
+
const chunks = await StreamUtil.readAll(completionStream);
|
|
164
|
+
const completion = ChatGptCompletionMessageUtil.merge(chunks);
|
|
173
165
|
//----
|
|
174
166
|
// VALIDATION
|
|
175
167
|
//----
|
|
@@ -194,7 +186,7 @@ export namespace ChatGptSelectFunctionAgent {
|
|
|
194
186
|
//----
|
|
195
187
|
// PROCESS COMPLETION
|
|
196
188
|
//----
|
|
197
|
-
const prompts:
|
|
189
|
+
const prompts: AgenticaPrompt<Model>[] = [];
|
|
198
190
|
for (const choice of completion.choices) {
|
|
199
191
|
// TOOL CALLING HANDLER
|
|
200
192
|
if (choice.message.tool_calls)
|
|
@@ -206,27 +198,23 @@ export namespace ChatGptSelectFunctionAgent {
|
|
|
206
198
|
);
|
|
207
199
|
if (typia.is(input) === false) continue;
|
|
208
200
|
else if (tc.function.name === "selectFunctions") {
|
|
209
|
-
const collection:
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
201
|
+
const collection: AgenticaSelectPrompt<Model> =
|
|
202
|
+
new AgenticaSelectPrompt({
|
|
203
|
+
id: tc.id,
|
|
204
|
+
selections: [],
|
|
205
|
+
});
|
|
214
206
|
for (const reference of input.functions) {
|
|
215
|
-
const operation:
|
|
207
|
+
const operation: AgenticaOperation<Model> | null =
|
|
216
208
|
await selectFunction(ctx, reference);
|
|
217
209
|
if (operation !== null)
|
|
218
|
-
collection.
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
controller:
|
|
222
|
-
operation.controller as IAgenticaController.IHttp<Model>,
|
|
223
|
-
function: operation.function as IHttpLlmFunction<Model>,
|
|
224
|
-
name: operation.name,
|
|
210
|
+
collection.selections.push(
|
|
211
|
+
new AgenticaOperationSelection({
|
|
212
|
+
operation,
|
|
225
213
|
reason: reference.reason,
|
|
226
214
|
}),
|
|
227
215
|
);
|
|
228
216
|
}
|
|
229
|
-
if (collection.
|
|
217
|
+
if (collection.selections.length !== 0) prompts.push(collection);
|
|
230
218
|
}
|
|
231
219
|
}
|
|
232
220
|
|
|
@@ -235,40 +223,44 @@ export namespace ChatGptSelectFunctionAgent {
|
|
|
235
223
|
choice.message.role === "assistant" &&
|
|
236
224
|
!!choice.message.content?.length
|
|
237
225
|
) {
|
|
238
|
-
const text:
|
|
239
|
-
type: "text",
|
|
226
|
+
const text: AgenticaTextPrompt = new AgenticaTextPrompt({
|
|
240
227
|
role: "assistant",
|
|
241
228
|
text: choice.message.content,
|
|
242
|
-
};
|
|
229
|
+
});
|
|
243
230
|
prompts.push(text);
|
|
244
|
-
await ctx.dispatch(
|
|
231
|
+
await ctx.dispatch(
|
|
232
|
+
new AgenticaTextEvent({
|
|
233
|
+
role: "assistant",
|
|
234
|
+
stream: StreamUtil.to(text.text),
|
|
235
|
+
join: () => Promise.resolve(text.text),
|
|
236
|
+
done: () => true,
|
|
237
|
+
get: () => text.text,
|
|
238
|
+
}),
|
|
239
|
+
);
|
|
245
240
|
}
|
|
246
241
|
}
|
|
247
242
|
return prompts;
|
|
248
243
|
};
|
|
249
244
|
|
|
250
245
|
const selectFunction = async <Model extends ILlmSchema.Model>(
|
|
251
|
-
ctx:
|
|
246
|
+
ctx: AgenticaContext<Model>,
|
|
252
247
|
reference: __IChatFunctionReference,
|
|
253
|
-
): Promise<
|
|
254
|
-
const operation:
|
|
248
|
+
): Promise<AgenticaOperation<Model> | null> => {
|
|
249
|
+
const operation: AgenticaOperation<Model> | undefined =
|
|
255
250
|
ctx.operations.flat.get(reference.name);
|
|
256
251
|
if (operation === undefined) return null;
|
|
257
252
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
controller: operation.controller as IAgenticaController.IHttp<Model>,
|
|
262
|
-
function: operation.function as IHttpLlmFunction<Model>,
|
|
263
|
-
name: reference.name,
|
|
253
|
+
const selection: AgenticaOperationSelection<Model> =
|
|
254
|
+
new AgenticaOperationSelection({
|
|
255
|
+
operation,
|
|
264
256
|
reason: reference.reason,
|
|
257
|
+
});
|
|
258
|
+
ctx.stack.push(selection);
|
|
259
|
+
void ctx.dispatch(
|
|
260
|
+
new AgenticaSelectEvent({
|
|
261
|
+
selection,
|
|
265
262
|
}),
|
|
266
263
|
);
|
|
267
|
-
await ctx.dispatch({
|
|
268
|
-
type: "select",
|
|
269
|
-
reason: reference.reason,
|
|
270
|
-
operation,
|
|
271
|
-
});
|
|
272
264
|
return operation;
|
|
273
265
|
};
|
|
274
266
|
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { CompletionUsage } from "openai/resources";
|
|
2
|
+
|
|
3
|
+
export namespace ChatGptUsageAggregator {
|
|
4
|
+
export const sumCompletionTokenDetail = (
|
|
5
|
+
x: CompletionUsage.CompletionTokensDetails,
|
|
6
|
+
y: CompletionUsage.CompletionTokensDetails,
|
|
7
|
+
): CompletionUsage.CompletionTokensDetails => {
|
|
8
|
+
return {
|
|
9
|
+
accepted_prediction_tokens:
|
|
10
|
+
(x.accepted_prediction_tokens ?? 0) +
|
|
11
|
+
(y.accepted_prediction_tokens ?? 0),
|
|
12
|
+
reasoning_tokens: (x.reasoning_tokens ?? 0) + (y.reasoning_tokens ?? 0),
|
|
13
|
+
rejected_prediction_tokens:
|
|
14
|
+
(x.rejected_prediction_tokens ?? 0) +
|
|
15
|
+
(y.rejected_prediction_tokens ?? 0),
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const sumPromptTokenDetail = (
|
|
20
|
+
x: CompletionUsage.PromptTokensDetails,
|
|
21
|
+
y: CompletionUsage.PromptTokensDetails,
|
|
22
|
+
): CompletionUsage.PromptTokensDetails => {
|
|
23
|
+
return {
|
|
24
|
+
audio_tokens: (x.audio_tokens ?? 0) + (y.audio_tokens ?? 0),
|
|
25
|
+
cached_tokens: (x.cached_tokens ?? 0) + (y.cached_tokens ?? 0),
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const sum = (
|
|
30
|
+
x: CompletionUsage,
|
|
31
|
+
y: CompletionUsage,
|
|
32
|
+
): CompletionUsage => {
|
|
33
|
+
return {
|
|
34
|
+
prompt_tokens: (x.prompt_tokens ?? 0) + (y.prompt_tokens ?? 0),
|
|
35
|
+
completion_tokens:
|
|
36
|
+
(x.completion_tokens ?? 0) + (y.completion_tokens ?? 0),
|
|
37
|
+
total_tokens: (x.total_tokens ?? 0) + (y.total_tokens ?? 0),
|
|
38
|
+
completion_tokens_details: sumCompletionTokenDetail(
|
|
39
|
+
x.completion_tokens_details ?? {
|
|
40
|
+
accepted_prediction_tokens: 0,
|
|
41
|
+
reasoning_tokens: 0,
|
|
42
|
+
rejected_prediction_tokens: 0,
|
|
43
|
+
},
|
|
44
|
+
y.completion_tokens_details ?? {
|
|
45
|
+
accepted_prediction_tokens: 0,
|
|
46
|
+
reasoning_tokens: 0,
|
|
47
|
+
rejected_prediction_tokens: 0,
|
|
48
|
+
},
|
|
49
|
+
),
|
|
50
|
+
prompt_tokens_details: sumPromptTokenDetail(
|
|
51
|
+
x.prompt_tokens_details ?? {
|
|
52
|
+
audio_tokens: 0,
|
|
53
|
+
cached_tokens: 0,
|
|
54
|
+
},
|
|
55
|
+
y.prompt_tokens_details ?? {
|
|
56
|
+
audio_tokens: 0,
|
|
57
|
+
cached_tokens: 0,
|
|
58
|
+
},
|
|
59
|
+
),
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
|
|
3
|
+
import { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
|
|
4
|
+
import { AgenticaPromptBase } from "../prompts/AgenticaPromptBase";
|
|
5
|
+
import { AgenticaOperationSelection } from "./AgenticaOperationSelection";
|
|
6
|
+
|
|
7
|
+
export class AgenticaCancelPrompt<
|
|
8
|
+
Model extends ILlmSchema.Model,
|
|
9
|
+
> extends AgenticaPromptBase<"cancel", IAgenticaPromptJson.ICancel> {
|
|
10
|
+
public readonly id: string;
|
|
11
|
+
public readonly selections: AgenticaOperationSelection<Model>[];
|
|
12
|
+
|
|
13
|
+
public constructor(props: AgenticaCancelPrompt.IProps<Model>) {
|
|
14
|
+
super("cancel");
|
|
15
|
+
this.id = props.id;
|
|
16
|
+
this.selections = props.selections;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public toJSON(): IAgenticaPromptJson.ICancel {
|
|
20
|
+
return {
|
|
21
|
+
type: this.type,
|
|
22
|
+
id: this.id,
|
|
23
|
+
selections: this.selections.map((s) => s.toJSON()),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export namespace AgenticaCancelPrompt {
|
|
28
|
+
export interface IProps<Model extends ILlmSchema.Model> {
|
|
29
|
+
id: string;
|
|
30
|
+
selections: AgenticaOperationSelection<Model>[];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ILlmApplication, ILlmFunction, ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
|
|
3
|
+
import { AgenticaOperationBase } from "./AgenticaOperationBase";
|
|
4
|
+
|
|
5
|
+
export class AgenticaClassOperation<
|
|
6
|
+
Model extends ILlmSchema.Model,
|
|
7
|
+
> extends AgenticaOperationBase<
|
|
8
|
+
"class",
|
|
9
|
+
ILlmApplication<Model>,
|
|
10
|
+
ILlmFunction<Model>
|
|
11
|
+
> {
|
|
12
|
+
public constructor(props: AgenticaClassOperation.IProps<Model>) {
|
|
13
|
+
super(props);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export namespace AgenticaClassOperation {
|
|
17
|
+
export type IProps<Model extends ILlmSchema.Model> =
|
|
18
|
+
AgenticaOperationBase.IProps<
|
|
19
|
+
"class",
|
|
20
|
+
ILlmApplication<Model>,
|
|
21
|
+
ILlmFunction<Model>
|
|
22
|
+
>;
|
|
23
|
+
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
import OpenAI from "openai";
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
4
|
+
import { AgenticaEvent } from "../events/AgenticaEvent";
|
|
5
|
+
import { AgenticaEventSource } from "../events/AgenticaEventSource";
|
|
6
|
+
import { AgenticaPrompt } from "../prompts/AgenticaPrompt";
|
|
7
|
+
import { AgenticaTextPrompt } from "../prompts/AgenticaTextPrompt";
|
|
8
|
+
import { IAgenticaConfig } from "../structures/IAgenticaConfig";
|
|
9
|
+
import { AgenticaOperationCollection } from "./AgenticaOperationCollection";
|
|
10
|
+
import { AgenticaOperationSelection } from "./AgenticaOperationSelection";
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Context of the Nestia A.I. agent.
|
|
@@ -39,7 +40,7 @@ import { IAgenticaPrompt } from "./IAgenticaPrompt";
|
|
|
39
40
|
*
|
|
40
41
|
* @author Samchon
|
|
41
42
|
*/
|
|
42
|
-
export interface
|
|
43
|
+
export interface AgenticaContext<Model extends ILlmSchema.Model> {
|
|
43
44
|
//----
|
|
44
45
|
// APPLICATION
|
|
45
46
|
//----
|
|
@@ -50,7 +51,7 @@ export interface IAgenticaContext<Model extends ILlmSchema.Model> {
|
|
|
50
51
|
* groups composed by the divide and conquer rule for the
|
|
51
52
|
* efficient operation selection if configured.
|
|
52
53
|
*/
|
|
53
|
-
operations:
|
|
54
|
+
operations: AgenticaOperationCollection<Model>;
|
|
54
55
|
|
|
55
56
|
/**
|
|
56
57
|
* Configuration of the agent.
|
|
@@ -68,14 +69,14 @@ export interface IAgenticaContext<Model extends ILlmSchema.Model> {
|
|
|
68
69
|
/**
|
|
69
70
|
* Prompt histories.
|
|
70
71
|
*/
|
|
71
|
-
histories:
|
|
72
|
+
histories: AgenticaPrompt<Model>[];
|
|
72
73
|
|
|
73
74
|
/**
|
|
74
75
|
* Stacked operations.
|
|
75
76
|
*
|
|
76
77
|
* In other words, list of candidate operations for the LLM function calling.
|
|
77
78
|
*/
|
|
78
|
-
stack:
|
|
79
|
+
stack: AgenticaOperationSelection<Model>[];
|
|
79
80
|
|
|
80
81
|
/**
|
|
81
82
|
* Text prompt of the user.
|
|
@@ -83,7 +84,7 @@ export interface IAgenticaContext<Model extends ILlmSchema.Model> {
|
|
|
83
84
|
* Text conversation written the by user through the
|
|
84
85
|
* {@link Agentica.conversate} function.
|
|
85
86
|
*/
|
|
86
|
-
prompt:
|
|
87
|
+
prompt: AgenticaTextPrompt<"user">;
|
|
87
88
|
|
|
88
89
|
/**
|
|
89
90
|
* Whether the agent is ready.
|
|
@@ -91,7 +92,7 @@ export interface IAgenticaContext<Model extends ILlmSchema.Model> {
|
|
|
91
92
|
* Returns a boolean value indicates whether the agent is ready to
|
|
92
93
|
* perform the function calling.
|
|
93
94
|
*
|
|
94
|
-
* If the agent has called the {@link
|
|
95
|
+
* If the agent has called the {@link AgenticaContext.initialize},
|
|
95
96
|
* it returns `true`. Otherwise the {@link initialize} has never been
|
|
96
97
|
* called, returns `false`.
|
|
97
98
|
*/
|
|
@@ -108,7 +109,7 @@ export interface IAgenticaContext<Model extends ILlmSchema.Model> {
|
|
|
108
109
|
*
|
|
109
110
|
* @param event Event to deliver
|
|
110
111
|
*/
|
|
111
|
-
dispatch: (event:
|
|
112
|
+
dispatch: (event: AgenticaEvent<Model>) => Promise<void>;
|
|
112
113
|
|
|
113
114
|
/**
|
|
114
115
|
* Request to the OpenAI server.
|
|
@@ -118,9 +119,9 @@ export interface IAgenticaContext<Model extends ILlmSchema.Model> {
|
|
|
118
119
|
* @returns Response from the OpenAI server
|
|
119
120
|
*/
|
|
120
121
|
request: (
|
|
121
|
-
source:
|
|
122
|
-
body: Omit<OpenAI.
|
|
123
|
-
) => Promise<OpenAI.
|
|
122
|
+
source: AgenticaEventSource,
|
|
123
|
+
body: Omit<OpenAI.ChatCompletionCreateParamsStreaming, "model" | "stream">,
|
|
124
|
+
) => Promise<ReadableStream<OpenAI.Chat.Completions.ChatCompletionChunk>>;
|
|
124
125
|
|
|
125
126
|
/**
|
|
126
127
|
* Initialize the agent.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IHttpLlmApplication,
|
|
3
|
+
IHttpLlmFunction,
|
|
4
|
+
ILlmSchema,
|
|
5
|
+
} from "@samchon/openapi";
|
|
6
|
+
|
|
7
|
+
import { AgenticaOperationBase } from "./AgenticaOperationBase";
|
|
8
|
+
|
|
9
|
+
export class AgenticaHttpOperation<
|
|
10
|
+
Model extends ILlmSchema.Model,
|
|
11
|
+
> extends AgenticaOperationBase<
|
|
12
|
+
"http",
|
|
13
|
+
IHttpLlmApplication<Model>,
|
|
14
|
+
IHttpLlmFunction<Model>
|
|
15
|
+
> {
|
|
16
|
+
public constructor(props: AgenticaHttpOperation.IProps<Model>) {
|
|
17
|
+
super(props);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export namespace AgenticaHttpOperation {
|
|
21
|
+
export type IProps<Model extends ILlmSchema.Model> =
|
|
22
|
+
AgenticaOperationBase.IProps<
|
|
23
|
+
"http",
|
|
24
|
+
IHttpLlmApplication<Model>,
|
|
25
|
+
IHttpLlmFunction<Model>
|
|
26
|
+
>;
|
|
27
|
+
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { IHttpLlmFunction, ILlmFunction, ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { IAgenticaOperationJson } from "../json/IAgenticaOperationJson";
|
|
4
|
+
import { IAgenticaController } from "../structures/IAgenticaController";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
|
-
* Operation information in the
|
|
7
|
+
* Operation information in the Agentica Agent.
|
|
7
8
|
*
|
|
8
|
-
* `
|
|
9
|
+
* `AgenticaOperation` is a type represents an operation that would
|
|
9
10
|
* be selected by the A.I. chatbot of {@link Agentica} class to
|
|
10
11
|
* perform the LLM (Large Language Model) function calling.
|
|
11
12
|
*
|
|
@@ -17,29 +18,26 @@ import { IAgenticaController } from "./IAgenticaController";
|
|
|
17
18
|
*
|
|
18
19
|
* @author Samchon
|
|
19
20
|
*/
|
|
20
|
-
export type
|
|
21
|
-
|
|
|
22
|
-
|
|
|
23
|
-
export namespace
|
|
24
|
-
|
|
25
|
-
* HTTP API operation.
|
|
26
|
-
*/
|
|
27
|
-
export type IHttp<Model extends ILlmSchema.Model> = IBase<
|
|
28
|
-
"http",
|
|
29
|
-
IAgenticaController.IHttp<Model>,
|
|
30
|
-
IHttpLlmFunction<Model>
|
|
31
|
-
>;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* TypeScript class operation.
|
|
35
|
-
*/
|
|
36
|
-
export type IClass<Model extends ILlmSchema.Model> = IBase<
|
|
21
|
+
export type AgenticaOperation<Model extends ILlmSchema.Model> =
|
|
22
|
+
| AgenticaOperation.Class<Model>
|
|
23
|
+
| AgenticaOperation.Http<Model>;
|
|
24
|
+
export namespace AgenticaOperation {
|
|
25
|
+
export type Class<Model extends ILlmSchema.Model> = Base<
|
|
37
26
|
"class",
|
|
38
27
|
IAgenticaController.IClass<Model>,
|
|
39
28
|
ILlmFunction<Model>
|
|
40
29
|
>;
|
|
30
|
+
export type Http<Model extends ILlmSchema.Model> = Base<
|
|
31
|
+
"http",
|
|
32
|
+
IAgenticaController.IHttp<Model>,
|
|
33
|
+
IHttpLlmFunction<Model>
|
|
34
|
+
>;
|
|
41
35
|
|
|
42
|
-
interface
|
|
36
|
+
interface Base<
|
|
37
|
+
Protocol extends "http" | "class",
|
|
38
|
+
Controller extends object,
|
|
39
|
+
Function extends object,
|
|
40
|
+
> {
|
|
43
41
|
/**
|
|
44
42
|
* Protocol discriminator.
|
|
45
43
|
*/
|
|
@@ -48,7 +46,7 @@ export namespace IAgenticaOperation {
|
|
|
48
46
|
/**
|
|
49
47
|
* Belonged controller of the target function.
|
|
50
48
|
*/
|
|
51
|
-
controller:
|
|
49
|
+
controller: Controller;
|
|
52
50
|
|
|
53
51
|
/**
|
|
54
52
|
* Target function to call.
|
|
@@ -59,5 +57,10 @@ export namespace IAgenticaOperation {
|
|
|
59
57
|
* Identifier name.
|
|
60
58
|
*/
|
|
61
59
|
name: string;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Convert to primitive JSON object.
|
|
63
|
+
*/
|
|
64
|
+
toJSON(): IAgenticaOperationJson;
|
|
62
65
|
}
|
|
63
66
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { IAgenticaOperationJson } from "../json/IAgenticaOperationJson";
|
|
2
|
+
|
|
3
|
+
export abstract class AgenticaOperationBase<
|
|
4
|
+
Protocol extends "http" | "class",
|
|
5
|
+
Controller extends object,
|
|
6
|
+
Function extends object,
|
|
7
|
+
> {
|
|
8
|
+
/**
|
|
9
|
+
* Protocol discriminator.
|
|
10
|
+
*/
|
|
11
|
+
public readonly protocol: Protocol;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Belonged controller of the target function.
|
|
15
|
+
*/
|
|
16
|
+
public readonly controller: Controller;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Target function to call.
|
|
20
|
+
*/
|
|
21
|
+
public readonly function: Function;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Identifier name.
|
|
25
|
+
*/
|
|
26
|
+
public readonly name: string;
|
|
27
|
+
|
|
28
|
+
protected constructor(
|
|
29
|
+
props: AgenticaOperationBase.IProps<Protocol, Controller, Function>,
|
|
30
|
+
) {
|
|
31
|
+
this.protocol = props.protocol;
|
|
32
|
+
this.controller = props.controller;
|
|
33
|
+
this.function = props.function;
|
|
34
|
+
this.name = props.name;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public toJSON(): IAgenticaOperationJson {
|
|
38
|
+
return {
|
|
39
|
+
protocol: this.protocol,
|
|
40
|
+
controller: this.controller.constructor.name,
|
|
41
|
+
function: this.function.constructor.name,
|
|
42
|
+
name: this.name,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export namespace AgenticaOperationBase {
|
|
47
|
+
export interface IProps<
|
|
48
|
+
Protocol extends "http" | "class",
|
|
49
|
+
Controller extends object,
|
|
50
|
+
Function extends object,
|
|
51
|
+
> {
|
|
52
|
+
protocol: Protocol;
|
|
53
|
+
controller: Controller;
|
|
54
|
+
function: Function;
|
|
55
|
+
name: string;
|
|
56
|
+
}
|
|
57
|
+
}
|
package/src/{structures/IAgenticaOperationCollection.ts → context/AgenticaOperationCollection.ts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { AgenticaOperation } from "./AgenticaOperation";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Collection of operations used in the Nestia Agent.
|
|
@@ -11,11 +11,11 @@ import { IAgenticaOperation } from "./IAgenticaOperation";
|
|
|
11
11
|
*
|
|
12
12
|
* @author Samchon
|
|
13
13
|
*/
|
|
14
|
-
export interface
|
|
14
|
+
export interface AgenticaOperationCollection<Model extends ILlmSchema.Model> {
|
|
15
15
|
/**
|
|
16
16
|
* List of every operations.
|
|
17
17
|
*/
|
|
18
|
-
array:
|
|
18
|
+
array: AgenticaOperation<Model>[];
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Divided operations.
|
|
@@ -32,14 +32,14 @@ export interface IAgenticaOperationCollection<Model extends ILlmSchema.Model> {
|
|
|
32
32
|
* Otherwise, if the {@link IAgenticaConfig.capacity} has not been
|
|
33
33
|
* configured, this `divided` property would be the `undefined` value.
|
|
34
34
|
*/
|
|
35
|
-
divided?:
|
|
35
|
+
divided?: AgenticaOperation<Model>[][] | undefined;
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* Flat dictionary of operations.
|
|
39
39
|
*
|
|
40
40
|
* Dictionary of operations with their {@link IAgenticaOperation.name}.
|
|
41
41
|
*/
|
|
42
|
-
flat: Map<string,
|
|
42
|
+
flat: Map<string, AgenticaOperation<Model>>;
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* Group dictionary of operations.
|
|
@@ -48,5 +48,5 @@ export interface IAgenticaOperationCollection<Model extends ILlmSchema.Model> {
|
|
|
48
48
|
* {@link IAgenticaOperation.controller.name} and
|
|
49
49
|
* {@link IAgenticaOperation.function.name}.
|
|
50
50
|
*/
|
|
51
|
-
group: Map<string, Map<string,
|
|
51
|
+
group: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
52
52
|
}
|