@agentica/core 0.10.3 → 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/README.md +2 -2
- package/lib/Agentica.d.ts +14 -14
- package/lib/Agentica.js +54 -29
- 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/context/internal/AgenticaTokenUsageAggregator.js +47 -0
- 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 -304
- 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 +94 -61
- 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 +0 -92
- 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 -115
- 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
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
|
|
3
|
+
import { AgenticaOperation } from "../context/AgenticaOperation";
|
|
4
|
+
import { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
|
|
5
|
+
import { AgenticaCallEvent } from "../events/AgenticaCallEvent";
|
|
6
|
+
import { AgenticaCancelEvent } from "../events/AgenticaCancelEvent";
|
|
7
|
+
import { AgenticaDescribeEvent } from "../events/AgenticaDescribeEvent";
|
|
8
|
+
import { AgenticaEvent } from "../events/AgenticaEvent";
|
|
9
|
+
import { AgenticaExecuteEvent } from "../events/AgenticaExecuteEvent";
|
|
10
|
+
import { AgenticaInitializeEvent } from "../events/AgenticaInitializeEvent";
|
|
11
|
+
import { AgenticaRequestEvent } from "../events/AgenticaRequestEvent";
|
|
12
|
+
import { AgenticaSelectEvent } from "../events/AgenticaSelectEvent";
|
|
13
|
+
import { AgenticaTextEvent } from "../events/AgenticaTextEvent";
|
|
14
|
+
import { StreamUtil } from "../internal/StreamUtil";
|
|
15
|
+
import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
16
|
+
|
|
17
|
+
export namespace AgenticaEventTransformer {
|
|
18
|
+
export const transform = <Model extends ILlmSchema.Model>(props: {
|
|
19
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
20
|
+
event: IAgenticaEventJson;
|
|
21
|
+
}): AgenticaEvent<Model> => {
|
|
22
|
+
if (props.event.type === "call")
|
|
23
|
+
return transformCall({
|
|
24
|
+
operations: props.operations,
|
|
25
|
+
event: props.event,
|
|
26
|
+
});
|
|
27
|
+
else if (props.event.type === "cancel")
|
|
28
|
+
return transformCancel({
|
|
29
|
+
operations: props.operations,
|
|
30
|
+
event: props.event,
|
|
31
|
+
});
|
|
32
|
+
else if (props.event.type === "describe")
|
|
33
|
+
return transformDescribe({
|
|
34
|
+
operations: props.operations,
|
|
35
|
+
event: props.event,
|
|
36
|
+
});
|
|
37
|
+
else if (props.event.type === "execute")
|
|
38
|
+
return transformExecute({
|
|
39
|
+
operations: props.operations,
|
|
40
|
+
event: props.event,
|
|
41
|
+
});
|
|
42
|
+
else if (props.event.type === "initialize") return transformInitialize();
|
|
43
|
+
else if (props.event.type === "request")
|
|
44
|
+
return transformRequest({
|
|
45
|
+
event: props.event,
|
|
46
|
+
});
|
|
47
|
+
else if (props.event.type === "select")
|
|
48
|
+
return transformSelect({
|
|
49
|
+
operations: props.operations,
|
|
50
|
+
event: props.event,
|
|
51
|
+
});
|
|
52
|
+
else if (props.event.type === "text")
|
|
53
|
+
return transformText({
|
|
54
|
+
event: props.event,
|
|
55
|
+
});
|
|
56
|
+
else throw new Error("Unknown event type");
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const transformCall = <Model extends ILlmSchema.Model>(props: {
|
|
60
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
61
|
+
event: IAgenticaEventJson.ICall;
|
|
62
|
+
}): AgenticaCallEvent<Model> =>
|
|
63
|
+
new AgenticaCallEvent({
|
|
64
|
+
id: props.event.id,
|
|
65
|
+
operation: findOperation({
|
|
66
|
+
operations: props.operations,
|
|
67
|
+
input: props.event.operation,
|
|
68
|
+
}),
|
|
69
|
+
arguments: props.event.arguments,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export const transformCancel = <Model extends ILlmSchema.Model>(props: {
|
|
73
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
74
|
+
event: IAgenticaEventJson.ICancel;
|
|
75
|
+
}): AgenticaCancelEvent<Model> =>
|
|
76
|
+
new AgenticaCancelEvent({
|
|
77
|
+
selection: new AgenticaOperationSelection({
|
|
78
|
+
operation: findOperation({
|
|
79
|
+
operations: props.operations,
|
|
80
|
+
input: props.event.selection.operation,
|
|
81
|
+
}),
|
|
82
|
+
reason: props.event.selection.reason,
|
|
83
|
+
}),
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
export const transformDescribe = <Model extends ILlmSchema.Model>(props: {
|
|
87
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
88
|
+
event: IAgenticaEventJson.IDescribe;
|
|
89
|
+
}): AgenticaDescribeEvent<Model> =>
|
|
90
|
+
new AgenticaDescribeEvent({
|
|
91
|
+
executes: props.event.executes.map((next) =>
|
|
92
|
+
transformExecute({
|
|
93
|
+
operations: props.operations,
|
|
94
|
+
event: next,
|
|
95
|
+
}),
|
|
96
|
+
),
|
|
97
|
+
stream: StreamUtil.to(props.event.text),
|
|
98
|
+
done: () => true,
|
|
99
|
+
get: () => props.event.text,
|
|
100
|
+
join: async () => props.event.text,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
export const transformExecute = <Model extends ILlmSchema.Model>(props: {
|
|
104
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
105
|
+
event: IAgenticaEventJson.IExecute;
|
|
106
|
+
}): AgenticaExecuteEvent<Model> =>
|
|
107
|
+
new AgenticaExecuteEvent({
|
|
108
|
+
id: props.event.id,
|
|
109
|
+
operation: findOperation({
|
|
110
|
+
operations: props.operations,
|
|
111
|
+
input: props.event.operation,
|
|
112
|
+
}),
|
|
113
|
+
arguments: props.event.arguments,
|
|
114
|
+
value: props.event.value,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
export const transformInitialize = (): AgenticaInitializeEvent =>
|
|
118
|
+
new AgenticaInitializeEvent();
|
|
119
|
+
|
|
120
|
+
export const transformRequest = (props: {
|
|
121
|
+
event: IAgenticaEventJson.IRequest;
|
|
122
|
+
}): AgenticaRequestEvent => new AgenticaRequestEvent(props.event);
|
|
123
|
+
|
|
124
|
+
export const transformSelect = <Model extends ILlmSchema.Model>(props: {
|
|
125
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
126
|
+
event: IAgenticaEventJson.ISelect;
|
|
127
|
+
}): AgenticaSelectEvent<Model> =>
|
|
128
|
+
new AgenticaSelectEvent({
|
|
129
|
+
selection: new AgenticaOperationSelection({
|
|
130
|
+
operation: findOperation({
|
|
131
|
+
operations: props.operations,
|
|
132
|
+
input: props.event.selection.operation,
|
|
133
|
+
}),
|
|
134
|
+
reason: props.event.selection.reason,
|
|
135
|
+
}),
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
export const transformText = (props: {
|
|
139
|
+
event: IAgenticaEventJson.IText;
|
|
140
|
+
}): AgenticaTextEvent =>
|
|
141
|
+
new AgenticaTextEvent({
|
|
142
|
+
role: props.event.role,
|
|
143
|
+
stream: StreamUtil.to(props.event.text),
|
|
144
|
+
done: () => true,
|
|
145
|
+
get: () => props.event.text,
|
|
146
|
+
join: async () => props.event.text,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const findOperation = <Model extends ILlmSchema.Model>(props: {
|
|
151
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
152
|
+
input: {
|
|
153
|
+
controller: string;
|
|
154
|
+
function: string;
|
|
155
|
+
};
|
|
156
|
+
}): AgenticaOperation<Model> => {
|
|
157
|
+
const found: AgenticaOperation<Model> | undefined = props.operations
|
|
158
|
+
.get(props.input.controller)
|
|
159
|
+
?.get(props.input.function);
|
|
160
|
+
if (found === undefined)
|
|
161
|
+
throw new Error(
|
|
162
|
+
`No operation found: (controller: ${props.input.controller}, function: ${props.input.function})`,
|
|
163
|
+
);
|
|
164
|
+
return found;
|
|
165
|
+
};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
|
|
3
|
+
import { AgenticaOperation } from "../context/AgenticaOperation";
|
|
4
|
+
import { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
|
|
5
|
+
import { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
|
|
6
|
+
import { AgenticaCancelPrompt } from "../prompts/AgenticaCancelPrompt";
|
|
7
|
+
import { AgenticaDescribePrompt } from "../prompts/AgenticaDescribePrompt";
|
|
8
|
+
import { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
|
|
9
|
+
import { AgenticaPrompt } from "../prompts/AgenticaPrompt";
|
|
10
|
+
import { AgenticaSelectPrompt } from "../prompts/AgenticaSelectPrompt";
|
|
11
|
+
import { AgenticaTextPrompt } from "../prompts/AgenticaTextPrompt";
|
|
12
|
+
|
|
13
|
+
export namespace AgenticaPromptTransformer {
|
|
14
|
+
export const transform = <Model extends ILlmSchema.Model>(props: {
|
|
15
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
16
|
+
prompt: IAgenticaPromptJson;
|
|
17
|
+
}): AgenticaPrompt<Model> => {
|
|
18
|
+
// TEXT
|
|
19
|
+
if (props.prompt.type === "text")
|
|
20
|
+
return transformText({
|
|
21
|
+
prompt: props.prompt,
|
|
22
|
+
});
|
|
23
|
+
// SELECT & CANCEL
|
|
24
|
+
else if (props.prompt.type === "select")
|
|
25
|
+
return transformSelect({
|
|
26
|
+
operations: props.operations,
|
|
27
|
+
prompt: props.prompt,
|
|
28
|
+
});
|
|
29
|
+
else if (props.prompt.type === "cancel")
|
|
30
|
+
return transformCancel({
|
|
31
|
+
operations: props.operations,
|
|
32
|
+
prompt: props.prompt,
|
|
33
|
+
});
|
|
34
|
+
// EXECUTE
|
|
35
|
+
else if (props.prompt.type === "execute")
|
|
36
|
+
return transformExecute({
|
|
37
|
+
operations: props.operations,
|
|
38
|
+
prompt: props.prompt,
|
|
39
|
+
});
|
|
40
|
+
else if (props.prompt.type === "describe")
|
|
41
|
+
return transformDescribe({
|
|
42
|
+
operations: props.operations,
|
|
43
|
+
prompt: props.prompt,
|
|
44
|
+
});
|
|
45
|
+
throw new Error("Invalid prompt type.");
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const transformText = (props: {
|
|
49
|
+
prompt: IAgenticaPromptJson.IText;
|
|
50
|
+
}): AgenticaTextPrompt => {
|
|
51
|
+
return new AgenticaTextPrompt(props.prompt);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const transformSelect = <Model extends ILlmSchema.Model>(props: {
|
|
55
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
56
|
+
prompt: IAgenticaPromptJson.ISelect;
|
|
57
|
+
}): AgenticaSelectPrompt<Model> =>
|
|
58
|
+
new AgenticaSelectPrompt({
|
|
59
|
+
id: props.prompt.id,
|
|
60
|
+
selections: props.prompt.selections.map(
|
|
61
|
+
(select) =>
|
|
62
|
+
new AgenticaOperationSelection({
|
|
63
|
+
operation: findOperation({
|
|
64
|
+
operations: props.operations,
|
|
65
|
+
input: select.operation,
|
|
66
|
+
}),
|
|
67
|
+
reason: select.reason,
|
|
68
|
+
}),
|
|
69
|
+
),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export const transformCancel = <Model extends ILlmSchema.Model>(props: {
|
|
73
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
74
|
+
prompt: IAgenticaPromptJson.ICancel;
|
|
75
|
+
}): AgenticaCancelPrompt<Model> =>
|
|
76
|
+
new AgenticaCancelPrompt({
|
|
77
|
+
id: props.prompt.id,
|
|
78
|
+
selections: props.prompt.selections.map(
|
|
79
|
+
(select) =>
|
|
80
|
+
new AgenticaOperationSelection({
|
|
81
|
+
operation: findOperation({
|
|
82
|
+
operations: props.operations,
|
|
83
|
+
input: select.operation,
|
|
84
|
+
}),
|
|
85
|
+
reason: select.reason,
|
|
86
|
+
}),
|
|
87
|
+
),
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
export const transformExecute = <Model extends ILlmSchema.Model>(props: {
|
|
91
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
92
|
+
prompt: IAgenticaPromptJson.IExecute;
|
|
93
|
+
}): AgenticaExecutePrompt<Model> =>
|
|
94
|
+
new AgenticaExecutePrompt({
|
|
95
|
+
id: props.prompt.id,
|
|
96
|
+
operation: findOperation({
|
|
97
|
+
operations: props.operations,
|
|
98
|
+
input: props.prompt.operation,
|
|
99
|
+
}),
|
|
100
|
+
arguments: props.prompt.arguments,
|
|
101
|
+
value: props.prompt.value,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
export const transformDescribe = <Model extends ILlmSchema.Model>(props: {
|
|
105
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
106
|
+
prompt: IAgenticaPromptJson.IDescribe;
|
|
107
|
+
}): AgenticaDescribePrompt<Model> =>
|
|
108
|
+
new AgenticaDescribePrompt({
|
|
109
|
+
text: props.prompt.text,
|
|
110
|
+
executes: props.prompt.executions.map((next) =>
|
|
111
|
+
transformExecute({
|
|
112
|
+
operations: props.operations,
|
|
113
|
+
prompt: next,
|
|
114
|
+
}),
|
|
115
|
+
),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const findOperation = <Model extends ILlmSchema.Model>(props: {
|
|
120
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
121
|
+
input: {
|
|
122
|
+
controller: string;
|
|
123
|
+
function: string;
|
|
124
|
+
};
|
|
125
|
+
}): AgenticaOperation<Model> => {
|
|
126
|
+
const found: AgenticaOperation<Model> | undefined = props.operations
|
|
127
|
+
.get(props.input.controller)
|
|
128
|
+
?.get(props.input.function);
|
|
129
|
+
if (found === undefined)
|
|
130
|
+
throw new Error(
|
|
131
|
+
`No operation found: (controller: ${props.input.controller}, function: ${props.input.function})`,
|
|
132
|
+
);
|
|
133
|
+
return found;
|
|
134
|
+
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
import { IAgenticaOperationSelection } from "../structures/IAgenticaOperationSelection";
|
|
3
|
-
import { IAgenticaPrompt } from "../structures/IAgenticaPrompt";
|
|
4
|
-
export declare namespace AgenticaPromptFactory {
|
|
5
|
-
const execute: <Model extends ILlmSchema.Model>(props: Omit<IAgenticaPrompt.IExecute<Model>, "toJSON">) => IAgenticaPrompt.IExecute<Model>;
|
|
6
|
-
const selection: <Model extends ILlmSchema.Model>(props: Omit<IAgenticaOperationSelection<Model>, "toJSON">) => IAgenticaOperationSelection<Model>;
|
|
7
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AgenticaPromptFactory = void 0;
|
|
4
|
-
var AgenticaPromptFactory;
|
|
5
|
-
(function (AgenticaPromptFactory) {
|
|
6
|
-
AgenticaPromptFactory.execute = (props) => (Object.assign(Object.assign({}, props), { toJSON: () => (Object.assign(Object.assign({}, props), { controller: props.controller.name, function: props.function.name })) }));
|
|
7
|
-
AgenticaPromptFactory.selection = (props) => (Object.assign(Object.assign({}, props), { toJSON: () => (Object.assign(Object.assign({}, props), { controller: props.controller.name, function: props.function.name })) }));
|
|
8
|
-
})(AgenticaPromptFactory || (exports.AgenticaPromptFactory = AgenticaPromptFactory = {}));
|
|
9
|
-
//# sourceMappingURL=AgenticaPromptFactory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AgenticaPromptFactory.js","sourceRoot":"","sources":["../../src/internal/AgenticaPromptFactory.ts"],"names":[],"mappings":";;;AAKA,IAAiB,qBAAqB,CA0BrC;AA1BD,WAAiB,qBAAqB;IACvB,6BAAO,GAAG,CACrB,KAAsD,EACrB,EAAE,CACnC,iCACK,KAAK,KACR,MAAM,EAAE,GAAG,EAAE,CACX,iCACK,KAAK,KACR,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,IAAI,EACjC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,IAAI,IACtB,IACwB,CAAC;IAE3B,+BAAS,GAAG,CACvB,KAAyD,EACrB,EAAE,CACtC,iCACK,KAAK,KACR,MAAM,EAAE,GAAG,EAAE,CACX,iCACK,KAAK,KACR,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,IAAI,EACjC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,IAAI,IACtB,IAC2B,CAAC;AAC7C,CAAC,EA1BgB,qBAAqB,qCAArB,qBAAqB,QA0BrC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
import { Primitive } from "typia";
|
|
3
|
-
import { IAgenticaOperation } from "../structures/IAgenticaOperation";
|
|
4
|
-
import { IAgenticaPrompt } from "../structures/IAgenticaPrompt";
|
|
5
|
-
export declare namespace AgenticaPromptTransformer {
|
|
6
|
-
const transform: <Model extends ILlmSchema.Model>(props: {
|
|
7
|
-
operations: Map<string, Map<string, IAgenticaOperation<Model>>>;
|
|
8
|
-
input: Primitive<IAgenticaPrompt<Model>>;
|
|
9
|
-
}) => IAgenticaPrompt<Model>;
|
|
10
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AgenticaPromptTransformer = void 0;
|
|
4
|
-
const AgenticaPromptFactory_1 = require("./AgenticaPromptFactory");
|
|
5
|
-
var AgenticaPromptTransformer;
|
|
6
|
-
(function (AgenticaPromptTransformer) {
|
|
7
|
-
AgenticaPromptTransformer.transform = (props) => {
|
|
8
|
-
// TEXT
|
|
9
|
-
if (props.input.type === "text")
|
|
10
|
-
return props.input;
|
|
11
|
-
// SELECT & CANCEL
|
|
12
|
-
else if (props.input.type === "select" || props.input.type === "cancel")
|
|
13
|
-
return Object.assign(Object.assign({}, props.input), { operations: props.input.operations.map((func) => AgenticaPromptFactory_1.AgenticaPromptFactory.selection(Object.assign(Object.assign({}, findOperation({
|
|
14
|
-
operations: props.operations,
|
|
15
|
-
input: func,
|
|
16
|
-
})), { reason: func.reason }))) });
|
|
17
|
-
// EXECUTE
|
|
18
|
-
else if (props.input.type === "execute")
|
|
19
|
-
return transformExecute({
|
|
20
|
-
operations: props.operations,
|
|
21
|
-
input: props.input,
|
|
22
|
-
});
|
|
23
|
-
// DESCRIBE
|
|
24
|
-
return {
|
|
25
|
-
type: "describe",
|
|
26
|
-
text: props.input.text,
|
|
27
|
-
executions: props.input.executions.map((next) => transformExecute({
|
|
28
|
-
operations: props.operations,
|
|
29
|
-
input: next,
|
|
30
|
-
})),
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
const transformExecute = (props) => {
|
|
34
|
-
const operation = findOperation({
|
|
35
|
-
operations: props.operations,
|
|
36
|
-
input: props.input,
|
|
37
|
-
});
|
|
38
|
-
return AgenticaPromptFactory_1.AgenticaPromptFactory.execute({
|
|
39
|
-
type: "execute",
|
|
40
|
-
protocol: operation.protocol,
|
|
41
|
-
controller: operation.controller,
|
|
42
|
-
function: operation.function,
|
|
43
|
-
id: props.input.id,
|
|
44
|
-
name: props.input.name,
|
|
45
|
-
arguments: props.input.arguments,
|
|
46
|
-
value: props.input.value,
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
const findOperation = (props) => {
|
|
50
|
-
var _a;
|
|
51
|
-
const found = (_a = props.operations
|
|
52
|
-
.get(props.input.controller)) === null || _a === void 0 ? void 0 : _a.get(props.input.function);
|
|
53
|
-
if (found === undefined)
|
|
54
|
-
throw new Error(`No operation found: (controller: ${props.input.controller}, function: ${props.input.function})`);
|
|
55
|
-
return found;
|
|
56
|
-
};
|
|
57
|
-
})(AgenticaPromptTransformer || (exports.AgenticaPromptTransformer = AgenticaPromptTransformer = {}));
|
|
58
|
-
//# sourceMappingURL=AgenticaPromptTransformer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AgenticaPromptTransformer.js","sourceRoot":"","sources":["../../src/internal/AgenticaPromptTransformer.ts"],"names":[],"mappings":";;;AAKA,mEAAgE;AAEhE,IAAiB,yBAAyB,CA8EzC;AA9ED,WAAiB,yBAAyB;IAC3B,mCAAS,GAAG,CAAiC,KAGzD,EAA0B,EAAE;QAC3B,OAAO;QACP,IAAI,K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,IAAI,EAAE,SAAS;YACf,QAAQ,EAAE,SAAS,CAAC,QAAkB;YACtC,UAAU,EAAE,SAAS,CAAC,UAAU;YAChC,QAAQ,EAAE,SAAS,CAAC,QAAQ;YAC5B,EAAE,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE;YAClB,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI;YACtB,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS;YAChC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK;SACzB,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,MAAM,aAAa,GAAG,CAAiC,KAMtD,EAAmC,EAAE;;QACpC,MAAM,KAAK,GAA0C,MAAA,KAAK,CAAC,UAAU;aAClE,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,0CAC1B,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC9B,IAAI,KAAK,KAAK,SAAS;YACrB,MAAM,IAAI,KAAK,CACb,oCAAoC,KAAK,CAAC,KAAK,CAAC,UAAU,eAAe,KAAK,CAAC,KAAK,CAAC,QAAQ,GAAG,CACjG,CAAC;QACJ,OAAO,KAAwC,CAAC;IAClD,CAAC,CAAC;AACJ,CAAC,EA9EgB,yBAAyB,yCAAzB,yBAAyB,QA8EzC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import OpenAI from "openai";
|
|
2
|
-
import { IAgenticaTokenUsage } from "../structures/IAgenticaTokenUsage";
|
|
3
|
-
export declare namespace AgenticaTokenUsageAggregator {
|
|
4
|
-
const aggregate: (props: {
|
|
5
|
-
kind: Exclude<keyof IAgenticaTokenUsage, "aggregate">;
|
|
6
|
-
completion: OpenAI.ChatCompletion;
|
|
7
|
-
usage: IAgenticaTokenUsage;
|
|
8
|
-
}) => void;
|
|
9
|
-
const plus: (x: IAgenticaTokenUsage, y: IAgenticaTokenUsage) => IAgenticaTokenUsage;
|
|
10
|
-
const zero: () => IAgenticaTokenUsage;
|
|
11
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AgenticaTokenUsageAggregator = void 0;
|
|
4
|
-
var AgenticaTokenUsageAggregator;
|
|
5
|
-
(function (AgenticaTokenUsageAggregator) {
|
|
6
|
-
AgenticaTokenUsageAggregator.aggregate = (props) => {
|
|
7
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
8
|
-
if (!props.completion.usage)
|
|
9
|
-
return;
|
|
10
|
-
//----
|
|
11
|
-
// COMPONENT
|
|
12
|
-
//----
|
|
13
|
-
const component = props.usage[props.kind];
|
|
14
|
-
// TOTAL
|
|
15
|
-
component.total += props.completion.usage.total_tokens;
|
|
16
|
-
// PROMPT
|
|
17
|
-
component.input.total += props.completion.usage.prompt_tokens;
|
|
18
|
-
(_b = (_a = props.completion.usage.prompt_tokens_details) === null || _a === void 0 ? void 0 : _a.audio_tokens) !== null && _b !== void 0 ? _b : 0;
|
|
19
|
-
component.input.cached +=
|
|
20
|
-
(_d = (_c = props.completion.usage.prompt_tokens_details) === null || _c === void 0 ? void 0 : _c.cached_tokens) !== null && _d !== void 0 ? _d : 0;
|
|
21
|
-
// COMPLETION
|
|
22
|
-
component.output.total += props.completion.usage.total_tokens;
|
|
23
|
-
component.output.accepted_prediction +=
|
|
24
|
-
(_f = (_e = props.completion.usage.completion_tokens_details) === null || _e === void 0 ? void 0 : _e.accepted_prediction_tokens) !== null && _f !== void 0 ? _f : 0;
|
|
25
|
-
component.output.reasoning +=
|
|
26
|
-
(_h = (_g = props.completion.usage.completion_tokens_details) === null || _g === void 0 ? void 0 : _g.reasoning_tokens) !== null && _h !== void 0 ? _h : 0;
|
|
27
|
-
component.output.rejected_prediction +=
|
|
28
|
-
(_k = (_j = props.completion.usage.completion_tokens_details) === null || _j === void 0 ? void 0 : _j.rejected_prediction_tokens) !== null && _k !== void 0 ? _k : 0;
|
|
29
|
-
//----
|
|
30
|
-
// RE-AGGREGATE
|
|
31
|
-
//----
|
|
32
|
-
const sum = (getter) => Object.entries(props.usage)
|
|
33
|
-
.filter(([key]) => key !== "aggregate")
|
|
34
|
-
.map(([_, comp]) => getter(comp))
|
|
35
|
-
.reduce((a, b) => a + b, 0);
|
|
36
|
-
const aggregate = props.usage.aggregate;
|
|
37
|
-
aggregate.total = sum((comp) => comp.total);
|
|
38
|
-
aggregate.input.total = sum((comp) => comp.input.total);
|
|
39
|
-
aggregate.input.cached = sum((comp) => comp.input.cached);
|
|
40
|
-
aggregate.output.total = sum((comp) => comp.output.total);
|
|
41
|
-
aggregate.output.reasoning = sum((comp) => comp.output.reasoning);
|
|
42
|
-
aggregate.output.accepted_prediction = sum((comp) => comp.output.accepted_prediction);
|
|
43
|
-
aggregate.output.rejected_prediction = sum((comp) => comp.output.rejected_prediction);
|
|
44
|
-
};
|
|
45
|
-
AgenticaTokenUsageAggregator.plus = (x, y) => {
|
|
46
|
-
const component = (a, b) => ({
|
|
47
|
-
total: a.total + b.total,
|
|
48
|
-
input: {
|
|
49
|
-
total: a.input.total + b.input.total,
|
|
50
|
-
cached: a.input.cached + b.input.cached,
|
|
51
|
-
},
|
|
52
|
-
output: {
|
|
53
|
-
total: a.output.total + b.output.total,
|
|
54
|
-
reasoning: a.output.reasoning + b.output.reasoning,
|
|
55
|
-
accepted_prediction: a.output.accepted_prediction + b.output.accepted_prediction,
|
|
56
|
-
rejected_prediction: a.output.rejected_prediction + b.output.rejected_prediction,
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
return {
|
|
60
|
-
aggregate: component(x.aggregate, y.aggregate),
|
|
61
|
-
initialize: component(x.initialize, y.initialize),
|
|
62
|
-
select: component(x.select, y.select),
|
|
63
|
-
cancel: component(x.cancel, y.cancel),
|
|
64
|
-
call: component(x.call, y.call),
|
|
65
|
-
describe: component(x.describe, y.describe),
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
AgenticaTokenUsageAggregator.zero = () => {
|
|
69
|
-
const component = () => ({
|
|
70
|
-
total: 0,
|
|
71
|
-
input: {
|
|
72
|
-
total: 0,
|
|
73
|
-
cached: 0,
|
|
74
|
-
},
|
|
75
|
-
output: {
|
|
76
|
-
total: 0,
|
|
77
|
-
reasoning: 0,
|
|
78
|
-
accepted_prediction: 0,
|
|
79
|
-
rejected_prediction: 0,
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
return {
|
|
83
|
-
aggregate: component(),
|
|
84
|
-
initialize: component(),
|
|
85
|
-
select: component(),
|
|
86
|
-
cancel: component(),
|
|
87
|
-
call: component(),
|
|
88
|
-
describe: component(),
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
|
-
})(AgenticaTokenUsageAggregator || (exports.AgenticaTokenUsageAggregator = AgenticaTokenUsageAggregator = {}));
|
|
92
|
-
//# sourceMappingURL=AgenticaTokenUsageAggregator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AgenticaTokenUsageAggregator.js","sourceRoot":"","sources":["../../src/internal/AgenticaTokenUsageAggregator.ts"],"names":[],"mappings":";;;AAIA,IAAiB,4BAA4B,CA8G5C;AA9GD,WAAiB,4BAA4B;IAC9B,sCAAS,GAAG,CAAC,KAIzB,EAAQ,EAAE;;QACT,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK;YAAE,OAAO;QAEpC,MAAM;QACN,YAAY;QACZ,MAAM;QACN,MAAM,SAAS,GAAmC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAE1E,QAAQ;QACR,SAAS,CAAC,KAAK,IAAI,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,YAAY,CAAC;QAEvD,SAAS;QACT,SAAS,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,aAAa,CAAC;QAC9D,MAAA,MAAA,KAAK,CAAC,UAAU,CA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