@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,134 +1,156 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
-
import { AgenticaOperation } from "../context/AgenticaOperation";
|
|
3
|
+
import type { AgenticaOperation } from "../context/AgenticaOperation";
|
|
4
|
+
import type { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
|
|
5
|
+
import type { AgenticaPrompt } from "../prompts/AgenticaPrompt";
|
|
4
6
|
import { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
|
|
5
|
-
import { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
|
|
6
7
|
import { AgenticaCancelPrompt } from "../prompts/AgenticaCancelPrompt";
|
|
7
8
|
import { AgenticaDescribePrompt } from "../prompts/AgenticaDescribePrompt";
|
|
8
9
|
import { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
|
|
9
|
-
import { AgenticaPrompt } from "../prompts/AgenticaPrompt";
|
|
10
10
|
import { AgenticaSelectPrompt } from "../prompts/AgenticaSelectPrompt";
|
|
11
11
|
import { AgenticaTextPrompt } from "../prompts/AgenticaTextPrompt";
|
|
12
12
|
|
|
13
|
-
export
|
|
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
|
-
|
|
46
|
-
|
|
13
|
+
export function transform<Model extends ILlmSchema.Model>(props: {
|
|
14
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
15
|
+
prompt: IAgenticaPromptJson;
|
|
16
|
+
}): AgenticaPrompt<Model> {
|
|
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
|
+
}
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}): AgenticaTextPrompt => {
|
|
51
|
-
return new AgenticaTextPrompt(props.prompt);
|
|
52
|
-
};
|
|
50
|
+
throw new Error("Invalid prompt type.");
|
|
51
|
+
}
|
|
53
52
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
53
|
+
export function transformText(props: {
|
|
54
|
+
prompt: IAgenticaPromptJson.IText;
|
|
55
|
+
}): AgenticaTextPrompt {
|
|
56
|
+
return new AgenticaTextPrompt(props.prompt);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function transformSelect<Model extends ILlmSchema.Model>(props: {
|
|
60
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
61
|
+
prompt: IAgenticaPromptJson.ISelect;
|
|
62
|
+
}): AgenticaSelectPrompt<Model> {
|
|
63
|
+
return new AgenticaSelectPrompt({
|
|
64
|
+
id: props.prompt.id,
|
|
65
|
+
selections: props.prompt.selections.map(
|
|
66
|
+
select =>
|
|
67
|
+
new AgenticaOperationSelection({
|
|
68
|
+
operation: findOperation({
|
|
69
|
+
operations: props.operations,
|
|
70
|
+
input: select.operation,
|
|
68
71
|
}),
|
|
69
|
-
|
|
70
|
-
|
|
72
|
+
reason: select.reason,
|
|
73
|
+
}),
|
|
74
|
+
),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
71
77
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}),
|
|
85
|
-
reason: select.reason,
|
|
78
|
+
export function transformCancel<Model extends ILlmSchema.Model>(props: {
|
|
79
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
80
|
+
prompt: IAgenticaPromptJson.ICancel;
|
|
81
|
+
}): AgenticaCancelPrompt<Model> {
|
|
82
|
+
return new AgenticaCancelPrompt({
|
|
83
|
+
id: props.prompt.id,
|
|
84
|
+
selections: props.prompt.selections.map(
|
|
85
|
+
select =>
|
|
86
|
+
new AgenticaOperationSelection({
|
|
87
|
+
operation: findOperation({
|
|
88
|
+
operations: props.operations,
|
|
89
|
+
input: select.operation,
|
|
86
90
|
}),
|
|
87
|
-
|
|
88
|
-
|
|
91
|
+
reason: select.reason,
|
|
92
|
+
}),
|
|
93
|
+
),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function transformExecute<Model extends ILlmSchema.Model>(props: {
|
|
98
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
99
|
+
prompt: IAgenticaPromptJson.IExecute;
|
|
100
|
+
}): AgenticaExecutePrompt<Model> {
|
|
101
|
+
return new AgenticaExecutePrompt({
|
|
102
|
+
id: props.prompt.id,
|
|
103
|
+
operation: findOperation({
|
|
104
|
+
operations: props.operations,
|
|
105
|
+
input: props.prompt.operation,
|
|
106
|
+
}),
|
|
107
|
+
arguments: props.prompt.arguments,
|
|
108
|
+
/**
|
|
109
|
+
* @TODO fix it
|
|
110
|
+
* The property and value have a type mismatch, but it works.
|
|
111
|
+
*/
|
|
112
|
+
value: props.prompt.value as unknown as Record<string, unknown>,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
89
115
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
116
|
+
export function transformDescribe<Model extends ILlmSchema.Model>(props: {
|
|
117
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
118
|
+
prompt: IAgenticaPromptJson.IDescribe;
|
|
119
|
+
}): AgenticaDescribePrompt<Model> {
|
|
120
|
+
return new AgenticaDescribePrompt({
|
|
121
|
+
text: props.prompt.text,
|
|
122
|
+
executes: props.prompt.executes.map(next =>
|
|
123
|
+
transformExecute({
|
|
97
124
|
operations: props.operations,
|
|
98
|
-
|
|
125
|
+
prompt: next,
|
|
99
126
|
}),
|
|
100
|
-
|
|
101
|
-
|
|
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.executes.map((next) =>
|
|
111
|
-
transformExecute({
|
|
112
|
-
operations: props.operations,
|
|
113
|
-
prompt: next,
|
|
114
|
-
}),
|
|
115
|
-
),
|
|
116
|
-
});
|
|
127
|
+
),
|
|
128
|
+
});
|
|
117
129
|
}
|
|
118
130
|
|
|
119
|
-
|
|
131
|
+
function findOperation<Model extends ILlmSchema.Model>(props: {
|
|
120
132
|
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
121
133
|
input: {
|
|
122
134
|
controller: string;
|
|
123
135
|
function: string;
|
|
124
136
|
};
|
|
125
|
-
}): AgenticaOperation<Model>
|
|
137
|
+
}): AgenticaOperation<Model> {
|
|
126
138
|
const found: AgenticaOperation<Model> | undefined = props.operations
|
|
127
139
|
.get(props.input.controller)
|
|
128
140
|
?.get(props.input.function);
|
|
129
|
-
if (found === undefined)
|
|
141
|
+
if (found === undefined) {
|
|
130
142
|
throw new Error(
|
|
131
143
|
`No operation found: (controller: ${props.input.controller}, function: ${props.input.function})`,
|
|
132
144
|
);
|
|
145
|
+
}
|
|
133
146
|
return found;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export const AgenticaPromptTransformer = {
|
|
150
|
+
transform,
|
|
151
|
+
transformText,
|
|
152
|
+
transformSelect,
|
|
153
|
+
transformCancel,
|
|
154
|
+
transformExecute,
|
|
155
|
+
transformDescribe,
|
|
134
156
|
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export declare namespace MPSCUtil {
|
|
2
|
-
interface Output<T> {
|
|
3
|
-
consumer: ReadableStream<T>;
|
|
4
|
-
produce: (chunk: T) => void;
|
|
5
|
-
close: () => void;
|
|
6
|
-
/**
|
|
7
|
-
* Wait until the producing is finished.
|
|
8
|
-
*/
|
|
9
|
-
waitClosed: () => Promise<void>;
|
|
10
|
-
/**
|
|
11
|
-
* Wait until the consuming is finished.(finished producing and consuming)
|
|
12
|
-
*/
|
|
13
|
-
waitUntilEmpty: () => Promise<void>;
|
|
14
|
-
/**
|
|
15
|
-
* Check if producing is done and consuming is finished.
|
|
16
|
-
*/
|
|
17
|
-
done: () => boolean;
|
|
18
|
-
}
|
|
19
|
-
const create: <T>() => Output<T>;
|
|
20
|
-
class AsyncQueue<T> {
|
|
21
|
-
private queue;
|
|
22
|
-
private resolvers;
|
|
23
|
-
private closeResolvers;
|
|
24
|
-
private emptyResolvers;
|
|
25
|
-
private closed;
|
|
26
|
-
enqueue(item: T): void;
|
|
27
|
-
dequeue(): Promise<IteratorResult<T, undefined>>;
|
|
28
|
-
isEmpty(): boolean;
|
|
29
|
-
isClosed(): boolean;
|
|
30
|
-
done(): boolean;
|
|
31
|
-
close(): void;
|
|
32
|
-
waitUntilEmpty(): Promise<void>;
|
|
33
|
-
waitClosed(): Promise<void>;
|
|
34
|
-
}
|
|
35
|
-
}
|
package/lib/internal/MPSCUtil.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.MPSCUtil = void 0;
|
|
13
|
-
var MPSCUtil;
|
|
14
|
-
(function (MPSCUtil) {
|
|
15
|
-
MPSCUtil.create = () => {
|
|
16
|
-
const queue = new AsyncQueue();
|
|
17
|
-
const consumer = new ReadableStream({
|
|
18
|
-
pull(controller) {
|
|
19
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
const { value, done } = yield queue.dequeue();
|
|
21
|
-
if (done) {
|
|
22
|
-
controller.close();
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
controller.enqueue(value);
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
return {
|
|
31
|
-
consumer,
|
|
32
|
-
produce: (chunk) => queue.enqueue(chunk),
|
|
33
|
-
close: () => queue.close(),
|
|
34
|
-
done: () => queue.done(),
|
|
35
|
-
waitClosed: () => queue.waitClosed(),
|
|
36
|
-
waitUntilEmpty: () => queue.waitUntilEmpty(),
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
class AsyncQueue {
|
|
40
|
-
constructor() {
|
|
41
|
-
this.queue = [];
|
|
42
|
-
this.resolvers = [];
|
|
43
|
-
this.closeResolvers = [];
|
|
44
|
-
this.emptyResolvers = [];
|
|
45
|
-
this.closed = false;
|
|
46
|
-
}
|
|
47
|
-
enqueue(item) {
|
|
48
|
-
var _a;
|
|
49
|
-
this.queue.push(item);
|
|
50
|
-
if (this.resolvers.length > 0) {
|
|
51
|
-
(_a = this.resolvers.shift()) === null || _a === void 0 ? void 0 : _a({ value: this.queue.shift(), done: false });
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
dequeue() {
|
|
55
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
if (this.queue.length > 0) {
|
|
57
|
-
return { value: this.queue.shift(), done: false };
|
|
58
|
-
}
|
|
59
|
-
if (this.closed) {
|
|
60
|
-
if (this.emptyResolvers.length > 0) {
|
|
61
|
-
this.emptyResolvers.forEach((resolve) => resolve());
|
|
62
|
-
this.emptyResolvers = [];
|
|
63
|
-
}
|
|
64
|
-
return { value: undefined, done: true };
|
|
65
|
-
}
|
|
66
|
-
return new Promise((resolve) => this.resolvers.push(resolve));
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
isEmpty() {
|
|
70
|
-
return this.queue.length === 0;
|
|
71
|
-
}
|
|
72
|
-
isClosed() {
|
|
73
|
-
return this.closed;
|
|
74
|
-
}
|
|
75
|
-
done() {
|
|
76
|
-
return this.isClosed() && this.isEmpty();
|
|
77
|
-
}
|
|
78
|
-
close() {
|
|
79
|
-
var _a;
|
|
80
|
-
this.closed = true;
|
|
81
|
-
while (this.resolvers.length > 0) {
|
|
82
|
-
(_a = this.resolvers.shift()) === null || _a === void 0 ? void 0 : _a({ value: undefined, done: true });
|
|
83
|
-
}
|
|
84
|
-
this.closeResolvers.forEach((resolve) => resolve());
|
|
85
|
-
}
|
|
86
|
-
waitUntilEmpty() {
|
|
87
|
-
if (this.isEmpty()) {
|
|
88
|
-
return Promise.resolve();
|
|
89
|
-
}
|
|
90
|
-
return new Promise((resolve) => {
|
|
91
|
-
this.emptyResolvers.push(resolve);
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
waitClosed() {
|
|
95
|
-
if (this.isClosed()) {
|
|
96
|
-
return Promise.resolve();
|
|
97
|
-
}
|
|
98
|
-
return new Promise((resolve) => {
|
|
99
|
-
this.closeResolvers.push(resolve);
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
MPSCUtil.AsyncQueue = AsyncQueue;
|
|
104
|
-
})(MPSCUtil || (exports.MPSCUtil = MPSCUtil = {}));
|
|
105
|
-
//# sourceMappingURL=MPSCUtil.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MPSCUtil.js","sourceRoot":"","sources":["../../src/internal/MPSCUtil.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAiB,QAAQ,CA8GxB;AA9GD,WAAiB,QAAQ;IAoBV,eAAM,GAAG,GAAiB,EAAE;QACvC,MAAM,KAAK,GAAG,IAAI,UAAU,EAAK,CAAC;QAClC,MAAM,QAAQ,GAAG,IAAI,cAAc,CAAI;YAC/B,IAAI,CAAC,UAAU;;oBACnB,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;oBAC9C,IAAI,IAAI,EAAE,CAAC;wBACT,UAAU,CAAC,KAAK,EAAE,CAAC;oBACrB,CAAC;yBAAM,CAAC;wBACN,UAAU,CAAC,OAAO,CAAC,KAA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AAC,OAAO,CAAC,CAAC;YACpC,CAAC,CAAC,CAAC;QACL,CAAC;QAED,UAAU;YACR,IAAI,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC;gBACpB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;YAC3B,CAAC;YAED,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;gBACnC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACpC,CAAC,CAAC,CAAC;QACL,CAAC;KACF;IAlEY,mBAAU,aAkEtB,CAAA;AACH,CAAC,EA9GgB,QAAQ,wBAAR,QAAQ,QA8GxB"}
|
package/src/internal/MPSCUtil.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
export namespace MPSCUtil {
|
|
2
|
-
export interface Output<T> {
|
|
3
|
-
consumer: ReadableStream<T>;
|
|
4
|
-
produce: (chunk: T) => void;
|
|
5
|
-
close: () => void;
|
|
6
|
-
/**
|
|
7
|
-
* Wait until the producing is finished.
|
|
8
|
-
*/
|
|
9
|
-
waitClosed: () => Promise<void>;
|
|
10
|
-
/**
|
|
11
|
-
* Wait until the consuming is finished.(finished producing and consuming)
|
|
12
|
-
*/
|
|
13
|
-
waitUntilEmpty: () => Promise<void>;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Check if producing is done and consuming is finished.
|
|
17
|
-
*/
|
|
18
|
-
done: () => boolean;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const create = <T>(): Output<T> => {
|
|
22
|
-
const queue = new AsyncQueue<T>();
|
|
23
|
-
const consumer = new ReadableStream<T>({
|
|
24
|
-
async pull(controller) {
|
|
25
|
-
const { value, done } = await queue.dequeue();
|
|
26
|
-
if (done) {
|
|
27
|
-
controller.close();
|
|
28
|
-
} else {
|
|
29
|
-
controller.enqueue(value);
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
consumer,
|
|
36
|
-
produce: (chunk: T) => queue.enqueue(chunk),
|
|
37
|
-
close: () => queue.close(),
|
|
38
|
-
done: () => queue.done(),
|
|
39
|
-
waitClosed: () => queue.waitClosed(),
|
|
40
|
-
waitUntilEmpty: () => queue.waitUntilEmpty(),
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export class AsyncQueue<T> {
|
|
45
|
-
private queue: T[] = [];
|
|
46
|
-
private resolvers: ((value: IteratorResult<T, undefined>) => void)[] = [];
|
|
47
|
-
private closeResolvers: (() => void)[] = [];
|
|
48
|
-
private emptyResolvers: (() => void)[] = [];
|
|
49
|
-
private closed = false;
|
|
50
|
-
|
|
51
|
-
enqueue(item: T) {
|
|
52
|
-
this.queue.push(item);
|
|
53
|
-
if (this.resolvers.length > 0) {
|
|
54
|
-
this.resolvers.shift()?.({ value: this.queue.shift()!, done: false });
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async dequeue(): Promise<IteratorResult<T, undefined>> {
|
|
59
|
-
if (this.queue.length > 0) {
|
|
60
|
-
return { value: this.queue.shift()!, done: false };
|
|
61
|
-
}
|
|
62
|
-
if (this.closed) {
|
|
63
|
-
if (this.emptyResolvers.length > 0) {
|
|
64
|
-
this.emptyResolvers.forEach((resolve) => resolve());
|
|
65
|
-
this.emptyResolvers = [];
|
|
66
|
-
}
|
|
67
|
-
return { value: undefined, done: true };
|
|
68
|
-
}
|
|
69
|
-
return new Promise((resolve) => this.resolvers.push(resolve));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
isEmpty() {
|
|
73
|
-
return this.queue.length === 0;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
isClosed() {
|
|
77
|
-
return this.closed;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
done() {
|
|
81
|
-
return this.isClosed() && this.isEmpty();
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
close() {
|
|
85
|
-
this.closed = true;
|
|
86
|
-
while (this.resolvers.length > 0) {
|
|
87
|
-
this.resolvers.shift()?.({ value: undefined, done: true });
|
|
88
|
-
}
|
|
89
|
-
this.closeResolvers.forEach((resolve) => resolve());
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
waitUntilEmpty() {
|
|
93
|
-
if (this.isEmpty()) {
|
|
94
|
-
return Promise.resolve();
|
|
95
|
-
}
|
|
96
|
-
return new Promise<void>((resolve) => {
|
|
97
|
-
this.emptyResolvers.push(resolve);
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
waitClosed() {
|
|
102
|
-
if (this.isClosed()) {
|
|
103
|
-
return Promise.resolve();
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return new Promise<void>((resolve) => {
|
|
107
|
-
this.closeResolvers.push(resolve);
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|