@agentica/core 0.12.20 → 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
package/src/index.ts
CHANGED
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export * from "./structures/IAgenticaConfig";
|
|
3
|
-
export * from "./structures/IAgenticaController";
|
|
4
|
-
export * from "./structures/IAgenticaExecutor";
|
|
5
|
-
export * from "./structures/IAgenticaProps";
|
|
6
|
-
export * from "./structures/IAgenticaVendor";
|
|
7
|
-
export * from "./structures/IAgenticaSystemPrompt";
|
|
8
|
-
|
|
9
|
-
export * from "./json/IAgenticaEventJson";
|
|
10
|
-
export * from "./json/IAgenticaOperationJson";
|
|
11
|
-
export * from "./json/IAgenticaOperationSelectionJson";
|
|
12
|
-
export * from "./json/IAgenticaPromptJson";
|
|
13
|
-
export * from "./json/IAgenticaTokenUsageJson";
|
|
14
|
-
|
|
1
|
+
export * from "./Agentica";
|
|
15
2
|
// CONTEXT
|
|
16
3
|
export * from "./context/AgenticaContext";
|
|
17
4
|
export * from "./context/AgenticaOperation";
|
|
@@ -19,19 +6,13 @@ export * from "./context/AgenticaOperationCollection";
|
|
|
19
6
|
export * from "./context/AgenticaOperationSelection";
|
|
20
7
|
export * from "./context/AgenticaTokenUsage";
|
|
21
8
|
|
|
22
|
-
export * from "./prompts/AgenticaPrompt";
|
|
23
|
-
export * from "./prompts/AgenticaCancelPrompt";
|
|
24
|
-
export * from "./prompts/AgenticaDescribePrompt";
|
|
25
|
-
export * from "./prompts/AgenticaExecutePrompt";
|
|
26
|
-
export * from "./prompts/AgenticaSelectPrompt";
|
|
27
|
-
export * from "./prompts/AgenticaTextPrompt";
|
|
28
|
-
|
|
29
|
-
// EVENTS
|
|
30
|
-
export * from "./events/AgenticaEvent";
|
|
31
9
|
export * from "./events/AgenticaCallEvent";
|
|
32
10
|
export * from "./events/AgenticaCancelEvent";
|
|
33
11
|
export * from "./events/AgenticaDescribeEvent";
|
|
12
|
+
// EVENTS
|
|
13
|
+
export * from "./events/AgenticaEvent";
|
|
34
14
|
export * from "./events/AgenticaEventSource";
|
|
15
|
+
|
|
35
16
|
export * from "./events/AgenticaExecuteEvent";
|
|
36
17
|
export * from "./events/AgenticaRequestEvent";
|
|
37
18
|
export * from "./events/AgenticaResponseEvent";
|
|
@@ -41,4 +22,23 @@ export * from "./events/AgenticaTextEvent";
|
|
|
41
22
|
// FACADE CLASS
|
|
42
23
|
export * from "./functional/assertHttpLlmApplication";
|
|
43
24
|
export * from "./functional/validateHttpLlmApplication";
|
|
44
|
-
export * from "./
|
|
25
|
+
export * from "./json/IAgenticaEventJson";
|
|
26
|
+
export * from "./json/IAgenticaOperationJson";
|
|
27
|
+
export * from "./json/IAgenticaOperationSelectionJson";
|
|
28
|
+
export * from "./json/IAgenticaPromptJson";
|
|
29
|
+
|
|
30
|
+
export * from "./json/IAgenticaTokenUsageJson";
|
|
31
|
+
export * from "./prompts/AgenticaCancelPrompt";
|
|
32
|
+
export * from "./prompts/AgenticaDescribePrompt";
|
|
33
|
+
export * from "./prompts/AgenticaExecutePrompt";
|
|
34
|
+
export * from "./prompts/AgenticaPrompt";
|
|
35
|
+
export * from "./prompts/AgenticaSelectPrompt";
|
|
36
|
+
export * from "./prompts/AgenticaTextPrompt";
|
|
37
|
+
// STRUCTURES
|
|
38
|
+
export * from "./structures/IAgenticaConfig";
|
|
39
|
+
export * from "./structures/IAgenticaController";
|
|
40
|
+
export * from "./structures/IAgenticaExecutor";
|
|
41
|
+
|
|
42
|
+
export * from "./structures/IAgenticaProps";
|
|
43
|
+
export * from "./structures/IAgenticaSystemPrompt";
|
|
44
|
+
export * from "./structures/IAgenticaVendor";
|
|
@@ -1,28 +1,34 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
-
import { IAgenticaConfig } from "../structures/IAgenticaConfig";
|
|
3
|
+
import type { IAgenticaConfig } from "../structures/IAgenticaConfig";
|
|
4
4
|
import { AgenticaSystemPrompt } from "./AgenticaSystemPrompt";
|
|
5
5
|
import { Singleton } from "./Singleton";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
|
|
7
|
+
/**
|
|
8
|
+
* @TODO maybe this code will rewrite
|
|
9
|
+
*/
|
|
10
|
+
const isNode = new Singleton(() => {
|
|
11
|
+
const isObject = (obj: any) => typeof obj === "object" && obj !== null;
|
|
12
|
+
return (
|
|
13
|
+
// eslint-disable-next-line no-restricted-globals
|
|
14
|
+
typeof global === "object"
|
|
15
|
+
// eslint-disable-next-line no-restricted-globals
|
|
16
|
+
&& isObject(global)
|
|
17
|
+
// eslint-disable-next-line node/prefer-global/process, no-restricted-globals
|
|
18
|
+
&& isObject(global.process)
|
|
19
|
+
// eslint-disable-next-line node/prefer-global/process, no-restricted-globals
|
|
20
|
+
&& isObject(global.process.versions)
|
|
21
|
+
// eslint-disable-next-line node/prefer-global/process, no-restricted-globals
|
|
22
|
+
&& typeof global.process.versions.node !== "undefined"
|
|
23
|
+
);
|
|
24
|
+
});
|
|
23
25
|
|
|
26
|
+
/**
|
|
27
|
+
* @TODO maybe replace `process` property for lint pass
|
|
28
|
+
*/
|
|
24
29
|
const getLocale = new Singleton(() =>
|
|
25
30
|
isNode.get()
|
|
31
|
+
// eslint-disable-next-line node/prefer-global/process
|
|
26
32
|
? (process.env.LANG?.split(".")[0] ?? "en-US")
|
|
27
33
|
: navigator.language,
|
|
28
34
|
);
|
|
@@ -31,13 +37,21 @@ const getTimezone = new Singleton(
|
|
|
31
37
|
() => Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
32
38
|
);
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
export function write<Model extends ILlmSchema.Model>(config?: IAgenticaConfig<Model>): string {
|
|
41
|
+
if (config?.systemPrompt?.common !== undefined) {
|
|
42
|
+
return config?.systemPrompt?.common(config);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const locale: string = config?.locale ?? getLocale.get();
|
|
46
|
+
const timezone: string = config?.timezone ?? getTimezone.get();
|
|
47
|
+
|
|
48
|
+
return AgenticaSystemPrompt.COMMON
|
|
49
|
+
// intended code
|
|
50
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
51
|
+
.replace("${locale}", locale)
|
|
52
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
53
|
+
.replace("${timezone}", timezone);
|
|
54
|
+
}
|
|
55
|
+
export const AgenticaDefaultPrompt = {
|
|
56
|
+
write,
|
|
57
|
+
};
|
|
@@ -1,37 +1,36 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
-
import { AgenticaOperation } from "../context/AgenticaOperation";
|
|
4
|
-
import { AgenticaOperationCollection } from "../context/AgenticaOperationCollection";
|
|
5
|
-
import { IAgenticaConfig } from "../structures/IAgenticaConfig";
|
|
6
|
-
import { IAgenticaController } from "../structures/IAgenticaController";
|
|
3
|
+
import type { AgenticaOperation } from "../context/AgenticaOperation";
|
|
4
|
+
import type { AgenticaOperationCollection } from "../context/AgenticaOperationCollection";
|
|
5
|
+
import type { IAgenticaConfig } from "../structures/IAgenticaConfig";
|
|
6
|
+
import type { IAgenticaController } from "../structures/IAgenticaController";
|
|
7
7
|
import { __map_take } from "./__map_take";
|
|
8
8
|
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
unique ? func : `_${ci}_${func}`;
|
|
9
|
+
export function compose<Model extends ILlmSchema.Model>(props: {
|
|
10
|
+
controllers: IAgenticaController<Model>[];
|
|
11
|
+
config?: IAgenticaConfig<Model> | undefined;
|
|
12
|
+
}): AgenticaOperationCollection<Model> {
|
|
13
|
+
const unique: boolean
|
|
14
|
+
= props.controllers.length === 1
|
|
15
|
+
|| (() => {
|
|
16
|
+
const names: string[] = props.controllers
|
|
17
|
+
.map(controller =>
|
|
18
|
+
controller.application.functions.map(func => func.name),
|
|
19
|
+
)
|
|
20
|
+
.flat();
|
|
21
|
+
return new Set(names).size === names.length;
|
|
22
|
+
})();
|
|
23
|
+
const naming = (func: string, ci: number) =>
|
|
24
|
+
unique ? func : `_${ci}_${func}`;
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
const array: AgenticaOperation<Model>[] = props.controllers
|
|
27
|
+
.map((controller, ci) =>
|
|
28
|
+
controller.protocol === "http"
|
|
29
|
+
? controller.application.functions.map(
|
|
30
|
+
func =>
|
|
32
31
|
({
|
|
33
32
|
protocol: "http",
|
|
34
|
-
controller
|
|
33
|
+
controller,
|
|
35
34
|
function: func,
|
|
36
35
|
name: naming(func.name, ci),
|
|
37
36
|
toJSON: () => ({
|
|
@@ -41,9 +40,9 @@ export namespace AgenticaOperationComposer {
|
|
|
41
40
|
name: naming(func.name, ci),
|
|
42
41
|
}),
|
|
43
42
|
}) satisfies AgenticaOperation.Http<Model>,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
)
|
|
44
|
+
: controller.application.functions.map(
|
|
45
|
+
func =>
|
|
47
46
|
({
|
|
48
47
|
protocol: "class",
|
|
49
48
|
controller,
|
|
@@ -56,41 +55,44 @@ export namespace AgenticaOperationComposer {
|
|
|
56
55
|
name: naming(func.name, ci),
|
|
57
56
|
}),
|
|
58
57
|
}) satisfies AgenticaOperation.Class<Model>,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
?
|
|
58
|
+
),
|
|
59
|
+
)
|
|
60
|
+
.flat();
|
|
61
|
+
const divided: AgenticaOperation<Model>[][] | undefined
|
|
62
|
+
= props.config?.capacity !== undefined && array.length > props.config.capacity
|
|
63
|
+
? divide({
|
|
65
64
|
array,
|
|
66
65
|
capacity: props.config.capacity,
|
|
67
66
|
})
|
|
68
67
|
: undefined;
|
|
69
68
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
};
|
|
69
|
+
const flat: Map<string, AgenticaOperation<Model>> = new Map();
|
|
70
|
+
const group: Map<string, Map<string, AgenticaOperation<Model>>> = new Map();
|
|
71
|
+
for (const item of array) {
|
|
72
|
+
flat.set(item.name, item);
|
|
73
|
+
__map_take(group, item.controller.name, () => new Map()).set(
|
|
74
|
+
item.name,
|
|
75
|
+
item,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
array,
|
|
80
|
+
divided,
|
|
81
|
+
flat,
|
|
82
|
+
group,
|
|
85
83
|
};
|
|
84
|
+
}
|
|
86
85
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
};
|
|
86
|
+
function divide<T>(props: {
|
|
87
|
+
array: T[];
|
|
88
|
+
capacity: number;
|
|
89
|
+
}): T[][] {
|
|
90
|
+
const size: number = Math.ceil(props.array.length / props.capacity);
|
|
91
|
+
const capacity: number = Math.ceil(props.array.length / size);
|
|
92
|
+
const replica: T[] = props.array.slice();
|
|
93
|
+
return Array.from({ length: size }, () => replica.splice(0, capacity));
|
|
96
94
|
}
|
|
95
|
+
|
|
96
|
+
export const AgenticaOperationComposer = {
|
|
97
|
+
compose,
|
|
98
|
+
};
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
/* eslint-disable no-template-curly-in-string */
|
|
2
|
+
export const AgenticaSystemPrompt = {
|
|
3
|
+
CANCEL:
|
|
4
|
+
"You are a helpful assistant for cancelling functions which are prepared to call.\n\nUse the supplied tools to select some functions to cancel of `getApiFunctions()` returned.\n\nIf you can't find any proper function to select, don't talk, don't do anything.",
|
|
5
|
+
COMMON:
|
|
6
|
+
"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.\n\nAt 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.",
|
|
7
|
+
DESCRIBE:
|
|
8
|
+
"You are a helpful assistant describing return values of function calls.\n\nAbove messages are the list of function call histories. When describing the return values, please do not too much shortly summarize them. Instead, provide detailed descriptions as much as.\n\nAlso, 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.\n\nAt last, if user's language locale code is different with your description, please translate it to the user's language.",
|
|
9
|
+
EXECUTE:
|
|
10
|
+
"You are a helpful assistant for tool calling.\n\nUse the supplied tools to assist the user.\n\nIf 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.\n\nFor 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.",
|
|
11
|
+
INITIALIZE:
|
|
12
|
+
"You are a helpful assistant.\n\nUse the supplied tools to assist the user.",
|
|
13
|
+
SELECT:
|
|
14
|
+
"You are a helpful assistant for selecting functions to call.\n\nUse the supplied tools to select some functions of `getApiFunctions()` returned.\n\nWhen selecting functions to call, pay attention to the relationship between functions. In particular, check the prerequisites between each function.\n\nIf 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.",
|
|
15
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export class AsyncQueue<T> {
|
|
2
|
+
private queue: T[] = [];
|
|
3
|
+
private resolvers: ((value: IteratorResult<T, undefined>) => void)[] = [];
|
|
4
|
+
private closeResolvers: (() => void)[] = [];
|
|
5
|
+
private emptyResolvers: (() => void)[] = [];
|
|
6
|
+
private closed = false;
|
|
7
|
+
|
|
8
|
+
enqueue(item: T) {
|
|
9
|
+
this.queue.push(item);
|
|
10
|
+
if (this.resolvers.length > 0) {
|
|
11
|
+
this.resolvers.shift()?.({ value: this.queue.shift()!, done: false });
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async dequeue(): Promise<IteratorResult<T, undefined>> {
|
|
16
|
+
if (this.queue.length > 0) {
|
|
17
|
+
return { value: this.queue.shift()!, done: false };
|
|
18
|
+
}
|
|
19
|
+
if (this.closed) {
|
|
20
|
+
if (this.emptyResolvers.length > 0) {
|
|
21
|
+
this.emptyResolvers.forEach(resolve => resolve());
|
|
22
|
+
this.emptyResolvers = [];
|
|
23
|
+
}
|
|
24
|
+
return { value: undefined, done: true };
|
|
25
|
+
}
|
|
26
|
+
return new Promise(resolve => this.resolvers.push(resolve));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
isEmpty() {
|
|
30
|
+
return this.queue.length === 0;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
isClosed() {
|
|
34
|
+
return this.closed;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
done() {
|
|
38
|
+
return this.isClosed() && this.isEmpty();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
close() {
|
|
42
|
+
this.closed = true;
|
|
43
|
+
while (this.resolvers.length > 0) {
|
|
44
|
+
this.resolvers.shift()?.({ value: undefined, done: true });
|
|
45
|
+
}
|
|
46
|
+
this.closeResolvers.forEach(resolve => resolve());
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async waitUntilEmpty() {
|
|
50
|
+
if (this.isEmpty()) {
|
|
51
|
+
return Promise.resolve();
|
|
52
|
+
}
|
|
53
|
+
return new Promise<void>((resolve) => {
|
|
54
|
+
this.emptyResolvers.push(resolve);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async waitClosed() {
|
|
59
|
+
if (this.isClosed()) {
|
|
60
|
+
return Promise.resolve();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return new Promise<void>((resolve) => {
|
|
64
|
+
this.closeResolvers.push(resolve);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { AsyncQueue } from "./AsyncQueue";
|
|
2
|
+
|
|
3
|
+
export class MPSC<T> {
|
|
4
|
+
private readonly queue: AsyncQueue<T>;
|
|
5
|
+
public readonly consumer: ReadableStream<T>;
|
|
6
|
+
|
|
7
|
+
public constructor() {
|
|
8
|
+
this.queue = new AsyncQueue<T>();
|
|
9
|
+
this.consumer = new ReadableStream<T>({
|
|
10
|
+
pull: async (controller) => {
|
|
11
|
+
const { value, done } = await this.queue.dequeue();
|
|
12
|
+
if (done === true) {
|
|
13
|
+
controller.close();
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
controller.enqueue(value);
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
produce(chunk: T) {
|
|
22
|
+
this.queue.enqueue(chunk);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
close() {
|
|
26
|
+
this.queue.close();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
done() {
|
|
30
|
+
return this.queue.done();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async waitClosed() {
|
|
34
|
+
await this.queue.waitClosed();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async waitUntilEmpty() {
|
|
38
|
+
await this.queue.waitUntilEmpty();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
*/
|
|
4
|
+
const NOT_MOUNTED_YET = {};
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* @internal
|
|
3
8
|
*/
|
|
@@ -11,12 +16,9 @@ export class Singleton<T, Args extends any[] = []> {
|
|
|
11
16
|
}
|
|
12
17
|
|
|
13
18
|
public get(...args: Args): T {
|
|
14
|
-
if (this.value_ === NOT_MOUNTED_YET)
|
|
19
|
+
if (this.value_ === NOT_MOUNTED_YET) {
|
|
20
|
+
this.value_ = this.closure_(...args);
|
|
21
|
+
}
|
|
15
22
|
return this.value_ as T;
|
|
16
23
|
}
|
|
17
24
|
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @internal
|
|
21
|
-
*/
|
|
22
|
-
const NOT_MOUNTED_YET = {};
|
|
@@ -1,64 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const { done, value } = await reader.read();
|
|
7
|
-
if (done) break;
|
|
8
|
-
result.push(value);
|
|
9
|
-
}
|
|
10
|
-
return result;
|
|
11
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* @module StreamUtil
|
|
3
|
+
*
|
|
4
|
+
* Utility functions for streams.
|
|
5
|
+
*/
|
|
12
6
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
7
|
+
async function readAll<T>(stream: ReadableStream<T>): Promise<T[]> {
|
|
8
|
+
const reader = stream.getReader();
|
|
9
|
+
const result: T[] = [];
|
|
10
|
+
while (true) {
|
|
11
|
+
const { done, value } = await reader.read();
|
|
12
|
+
if (done) {
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
result.push(value);
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
async function reduce<T, R = T>(stream: ReadableStream<T>, reducer: (acc: T | R, cur: T) => R, initial?: R): Promise<R | null> {
|
|
21
|
+
const reader = stream.getReader();
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
const { done, value } = await reader.read();
|
|
24
|
-
if (done) break;
|
|
25
|
-
if (acc === null) {
|
|
26
|
-
acc = value;
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
23
|
+
let acc = (initial ?? null) as R | null | T;
|
|
29
24
|
|
|
30
|
-
|
|
25
|
+
while (true) {
|
|
26
|
+
const { done, value } = await reader.read();
|
|
27
|
+
if (done) {
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
if (acc === null) {
|
|
31
|
+
acc = value;
|
|
32
|
+
continue;
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
+
acc = reducer(acc, value);
|
|
36
|
+
}
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
return acc as R;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function to<T>(value: T): ReadableStream<T> {
|
|
42
|
+
const stream = new ReadableStream<T>({
|
|
43
|
+
start: (controller) => {
|
|
44
|
+
controller.enqueue(value);
|
|
45
|
+
controller.close();
|
|
46
|
+
},
|
|
47
|
+
});
|
|
43
48
|
|
|
44
|
-
|
|
45
|
-
|
|
49
|
+
return stream;
|
|
50
|
+
}
|
|
46
51
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
transformer: (value: T) => R,
|
|
50
|
-
): ReadableStream<R> => {
|
|
51
|
-
const reader = stream.getReader();
|
|
52
|
+
function transform<T, R>(stream: ReadableStream<T>, transformer: (value: T) => R): ReadableStream<R> {
|
|
53
|
+
const reader = stream.getReader();
|
|
52
54
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
};
|
|
55
|
+
return new ReadableStream<R>({
|
|
56
|
+
pull: async (controller) => {
|
|
57
|
+
const { done, value } = await reader.read();
|
|
58
|
+
if (!done) {
|
|
59
|
+
controller.enqueue(transformer(value));
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
controller.close();
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
});
|
|
64
66
|
}
|
|
67
|
+
|
|
68
|
+
export const StreamUtil = {
|
|
69
|
+
readAll,
|
|
70
|
+
reduce,
|
|
71
|
+
to,
|
|
72
|
+
transform,
|
|
73
|
+
};
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @internal
|
|
3
3
|
*/
|
|
4
|
-
export
|
|
5
|
-
dict: Map<Key, T>,
|
|
6
|
-
key: Key,
|
|
7
|
-
generator: () => T,
|
|
8
|
-
): T => {
|
|
4
|
+
export function __map_take<Key, T>(dict: Map<Key, T>, key: Key, generator: () => T): T {
|
|
9
5
|
const oldbie: T | undefined = dict.get(key);
|
|
10
|
-
if (oldbie)
|
|
6
|
+
if (oldbie !== undefined) {
|
|
7
|
+
return oldbie;
|
|
8
|
+
}
|
|
11
9
|
|
|
12
10
|
const value: T = generator();
|
|
13
11
|
dict.set(key, value);
|
|
14
12
|
return value;
|
|
15
|
-
}
|
|
13
|
+
}
|