@agentica/core 0.20.0 → 0.22.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 +115 -413
- package/lib/Agentica.d.ts +2 -1
- package/lib/Agentica.js +15 -13
- package/lib/Agentica.js.map +1 -1
- package/lib/MicroAgentica.d.ts +2 -1
- package/lib/MicroAgentica.js +16 -11
- package/lib/MicroAgentica.js.map +1 -1
- package/lib/context/AgenticaContext.d.ts +4 -4
- package/lib/context/MicroAgenticaContext.d.ts +2 -2
- package/lib/context/internal/AgenticaOperationComposer.js +1 -8
- package/lib/context/internal/AgenticaOperationComposer.js.map +1 -1
- package/lib/events/AgenticaEvent.d.ts +3 -1
- package/lib/events/AgenticaTextEvent.d.ts +2 -2
- package/lib/events/AgenticaUserInputEvent.d.ts +10 -0
- package/lib/events/AgenticaUserInputEvent.js +3 -0
- package/lib/events/AgenticaUserInputEvent.js.map +1 -0
- package/lib/events/MicroAgenticaEvent.d.ts +3 -1
- package/lib/factory/events.d.ts +7 -3
- package/lib/factory/events.js +29 -4
- package/lib/factory/events.js.map +1 -1
- package/lib/factory/histories.d.ts +6 -3
- package/lib/factory/histories.js +59 -32
- package/lib/factory/histories.js.map +1 -1
- package/lib/functional/assertMcpController.js +0 -2
- package/lib/functional/assertMcpController.js.map +1 -1
- package/lib/histories/AgenticaHistory.d.ts +3 -1
- package/lib/histories/AgenticaTextHistory.d.ts +2 -2
- package/lib/histories/AgenticaUserInputHistory.d.ts +80 -0
- package/lib/histories/AgenticaUserInputHistory.js +3 -0
- package/lib/histories/AgenticaUserInputHistory.js.map +1 -0
- package/lib/histories/MicroAgenticaHistory.d.ts +2 -1
- package/lib/index.mjs +138 -105
- package/lib/index.mjs.map +1 -1
- package/lib/json/IAgenticaEventJson.d.ts +8 -1
- package/lib/json/IAgenticaHistoryJson.d.ts +15 -3
- package/lib/orchestrate/call.js +3 -17
- package/lib/orchestrate/call.js.map +1 -1
- package/lib/orchestrate/cancel.js +1 -1
- package/lib/orchestrate/cancel.js.map +1 -1
- package/lib/orchestrate/execute.js +13 -7
- package/lib/orchestrate/execute.js.map +1 -1
- package/lib/orchestrate/initialize.js +2 -6
- package/lib/orchestrate/initialize.js.map +1 -1
- package/lib/orchestrate/select.js +2 -6
- package/lib/orchestrate/select.js.map +1 -1
- package/lib/structures/IAgenticaExecutor.d.ts +10 -6
- package/lib/structures/IMicroAgenticaExecutor.d.ts +4 -1
- package/lib/transformers/AgenticaEventTransformer.js +0 -1
- package/lib/transformers/AgenticaEventTransformer.js.map +1 -1
- package/package.json +2 -2
- package/src/Agentica.ts +21 -18
- package/src/MicroAgentica.ts +20 -16
- package/src/context/AgenticaContext.ts +4 -4
- package/src/context/MicroAgenticaContext.ts +2 -2
- package/src/context/internal/AgenticaOperationComposer.ts +5 -6
- package/src/events/AgenticaEvent.ts +4 -1
- package/src/events/AgenticaTextEvent.ts +2 -4
- package/src/events/AgenticaUserInputEvent.ts +12 -0
- package/src/events/MicroAgenticaEvent.ts +4 -1
- package/src/factory/events.ts +26 -8
- package/src/factory/histories.ts +76 -43
- package/src/functional/assertMcpController.ts +1 -2
- package/src/histories/AgenticaHistory.ts +4 -1
- package/src/histories/AgenticaTextHistory.ts +2 -4
- package/src/histories/AgenticaUserInputHistory.ts +88 -0
- package/src/histories/MicroAgenticaHistory.ts +3 -1
- package/src/json/IAgenticaEventJson.ts +9 -1
- package/src/json/IAgenticaHistoryJson.ts +16 -4
- package/src/orchestrate/call.ts +15 -17
- package/src/orchestrate/cancel.ts +1 -1
- package/src/orchestrate/execute.ts +13 -7
- package/src/orchestrate/initialize.ts +2 -6
- package/src/orchestrate/select.ts +2 -7
- package/src/structures/IAgenticaExecutor.ts +16 -8
- package/src/structures/IMicroAgenticaExecutor.ts +10 -4
- package/src/transformers/AgenticaEventTransformer.ts +0 -1
|
@@ -22,7 +22,7 @@ export function compose<Model extends ILlmSchema.Model>(props: {
|
|
|
22
22
|
}): AgenticaOperationCollection<Model> {
|
|
23
23
|
const unique: boolean = (props.controllers.length === 1 || (() => {
|
|
24
24
|
const names = props.controllers.map(
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
controllers => controllers.application.functions.map((func: { name: string }) => func.name),
|
|
27
27
|
).flat();
|
|
28
28
|
return new Set(names).size === names.length;
|
|
@@ -133,20 +133,19 @@ export function toMcpOperations<Model extends ILlmSchema.Model>(props: {
|
|
|
133
133
|
index: number;
|
|
134
134
|
naming: (func: string, controllerIndex: number) => string;
|
|
135
135
|
}): AgenticaOperation<Model>[] {
|
|
136
|
-
// eslint-disable-next-line ts/no-unsafe-call, ts/no-unsafe-member-access, ts/no-unsafe-return
|
|
137
136
|
return props.controller.application.functions.map(func => ({
|
|
138
137
|
protocol: "mcp",
|
|
139
138
|
controller: props.controller,
|
|
140
|
-
|
|
139
|
+
|
|
141
140
|
function: func,
|
|
142
|
-
|
|
141
|
+
|
|
143
142
|
name: props.naming(func.name, props.index),
|
|
144
143
|
toJSON: () => ({
|
|
145
144
|
protocol: "mcp",
|
|
146
145
|
controller: props.controller.name,
|
|
147
|
-
|
|
146
|
+
|
|
148
147
|
function: func.name,
|
|
149
|
-
|
|
148
|
+
|
|
150
149
|
name: props.naming(func.name, props.index),
|
|
151
150
|
}),
|
|
152
151
|
}));
|
|
@@ -9,6 +9,7 @@ import type { AgenticaRequestEvent } from "./AgenticaRequestEvent";
|
|
|
9
9
|
import type { AgenticaResponseEvent } from "./AgenticaResponseEvent";
|
|
10
10
|
import type { AgenticaSelectEvent } from "./AgenticaSelectEvent";
|
|
11
11
|
import type { AgenticaTextEvent } from "./AgenticaTextEvent";
|
|
12
|
+
import type { AgenticaUserInputEvent } from "./AgenticaUserInputEvent";
|
|
12
13
|
import type { AgenticaValidateEvent } from "./AgenticaValidateEvent";
|
|
13
14
|
|
|
14
15
|
/**
|
|
@@ -31,7 +32,8 @@ export type AgenticaEvent<Model extends ILlmSchema.Model> =
|
|
|
31
32
|
| AgenticaResponseEvent
|
|
32
33
|
| AgenticaSelectEvent<Model>
|
|
33
34
|
| AgenticaTextEvent
|
|
34
|
-
| AgenticaValidateEvent<Model
|
|
35
|
+
| AgenticaValidateEvent<Model>
|
|
36
|
+
| AgenticaUserInputEvent;
|
|
35
37
|
export namespace AgenticaEvent {
|
|
36
38
|
export type Type = AgenticaEvent<any>["type"];
|
|
37
39
|
export interface Mapper<Model extends ILlmSchema.Model> {
|
|
@@ -45,6 +47,7 @@ export namespace AgenticaEvent {
|
|
|
45
47
|
select: AgenticaSelectEvent<Model>;
|
|
46
48
|
text: AgenticaTextEvent;
|
|
47
49
|
validate: AgenticaValidateEvent<Model>;
|
|
50
|
+
user_input: AgenticaUserInputEvent;
|
|
48
51
|
}
|
|
49
52
|
export type Source =
|
|
50
53
|
| "initialize"
|
|
@@ -3,10 +3,8 @@ import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
|
3
3
|
|
|
4
4
|
import type { AgenticaEventBase } from "./AgenticaEventBase";
|
|
5
5
|
|
|
6
|
-
export interface AgenticaTextEvent<
|
|
7
|
-
|
|
8
|
-
> extends AgenticaEventBase<"text"> {
|
|
9
|
-
role: Role;
|
|
6
|
+
export interface AgenticaTextEvent extends AgenticaEventBase<"text"> {
|
|
7
|
+
role: "assistant";
|
|
10
8
|
stream: AsyncGenerator<string, undefined, undefined>;
|
|
11
9
|
join: () => Promise<string>;
|
|
12
10
|
toJSON: () => IAgenticaEventJson.IText;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AgenticaUserInputHistory } from "../histories/AgenticaUserInputHistory";
|
|
2
|
+
import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
3
|
+
|
|
4
|
+
import type { AgenticaEventBase } from "./AgenticaEventBase";
|
|
5
|
+
|
|
6
|
+
export interface AgenticaUserInputEvent extends AgenticaEventBase<"user_input"> {
|
|
7
|
+
role: "user";
|
|
8
|
+
contents: Array<AgenticaUserInputHistory.Contents>;
|
|
9
|
+
join: () => Promise<Array<AgenticaUserInputHistory.Contents>>;
|
|
10
|
+
toJSON: () => IAgenticaEventJson.IUserInput;
|
|
11
|
+
toHistory: () => AgenticaUserInputHistory;
|
|
12
|
+
}
|
|
@@ -6,6 +6,7 @@ import type { AgenticaExecuteEvent } from "./AgenticaExecuteEvent";
|
|
|
6
6
|
import type { AgenticaRequestEvent } from "./AgenticaRequestEvent";
|
|
7
7
|
import type { AgenticaResponseEvent } from "./AgenticaResponseEvent";
|
|
8
8
|
import type { AgenticaTextEvent } from "./AgenticaTextEvent";
|
|
9
|
+
import type { AgenticaUserInputEvent } from "./AgenticaUserInputEvent";
|
|
9
10
|
import type { AgenticaValidateEvent } from "./AgenticaValidateEvent";
|
|
10
11
|
|
|
11
12
|
/**
|
|
@@ -25,7 +26,8 @@ export type MicroAgenticaEvent<Model extends ILlmSchema.Model> =
|
|
|
25
26
|
| AgenticaRequestEvent
|
|
26
27
|
| AgenticaResponseEvent
|
|
27
28
|
| AgenticaTextEvent
|
|
28
|
-
| AgenticaValidateEvent<Model
|
|
29
|
+
| AgenticaValidateEvent<Model>
|
|
30
|
+
| AgenticaUserInputEvent;
|
|
29
31
|
export namespace MicroAgenticaEvent {
|
|
30
32
|
export type Type = MicroAgenticaEvent<any>["type"];
|
|
31
33
|
export interface Mapper<Model extends ILlmSchema.Model> {
|
|
@@ -36,6 +38,7 @@ export namespace MicroAgenticaEvent {
|
|
|
36
38
|
response: AgenticaResponseEvent;
|
|
37
39
|
text: AgenticaTextEvent;
|
|
38
40
|
validate: AgenticaValidateEvent<Model>;
|
|
41
|
+
user_input: AgenticaUserInputEvent;
|
|
39
42
|
}
|
|
40
43
|
export type Source = "call" | "describe";
|
|
41
44
|
}
|
package/src/factory/events.ts
CHANGED
|
@@ -15,11 +15,13 @@ import type { AgenticaRequestEvent } from "../events/AgenticaRequestEvent";
|
|
|
15
15
|
import type { AgenticaResponseEvent } from "../events/AgenticaResponseEvent";
|
|
16
16
|
import type { AgenticaSelectEvent } from "../events/AgenticaSelectEvent";
|
|
17
17
|
import type { AgenticaTextEvent } from "../events/AgenticaTextEvent";
|
|
18
|
+
import type { AgenticaUserInputEvent } from "../events/AgenticaUserInputEvent";
|
|
18
19
|
import type { AgenticaValidateEvent } from "../events/AgenticaValidateEvent";
|
|
19
20
|
import type { AgenticaExecuteHistory } from "../histories/AgenticaExecuteHistory";
|
|
21
|
+
import type { AgenticaUserInputHistory } from "../histories/AgenticaUserInputHistory";
|
|
20
22
|
import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
21
23
|
|
|
22
|
-
import { createExecuteHistory, createSelectHistory } from "./histories";
|
|
24
|
+
import { createExecuteHistory, createSelectHistory, createUserInputHistory } from "./histories";
|
|
23
25
|
|
|
24
26
|
/* -----------------------------------------------------------
|
|
25
27
|
FUNCTION SELECTS
|
|
@@ -34,6 +36,23 @@ export function createInitializeEvent(): AgenticaInitializeEvent {
|
|
|
34
36
|
};
|
|
35
37
|
}
|
|
36
38
|
|
|
39
|
+
export function createUserInputEvent(props: {
|
|
40
|
+
contents: Array<AgenticaUserInputHistory.Contents>;
|
|
41
|
+
}): AgenticaUserInputEvent {
|
|
42
|
+
return {
|
|
43
|
+
type: "user_input",
|
|
44
|
+
role: "user",
|
|
45
|
+
contents: props.contents,
|
|
46
|
+
join: async () => props.contents,
|
|
47
|
+
toJSON: () => ({
|
|
48
|
+
type: "user_input",
|
|
49
|
+
contents: props.contents,
|
|
50
|
+
}),
|
|
51
|
+
toHistory: () => createUserInputHistory({
|
|
52
|
+
contents: props.contents,
|
|
53
|
+
}),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
37
56
|
export function createSelectEvent<Model extends ILlmSchema.Model>(props: {
|
|
38
57
|
selection: AgenticaOperationSelection<Model>;
|
|
39
58
|
}): AgenticaSelectEvent<Model> {
|
|
@@ -134,31 +153,30 @@ export function createExecuteEvent<Model extends ILlmSchema.Model>(props: {
|
|
|
134
153
|
/* -----------------------------------------------------------
|
|
135
154
|
TEXT STEAMING
|
|
136
155
|
----------------------------------------------------------- */
|
|
137
|
-
export function createTextEvent
|
|
138
|
-
role: Role;
|
|
156
|
+
export function createTextEvent(props: {
|
|
139
157
|
stream: AsyncGenerator<string, undefined, undefined>;
|
|
140
158
|
done: () => boolean;
|
|
141
159
|
get: () => string;
|
|
142
160
|
join: () => Promise<string>;
|
|
143
|
-
}): AgenticaTextEvent
|
|
161
|
+
}): AgenticaTextEvent {
|
|
144
162
|
return {
|
|
145
163
|
type: "text",
|
|
146
|
-
role:
|
|
164
|
+
role: "assistant",
|
|
147
165
|
stream: props.stream,
|
|
148
166
|
join: props.join,
|
|
149
167
|
toJSON: () => ({
|
|
150
168
|
type: "text",
|
|
151
|
-
role:
|
|
169
|
+
role: "assistant",
|
|
152
170
|
done: props.done(),
|
|
153
171
|
text: props.get(),
|
|
154
172
|
}),
|
|
155
173
|
toHistory: () => ({
|
|
156
174
|
type: "text",
|
|
157
|
-
role:
|
|
175
|
+
role: "assistant",
|
|
158
176
|
text: props.get(),
|
|
159
177
|
toJSON: () => ({
|
|
160
178
|
type: "text",
|
|
161
|
-
role:
|
|
179
|
+
role: "assistant",
|
|
162
180
|
text: props.get(),
|
|
163
181
|
}),
|
|
164
182
|
}),
|
package/src/factory/histories.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type { AgenticaExecuteHistory } from "../histories/AgenticaExecuteHistory
|
|
|
9
9
|
import type { AgenticaHistory } from "../histories/AgenticaHistory";
|
|
10
10
|
import type { AgenticaSelectHistory } from "../histories/AgenticaSelectHistory";
|
|
11
11
|
import type { AgenticaTextHistory } from "../histories/AgenticaTextHistory";
|
|
12
|
+
import type { AgenticaUserInputHistory } from "../histories/AgenticaUserInputHistory";
|
|
12
13
|
import type { IAgenticaHistoryJson } from "../json/IAgenticaHistoryJson";
|
|
13
14
|
|
|
14
15
|
export function decodeHistory<Model extends ILlmSchema.Model>(history: AgenticaHistory<Model>): OpenAI.ChatCompletionMessageParam[] {
|
|
@@ -16,7 +17,8 @@ export function decodeHistory<Model extends ILlmSchema.Model>(history: AgenticaH
|
|
|
16
17
|
if (history.type === "describe") {
|
|
17
18
|
return [];
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
+
|
|
21
|
+
if (history.type === "text") {
|
|
20
22
|
return [
|
|
21
23
|
{
|
|
22
24
|
role: history.role,
|
|
@@ -24,7 +26,8 @@ export function decodeHistory<Model extends ILlmSchema.Model>(history: AgenticaH
|
|
|
24
26
|
},
|
|
25
27
|
];
|
|
26
28
|
}
|
|
27
|
-
|
|
29
|
+
|
|
30
|
+
if (history.type === "select" || history.type === "cancel") {
|
|
28
31
|
return [
|
|
29
32
|
{
|
|
30
33
|
role: "assistant",
|
|
@@ -52,59 +55,89 @@ export function decodeHistory<Model extends ILlmSchema.Model>(history: AgenticaH
|
|
|
52
55
|
];
|
|
53
56
|
}
|
|
54
57
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
if (history.type === "execute") {
|
|
59
|
+
return [
|
|
60
|
+
{
|
|
61
|
+
role: "assistant",
|
|
62
|
+
tool_calls: [
|
|
63
|
+
{
|
|
64
|
+
type: "function",
|
|
65
|
+
id: history.id,
|
|
66
|
+
function: {
|
|
67
|
+
name: history.operation.name,
|
|
68
|
+
arguments: JSON.stringify(history.arguments),
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
role: "tool",
|
|
75
|
+
tool_call_id: history.id,
|
|
76
|
+
content: JSON.stringify({
|
|
62
77
|
function: {
|
|
63
|
-
|
|
64
|
-
|
|
78
|
+
protocol: history.operation.protocol,
|
|
79
|
+
description: history.operation.function.description,
|
|
80
|
+
parameters: history.operation.function.parameters,
|
|
81
|
+
output: history.operation.function.output,
|
|
82
|
+
...(history.operation.protocol === "http"
|
|
83
|
+
? {
|
|
84
|
+
method: history.operation.function.method,
|
|
85
|
+
path: history.operation.function.path,
|
|
86
|
+
}
|
|
87
|
+
: {}),
|
|
65
88
|
},
|
|
66
|
-
},
|
|
67
|
-
],
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
role: "tool",
|
|
71
|
-
tool_call_id: history.id,
|
|
72
|
-
content: JSON.stringify({
|
|
73
|
-
function: {
|
|
74
|
-
protocol: history.operation.protocol,
|
|
75
|
-
description: history.operation.function.description,
|
|
76
|
-
parameters: history.operation.function.parameters,
|
|
77
|
-
output: history.operation.function.output,
|
|
78
89
|
...(history.operation.protocol === "http"
|
|
79
90
|
? {
|
|
80
|
-
|
|
81
|
-
|
|
91
|
+
status: (history.value as IHttpResponse).status,
|
|
92
|
+
data: (history.value as IHttpResponse).body,
|
|
82
93
|
}
|
|
83
|
-
: {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
: {
|
|
95
|
+
value: history.value,
|
|
96
|
+
}),
|
|
97
|
+
}),
|
|
98
|
+
},
|
|
99
|
+
];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (history.type === "user_input") {
|
|
103
|
+
return [
|
|
104
|
+
{
|
|
105
|
+
role: "user",
|
|
106
|
+
content: history.contents,
|
|
107
|
+
},
|
|
108
|
+
];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
history satisfies never;
|
|
112
|
+
throw new Error("Invalid history type");
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/* -----------------------------------------------------------
|
|
116
|
+
USER INPUT PROMPTS
|
|
117
|
+
----------------------------------------------------------- */
|
|
118
|
+
export function createUserInputHistory(props: {
|
|
119
|
+
contents: Array<AgenticaUserInputHistory.Contents>;
|
|
120
|
+
}): AgenticaUserInputHistory {
|
|
121
|
+
return {
|
|
122
|
+
type: "user_input",
|
|
123
|
+
role: "user",
|
|
124
|
+
contents: props.contents,
|
|
125
|
+
toJSON: () => ({
|
|
126
|
+
type: "user_input",
|
|
127
|
+
contents: props.contents,
|
|
128
|
+
}),
|
|
129
|
+
};
|
|
96
130
|
}
|
|
97
131
|
|
|
98
132
|
/* -----------------------------------------------------------
|
|
99
133
|
TEXT PROMPTS
|
|
100
134
|
----------------------------------------------------------- */
|
|
101
|
-
export function createTextHistory
|
|
102
|
-
role: Role;
|
|
135
|
+
export function createTextHistory(props: {
|
|
103
136
|
text: string;
|
|
104
|
-
}): AgenticaTextHistory
|
|
105
|
-
const prompt: IAgenticaHistoryJson.IText
|
|
137
|
+
}): AgenticaTextHistory {
|
|
138
|
+
const prompt: IAgenticaHistoryJson.IText = {
|
|
106
139
|
type: "text",
|
|
107
|
-
role:
|
|
140
|
+
role: "assistant",
|
|
108
141
|
text: props.text,
|
|
109
142
|
};
|
|
110
143
|
return {
|
|
@@ -33,7 +33,6 @@ export async function assertMcpController<Model extends ILlmSchema.Model>(props:
|
|
|
33
33
|
// get list of tools
|
|
34
34
|
const { tools } = await props.client.request({ method: "tools/list" }, ListToolsResultSchema);
|
|
35
35
|
|
|
36
|
-
// eslint-disable-next-line ts/no-unsafe-assignment, ts/no-unsafe-call, ts/no-unsafe-member-access
|
|
37
36
|
const application: IMcpLlmApplication<Model> = McpLlm.application<Model>({
|
|
38
37
|
model: props.model,
|
|
39
38
|
tools: typia.assert<Array<IMcpTool>>(tools),
|
|
@@ -43,7 +42,7 @@ export async function assertMcpController<Model extends ILlmSchema.Model>(props:
|
|
|
43
42
|
protocol: "mcp",
|
|
44
43
|
name: props.name,
|
|
45
44
|
client: props.client,
|
|
46
|
-
|
|
45
|
+
|
|
47
46
|
application,
|
|
48
47
|
};
|
|
49
48
|
}
|
|
@@ -5,13 +5,15 @@ import type { AgenticaDescribeHistory } from "./AgenticaDescribeHistory";
|
|
|
5
5
|
import type { AgenticaExecuteHistory } from "./AgenticaExecuteHistory";
|
|
6
6
|
import type { AgenticaSelectHistory } from "./AgenticaSelectHistory";
|
|
7
7
|
import type { AgenticaTextHistory } from "./AgenticaTextHistory";
|
|
8
|
+
import type { AgenticaUserInputHistory } from "./AgenticaUserInputHistory";
|
|
8
9
|
|
|
9
10
|
export type AgenticaHistory<Model extends ILlmSchema.Model> =
|
|
10
11
|
| AgenticaCancelHistory<Model>
|
|
11
12
|
| AgenticaDescribeHistory<Model>
|
|
12
13
|
| AgenticaExecuteHistory<Model>
|
|
13
14
|
| AgenticaSelectHistory<Model>
|
|
14
|
-
| AgenticaTextHistory
|
|
15
|
+
| AgenticaTextHistory
|
|
16
|
+
| AgenticaUserInputHistory;
|
|
15
17
|
export namespace AgenticaHistory {
|
|
16
18
|
export type Type = AgenticaHistory<any>["type"];
|
|
17
19
|
export interface Mapper<Model extends ILlmSchema.Model> {
|
|
@@ -20,5 +22,6 @@ export namespace AgenticaHistory {
|
|
|
20
22
|
execute: AgenticaExecuteHistory<Model>;
|
|
21
23
|
select: AgenticaSelectHistory<Model>;
|
|
22
24
|
text: AgenticaTextHistory;
|
|
25
|
+
user_input: AgenticaUserInputHistory;
|
|
23
26
|
}
|
|
24
27
|
}
|
|
@@ -2,9 +2,7 @@ import type { IAgenticaHistoryJson } from "../json/IAgenticaHistoryJson";
|
|
|
2
2
|
|
|
3
3
|
import type { AgenticaHistoryBase } from "./AgenticaHistoryBase";
|
|
4
4
|
|
|
5
|
-
export interface AgenticaTextHistory<
|
|
6
|
-
|
|
7
|
-
> extends AgenticaHistoryBase<"text", IAgenticaHistoryJson.IText> {
|
|
8
|
-
role: Role;
|
|
5
|
+
export interface AgenticaTextHistory extends AgenticaHistoryBase<"text", IAgenticaHistoryJson.IText> {
|
|
6
|
+
role: "assistant";
|
|
9
7
|
text: string;
|
|
10
8
|
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { IAgenticaHistoryJson } from "../json/IAgenticaHistoryJson";
|
|
2
|
+
|
|
3
|
+
import type { AgenticaHistoryBase } from "./AgenticaHistoryBase";
|
|
4
|
+
|
|
5
|
+
export interface AgenticaUserInputHistory extends AgenticaHistoryBase<"user_input", IAgenticaHistoryJson.IUserInput> {
|
|
6
|
+
role: "user";
|
|
7
|
+
contents: Array<AgenticaUserInputHistory.Contents>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export namespace AgenticaUserInputHistory {
|
|
11
|
+
export type Contents = Contents.File | Contents.Image | Contents.InputAudio | Contents.Text;
|
|
12
|
+
export namespace Contents {
|
|
13
|
+
interface ContentsBase<Type extends string> {
|
|
14
|
+
/**
|
|
15
|
+
* The type of the content part.
|
|
16
|
+
*/
|
|
17
|
+
type: Type;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Learn about
|
|
21
|
+
* [text inputs](https://platform.openai.com/docs/guides/text-generation).
|
|
22
|
+
*/
|
|
23
|
+
export interface Text extends ContentsBase<"text"> {
|
|
24
|
+
/**
|
|
25
|
+
* The text content.
|
|
26
|
+
*/
|
|
27
|
+
text: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Learn about [image inputs](https://platform.openai.com/docs/guides/vision).
|
|
32
|
+
*/
|
|
33
|
+
export interface Image extends ContentsBase<"image_url"> {
|
|
34
|
+
image_url: {
|
|
35
|
+
/**
|
|
36
|
+
* Either a URL of the image or the base64 encoded image data.
|
|
37
|
+
*/
|
|
38
|
+
url: string;
|
|
39
|
+
/**
|
|
40
|
+
* Specifies the detail level of the image. Learn more in the
|
|
41
|
+
* [Vision guide](https://platform.openai.com/docs/guides/vision#low-or-high-fidelity-image-understanding).
|
|
42
|
+
*/
|
|
43
|
+
detail?: "auto" | "high" | "low";
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Learn about [audio inputs](https://platform.openai.com/docs/guides/audio).
|
|
49
|
+
*/
|
|
50
|
+
export interface InputAudio extends ContentsBase<"input_audio"> {
|
|
51
|
+
input_audio: {
|
|
52
|
+
/**
|
|
53
|
+
* Base64 encoded audio data.
|
|
54
|
+
*/
|
|
55
|
+
data: string;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The format of the encoded audio data. Currently supports "wav" and "mp3".
|
|
59
|
+
*/
|
|
60
|
+
format: "wav" | "mp3";
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Learn about [file inputs](https://platform.openai.com/docs/guides/text) for text
|
|
66
|
+
* generation.
|
|
67
|
+
*/
|
|
68
|
+
export interface File extends ContentsBase<"file"> {
|
|
69
|
+
file: {
|
|
70
|
+
/**
|
|
71
|
+
* The base64 encoded file data, used when passing the file to the model as a
|
|
72
|
+
* string.
|
|
73
|
+
*/
|
|
74
|
+
file_data?: string;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The ID of an uploaded file to use as input.
|
|
78
|
+
*/
|
|
79
|
+
file_id?: string;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The name of the file, used when passing the file to the model as a string.
|
|
83
|
+
*/
|
|
84
|
+
filename?: string;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -3,11 +3,13 @@ import type { ILlmSchema } from "@samchon/openapi";
|
|
|
3
3
|
import type { AgenticaDescribeHistory } from "./AgenticaDescribeHistory";
|
|
4
4
|
import type { AgenticaExecuteHistory } from "./AgenticaExecuteHistory";
|
|
5
5
|
import type { AgenticaTextHistory } from "./AgenticaTextHistory";
|
|
6
|
+
import type { AgenticaUserInputHistory } from "./AgenticaUserInputHistory";
|
|
6
7
|
|
|
7
8
|
export type MicroAgenticaHistory<Model extends ILlmSchema.Model> =
|
|
8
9
|
| AgenticaDescribeHistory<Model>
|
|
9
10
|
| AgenticaExecuteHistory<Model>
|
|
10
|
-
| AgenticaTextHistory
|
|
11
|
+
| AgenticaTextHistory
|
|
12
|
+
| AgenticaUserInputHistory;
|
|
11
13
|
export namespace MicroAgenticaHistory {
|
|
12
14
|
export type Type = MicroAgenticaHistory<any>["type"];
|
|
13
15
|
export interface Mapper<Model extends ILlmSchema.Model> {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type OpenAI from "openai";
|
|
2
2
|
|
|
3
3
|
import type { AgenticaEventSource } from "../events/AgenticaEventSource";
|
|
4
|
+
import type { AgenticaUserInputHistory } from "../histories/AgenticaUserInputHistory";
|
|
4
5
|
|
|
5
6
|
import type { IAgenticaHistoryJson } from "./IAgenticaHistoryJson";
|
|
6
7
|
import type { IAgenticaOperationJson } from "./IAgenticaOperationJson";
|
|
@@ -39,6 +40,13 @@ export namespace IAgenticaEventJson {
|
|
|
39
40
|
request: IRequest;
|
|
40
41
|
}
|
|
41
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Event of user input.
|
|
45
|
+
*/
|
|
46
|
+
export interface IUserInput extends IBase<"user_input"> {
|
|
47
|
+
contents: Array<AgenticaUserInputHistory.Contents>;
|
|
48
|
+
}
|
|
49
|
+
|
|
42
50
|
/**
|
|
43
51
|
* Event of initializing the chatbot.
|
|
44
52
|
*/
|
|
@@ -140,7 +148,7 @@ export namespace IAgenticaEventJson {
|
|
|
140
148
|
/**
|
|
141
149
|
* Role of the orator.
|
|
142
150
|
*/
|
|
143
|
-
role: "assistant"
|
|
151
|
+
role: "assistant";
|
|
144
152
|
|
|
145
153
|
/**
|
|
146
154
|
* Conversation text.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { AgenticaUserInputHistory } from "../histories/AgenticaUserInputHistory";
|
|
2
|
+
|
|
1
3
|
import type { IAgenticaOperationJson } from "./IAgenticaOperationJson";
|
|
2
4
|
import type { IAgenticaOperationSelectionJson } from "./IAgenticaOperationSelectionJson";
|
|
3
5
|
|
|
@@ -18,12 +20,24 @@ import type { IAgenticaOperationSelectionJson } from "./IAgenticaOperationSelect
|
|
|
18
20
|
* @author Samchon
|
|
19
21
|
*/
|
|
20
22
|
export type IAgenticaHistoryJson =
|
|
23
|
+
| IAgenticaHistoryJson.IUserInput
|
|
21
24
|
| IAgenticaHistoryJson.IText
|
|
22
25
|
| IAgenticaHistoryJson.ISelect
|
|
23
26
|
| IAgenticaHistoryJson.ICancel
|
|
24
27
|
| IAgenticaHistoryJson.IExecute
|
|
25
28
|
| IAgenticaHistoryJson.IDescribe;
|
|
26
29
|
export namespace IAgenticaHistoryJson {
|
|
30
|
+
/**
|
|
31
|
+
* User input prompt.
|
|
32
|
+
*
|
|
33
|
+
* User input prompt about the user's input.
|
|
34
|
+
*/
|
|
35
|
+
export interface IUserInput extends IBase<"user_input"> {
|
|
36
|
+
/**
|
|
37
|
+
* User input.
|
|
38
|
+
*/
|
|
39
|
+
contents: Array<AgenticaUserInputHistory.Contents>;
|
|
40
|
+
}
|
|
27
41
|
/**
|
|
28
42
|
* Select prompt.
|
|
29
43
|
*
|
|
@@ -107,13 +121,11 @@ export namespace IAgenticaHistoryJson {
|
|
|
107
121
|
/**
|
|
108
122
|
* Text prompt.
|
|
109
123
|
*/
|
|
110
|
-
export interface IText<
|
|
111
|
-
Role extends "assistant" | "user" = "assistant" | "user",
|
|
112
|
-
> extends IBase<"text"> {
|
|
124
|
+
export interface IText extends IBase<"text"> {
|
|
113
125
|
/**
|
|
114
126
|
* Role of the orator.
|
|
115
127
|
*/
|
|
116
|
-
role:
|
|
128
|
+
role: "assistant";
|
|
117
129
|
|
|
118
130
|
/**
|
|
119
131
|
* The text content.
|