@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,57 @@
|
|
|
1
|
+
import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
2
|
+
import { AgenticaTextPrompt } from "../prompts/AgenticaTextPrompt";
|
|
3
|
+
import { AgenticaEventBase } from "./AgenticaEventBase";
|
|
4
|
+
|
|
5
|
+
export class AgenticaTextEvent extends AgenticaEventBase<"text"> {
|
|
6
|
+
public readonly role: "assistant" | "user";
|
|
7
|
+
public readonly stream: ReadableStream<string>;
|
|
8
|
+
public get text(): string {
|
|
9
|
+
return this.get_();
|
|
10
|
+
}
|
|
11
|
+
public get done(): boolean {
|
|
12
|
+
return this.done_();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public constructor(props: AgenticaTextEvent.IProps) {
|
|
16
|
+
super("text");
|
|
17
|
+
this.role = props.role;
|
|
18
|
+
this.stream = props.stream;
|
|
19
|
+
|
|
20
|
+
this.done_ = props.done;
|
|
21
|
+
this.get_ = props.get;
|
|
22
|
+
this.join_ = props.join;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public join(): Promise<string> {
|
|
26
|
+
return this.join_();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public toJSON(): IAgenticaEventJson.IText {
|
|
30
|
+
return {
|
|
31
|
+
type: "text",
|
|
32
|
+
role: this.role,
|
|
33
|
+
text: this.text,
|
|
34
|
+
done: this.done,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public toPrompt(): AgenticaTextPrompt {
|
|
39
|
+
return new AgenticaTextPrompt({
|
|
40
|
+
role: this.role,
|
|
41
|
+
text: this.text,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private readonly done_: () => boolean;
|
|
46
|
+
private readonly get_: () => string;
|
|
47
|
+
private readonly join_: () => Promise<string>;
|
|
48
|
+
}
|
|
49
|
+
export namespace AgenticaTextEvent {
|
|
50
|
+
export interface IProps {
|
|
51
|
+
role: "assistant" | "user";
|
|
52
|
+
stream: ReadableStream<string>;
|
|
53
|
+
done: () => boolean;
|
|
54
|
+
get: () => string;
|
|
55
|
+
join: () => Promise<string>;
|
|
56
|
+
}
|
|
57
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,18 +1,42 @@
|
|
|
1
|
-
//
|
|
1
|
+
// STRUCTURES
|
|
2
2
|
export * from "./structures/IAgenticaConfig";
|
|
3
|
-
export * from "./structures/IAgenticaContext";
|
|
4
3
|
export * from "./structures/IAgenticaController";
|
|
5
|
-
export * from "./structures/IAgenticaEvent";
|
|
6
4
|
export * from "./structures/IAgenticaExecutor";
|
|
7
|
-
export * from "./structures/IAgenticaOperation";
|
|
8
|
-
export * from "./structures/IAgenticaOperationCollection";
|
|
9
|
-
export * from "./structures/IAgenticaOperationSelection";
|
|
10
|
-
export * from "./structures/IAgenticaPrompt";
|
|
11
5
|
export * from "./structures/IAgenticaProps";
|
|
12
6
|
export * from "./structures/IAgenticaVendor";
|
|
13
7
|
export * from "./structures/IAgenticaSystemPrompt";
|
|
14
|
-
|
|
15
|
-
export * from "./
|
|
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
|
+
|
|
15
|
+
// CONTEXT
|
|
16
|
+
export * from "./context/AgenticaContext";
|
|
17
|
+
export * from "./context/AgenticaOperation";
|
|
18
|
+
export * from "./context/AgenticaOperationCollection";
|
|
19
|
+
export * from "./context/AgenticaOperationSelection";
|
|
20
|
+
export * from "./context/AgenticaTokenUsage";
|
|
21
|
+
|
|
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
|
+
export * from "./events/AgenticaCallEvent";
|
|
32
|
+
export * from "./events/AgenticaCancelEvent";
|
|
33
|
+
export * from "./events/AgenticaDescribeEvent";
|
|
34
|
+
export * from "./events/AgenticaEventSource";
|
|
35
|
+
export * from "./events/AgenticaExecuteEvent";
|
|
36
|
+
export * from "./events/AgenticaRequestEvent";
|
|
37
|
+
export * from "./events/AgenticaResponseEvent";
|
|
38
|
+
export * from "./events/AgenticaSelectEvent";
|
|
39
|
+
export * from "./events/AgenticaTextEvent";
|
|
16
40
|
|
|
17
41
|
// FACADE CLASS
|
|
18
42
|
export * from "./functional/createHttpLlmApplication";
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
+
import { AgenticaOperation } from "../context/AgenticaOperation";
|
|
4
|
+
import { AgenticaOperationCollection } from "../context/AgenticaOperationCollection";
|
|
3
5
|
import { IAgenticaConfig } from "../structures/IAgenticaConfig";
|
|
4
6
|
import { IAgenticaController } from "../structures/IAgenticaController";
|
|
5
|
-
import { IAgenticaOperation } from "../structures/IAgenticaOperation";
|
|
6
|
-
import { IAgenticaOperationCollection } from "../structures/IAgenticaOperationCollection";
|
|
7
7
|
import { __map_take } from "./__map_take";
|
|
8
8
|
|
|
9
9
|
export namespace AgenticaOperationComposer {
|
|
10
10
|
export const compose = <Model extends ILlmSchema.Model>(props: {
|
|
11
11
|
controllers: IAgenticaController<Model>[];
|
|
12
12
|
config?: IAgenticaConfig<Model> | undefined;
|
|
13
|
-
}):
|
|
13
|
+
}): AgenticaOperationCollection<Model> => {
|
|
14
14
|
const unique: boolean =
|
|
15
15
|
props.controllers.length === 1 ||
|
|
16
16
|
(() => {
|
|
@@ -24,7 +24,7 @@ export namespace AgenticaOperationComposer {
|
|
|
24
24
|
const naming = (func: string, ci: number) =>
|
|
25
25
|
unique ? func : `_${ci}_${func}`;
|
|
26
26
|
|
|
27
|
-
const array:
|
|
27
|
+
const array: AgenticaOperation<Model>[] = props.controllers
|
|
28
28
|
.map((controller, ci) =>
|
|
29
29
|
controller.protocol === "http"
|
|
30
30
|
? controller.application.functions.map(
|
|
@@ -34,7 +34,13 @@ export namespace AgenticaOperationComposer {
|
|
|
34
34
|
controller: controller,
|
|
35
35
|
function: func,
|
|
36
36
|
name: naming(func.name, ci),
|
|
37
|
-
|
|
37
|
+
toJSON: () => ({
|
|
38
|
+
protocol: "http",
|
|
39
|
+
controller: controller.name,
|
|
40
|
+
function: func.name,
|
|
41
|
+
name: naming(func.name, ci),
|
|
42
|
+
}),
|
|
43
|
+
}) satisfies AgenticaOperation.Http<Model>,
|
|
38
44
|
)
|
|
39
45
|
: controller.application.functions.map(
|
|
40
46
|
(func) =>
|
|
@@ -43,11 +49,17 @@ export namespace AgenticaOperationComposer {
|
|
|
43
49
|
controller,
|
|
44
50
|
function: func,
|
|
45
51
|
name: naming(func.name, ci),
|
|
46
|
-
|
|
52
|
+
toJSON: () => ({
|
|
53
|
+
protocol: "class",
|
|
54
|
+
controller: controller.name,
|
|
55
|
+
function: func.name,
|
|
56
|
+
name: naming(func.name, ci),
|
|
57
|
+
}),
|
|
58
|
+
}) satisfies AgenticaOperation.Class<Model>,
|
|
47
59
|
),
|
|
48
60
|
)
|
|
49
61
|
.flat();
|
|
50
|
-
const divided:
|
|
62
|
+
const divided: AgenticaOperation<Model>[][] | undefined =
|
|
51
63
|
!!props.config?.capacity && array.length > props.config.capacity
|
|
52
64
|
? divideOperations({
|
|
53
65
|
array,
|
|
@@ -55,11 +67,8 @@ export namespace AgenticaOperationComposer {
|
|
|
55
67
|
})
|
|
56
68
|
: undefined;
|
|
57
69
|
|
|
58
|
-
const flat: Map<string,
|
|
59
|
-
const group: Map<
|
|
60
|
-
string,
|
|
61
|
-
Map<string, IAgenticaOperation<Model>>
|
|
62
|
-
> = new Map();
|
|
70
|
+
const flat: Map<string, AgenticaOperation<Model>> = new Map();
|
|
71
|
+
const group: Map<string, Map<string, AgenticaOperation<Model>>> = new Map();
|
|
63
72
|
for (const item of array) {
|
|
64
73
|
flat.set(item.name, item);
|
|
65
74
|
__map_take(group, item.controller.name, () => new Map()).set(
|
|
@@ -76,12 +85,12 @@ export namespace AgenticaOperationComposer {
|
|
|
76
85
|
};
|
|
77
86
|
|
|
78
87
|
const divideOperations = <Model extends ILlmSchema.Model>(props: {
|
|
79
|
-
array:
|
|
88
|
+
array: AgenticaOperation<Model>[];
|
|
80
89
|
capacity: number;
|
|
81
|
-
}):
|
|
90
|
+
}): AgenticaOperation<Model>[][] => {
|
|
82
91
|
const size: number = Math.ceil(props.array.length / props.capacity);
|
|
83
92
|
const capacity: number = Math.ceil(props.array.length / size);
|
|
84
|
-
const replica:
|
|
93
|
+
const replica: AgenticaOperation<Model>[] = props.array.slice();
|
|
85
94
|
return new Array(size).fill(0).map(() => replica.splice(0, capacity));
|
|
86
95
|
};
|
|
87
96
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export namespace MPSCUtil {
|
|
2
|
+
export interface Output<T> {
|
|
3
|
+
consumer: ReadableStream<T>;
|
|
4
|
+
produce: (chunk: T) => void;
|
|
5
|
+
close: () => void;
|
|
6
|
+
waitClose: () => Promise<void>;
|
|
7
|
+
done: () => boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const create = <T>(): Output<T> => {
|
|
11
|
+
const queue = new AsyncQueue<T>();
|
|
12
|
+
const consumer = new ReadableStream<T>({
|
|
13
|
+
async pull(controller) {
|
|
14
|
+
const { value, done } = await queue.dequeue();
|
|
15
|
+
if (done) {
|
|
16
|
+
controller.close();
|
|
17
|
+
} else {
|
|
18
|
+
controller.enqueue(value);
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
consumer,
|
|
24
|
+
produce: (chunk: T) => queue.enqueue(chunk),
|
|
25
|
+
close: () => queue.close(),
|
|
26
|
+
done: () => queue.done(),
|
|
27
|
+
waitClose: () => queue.waitClose(),
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export class AsyncQueue<T> {
|
|
32
|
+
private queue: T[] = [];
|
|
33
|
+
private resolvers: ((value: IteratorResult<T, undefined>) => void)[] = [];
|
|
34
|
+
private closeResolvers: (() => void)[] = [];
|
|
35
|
+
|
|
36
|
+
private closed = false;
|
|
37
|
+
|
|
38
|
+
enqueue(item: T) {
|
|
39
|
+
this.queue.push(item);
|
|
40
|
+
if (this.resolvers.length > 0) {
|
|
41
|
+
this.resolvers.shift()?.({ value: this.queue.shift()!, done: false });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async dequeue(): Promise<IteratorResult<T, undefined>> {
|
|
46
|
+
if (this.queue.length > 0) {
|
|
47
|
+
return { value: this.queue.shift()!, done: false };
|
|
48
|
+
}
|
|
49
|
+
if (this.closed) return { value: undefined, done: true };
|
|
50
|
+
return new Promise((resolve) => this.resolvers.push(resolve));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
done() {
|
|
54
|
+
return this.closed;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
close() {
|
|
58
|
+
this.closed = true;
|
|
59
|
+
while (this.resolvers.length > 0) {
|
|
60
|
+
this.resolvers.shift()?.({ value: undefined, done: true });
|
|
61
|
+
}
|
|
62
|
+
this.closeResolvers.forEach((resolve) => resolve());
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
waitClose() {
|
|
66
|
+
if (this.closed) {
|
|
67
|
+
return Promise.resolve();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return new Promise<void>((resolve) => {
|
|
71
|
+
this.closeResolvers.push(resolve);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export namespace StreamUtil {
|
|
2
|
+
export const readAll = async <T>(stream: ReadableStream<T>): Promise<T[]> => {
|
|
3
|
+
const reader = stream.getReader();
|
|
4
|
+
const result: T[] = [];
|
|
5
|
+
while (true) {
|
|
6
|
+
const { done, value } = await reader.read();
|
|
7
|
+
if (done) break;
|
|
8
|
+
result.push(value);
|
|
9
|
+
}
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const reduce = async <T, R = T>(
|
|
14
|
+
stream: ReadableStream<T>,
|
|
15
|
+
reducer: (acc: T | R, cur: T) => R,
|
|
16
|
+
initial?: R,
|
|
17
|
+
): Promise<R | null> => {
|
|
18
|
+
const reader = stream.getReader();
|
|
19
|
+
|
|
20
|
+
let acc = (initial ?? null) as R | null | T;
|
|
21
|
+
|
|
22
|
+
while (true) {
|
|
23
|
+
const { done, value } = await reader.read();
|
|
24
|
+
if (done) break;
|
|
25
|
+
if (acc === null) {
|
|
26
|
+
acc = value;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
acc = reducer(acc, value);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return acc as R;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const to = <T>(value: T): ReadableStream<T> => {
|
|
37
|
+
const stream = new ReadableStream<T>({
|
|
38
|
+
start: (controller) => {
|
|
39
|
+
controller.enqueue(value);
|
|
40
|
+
controller.close();
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return stream;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const transform = <T, R>(
|
|
48
|
+
stream: ReadableStream<T>,
|
|
49
|
+
transformer: (value: T) => R,
|
|
50
|
+
): ReadableStream<R> => {
|
|
51
|
+
const reader = stream.getReader();
|
|
52
|
+
|
|
53
|
+
return new ReadableStream<R>({
|
|
54
|
+
pull: async (controller) => {
|
|
55
|
+
const { done, value } = await reader.read();
|
|
56
|
+
if (!done) {
|
|
57
|
+
controller.enqueue(transformer(value));
|
|
58
|
+
} else {
|
|
59
|
+
controller.close();
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import OpenAI from "openai";
|
|
2
|
+
|
|
3
|
+
import { AgenticaEventSource } from "../events/AgenticaEventSource";
|
|
4
|
+
import { IAgenticaOperationJson } from "./IAgenticaOperationJson";
|
|
5
|
+
import { IAgenticaOperationSelectionJson } from "./IAgenticaOperationSelectionJson";
|
|
6
|
+
import { IAgenticaPromptJson } from "./IAgenticaPromptJson";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Nestia A.I. chatbot event.
|
|
10
|
+
*
|
|
11
|
+
* `IAgenticaEventJson` is an union type of all possible events that can
|
|
12
|
+
* be emitted by the A.I. chatbot of the {@link Agentica} class. You
|
|
13
|
+
* can discriminate the subtype by checking the {@link type} property.
|
|
14
|
+
*
|
|
15
|
+
* @author Samchon
|
|
16
|
+
*/
|
|
17
|
+
export type IAgenticaEventJson =
|
|
18
|
+
| IAgenticaEventJson.ICall
|
|
19
|
+
| IAgenticaEventJson.ICancel
|
|
20
|
+
| IAgenticaEventJson.IDescribe
|
|
21
|
+
| IAgenticaEventJson.IExecute
|
|
22
|
+
| IAgenticaEventJson.IInitialize
|
|
23
|
+
| IAgenticaEventJson.IRequest
|
|
24
|
+
| IAgenticaEventJson.ISelect
|
|
25
|
+
| IAgenticaEventJson.IText;
|
|
26
|
+
export namespace IAgenticaEventJson {
|
|
27
|
+
export type Type = IAgenticaEventJson["type"];
|
|
28
|
+
export type Mapper = {
|
|
29
|
+
initialize: IInitialize;
|
|
30
|
+
select: ISelect;
|
|
31
|
+
cancel: ICancel;
|
|
32
|
+
call: ICall;
|
|
33
|
+
execute: IExecute;
|
|
34
|
+
describe: IDescribe;
|
|
35
|
+
text: IText;
|
|
36
|
+
request: IRequest;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Event of initializing the chatbot.
|
|
41
|
+
*/
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
43
|
+
export interface IInitialize extends IBase<"initialize"> {}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Event of selecting a function to call.
|
|
47
|
+
*/
|
|
48
|
+
export interface ISelect extends IBase<"select"> {
|
|
49
|
+
selection: IAgenticaOperationSelectionJson;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Event of canceling a function calling.
|
|
54
|
+
*/
|
|
55
|
+
export interface ICancel extends IBase<"cancel"> {
|
|
56
|
+
selection: IAgenticaOperationSelectionJson;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Event of calling a function.
|
|
61
|
+
*/
|
|
62
|
+
export interface ICall extends IBase<"call"> {
|
|
63
|
+
/**
|
|
64
|
+
* ID of the tool calling.
|
|
65
|
+
*/
|
|
66
|
+
id: string;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Target operation to call.
|
|
70
|
+
*/
|
|
71
|
+
operation: IAgenticaOperationJson;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Arguments of the function calling.
|
|
75
|
+
*
|
|
76
|
+
* If you modify this {@link arguments} property, it actually modifies
|
|
77
|
+
* the backend server's request. Therefore, be careful when you're
|
|
78
|
+
* trying to modify this property.
|
|
79
|
+
*/
|
|
80
|
+
arguments: Record<string, any>;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Event of function calling execution.
|
|
85
|
+
*/
|
|
86
|
+
export interface IExecute extends IBase<"execute"> {
|
|
87
|
+
/**
|
|
88
|
+
* ID of the tool calling.
|
|
89
|
+
*/
|
|
90
|
+
id: string;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Target operation had called.
|
|
94
|
+
*/
|
|
95
|
+
operation: IAgenticaOperationJson;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Arguments of the function calling.
|
|
99
|
+
*/
|
|
100
|
+
arguments: object;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Return value.
|
|
104
|
+
*/
|
|
105
|
+
value: any;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Event of description.
|
|
110
|
+
*
|
|
111
|
+
* Event describing return values of LLM function callings.
|
|
112
|
+
*/
|
|
113
|
+
export interface IDescribe extends IBase<"describe"> {
|
|
114
|
+
/**
|
|
115
|
+
* Executions of the LLM function calling.
|
|
116
|
+
*
|
|
117
|
+
* This prompt describes the return value of them.
|
|
118
|
+
*/
|
|
119
|
+
executes: IAgenticaPromptJson.IExecute[];
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Description text.
|
|
123
|
+
*/
|
|
124
|
+
text: string;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Whether the streaming is completed or not.
|
|
128
|
+
*/
|
|
129
|
+
done: boolean;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Event of text message.
|
|
134
|
+
*/
|
|
135
|
+
export interface IText extends IBase<"text"> {
|
|
136
|
+
/**
|
|
137
|
+
* Role of the orator.
|
|
138
|
+
*/
|
|
139
|
+
role: "assistant" | "user";
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Conversation text.
|
|
143
|
+
*/
|
|
144
|
+
text: string;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Whether the streaming is completed or not.
|
|
148
|
+
*/
|
|
149
|
+
done: boolean;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Request event of LLM vendor API.
|
|
154
|
+
*/
|
|
155
|
+
export interface IRequest extends IBase<"request"> {
|
|
156
|
+
/**
|
|
157
|
+
* The source agent of the request.
|
|
158
|
+
*/
|
|
159
|
+
source: AgenticaEventSource;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Request body.
|
|
163
|
+
*/
|
|
164
|
+
body: OpenAI.ChatCompletionCreateParamsStreaming;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Options for the request.
|
|
168
|
+
*/
|
|
169
|
+
options?: OpenAI.RequestOptions | undefined;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
interface IBase<Type extends string> {
|
|
173
|
+
/**
|
|
174
|
+
* Discriminator type.
|
|
175
|
+
*/
|
|
176
|
+
type: Type;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Operation information in the Agentica Agent.
|
|
3
|
+
*
|
|
4
|
+
* `IAgenticaOperation` is a type represents an operation that would
|
|
5
|
+
* be selected by the A.I. chatbot of {@link Agentica} class to
|
|
6
|
+
* perform the LLM (Large Language Model) function calling.
|
|
7
|
+
*
|
|
8
|
+
* Also, it is an union type that is discriminated by the {@link protocol}
|
|
9
|
+
* property. If the protocol value is `http`, it means that the HTTP API
|
|
10
|
+
* operation would be called by the A.I. chatbot. Otherwise, if the protocol
|
|
11
|
+
* value is `class`, it means that the operation has come from a
|
|
12
|
+
* TypeScript class.
|
|
13
|
+
*
|
|
14
|
+
* @author Samchon
|
|
15
|
+
*/
|
|
16
|
+
export interface IAgenticaOperationJson {
|
|
17
|
+
/**
|
|
18
|
+
* Protocol discriminator.
|
|
19
|
+
*/
|
|
20
|
+
protocol: "class" | "http";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Belonged controller of the target function.
|
|
24
|
+
*/
|
|
25
|
+
controller: string;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Target function to call.
|
|
29
|
+
*/
|
|
30
|
+
function: string;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Identifier name.
|
|
34
|
+
*/
|
|
35
|
+
name: string;
|
|
36
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IAgenticaOperationJson } from "./IAgenticaOperationJson";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Nestia agent operation selection.
|
|
5
|
+
*
|
|
6
|
+
* `IAgenticaOperationSelection` is a type represents an operation
|
|
7
|
+
* which has been selected by the A.I. chatbot of {@link Agentica}
|
|
8
|
+
* class for the LLM (Large Language Model) function calling with
|
|
9
|
+
* detailed {@link reason} of the selection (or cancellation).
|
|
10
|
+
*
|
|
11
|
+
* Also, `IAgenticaOperationSelection` is an union type that can
|
|
12
|
+
* specify a subtype by checking the {@link protocol} property.
|
|
13
|
+
*
|
|
14
|
+
* @author Samchon
|
|
15
|
+
*/
|
|
16
|
+
export interface IAgenticaOperationSelectionJson {
|
|
17
|
+
reason: string;
|
|
18
|
+
operation: IAgenticaOperationJson;
|
|
19
|
+
}
|