@agentica/core 0.12.21 → 0.13.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 +50 -47
- package/lib/Agentica.d.ts +9 -9
- package/lib/Agentica.js +23 -16
- package/lib/Agentica.js.map +1 -1
- package/lib/chatgpt/ChatGptAgent.d.ts +7 -7
- package/lib/chatgpt/ChatGptAgent.js +17 -12
- package/lib/chatgpt/ChatGptAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptCallFunctionAgent.d.ts +7 -6
- package/lib/chatgpt/ChatGptCallFunctionAgent.js +121 -81
- package/lib/chatgpt/ChatGptCallFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptCancelFunctionAgent.d.ts +9 -7
- package/lib/chatgpt/ChatGptCancelFunctionAgent.js +177 -145
- package/lib/chatgpt/ChatGptCancelFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptCompletionMessageUtil.d.ts +13 -8
- package/lib/chatgpt/ChatGptCompletionMessageUtil.js +499 -489
- package/lib/chatgpt/ChatGptCompletionMessageUtil.js.map +1 -1
- package/lib/chatgpt/ChatGptDescribeFunctionAgent.d.ts +7 -6
- package/lib/chatgpt/ChatGptDescribeFunctionAgent.js +33 -32
- package/lib/chatgpt/ChatGptDescribeFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptHistoryDecoder.d.ts +7 -6
- package/lib/chatgpt/ChatGptHistoryDecoder.js +60 -56
- package/lib/chatgpt/ChatGptHistoryDecoder.js.map +1 -1
- package/lib/chatgpt/ChatGptInitializeFunctionAgent.d.ts +7 -6
- package/lib/chatgpt/ChatGptInitializeFunctionAgent.js +121 -116
- package/lib/chatgpt/ChatGptInitializeFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptSelectFunctionAgent.d.ts +20 -5
- package/lib/chatgpt/ChatGptSelectFunctionAgent.js +183 -150
- package/lib/chatgpt/ChatGptSelectFunctionAgent.js.map +1 -1
- package/lib/chatgpt/ChatGptUsageAggregator.d.ts +9 -6
- package/lib/chatgpt/ChatGptUsageAggregator.js +46 -41
- package/lib/chatgpt/ChatGptUsageAggregator.js.map +1 -1
- package/lib/context/AgenticaCancelPrompt.d.ts +3 -3
- package/lib/context/AgenticaCancelPrompt.js +1 -1
- package/lib/context/AgenticaCancelPrompt.js.map +1 -1
- package/lib/context/AgenticaClassOperation.d.ts +1 -1
- package/lib/context/AgenticaClassOperation.js.map +1 -1
- package/lib/context/AgenticaContext.d.ts +9 -9
- package/lib/context/AgenticaHttpOperation.d.ts +1 -1
- package/lib/context/AgenticaHttpOperation.js.map +1 -1
- package/lib/context/AgenticaOperation.d.ts +4 -4
- package/lib/context/AgenticaOperationBase.d.ts +1 -1
- package/lib/context/AgenticaOperationCollection.d.ts +2 -2
- package/lib/context/AgenticaOperationSelection.d.ts +3 -3
- package/lib/context/AgenticaTokenUsage.d.ts +1 -1
- package/lib/context/AgenticaTokenUsage.js.map +1 -1
- package/lib/context/internal/AgenticaTokenUsageAggregator.d.ts +11 -10
- package/lib/context/internal/AgenticaTokenUsageAggregator.js +42 -43
- package/lib/context/internal/AgenticaTokenUsageAggregator.js.map +1 -1
- package/lib/context/internal/__IChatCancelFunctionsApplication.d.ts +2 -2
- package/lib/context/internal/__IChatInitialApplication.d.ts +2 -2
- package/lib/context/internal/__IChatSelectFunctionsApplication.d.ts +2 -2
- package/lib/events/AgenticaCallEvent.d.ts +3 -3
- package/lib/events/AgenticaCancelEvent.d.ts +3 -3
- package/lib/events/AgenticaDescribeEvent.d.ts +3 -3
- package/lib/events/AgenticaDescribeEvent.js +13 -2
- package/lib/events/AgenticaDescribeEvent.js.map +1 -1
- package/lib/events/AgenticaEvent.d.ts +12 -12
- package/lib/events/AgenticaExecuteEvent.d.ts +7 -7
- package/lib/events/AgenticaInitializeEvent.d.ts +1 -1
- package/lib/events/AgenticaRequestEvent.d.ts +3 -3
- package/lib/events/AgenticaRequestEvent.js.map +1 -1
- package/lib/events/AgenticaResponseEvent.d.ts +2 -2
- package/lib/events/AgenticaResponseEvent.js.map +1 -1
- package/lib/events/AgenticaSelectEvent.d.ts +3 -3
- package/lib/events/AgenticaSelectEvent.js.map +1 -1
- package/lib/events/AgenticaTextEvent.d.ts +1 -1
- package/lib/events/AgenticaTextEvent.js +12 -1
- package/lib/events/AgenticaTextEvent.js.map +1 -1
- package/lib/functional/assertHttpLlmApplication.d.ts +4 -3
- package/lib/functional/assertHttpLlmApplication.js +9339 -9338
- package/lib/functional/assertHttpLlmApplication.js.map +1 -1
- package/lib/functional/validateHttpLlmApplication.d.ts +5 -4
- package/lib/functional/validateHttpLlmApplication.js +19 -19
- package/lib/functional/validateHttpLlmApplication.js.map +1 -1
- package/lib/index.d.ts +19 -19
- package/lib/index.js +21 -21
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +19211 -18997
- package/lib/index.mjs.map +1 -1
- package/lib/internal/AgenticaDefaultPrompt.d.ts +6 -5
- package/lib/internal/AgenticaDefaultPrompt.js +39 -19
- package/lib/internal/AgenticaDefaultPrompt.js.map +1 -1
- package/lib/internal/AgenticaOperationComposer.d.ts +11 -10
- package/lib/internal/AgenticaOperationComposer.js +60 -59
- package/lib/internal/AgenticaOperationComposer.js.map +1 -1
- package/lib/internal/AgenticaSystemPrompt.d.ts +8 -8
- package/lib/internal/AgenticaSystemPrompt.js +9 -9
- package/lib/internal/AgenticaSystemPrompt.js.map +1 -1
- package/lib/internal/AsyncQueue.d.ts +15 -0
- package/lib/internal/AsyncQueue.js +82 -0
- package/lib/internal/AsyncQueue.js.map +1 -0
- package/lib/internal/ByteArrayUtil.d.ts +1 -1
- package/lib/internal/ByteArrayUtil.js +3 -2
- package/lib/internal/ByteArrayUtil.js.map +1 -1
- package/lib/internal/MPSC.d.ts +10 -0
- package/lib/internal/MPSC.js +49 -0
- package/lib/internal/MPSC.js.map +1 -0
- package/lib/internal/Singleton.js +6 -5
- package/lib/internal/Singleton.js.map +1 -1
- package/lib/internal/StreamUtil.d.ts +16 -6
- package/lib/internal/StreamUtil.js +43 -29
- package/lib/internal/StreamUtil.js.map +1 -1
- package/lib/internal/__map_take.js +5 -5
- package/lib/internal/__map_take.js.map +1 -1
- package/lib/json/IAgenticaEventJson.d.ts +7 -7
- package/lib/json/IAgenticaOperationSelectionJson.d.ts +1 -1
- package/lib/json/IAgenticaPromptJson.d.ts +2 -2
- package/lib/prompts/AgenticaCancelPrompt.d.ts +3 -3
- package/lib/prompts/AgenticaCancelPrompt.js +1 -1
- package/lib/prompts/AgenticaCancelPrompt.js.map +1 -1
- package/lib/prompts/AgenticaDescribePrompt.d.ts +3 -3
- package/lib/prompts/AgenticaDescribePrompt.js +1 -1
- package/lib/prompts/AgenticaDescribePrompt.js.map +1 -1
- package/lib/prompts/AgenticaExecutePrompt.d.ts +5 -5
- package/lib/prompts/AgenticaExecutePrompt.js.map +1 -1
- package/lib/prompts/AgenticaPrompt.d.ts +6 -6
- package/lib/prompts/AgenticaSelectPrompt.d.ts +3 -3
- package/lib/prompts/AgenticaSelectPrompt.js +1 -1
- package/lib/prompts/AgenticaSelectPrompt.js.map +1 -1
- package/lib/prompts/AgenticaTextPrompt.d.ts +1 -1
- package/lib/structures/IAgenticaConfig.d.ts +5 -5
- package/lib/structures/IAgenticaController.d.ts +1 -1
- package/lib/structures/IAgenticaExecutor.d.ts +4 -4
- package/lib/structures/IAgenticaProps.d.ts +5 -5
- package/lib/structures/IAgenticaSystemPrompt.d.ts +4 -4
- package/lib/structures/IAgenticaVendor.d.ts +1 -1
- package/lib/transformers/AgenticaEventTransformer.d.ts +55 -37
- package/lib/transformers/AgenticaEventTransformer.js +105 -58
- package/lib/transformers/AgenticaEventTransformer.js.map +1 -1
- package/lib/transformers/AgenticaPromptTransformer.d.ts +35 -29
- package/lib/transformers/AgenticaPromptTransformer.js +74 -45
- package/lib/transformers/AgenticaPromptTransformer.js.map +1 -1
- package/package.json +20 -23
- package/prompts/cancel.md +1 -1
- package/prompts/common.md +1 -1
- package/prompts/describe.md +1 -1
- package/prompts/execute.md +1 -1
- package/prompts/initialize.md +1 -1
- package/prompts/select.md +1 -1
- package/src/Agentica.ts +41 -31
- package/src/chatgpt/ChatGptAgent.ts +63 -57
- package/src/chatgpt/ChatGptCallFunctionAgent.ts +363 -337
- package/src/chatgpt/ChatGptCancelFunctionAgent.ts +188 -164
- package/src/chatgpt/ChatGptCompletionMessageUtil.ts +136 -137
- package/src/chatgpt/ChatGptDescribeFunctionAgent.ts +105 -101
- package/src/chatgpt/ChatGptHistoryDecoder.ts +69 -65
- package/src/chatgpt/ChatGptInitializeFunctionAgent.ts +128 -123
- package/src/chatgpt/ChatGptSelectFunctionAgent.ts +215 -189
- package/src/chatgpt/ChatGptUsageAggregator.ts +49 -54
- package/src/context/AgenticaCancelPrompt.ts +4 -4
- package/src/context/AgenticaClassOperation.ts +5 -5
- package/src/context/AgenticaContext.ts +15 -15
- package/src/context/AgenticaHttpOperation.ts +5 -5
- package/src/context/AgenticaOperation.ts +4 -4
- package/src/context/AgenticaOperationBase.ts +1 -1
- package/src/context/AgenticaOperationCollection.ts +2 -2
- package/src/context/AgenticaOperationSelection.ts +3 -3
- package/src/context/AgenticaTokenUsage.ts +4 -3
- package/src/context/internal/AgenticaTokenUsageAggregator.ts +59 -59
- package/src/context/internal/__IChatCancelFunctionsApplication.ts +2 -2
- package/src/context/internal/__IChatInitialApplication.ts +2 -2
- package/src/context/internal/__IChatSelectFunctionsApplication.ts +2 -2
- package/src/events/AgenticaCallEvent.ts +3 -3
- package/src/events/AgenticaCancelEvent.ts +3 -3
- package/src/events/AgenticaDescribeEvent.ts +5 -5
- package/src/events/AgenticaEvent.ts +12 -12
- package/src/events/AgenticaExecuteEvent.ts +7 -7
- package/src/events/AgenticaInitializeEvent.ts +1 -1
- package/src/events/AgenticaRequestEvent.ts +3 -3
- package/src/events/AgenticaResponseEvent.ts +2 -2
- package/src/events/AgenticaSelectEvent.ts +4 -4
- package/src/events/AgenticaTextEvent.ts +2 -2
- package/src/functional/assertHttpLlmApplication.ts +9 -6
- package/src/functional/validateHttpLlmApplication.ts +14 -8
- package/src/index.ts +24 -24
- package/src/internal/AgenticaDefaultPrompt.ts +42 -28
- package/src/internal/AgenticaOperationComposer.ts +63 -61
- package/src/internal/AgenticaSystemPrompt.ts +15 -14
- package/src/internal/AsyncQueue.ts +67 -0
- package/src/internal/ByteArrayUtil.ts +2 -2
- package/src/internal/MPSC.ts +40 -0
- package/src/internal/Singleton.ts +8 -6
- package/src/internal/StreamUtil.ts +62 -53
- package/src/internal/__map_take.ts +5 -7
- package/src/json/IAgenticaEventJson.ts +7 -8
- package/src/json/IAgenticaOperationSelectionJson.ts +1 -1
- package/src/json/IAgenticaPromptJson.ts +2 -2
- package/src/prompts/AgenticaCancelPrompt.ts +4 -4
- package/src/prompts/AgenticaDescribePrompt.ts +4 -4
- package/src/prompts/AgenticaExecutePrompt.ts +6 -5
- package/src/prompts/AgenticaPrompt.ts +6 -6
- package/src/prompts/AgenticaSelectPrompt.ts +4 -4
- package/src/prompts/AgenticaTextPrompt.ts +1 -1
- package/src/structures/IAgenticaConfig.ts +5 -5
- package/src/structures/IAgenticaController.ts +14 -14
- package/src/structures/IAgenticaExecutor.ts +4 -4
- package/src/structures/IAgenticaProps.ts +5 -5
- package/src/structures/IAgenticaSystemPrompt.ts +4 -4
- package/src/structures/IAgenticaVendor.ts +1 -1
- package/src/transformers/AgenticaEventTransformer.ts +169 -136
- package/src/transformers/AgenticaPromptTransformer.ts +125 -103
- package/lib/internal/MPSCUtil.d.ts +0 -35
- package/lib/internal/MPSCUtil.js +0 -105
- package/lib/internal/MPSCUtil.js.map +0 -1
- package/src/internal/MPSCUtil.ts +0 -111
|
@@ -1,34 +1,40 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
import { AgenticaOperation } from "../context/AgenticaOperation";
|
|
3
|
-
import { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
import type { AgenticaOperation } from "../context/AgenticaOperation";
|
|
3
|
+
import type { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
|
|
4
|
+
import type { AgenticaPrompt } from "../prompts/AgenticaPrompt";
|
|
4
5
|
import { AgenticaCancelPrompt } from "../prompts/AgenticaCancelPrompt";
|
|
5
6
|
import { AgenticaDescribePrompt } from "../prompts/AgenticaDescribePrompt";
|
|
6
7
|
import { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
|
|
7
|
-
import { AgenticaPrompt } from "../prompts/AgenticaPrompt";
|
|
8
8
|
import { AgenticaSelectPrompt } from "../prompts/AgenticaSelectPrompt";
|
|
9
9
|
import { AgenticaTextPrompt } from "../prompts/AgenticaTextPrompt";
|
|
10
|
-
export declare
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
10
|
+
export declare function transform<Model extends ILlmSchema.Model>(props: {
|
|
11
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
12
|
+
prompt: IAgenticaPromptJson;
|
|
13
|
+
}): AgenticaPrompt<Model>;
|
|
14
|
+
export declare function transformText(props: {
|
|
15
|
+
prompt: IAgenticaPromptJson.IText;
|
|
16
|
+
}): AgenticaTextPrompt;
|
|
17
|
+
export declare function transformSelect<Model extends ILlmSchema.Model>(props: {
|
|
18
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
19
|
+
prompt: IAgenticaPromptJson.ISelect;
|
|
20
|
+
}): AgenticaSelectPrompt<Model>;
|
|
21
|
+
export declare function transformCancel<Model extends ILlmSchema.Model>(props: {
|
|
22
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
23
|
+
prompt: IAgenticaPromptJson.ICancel;
|
|
24
|
+
}): AgenticaCancelPrompt<Model>;
|
|
25
|
+
export declare function transformExecute<Model extends ILlmSchema.Model>(props: {
|
|
26
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
27
|
+
prompt: IAgenticaPromptJson.IExecute;
|
|
28
|
+
}): AgenticaExecutePrompt<Model>;
|
|
29
|
+
export declare function transformDescribe<Model extends ILlmSchema.Model>(props: {
|
|
30
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
31
|
+
prompt: IAgenticaPromptJson.IDescribe;
|
|
32
|
+
}): AgenticaDescribePrompt<Model>;
|
|
33
|
+
export declare const AgenticaPromptTransformer: {
|
|
34
|
+
transform: typeof transform;
|
|
35
|
+
transformText: typeof transformText;
|
|
36
|
+
transformSelect: typeof transformSelect;
|
|
37
|
+
transformCancel: typeof transformCancel;
|
|
38
|
+
transformExecute: typeof transformExecute;
|
|
39
|
+
transformDescribe: typeof transformDescribe;
|
|
40
|
+
};
|
|
@@ -1,50 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AgenticaPromptTransformer = void 0;
|
|
4
|
+
exports.transform = transform;
|
|
5
|
+
exports.transformText = transformText;
|
|
6
|
+
exports.transformSelect = transformSelect;
|
|
7
|
+
exports.transformCancel = transformCancel;
|
|
8
|
+
exports.transformExecute = transformExecute;
|
|
9
|
+
exports.transformDescribe = transformDescribe;
|
|
4
10
|
const AgenticaOperationSelection_1 = require("../context/AgenticaOperationSelection");
|
|
5
11
|
const AgenticaCancelPrompt_1 = require("../prompts/AgenticaCancelPrompt");
|
|
6
12
|
const AgenticaDescribePrompt_1 = require("../prompts/AgenticaDescribePrompt");
|
|
7
13
|
const AgenticaExecutePrompt_1 = require("../prompts/AgenticaExecutePrompt");
|
|
8
14
|
const AgenticaSelectPrompt_1 = require("../prompts/AgenticaSelectPrompt");
|
|
9
15
|
const AgenticaTextPrompt_1 = require("../prompts/AgenticaTextPrompt");
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
16
|
+
function transform(props) {
|
|
17
|
+
// TEXT
|
|
18
|
+
if (props.prompt.type === "text") {
|
|
19
|
+
return transformText({
|
|
20
|
+
prompt: props.prompt,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
// SELECT & CANCEL
|
|
24
|
+
else if (props.prompt.type === "select") {
|
|
25
|
+
return transformSelect({
|
|
26
|
+
operations: props.operations,
|
|
27
|
+
prompt: props.prompt,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
else if (props.prompt.type === "cancel") {
|
|
31
|
+
return transformCancel({
|
|
32
|
+
operations: props.operations,
|
|
33
|
+
prompt: props.prompt,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
// EXECUTE
|
|
37
|
+
else if (props.prompt.type === "execute") {
|
|
38
|
+
return transformExecute({
|
|
39
|
+
operations: props.operations,
|
|
40
|
+
prompt: props.prompt,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
else if (props.prompt.type === "describe") {
|
|
44
|
+
return transformDescribe({
|
|
45
|
+
operations: props.operations,
|
|
46
|
+
prompt: props.prompt,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
throw new Error("Invalid prompt type.");
|
|
50
|
+
}
|
|
51
|
+
function transformText(props) {
|
|
52
|
+
return new AgenticaTextPrompt_1.AgenticaTextPrompt(props.prompt);
|
|
53
|
+
}
|
|
54
|
+
function transformSelect(props) {
|
|
55
|
+
return new AgenticaSelectPrompt_1.AgenticaSelectPrompt({
|
|
46
56
|
id: props.prompt.id,
|
|
47
|
-
selections: props.prompt.selections.map(
|
|
57
|
+
selections: props.prompt.selections.map(select => new AgenticaOperationSelection_1.AgenticaOperationSelection({
|
|
48
58
|
operation: findOperation({
|
|
49
59
|
operations: props.operations,
|
|
50
60
|
input: select.operation,
|
|
@@ -52,9 +62,11 @@ var AgenticaPromptTransformer;
|
|
|
52
62
|
reason: select.reason,
|
|
53
63
|
})),
|
|
54
64
|
});
|
|
55
|
-
|
|
65
|
+
}
|
|
66
|
+
function transformCancel(props) {
|
|
67
|
+
return new AgenticaCancelPrompt_1.AgenticaCancelPrompt({
|
|
56
68
|
id: props.prompt.id,
|
|
57
|
-
selections: props.prompt.selections.map(
|
|
69
|
+
selections: props.prompt.selections.map(select => new AgenticaOperationSelection_1.AgenticaOperationSelection({
|
|
58
70
|
operation: findOperation({
|
|
59
71
|
operations: props.operations,
|
|
60
72
|
input: select.operation,
|
|
@@ -62,29 +74,46 @@ var AgenticaPromptTransformer;
|
|
|
62
74
|
reason: select.reason,
|
|
63
75
|
})),
|
|
64
76
|
});
|
|
65
|
-
|
|
77
|
+
}
|
|
78
|
+
function transformExecute(props) {
|
|
79
|
+
return new AgenticaExecutePrompt_1.AgenticaExecutePrompt({
|
|
66
80
|
id: props.prompt.id,
|
|
67
81
|
operation: findOperation({
|
|
68
82
|
operations: props.operations,
|
|
69
83
|
input: props.prompt.operation,
|
|
70
84
|
}),
|
|
71
85
|
arguments: props.prompt.arguments,
|
|
86
|
+
/**
|
|
87
|
+
* @TODO fix it
|
|
88
|
+
* The property and value have a type mismatch, but it works.
|
|
89
|
+
*/
|
|
72
90
|
value: props.prompt.value,
|
|
73
91
|
});
|
|
74
|
-
|
|
92
|
+
}
|
|
93
|
+
function transformDescribe(props) {
|
|
94
|
+
return new AgenticaDescribePrompt_1.AgenticaDescribePrompt({
|
|
75
95
|
text: props.prompt.text,
|
|
76
|
-
executes: props.prompt.executes.map(
|
|
96
|
+
executes: props.prompt.executes.map(next => transformExecute({
|
|
77
97
|
operations: props.operations,
|
|
78
98
|
prompt: next,
|
|
79
99
|
})),
|
|
80
100
|
});
|
|
81
|
-
}
|
|
82
|
-
|
|
101
|
+
}
|
|
102
|
+
function findOperation(props) {
|
|
83
103
|
var _a;
|
|
84
104
|
const found = (_a = props.operations
|
|
85
105
|
.get(props.input.controller)) === null || _a === void 0 ? void 0 : _a.get(props.input.function);
|
|
86
|
-
if (found === undefined)
|
|
106
|
+
if (found === undefined) {
|
|
87
107
|
throw new Error(`No operation found: (controller: ${props.input.controller}, function: ${props.input.function})`);
|
|
108
|
+
}
|
|
88
109
|
return found;
|
|
110
|
+
}
|
|
111
|
+
exports.AgenticaPromptTransformer = {
|
|
112
|
+
transform,
|
|
113
|
+
transformText,
|
|
114
|
+
transformSelect,
|
|
115
|
+
transformCancel,
|
|
116
|
+
transformExecute,
|
|
117
|
+
transformDescribe,
|
|
89
118
|
};
|
|
90
119
|
//# sourceMappingURL=AgenticaPromptTransformer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgenticaPromptTransformer.js","sourceRoot":"","sources":["../../src/transformers/AgenticaPromptTransformer.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"AgenticaPromptTransformer.js","sourceRoot":"","sources":["../../src/transformers/AgenticaPromptTransformer.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentica/core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"main": "lib/index.js",
|
|
5
|
-
"publishConfig": {
|
|
6
|
-
"access": "public"
|
|
7
|
-
},
|
|
3
|
+
"version": "0.13.0",
|
|
8
4
|
"description": "Agentic AI Library specialized in LLM Function Calling",
|
|
9
5
|
"author": "Wrtn Technologies",
|
|
10
|
-
"homepage": "https://wrtnlabs.io/agentica",
|
|
11
6
|
"license": "MIT",
|
|
7
|
+
"homepage": "https://wrtnlabs.io/agentica",
|
|
12
8
|
"repository": {
|
|
13
9
|
"type": "git",
|
|
14
10
|
"url": "https://github.com/wrtnlabs/agentica"
|
|
@@ -27,25 +23,34 @@
|
|
|
27
23
|
"swagger",
|
|
28
24
|
"openapi"
|
|
29
25
|
],
|
|
26
|
+
"main": "lib/index.js",
|
|
30
27
|
"files": [
|
|
31
|
-
"README.md",
|
|
32
28
|
"LICENSE",
|
|
33
|
-
"
|
|
29
|
+
"README.md",
|
|
34
30
|
"lib",
|
|
31
|
+
"package.json",
|
|
35
32
|
"prompts",
|
|
36
33
|
"src"
|
|
37
34
|
],
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@samchon/openapi": ">=3.0.0 <4.0.0",
|
|
40
|
+
"openai": ">=4.80.0"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@samchon/openapi": "^3.0.0",
|
|
44
|
+
"typia": "^8.0.0",
|
|
45
|
+
"uuid": "^11.0.4"
|
|
46
|
+
},
|
|
38
47
|
"devDependencies": {
|
|
39
|
-
"@eslint/js": "^9.17.0",
|
|
40
48
|
"@nestia/e2e": "^0.8.2",
|
|
41
49
|
"@rollup/plugin-terser": "^0.4.4",
|
|
42
50
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
43
|
-
"@trivago/prettier-plugin-sort-imports": "^5.2.2",
|
|
44
51
|
"@types/node": "^22.13.4",
|
|
45
52
|
"@types/uuid": "^10.0.0",
|
|
46
|
-
"eslint": "^9.17.0",
|
|
47
53
|
"openai": "^4.80.0",
|
|
48
|
-
"prettier": "^3.5.0",
|
|
49
54
|
"rimraf": "^6.0.1",
|
|
50
55
|
"rollup": "^4.34.8",
|
|
51
56
|
"ts-node": "^10.9.2",
|
|
@@ -53,20 +58,12 @@
|
|
|
53
58
|
"typedoc": "^0.27.7",
|
|
54
59
|
"typescript": "~5.8.2"
|
|
55
60
|
},
|
|
56
|
-
"dependencies": {
|
|
57
|
-
"@samchon/openapi": "^3.0.0",
|
|
58
|
-
"typia": "^8.0.0",
|
|
59
|
-
"uuid": "^11.0.4"
|
|
60
|
-
},
|
|
61
|
-
"peerDependencies": {
|
|
62
|
-
"@samchon/openapi": ">=3.0.0 <4.0.0",
|
|
63
|
-
"openai": ">=4.80.0"
|
|
64
|
-
},
|
|
65
61
|
"scripts": {
|
|
66
62
|
"build": "rimraf lib && pnpm build:prompt && tsc && rollup -c",
|
|
67
|
-
"build:prompt": "
|
|
63
|
+
"build:prompt": "node build/prompt.js",
|
|
68
64
|
"dev": "rimraf lib && tsc --watch",
|
|
69
|
-
"
|
|
65
|
+
"lint": "eslint .",
|
|
66
|
+
"format": "eslint --fix ."
|
|
70
67
|
},
|
|
71
68
|
"module": "lib/index.mjs",
|
|
72
69
|
"typings": "lib/index.d.ts"
|
package/prompts/cancel.md
CHANGED
|
@@ -2,4 +2,4 @@ You are a helpful assistant for cancelling functions which are prepared to call.
|
|
|
2
2
|
|
|
3
3
|
Use the supplied tools to select some functions to cancel of `getApiFunctions()` returned.
|
|
4
4
|
|
|
5
|
-
If you can't find any proper function to select, don't talk, don't do anything.
|
|
5
|
+
If you can't find any proper function to select, don't talk, don't do anything.
|
package/prompts/common.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
At first, the user's language locale code is "${locale}". When you are conversating with the user or describing the function calling result, consider it and always translate to the target locale language. Never conversate with different locale language text with the user.
|
|
2
2
|
|
|
3
|
-
At second, the user's timezone is "${timezone}", and ISO datetime is ${datetime}. When you are conversating with the user, consider current time and user belonged timezone.
|
|
3
|
+
At second, the user's timezone is "${timezone}", and ISO datetime is ${datetime}. When you are conversating with the user, consider current time and user belonged timezone.
|
package/prompts/describe.md
CHANGED
|
@@ -4,4 +4,4 @@ Above messages are the list of function call histories. When describing the retu
|
|
|
4
4
|
|
|
5
5
|
Also, its content format must be markdown. If required, utilize the mermaid syntax for drawing some diagrams. When image contents are, just put them through the markdown image syntax.
|
|
6
6
|
|
|
7
|
-
At last, if user's language locale code is different with your description, please translate it to the user's language.
|
|
7
|
+
At last, if user's language locale code is different with your description, please translate it to the user's language.
|
package/prompts/execute.md
CHANGED
|
@@ -4,4 +4,4 @@ Use the supplied tools to assist the user.
|
|
|
4
4
|
|
|
5
5
|
If previous messages are not enough to compose the arguments, you can ask the user to write more information. By the way, when asking the user to write more information, make the text concise and clear.
|
|
6
6
|
|
|
7
|
-
For reference, in the "tool" role message content, the `function` property means metadata of the API operation. In other words, it is the function schema describing its purpose, parameters and return value types. And then the `data` property is the return value from the target function calling.
|
|
7
|
+
For reference, in the "tool" role message content, the `function` property means metadata of the API operation. In other words, it is the function schema describing its purpose, parameters and return value types. And then the `data` property is the return value from the target function calling.
|
package/prompts/initialize.md
CHANGED
package/prompts/select.md
CHANGED
|
@@ -4,4 +4,4 @@ Use the supplied tools to select some functions of `getApiFunctions()` returned.
|
|
|
4
4
|
|
|
5
5
|
When selecting functions to call, pay attention to the relationship between functions. In particular, check the prerequisites between each function.
|
|
6
6
|
|
|
7
|
-
If you can't find any proper function to select, just type your own message. By the way, when typing your own message, please consider the user's language locale code. If your message is different with the user's language, please translate it to the user's.
|
|
7
|
+
If you can't find any proper function to select, just type your own message. By the way, when typing your own message, please consider the user's language locale code. If your message is different with the user's language, please translate it to the user's.
|
package/src/Agentica.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
+
import type { AgenticaContext } from "./context/AgenticaContext";
|
|
4
|
+
import type { AgenticaOperation } from "./context/AgenticaOperation";
|
|
5
|
+
import type { AgenticaOperationCollection } from "./context/AgenticaOperationCollection";
|
|
6
|
+
import type { AgenticaOperationSelection } from "./context/AgenticaOperationSelection";
|
|
7
|
+
import type { AgenticaEvent } from "./events/AgenticaEvent";
|
|
8
|
+
import type { AgenticaPrompt } from "./prompts/AgenticaPrompt";
|
|
9
|
+
import type { IAgenticaConfig } from "./structures/IAgenticaConfig";
|
|
10
|
+
import type { IAgenticaController } from "./structures/IAgenticaController";
|
|
11
|
+
import type { IAgenticaProps } from "./structures/IAgenticaProps";
|
|
12
|
+
import type { IAgenticaVendor } from "./structures/IAgenticaVendor";
|
|
3
13
|
import { ChatGptAgent } from "./chatgpt/ChatGptAgent";
|
|
4
14
|
import { ChatGptCompletionMessageUtil } from "./chatgpt/ChatGptCompletionMessageUtil";
|
|
5
|
-
import { AgenticaContext } from "./context/AgenticaContext";
|
|
6
|
-
import { AgenticaOperation } from "./context/AgenticaOperation";
|
|
7
|
-
import { AgenticaOperationCollection } from "./context/AgenticaOperationCollection";
|
|
8
|
-
import { AgenticaOperationSelection } from "./context/AgenticaOperationSelection";
|
|
9
15
|
import { AgenticaTokenUsage } from "./context/AgenticaTokenUsage";
|
|
10
16
|
import { AgenticaTokenUsageAggregator } from "./context/internal/AgenticaTokenUsageAggregator";
|
|
11
|
-
import { AgenticaEvent } from "./events/AgenticaEvent";
|
|
12
17
|
import { AgenticaInitializeEvent } from "./events/AgenticaInitializeEvent";
|
|
13
18
|
import { AgenticaRequestEvent } from "./events/AgenticaRequestEvent";
|
|
14
19
|
import { AgenticaTextEvent } from "./events/AgenticaTextEvent";
|
|
20
|
+
import { __map_take } from "./internal/__map_take";
|
|
15
21
|
import { AgenticaOperationComposer } from "./internal/AgenticaOperationComposer";
|
|
16
22
|
import { StreamUtil } from "./internal/StreamUtil";
|
|
17
|
-
import { __map_take } from "./internal/__map_take";
|
|
18
|
-
import { AgenticaPrompt } from "./prompts/AgenticaPrompt";
|
|
19
23
|
import { AgenticaTextPrompt } from "./prompts/AgenticaTextPrompt";
|
|
20
|
-
import { IAgenticaConfig } from "./structures/IAgenticaConfig";
|
|
21
|
-
import { IAgenticaController } from "./structures/IAgenticaController";
|
|
22
|
-
import { IAgenticaProps } from "./structures/IAgenticaProps";
|
|
23
|
-
import { IAgenticaVendor } from "./structures/IAgenticaVendor";
|
|
24
24
|
import { AgenticaPromptTransformer } from "./transformers/AgenticaPromptTransformer";
|
|
25
25
|
|
|
26
26
|
/**
|
|
@@ -57,7 +57,7 @@ export class Agentica<Model extends ILlmSchema.Model> {
|
|
|
57
57
|
// STACK
|
|
58
58
|
private readonly stack_: AgenticaOperationSelection<Model>[];
|
|
59
59
|
private readonly prompt_histories_: AgenticaPrompt<Model>[];
|
|
60
|
-
private readonly listeners_: Map<string, Set<
|
|
60
|
+
private readonly listeners_: Map<string, Set<(event: AgenticaEvent<Model>) => Promise<void> | void>>;
|
|
61
61
|
|
|
62
62
|
// STATUS
|
|
63
63
|
private readonly token_usage_: AgenticaTokenUsage;
|
|
@@ -84,7 +84,7 @@ export class Agentica<Model extends ILlmSchema.Model> {
|
|
|
84
84
|
// STATUS
|
|
85
85
|
this.stack_ = [];
|
|
86
86
|
this.listeners_ = new Map();
|
|
87
|
-
this.prompt_histories_ = (props.histories ?? []).map(
|
|
87
|
+
this.prompt_histories_ = (props.histories ?? []).map(input =>
|
|
88
88
|
AgenticaPromptTransformer.transform({
|
|
89
89
|
operations: this.operations_.group,
|
|
90
90
|
prompt: input,
|
|
@@ -94,8 +94,8 @@ export class Agentica<Model extends ILlmSchema.Model> {
|
|
|
94
94
|
// STATUS
|
|
95
95
|
this.token_usage_ = AgenticaTokenUsage.zero();
|
|
96
96
|
this.ready_ = false;
|
|
97
|
-
this.executor_
|
|
98
|
-
typeof props.config?.executor === "function"
|
|
97
|
+
this.executor_
|
|
98
|
+
= typeof props.config?.executor === "function"
|
|
99
99
|
? props.config.executor
|
|
100
100
|
: ChatGptAgent.execute(props.config?.executor ?? null);
|
|
101
101
|
}
|
|
@@ -136,7 +136,7 @@ export class Agentica<Model extends ILlmSchema.Model> {
|
|
|
136
136
|
stream: StreamUtil.to(content),
|
|
137
137
|
done: () => true,
|
|
138
138
|
get: () => content,
|
|
139
|
-
join: () => Promise.resolve(content),
|
|
139
|
+
join: async () => Promise.resolve(content),
|
|
140
140
|
}),
|
|
141
141
|
);
|
|
142
142
|
|
|
@@ -180,7 +180,7 @@ export class Agentica<Model extends ILlmSchema.Model> {
|
|
|
180
180
|
* Get list of operations, which has capsuled the pair of controller
|
|
181
181
|
* and function from the {@link getControllers controllers}.
|
|
182
182
|
*
|
|
183
|
-
* @returns
|
|
183
|
+
* @returns List of operations
|
|
184
184
|
*/
|
|
185
185
|
public getOperations(): ReadonlyArray<AgenticaOperation<Model>> {
|
|
186
186
|
return this.operations_.array;
|
|
@@ -216,7 +216,7 @@ export class Agentica<Model extends ILlmSchema.Model> {
|
|
|
216
216
|
prompt: AgenticaTextPrompt<"user">;
|
|
217
217
|
usage: AgenticaTokenUsage;
|
|
218
218
|
}): AgenticaContext<Model> {
|
|
219
|
-
const dispatch = (event: AgenticaEvent<Model>) => this.dispatch(event);
|
|
219
|
+
const dispatch = async (event: AgenticaEvent<Model>) => this.dispatch(event);
|
|
220
220
|
return {
|
|
221
221
|
// APPLICATION
|
|
222
222
|
operations: this.operations_,
|
|
@@ -229,7 +229,7 @@ export class Agentica<Model extends ILlmSchema.Model> {
|
|
|
229
229
|
prompt: props.prompt,
|
|
230
230
|
|
|
231
231
|
// HANDLERS
|
|
232
|
-
dispatch:
|
|
232
|
+
dispatch: async event => this.dispatch(event),
|
|
233
233
|
request: async (source, body) => {
|
|
234
234
|
// request information
|
|
235
235
|
const event: AgenticaRequestEvent = new AgenticaRequestEvent({
|
|
@@ -254,7 +254,7 @@ export class Agentica<Model extends ILlmSchema.Model> {
|
|
|
254
254
|
|
|
255
255
|
const [streamForEvent, temporaryStream] = StreamUtil.transform(
|
|
256
256
|
completion.toReadableStream() as ReadableStream<Uint8Array>,
|
|
257
|
-
|
|
257
|
+
value =>
|
|
258
258
|
ChatGptCompletionMessageUtil.transformCompletionChunk(value),
|
|
259
259
|
).tee();
|
|
260
260
|
|
|
@@ -264,8 +264,10 @@ export class Agentica<Model extends ILlmSchema.Model> {
|
|
|
264
264
|
const reader = streamForAggregate.getReader();
|
|
265
265
|
while (true) {
|
|
266
266
|
const chunk = await reader.read();
|
|
267
|
-
if (chunk.done)
|
|
268
|
-
|
|
267
|
+
if (chunk.done) {
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
if (chunk.value.usage != null) {
|
|
269
271
|
AgenticaTokenUsageAggregator.aggregate({
|
|
270
272
|
kind: source,
|
|
271
273
|
completionUsage: chunk.value.usage,
|
|
@@ -278,7 +280,7 @@ export class Agentica<Model extends ILlmSchema.Model> {
|
|
|
278
280
|
const [streamForStream, streamForJoin] = streamForEvent.tee();
|
|
279
281
|
await dispatch({
|
|
280
282
|
type: "response",
|
|
281
|
-
source
|
|
283
|
+
source,
|
|
282
284
|
stream: streamForStream,
|
|
283
285
|
body: event.body,
|
|
284
286
|
options: event.options,
|
|
@@ -314,7 +316,10 @@ export class Agentica<Model extends ILlmSchema.Model> {
|
|
|
314
316
|
event: AgenticaEvent.Mapper<Model>[Type],
|
|
315
317
|
) => void | Promise<void>,
|
|
316
318
|
): this {
|
|
317
|
-
|
|
319
|
+
/**
|
|
320
|
+
* @TODO remove `as`
|
|
321
|
+
*/
|
|
322
|
+
__map_take(this.listeners_, type, () => new Set()).add(listener as (event: AgenticaEvent<Model>) => void | Promise<void>);
|
|
318
323
|
return this;
|
|
319
324
|
}
|
|
320
325
|
|
|
@@ -333,9 +338,14 @@ export class Agentica<Model extends ILlmSchema.Model> {
|
|
|
333
338
|
) => void | Promise<void>,
|
|
334
339
|
): this {
|
|
335
340
|
const set = this.listeners_.get(type);
|
|
336
|
-
if (set) {
|
|
337
|
-
|
|
338
|
-
|
|
341
|
+
if (set !== undefined) {
|
|
342
|
+
/**
|
|
343
|
+
* @TODO remove `as`
|
|
344
|
+
*/
|
|
345
|
+
set.delete(listener as (event: AgenticaEvent<Model>) => void | Promise<void>);
|
|
346
|
+
if (set.size === 0) {
|
|
347
|
+
this.listeners_.delete(type);
|
|
348
|
+
}
|
|
339
349
|
}
|
|
340
350
|
return this;
|
|
341
351
|
}
|
|
@@ -344,13 +354,13 @@ export class Agentica<Model extends ILlmSchema.Model> {
|
|
|
344
354
|
event: Event,
|
|
345
355
|
): Promise<void> {
|
|
346
356
|
const set = this.listeners_.get(event.type);
|
|
347
|
-
if (set) {
|
|
357
|
+
if (set !== undefined) {
|
|
348
358
|
await Promise.all(
|
|
349
359
|
Array.from(set).map(async (listener) => {
|
|
350
360
|
try {
|
|
351
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
352
361
|
await listener(event);
|
|
353
|
-
}
|
|
362
|
+
}
|
|
363
|
+
catch {
|
|
354
364
|
/* empty */
|
|
355
365
|
}
|
|
356
366
|
}),
|