@agentica/core 0.12.21 → 0.13.1
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 +120 -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 +19210 -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 +361 -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,9 +1,9 @@
|
|
|
1
|
-
import OpenAI from "openai";
|
|
1
|
+
import type OpenAI from "openai";
|
|
2
2
|
|
|
3
|
-
import { AgenticaEventSource } from "../events/AgenticaEventSource";
|
|
4
|
-
import { IAgenticaOperationJson } from "./IAgenticaOperationJson";
|
|
5
|
-
import { IAgenticaOperationSelectionJson } from "./IAgenticaOperationSelectionJson";
|
|
6
|
-
import { IAgenticaPromptJson } from "./IAgenticaPromptJson";
|
|
3
|
+
import type { AgenticaEventSource } from "../events/AgenticaEventSource";
|
|
4
|
+
import type { IAgenticaOperationJson } from "./IAgenticaOperationJson";
|
|
5
|
+
import type { IAgenticaOperationSelectionJson } from "./IAgenticaOperationSelectionJson";
|
|
6
|
+
import type { IAgenticaPromptJson } from "./IAgenticaPromptJson";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Nestia A.I. chatbot event.
|
|
@@ -25,7 +25,7 @@ export type IAgenticaEventJson =
|
|
|
25
25
|
| IAgenticaEventJson.IText;
|
|
26
26
|
export namespace IAgenticaEventJson {
|
|
27
27
|
export type Type = IAgenticaEventJson["type"];
|
|
28
|
-
export
|
|
28
|
+
export interface Mapper {
|
|
29
29
|
initialize: IInitialize;
|
|
30
30
|
select: ISelect;
|
|
31
31
|
cancel: ICancel;
|
|
@@ -34,12 +34,11 @@ export namespace IAgenticaEventJson {
|
|
|
34
34
|
describe: IDescribe;
|
|
35
35
|
text: IText;
|
|
36
36
|
request: IRequest;
|
|
37
|
-
}
|
|
37
|
+
}
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Event of initializing the chatbot.
|
|
41
41
|
*/
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
43
42
|
export interface IInitialize extends IBase<"initialize"> {}
|
|
44
43
|
|
|
45
44
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IAgenticaOperationJson } from "./IAgenticaOperationJson";
|
|
2
|
-
import { IAgenticaOperationSelectionJson } from "./IAgenticaOperationSelectionJson";
|
|
1
|
+
import type { IAgenticaOperationJson } from "./IAgenticaOperationJson";
|
|
2
|
+
import type { IAgenticaOperationSelectionJson } from "./IAgenticaOperationSelectionJson";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Nestia A.I. chatbot prompt.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
-
import { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
|
|
4
|
-
import { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
|
|
3
|
+
import type { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
|
|
4
|
+
import type { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
|
|
5
5
|
import { AgenticaPromptBase } from "./AgenticaPromptBase";
|
|
6
6
|
|
|
7
7
|
export class AgenticaCancelPrompt<
|
|
@@ -20,7 +20,7 @@ export class AgenticaCancelPrompt<
|
|
|
20
20
|
return {
|
|
21
21
|
type: this.type,
|
|
22
22
|
id: this.id,
|
|
23
|
-
selections: this.selections.map(
|
|
23
|
+
selections: this.selections.map(s => s.toJSON()),
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
-
import { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
|
|
4
|
-
import { AgenticaExecutePrompt } from "./AgenticaExecutePrompt";
|
|
3
|
+
import type { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
|
|
4
|
+
import type { AgenticaExecutePrompt } from "./AgenticaExecutePrompt";
|
|
5
5
|
import { AgenticaPromptBase } from "./AgenticaPromptBase";
|
|
6
6
|
|
|
7
7
|
export class AgenticaDescribePrompt<
|
|
@@ -28,7 +28,7 @@ export class AgenticaDescribePrompt<
|
|
|
28
28
|
public toJSON(): IAgenticaPromptJson.IDescribe {
|
|
29
29
|
return {
|
|
30
30
|
type: this.type,
|
|
31
|
-
executes: this.executes.map(
|
|
31
|
+
executes: this.executes.map(e => e.toJSON()),
|
|
32
32
|
text: this.text,
|
|
33
33
|
};
|
|
34
34
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { IHttpResponse, ILlmSchema } from "@samchon/openapi";
|
|
1
|
+
import type { IHttpResponse, ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
-
import { AgenticaOperation } from "../context/AgenticaOperation";
|
|
4
|
-
import { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
|
|
3
|
+
import type { AgenticaOperation } from "../context/AgenticaOperation";
|
|
4
|
+
import type { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
|
|
5
5
|
import { AgenticaPromptBase } from "./AgenticaPromptBase";
|
|
6
6
|
|
|
7
7
|
export class AgenticaExecutePrompt<
|
|
@@ -14,8 +14,9 @@ export class AgenticaExecutePrompt<
|
|
|
14
14
|
: Protocol extends "class"
|
|
15
15
|
? AgenticaOperation.Class<Model>
|
|
16
16
|
: AgenticaOperation<Model>;
|
|
17
|
-
|
|
18
|
-
public readonly
|
|
17
|
+
|
|
18
|
+
public readonly arguments: Record<string, unknown>;
|
|
19
|
+
public readonly value: Protocol extends "http" ? IHttpResponse : unknown;
|
|
19
20
|
|
|
20
21
|
public constructor(props: AgenticaExecutePrompt.IProps<Model, Protocol>) {
|
|
21
22
|
super("execute");
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
-
import { AgenticaCancelPrompt } from "../context/AgenticaCancelPrompt";
|
|
4
|
-
import { AgenticaDescribePrompt } from "./AgenticaDescribePrompt";
|
|
5
|
-
import { AgenticaExecutePrompt } from "./AgenticaExecutePrompt";
|
|
6
|
-
import { AgenticaSelectPrompt } from "./AgenticaSelectPrompt";
|
|
7
|
-
import { AgenticaTextPrompt } from "./AgenticaTextPrompt";
|
|
3
|
+
import type { AgenticaCancelPrompt } from "../context/AgenticaCancelPrompt";
|
|
4
|
+
import type { AgenticaDescribePrompt } from "./AgenticaDescribePrompt";
|
|
5
|
+
import type { AgenticaExecutePrompt } from "./AgenticaExecutePrompt";
|
|
6
|
+
import type { AgenticaSelectPrompt } from "./AgenticaSelectPrompt";
|
|
7
|
+
import type { AgenticaTextPrompt } from "./AgenticaTextPrompt";
|
|
8
8
|
|
|
9
9
|
export type AgenticaPrompt<Model extends ILlmSchema.Model> =
|
|
10
10
|
| AgenticaCancelPrompt<Model>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
-
import { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
|
|
4
|
-
import { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
|
|
3
|
+
import type { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
|
|
4
|
+
import type { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
|
|
5
5
|
import { AgenticaPromptBase } from "./AgenticaPromptBase";
|
|
6
6
|
|
|
7
7
|
export class AgenticaSelectPrompt<
|
|
@@ -20,7 +20,7 @@ export class AgenticaSelectPrompt<
|
|
|
20
20
|
return {
|
|
21
21
|
type: this.type,
|
|
22
22
|
id: this.id,
|
|
23
|
-
selections: this.selections.map(
|
|
23
|
+
selections: this.selections.map(s => s.toJSON()),
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
-
import { AgenticaContext } from "../context/AgenticaContext";
|
|
4
|
-
import { AgenticaPrompt } from "../prompts/AgenticaPrompt";
|
|
5
|
-
import { IAgenticaExecutor } from "./IAgenticaExecutor";
|
|
6
|
-
import { IAgenticaSystemPrompt } from "./IAgenticaSystemPrompt";
|
|
3
|
+
import type { AgenticaContext } from "../context/AgenticaContext";
|
|
4
|
+
import type { AgenticaPrompt } from "../prompts/AgenticaPrompt";
|
|
5
|
+
import type { IAgenticaExecutor } from "./IAgenticaExecutor";
|
|
6
|
+
import type { IAgenticaSystemPrompt } from "./IAgenticaSystemPrompt";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Configuration for Nestia Agent.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
IHttpConnection,
|
|
3
3
|
IHttpLlmApplication,
|
|
4
4
|
IHttpLlmFunction,
|
|
@@ -97,21 +97,21 @@ export namespace IAgenticaController {
|
|
|
97
97
|
execute:
|
|
98
98
|
| object
|
|
99
99
|
| ((props: {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
100
|
+
/**
|
|
101
|
+
* Target application schema.
|
|
102
|
+
*/
|
|
103
|
+
application: ILlmApplication<Model>;
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Target function schema.
|
|
107
|
+
*/
|
|
108
|
+
function: ILlmFunction<Model>;
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
110
|
+
/**
|
|
111
|
+
* Arguments of the function calling.
|
|
112
|
+
*/
|
|
113
|
+
arguments: object;
|
|
114
|
+
}) => Promise<unknown>);
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
interface IBase<Protocol, Application> {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
-
import { AgenticaContext } from "../context/AgenticaContext";
|
|
4
|
-
import { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
|
|
5
|
-
import { AgenticaPrompt } from "../prompts/AgenticaPrompt";
|
|
3
|
+
import type { AgenticaContext } from "../context/AgenticaContext";
|
|
4
|
+
import type { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
|
|
5
|
+
import type { AgenticaPrompt } from "../prompts/AgenticaPrompt";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Executor of the Agentic AI.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
-
import { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
|
|
4
|
-
import { IAgenticaConfig } from "./IAgenticaConfig";
|
|
5
|
-
import { IAgenticaController } from "./IAgenticaController";
|
|
6
|
-
import { IAgenticaVendor } from "./IAgenticaVendor";
|
|
3
|
+
import type { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
|
|
4
|
+
import type { IAgenticaConfig } from "./IAgenticaConfig";
|
|
5
|
+
import type { IAgenticaController } from "./IAgenticaController";
|
|
6
|
+
import type { IAgenticaVendor } from "./IAgenticaVendor";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Properties of the Nestia Agent.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
1
|
+
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
2
|
|
|
3
|
-
import { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
|
|
4
|
-
import { AgenticaPrompt } from "../prompts/AgenticaPrompt";
|
|
5
|
-
import { IAgenticaConfig } from "./IAgenticaConfig";
|
|
3
|
+
import type { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
|
|
4
|
+
import type { AgenticaPrompt } from "../prompts/AgenticaPrompt";
|
|
5
|
+
import type { IAgenticaConfig } from "./IAgenticaConfig";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* System prompt collection of the A.I. chatbot.
|
|
@@ -1,165 +1,198 @@
|
|
|
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 { AgenticaEvent } from "../events/AgenticaEvent";
|
|
5
|
+
import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
4
6
|
import { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
|
|
5
7
|
import { AgenticaCallEvent } from "../events/AgenticaCallEvent";
|
|
6
8
|
import { AgenticaCancelEvent } from "../events/AgenticaCancelEvent";
|
|
7
9
|
import { AgenticaDescribeEvent } from "../events/AgenticaDescribeEvent";
|
|
8
|
-
import { AgenticaEvent } from "../events/AgenticaEvent";
|
|
9
10
|
import { AgenticaExecuteEvent } from "../events/AgenticaExecuteEvent";
|
|
10
11
|
import { AgenticaInitializeEvent } from "../events/AgenticaInitializeEvent";
|
|
11
12
|
import { AgenticaRequestEvent } from "../events/AgenticaRequestEvent";
|
|
12
13
|
import { AgenticaSelectEvent } from "../events/AgenticaSelectEvent";
|
|
13
14
|
import { AgenticaTextEvent } from "../events/AgenticaTextEvent";
|
|
14
15
|
import { StreamUtil } from "../internal/StreamUtil";
|
|
15
|
-
import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (props.event.type === "call")
|
|
23
|
-
return transformCall({
|
|
24
|
-
operations: props.operations,
|
|
25
|
-
event: props.event,
|
|
26
|
-
});
|
|
27
|
-
else if (props.event.type === "cancel")
|
|
28
|
-
return transformCancel({
|
|
29
|
-
operations: props.operations,
|
|
30
|
-
event: props.event,
|
|
31
|
-
});
|
|
32
|
-
else if (props.event.type === "describe")
|
|
33
|
-
return transformDescribe({
|
|
34
|
-
operations: props.operations,
|
|
35
|
-
event: props.event,
|
|
36
|
-
});
|
|
37
|
-
else if (props.event.type === "execute")
|
|
38
|
-
return transformExecute({
|
|
39
|
-
operations: props.operations,
|
|
40
|
-
event: props.event,
|
|
41
|
-
});
|
|
42
|
-
else if (props.event.type === "initialize") return transformInitialize();
|
|
43
|
-
else if (props.event.type === "request")
|
|
44
|
-
return transformRequest({
|
|
45
|
-
event: props.event,
|
|
46
|
-
});
|
|
47
|
-
else if (props.event.type === "select")
|
|
48
|
-
return transformSelect({
|
|
49
|
-
operations: props.operations,
|
|
50
|
-
event: props.event,
|
|
51
|
-
});
|
|
52
|
-
else if (props.event.type === "text")
|
|
53
|
-
return transformText({
|
|
54
|
-
event: props.event,
|
|
55
|
-
});
|
|
56
|
-
else throw new Error("Unknown event type");
|
|
17
|
+
function findOperation<Model extends ILlmSchema.Model>(props: {
|
|
18
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
19
|
+
input: {
|
|
20
|
+
controller: string;
|
|
21
|
+
function: string;
|
|
57
22
|
};
|
|
23
|
+
}): AgenticaOperation<Model> {
|
|
24
|
+
const found: AgenticaOperation<Model> | undefined = props.operations
|
|
25
|
+
.get(props.input.controller)
|
|
26
|
+
?.get(props.input.function);
|
|
27
|
+
if (found === undefined) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
`No operation found: (controller: ${props.input.controller}, function: ${props.input.function})`,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
return found;
|
|
33
|
+
}
|
|
58
34
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
input: props.event.operation,
|
|
68
|
-
}),
|
|
69
|
-
arguments: props.event.arguments,
|
|
35
|
+
export function transform<Model extends ILlmSchema.Model>(props: {
|
|
36
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
37
|
+
event: IAgenticaEventJson;
|
|
38
|
+
}): AgenticaEvent<Model> {
|
|
39
|
+
if (props.event.type === "call") {
|
|
40
|
+
return transformCall({
|
|
41
|
+
operations: props.operations,
|
|
42
|
+
event: props.event,
|
|
70
43
|
});
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
new AgenticaCancelEvent({
|
|
77
|
-
selection: new AgenticaOperationSelection({
|
|
78
|
-
operation: findOperation({
|
|
79
|
-
operations: props.operations,
|
|
80
|
-
input: props.event.selection.operation,
|
|
81
|
-
}),
|
|
82
|
-
reason: props.event.selection.reason,
|
|
83
|
-
}),
|
|
44
|
+
}
|
|
45
|
+
else if (props.event.type === "cancel") {
|
|
46
|
+
return transformCancel({
|
|
47
|
+
operations: props.operations,
|
|
48
|
+
event: props.event,
|
|
84
49
|
});
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
new AgenticaDescribeEvent({
|
|
91
|
-
executes: props.event.executes.map((next) =>
|
|
92
|
-
transformExecute({
|
|
93
|
-
operations: props.operations,
|
|
94
|
-
event: next,
|
|
95
|
-
}),
|
|
96
|
-
),
|
|
97
|
-
stream: StreamUtil.to(props.event.text),
|
|
98
|
-
done: () => true,
|
|
99
|
-
get: () => props.event.text,
|
|
100
|
-
join: async () => props.event.text,
|
|
50
|
+
}
|
|
51
|
+
else if (props.event.type === "describe") {
|
|
52
|
+
return transformDescribe({
|
|
53
|
+
operations: props.operations,
|
|
54
|
+
event: props.event,
|
|
101
55
|
});
|
|
56
|
+
}
|
|
57
|
+
else if (props.event.type === "execute") {
|
|
58
|
+
return transformExecute({
|
|
59
|
+
operations: props.operations,
|
|
60
|
+
event: props.event,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
else if (props.event.type === "initialize") {
|
|
64
|
+
return transformInitialize();
|
|
65
|
+
}
|
|
66
|
+
else if (props.event.type === "request") {
|
|
67
|
+
return transformRequest({
|
|
68
|
+
event: props.event,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
else if (props.event.type === "select") {
|
|
72
|
+
return transformSelect({
|
|
73
|
+
operations: props.operations,
|
|
74
|
+
event: props.event,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
else if (props.event.type === "text") {
|
|
78
|
+
return transformText({
|
|
79
|
+
event: props.event,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
else { throw new Error("Unknown event type"); }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function transformCall<Model extends ILlmSchema.Model>(props: {
|
|
86
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
87
|
+
event: IAgenticaEventJson.ICall;
|
|
88
|
+
}): AgenticaCallEvent<Model> {
|
|
89
|
+
return new AgenticaCallEvent({
|
|
90
|
+
id: props.event.id,
|
|
91
|
+
operation: findOperation({
|
|
92
|
+
operations: props.operations,
|
|
93
|
+
input: props.event.operation,
|
|
94
|
+
}),
|
|
95
|
+
arguments: props.event.arguments,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
102
98
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
99
|
+
export function transformCancel<Model extends ILlmSchema.Model>(props: {
|
|
100
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
101
|
+
event: IAgenticaEventJson.ICancel;
|
|
102
|
+
}): AgenticaCancelEvent<Model> {
|
|
103
|
+
return new AgenticaCancelEvent({
|
|
104
|
+
selection: new AgenticaOperationSelection({
|
|
109
105
|
operation: findOperation({
|
|
110
106
|
operations: props.operations,
|
|
111
|
-
input: props.event.operation,
|
|
107
|
+
input: props.event.selection.operation,
|
|
112
108
|
}),
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
109
|
+
reason: props.event.selection.reason,
|
|
110
|
+
}),
|
|
111
|
+
});
|
|
112
|
+
}
|
|
116
113
|
|
|
117
|
-
|
|
118
|
-
|
|
114
|
+
export function transformDescribe<Model extends ILlmSchema.Model>(props: {
|
|
115
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
116
|
+
event: IAgenticaEventJson.IDescribe;
|
|
117
|
+
}): AgenticaDescribeEvent<Model> {
|
|
118
|
+
return new AgenticaDescribeEvent({
|
|
119
|
+
executes: props.event.executes.map(next =>
|
|
120
|
+
transformExecute({
|
|
121
|
+
operations: props.operations,
|
|
122
|
+
event: next,
|
|
123
|
+
}),
|
|
124
|
+
),
|
|
125
|
+
stream: StreamUtil.to(props.event.text),
|
|
126
|
+
done: () => true,
|
|
127
|
+
get: () => props.event.text,
|
|
128
|
+
join: async () => props.event.text,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
119
131
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
132
|
+
export function transformExecute<Model extends ILlmSchema.Model>(props: {
|
|
133
|
+
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
134
|
+
event: IAgenticaEventJson.IExecute;
|
|
135
|
+
}): AgenticaExecuteEvent<Model> {
|
|
136
|
+
return new AgenticaExecuteEvent({
|
|
137
|
+
id: props.event.id,
|
|
138
|
+
operation: findOperation({
|
|
139
|
+
operations: props.operations,
|
|
140
|
+
input: props.event.operation,
|
|
141
|
+
}),
|
|
142
|
+
/**
|
|
143
|
+
* @TODO remove `as`
|
|
144
|
+
*/
|
|
145
|
+
arguments: props.event.arguments as Record<string, any>,
|
|
146
|
+
value: props.event.value,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
123
149
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}): AgenticaSelectEvent<Model> =>
|
|
128
|
-
new AgenticaSelectEvent({
|
|
129
|
-
selection: new AgenticaOperationSelection({
|
|
130
|
-
operation: findOperation({
|
|
131
|
-
operations: props.operations,
|
|
132
|
-
input: props.event.selection.operation,
|
|
133
|
-
}),
|
|
134
|
-
reason: props.event.selection.reason,
|
|
135
|
-
}),
|
|
136
|
-
});
|
|
150
|
+
export function transformInitialize(): AgenticaInitializeEvent {
|
|
151
|
+
return new AgenticaInitializeEvent();
|
|
152
|
+
}
|
|
137
153
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
role: props.event.role,
|
|
143
|
-
stream: StreamUtil.to(props.event.text),
|
|
144
|
-
done: () => true,
|
|
145
|
-
get: () => props.event.text,
|
|
146
|
-
join: async () => props.event.text,
|
|
147
|
-
});
|
|
154
|
+
export function transformRequest(props: {
|
|
155
|
+
event: IAgenticaEventJson.IRequest;
|
|
156
|
+
}): AgenticaRequestEvent {
|
|
157
|
+
return new AgenticaRequestEvent(props.event);
|
|
148
158
|
}
|
|
149
159
|
|
|
150
|
-
|
|
160
|
+
export function transformSelect<Model extends ILlmSchema.Model>(props: {
|
|
151
161
|
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
162
|
+
event: IAgenticaEventJson.ISelect;
|
|
163
|
+
}): AgenticaSelectEvent<Model> {
|
|
164
|
+
return new AgenticaSelectEvent({
|
|
165
|
+
selection: new AgenticaOperationSelection({
|
|
166
|
+
operation: findOperation({
|
|
167
|
+
operations: props.operations,
|
|
168
|
+
input: props.event.selection.operation,
|
|
169
|
+
}),
|
|
170
|
+
reason: props.event.selection.reason,
|
|
171
|
+
}),
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function transformText(props: {
|
|
176
|
+
event: IAgenticaEventJson.IText;
|
|
177
|
+
}): AgenticaTextEvent {
|
|
178
|
+
return new AgenticaTextEvent({
|
|
179
|
+
role: props.event.role,
|
|
180
|
+
stream: StreamUtil.to(props.event.text),
|
|
181
|
+
done: () => true,
|
|
182
|
+
get: () => props.event.text,
|
|
183
|
+
join: async () => props.event.text,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export const AgenticaEventTransformer = {
|
|
188
|
+
transform,
|
|
189
|
+
transformCall,
|
|
190
|
+
transformCancel,
|
|
191
|
+
transformDescribe,
|
|
192
|
+
transformExecute,
|
|
193
|
+
transformInitialize,
|
|
194
|
+
transformRequest,
|
|
195
|
+
transformSelect,
|
|
196
|
+
transformText,
|
|
197
|
+
findOperation,
|
|
165
198
|
};
|