@agentica/core 0.25.0 → 0.26.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 +56 -17
- package/lib/context/internal/AgenticaOperationComposer.spec.js +13 -5
- package/lib/context/internal/AgenticaOperationComposer.spec.js.map +1 -1
- package/lib/events/AgenticaEvent.type.js +8 -0
- package/lib/events/AgenticaEvent.type.js.map +1 -0
- package/lib/factory/histories.js +38 -10
- package/lib/factory/histories.js.map +1 -1
- package/lib/histories/AgenticaHistory.d.ts +5 -3
- package/lib/histories/AgenticaSystemMessageHistory.d.ts +5 -0
- package/lib/histories/AgenticaSystemMessageHistory.js +3 -0
- package/lib/histories/AgenticaSystemMessageHistory.js.map +1 -0
- package/lib/histories/index.d.ts +1 -0
- package/lib/histories/index.js +1 -0
- package/lib/histories/index.js.map +1 -1
- package/lib/index.mjs +44 -8
- package/lib/index.mjs.map +1 -1
- package/lib/json/IAgenticaEventJson.d.ts +20 -1
- package/lib/json/IAgenticaEventJson.type.d.ts +1 -0
- package/lib/json/IAgenticaEventJson.type.js +8 -0
- package/lib/json/IAgenticaEventJson.type.js.map +1 -0
- package/lib/json/IAgenticaHistoryJson.d.ts +16 -6
- package/lib/json/IAgenticaHistoryJson.type.d.ts +1 -0
- package/lib/json/IAgenticaHistoryJson.type.js +8 -0
- package/lib/json/IAgenticaHistoryJson.type.js.map +1 -0
- package/lib/transformers/transformHistory.js +9 -0
- package/lib/transformers/transformHistory.js.map +1 -1
- package/lib/utils/types.d.ts +33 -0
- package/lib/utils/types.js +29 -0
- package/lib/utils/types.js.map +1 -0
- package/package.json +3 -2
- package/src/context/internal/AgenticaOperationComposer.spec.ts +15 -5
- package/src/events/AgenticaEvent.type.ts +19 -0
- package/src/factory/histories.ts +52 -10
- package/src/histories/AgenticaHistory.ts +6 -3
- package/src/histories/AgenticaSystemMessageHistory.ts +10 -0
- package/src/histories/index.ts +1 -0
- package/src/json/IAgenticaEventJson.ts +24 -0
- package/src/json/IAgenticaEventJson.type.ts +19 -0
- package/src/json/IAgenticaHistoryJson.ts +20 -8
- package/src/json/IAgenticaHistoryJson.type.ts +19 -0
- package/src/transformers/transformHistory.ts +14 -1
- package/src/utils/types.ts +50 -0
- package/lib/transformers/transformEvent.js +0 -198
- package/lib/transformers/transformEvent.js.map +0 -1
- package/src/transformers/transformEvent.ts +0 -248
- /package/lib/{transformers/transformEvent.d.ts → events/AgenticaEvent.type.d.ts} +0 -0
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.transformEvent = transformEvent;
|
|
13
|
-
exports.transformCall = transformCall;
|
|
14
|
-
const events_1 = require("../factory/events");
|
|
15
|
-
const operations_1 = require("../factory/operations");
|
|
16
|
-
const StreamUtil_1 = require("../utils/StreamUtil");
|
|
17
|
-
/**
|
|
18
|
-
* @internal
|
|
19
|
-
*/
|
|
20
|
-
function transformEvent(props) {
|
|
21
|
-
if (props.event.type === "call") {
|
|
22
|
-
return transformCall({
|
|
23
|
-
operations: props.operations,
|
|
24
|
-
event: props.event,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
else if (props.event.type === "cancel") {
|
|
28
|
-
return transformCancel({
|
|
29
|
-
operations: props.operations,
|
|
30
|
-
event: props.event,
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
else if (props.event.type === "describe") {
|
|
34
|
-
return transformDescribe({
|
|
35
|
-
operations: props.operations,
|
|
36
|
-
event: props.event,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
else if (props.event.type === "execute") {
|
|
40
|
-
return transformExecute({
|
|
41
|
-
operations: props.operations,
|
|
42
|
-
event: props.event,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
else if (props.event.type === "initialize") {
|
|
46
|
-
return transformInitialize();
|
|
47
|
-
}
|
|
48
|
-
else if (props.event.type === "request") {
|
|
49
|
-
return transformRequest({
|
|
50
|
-
event: props.event,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
else if (props.event.type === "select") {
|
|
54
|
-
return transformSelect({
|
|
55
|
-
operations: props.operations,
|
|
56
|
-
event: props.event,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
else if (props.event.type === "assistantMessage") {
|
|
60
|
-
return transformAssistantMessage({
|
|
61
|
-
event: props.event,
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
else if (props.event.type === "userMessage") {
|
|
65
|
-
return transformUserMessage({
|
|
66
|
-
event: props.event,
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
return transformValidateEvent({
|
|
70
|
-
operations: props.operations,
|
|
71
|
-
event: props.event,
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* @internal
|
|
76
|
-
*/
|
|
77
|
-
function transformCall(props) {
|
|
78
|
-
return (0, events_1.createCallEvent)({
|
|
79
|
-
id: props.event.id,
|
|
80
|
-
operation: findOperation({
|
|
81
|
-
operations: props.operations,
|
|
82
|
-
input: props.event.operation,
|
|
83
|
-
}),
|
|
84
|
-
arguments: props.event.arguments,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* @internal
|
|
89
|
-
*/
|
|
90
|
-
function transformCancel(props) {
|
|
91
|
-
return (0, events_1.createCancelEvent)({
|
|
92
|
-
selection: (0, operations_1.createOperationSelection)({
|
|
93
|
-
operation: findOperation({
|
|
94
|
-
operations: props.operations,
|
|
95
|
-
input: props.event.selection.operation,
|
|
96
|
-
}),
|
|
97
|
-
reason: props.event.selection.reason,
|
|
98
|
-
}),
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* @internal
|
|
103
|
-
*/
|
|
104
|
-
function transformDescribe(props) {
|
|
105
|
-
return (0, events_1.createDescribeEvent)({
|
|
106
|
-
executes: props.event.executes.map(next => transformExecute({
|
|
107
|
-
operations: props.operations,
|
|
108
|
-
event: next,
|
|
109
|
-
})),
|
|
110
|
-
stream: (0, StreamUtil_1.toAsyncGenerator)(props.event.text),
|
|
111
|
-
done: () => true,
|
|
112
|
-
get: () => props.event.text,
|
|
113
|
-
join: () => __awaiter(this, void 0, void 0, function* () { return props.event.text; }),
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* @internal
|
|
118
|
-
*/
|
|
119
|
-
function transformExecute(props) {
|
|
120
|
-
return (0, events_1.createExecuteEvent)({
|
|
121
|
-
id: props.event.id,
|
|
122
|
-
operation: findOperation({
|
|
123
|
-
operations: props.operations,
|
|
124
|
-
input: props.event.operation,
|
|
125
|
-
}),
|
|
126
|
-
arguments: props.event.arguments,
|
|
127
|
-
value: props.event.value,
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* @internal
|
|
132
|
-
*/
|
|
133
|
-
function transformInitialize() {
|
|
134
|
-
return (0, events_1.createInitializeEvent)();
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* @internal
|
|
138
|
-
*/
|
|
139
|
-
function transformRequest(props) {
|
|
140
|
-
return (0, events_1.createRequestEvent)(props.event);
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* @internal
|
|
144
|
-
*/
|
|
145
|
-
function transformSelect(props) {
|
|
146
|
-
return (0, events_1.createSelectEvent)({
|
|
147
|
-
selection: (0, operations_1.createOperationSelection)({
|
|
148
|
-
operation: findOperation({
|
|
149
|
-
operations: props.operations,
|
|
150
|
-
input: props.event.selection.operation,
|
|
151
|
-
}),
|
|
152
|
-
reason: props.event.selection.reason,
|
|
153
|
-
}),
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* @internal
|
|
158
|
-
*/
|
|
159
|
-
function transformAssistantMessage(props) {
|
|
160
|
-
return (0, events_1.creatAssistantEvent)({
|
|
161
|
-
stream: (0, StreamUtil_1.toAsyncGenerator)(props.event.text),
|
|
162
|
-
done: () => true,
|
|
163
|
-
get: () => props.event.text,
|
|
164
|
-
join: () => __awaiter(this, void 0, void 0, function* () { return props.event.text; }),
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* @internal
|
|
169
|
-
*/
|
|
170
|
-
function transformUserMessage(props) {
|
|
171
|
-
return (0, events_1.createUserMessageEvent)(props.event);
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* @internal
|
|
175
|
-
*/
|
|
176
|
-
function transformValidateEvent(props) {
|
|
177
|
-
return (0, events_1.createValidateEvent)({
|
|
178
|
-
id: props.event.id,
|
|
179
|
-
operation: findOperation({
|
|
180
|
-
operations: props.operations,
|
|
181
|
-
input: props.event.operation,
|
|
182
|
-
}),
|
|
183
|
-
result: props.event.result,
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* @internal
|
|
188
|
-
*/
|
|
189
|
-
function findOperation(props) {
|
|
190
|
-
var _a;
|
|
191
|
-
const found = (_a = props.operations
|
|
192
|
-
.get(props.input.controller)) === null || _a === void 0 ? void 0 : _a.get(props.input.function);
|
|
193
|
-
if (found === undefined) {
|
|
194
|
-
throw new Error(`No operation found: (controller: ${props.input.controller}, function: ${props.input.function})`);
|
|
195
|
-
}
|
|
196
|
-
return found;
|
|
197
|
-
}
|
|
198
|
-
//# sourceMappingURL=transformEvent.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transformEvent.js","sourceRoot":"","sources":["../../src/transformers/transformEvent.ts"],"names":[],"mappings":";;;;;;;;;;;AAsBA,wCAwDC;AAKD,sCAYC;AAhFD,8CAAgP;AAChP,sDAAiE;AACjE,oDAAuD;AAEvD;;GAEG;AACH,SAAgB,cAAc,CAAiC,KAG9D;IACC,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QAChC,OAAO,aAAa,CAAC;YACnB,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB,CAAC,CAAC;IACL,CAAC;SACI,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACvC,OAAO,eAAe,CAAC;YACrB,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB,CAAC,CAAC;IACL,CAAC;SACI,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QACzC,OAAO,iBAAiB,CAAC;YACvB,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB,CAAC,CAAC;IACL,CAAC;SACI,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QACxC,OAAO,gBAAgB,CAAC;YACtB,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB,CAAC,CAAC;IACL,CAAC;SACI,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QAC3C,OAAO,mBAAmB,EAAE,CAAC;IAC/B,CAAC;SACI,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,S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,KAAK,CAAC,MAAM;KAC3B,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,SAAS,aAAa,CAAiC,KAMtD;;IACC,MAAM,KAAK,GAAyC,MAAA,KAAK,CAAC,UAAU;SACjE,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,0CAC1B,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC9B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACb,oCAAoC,KAAK,CAAC,KAAK,CAAC,UAAU,eAAe,KAAK,CAAC,KAAK,CAAC,QAAQ,GAAG,CACjG,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
import type { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
|
|
3
|
-
import type { AgenticaOperation } from "../context/AgenticaOperation";
|
|
4
|
-
import type { AgenticaUserMessageEvent, AgenticaValidateEvent } from "../events";
|
|
5
|
-
import type { AgenticaAssistantMessageEvent } from "../events/AgenticaAssistantMessageEvent";
|
|
6
|
-
import type { AgenticaCallEvent } from "../events/AgenticaCallEvent";
|
|
7
|
-
import type { AgenticaCancelEvent } from "../events/AgenticaCancelEvent";
|
|
8
|
-
import type { AgenticaDescribeEvent } from "../events/AgenticaDescribeEvent";
|
|
9
|
-
import type { AgenticaEvent } from "../events/AgenticaEvent";
|
|
10
|
-
import type { AgenticaExecuteEvent } from "../events/AgenticaExecuteEvent";
|
|
11
|
-
import type { AgenticaInitializeEvent } from "../events/AgenticaInitializeEvent";
|
|
12
|
-
import type { AgenticaRequestEvent } from "../events/AgenticaRequestEvent";
|
|
13
|
-
import type { AgenticaSelectEvent } from "../events/AgenticaSelectEvent";
|
|
14
|
-
import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
|
|
15
|
-
|
|
16
|
-
import { creatAssistantEvent, createCallEvent, createCancelEvent, createDescribeEvent, createExecuteEvent, createInitializeEvent, createRequestEvent, createSelectEvent, createUserMessageEvent, createValidateEvent } from "../factory/events";
|
|
17
|
-
import { createOperationSelection } from "../factory/operations";
|
|
18
|
-
import { toAsyncGenerator } from "../utils/StreamUtil";
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @internal
|
|
22
|
-
*/
|
|
23
|
-
export function transformEvent<Model extends ILlmSchema.Model>(props: {
|
|
24
|
-
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
25
|
-
event: IAgenticaEventJson;
|
|
26
|
-
}): AgenticaEvent<Model> {
|
|
27
|
-
if (props.event.type === "call") {
|
|
28
|
-
return transformCall({
|
|
29
|
-
operations: props.operations,
|
|
30
|
-
event: props.event,
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
else if (props.event.type === "cancel") {
|
|
34
|
-
return transformCancel({
|
|
35
|
-
operations: props.operations,
|
|
36
|
-
event: props.event,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
else if (props.event.type === "describe") {
|
|
40
|
-
return transformDescribe({
|
|
41
|
-
operations: props.operations,
|
|
42
|
-
event: props.event,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
else if (props.event.type === "execute") {
|
|
46
|
-
return transformExecute({
|
|
47
|
-
operations: props.operations,
|
|
48
|
-
event: props.event,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
else if (props.event.type === "initialize") {
|
|
52
|
-
return transformInitialize();
|
|
53
|
-
}
|
|
54
|
-
else if (props.event.type === "request") {
|
|
55
|
-
return transformRequest({
|
|
56
|
-
event: props.event,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
else if (props.event.type === "select") {
|
|
60
|
-
return transformSelect({
|
|
61
|
-
operations: props.operations,
|
|
62
|
-
event: props.event,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
else if (props.event.type === "assistantMessage") {
|
|
66
|
-
return transformAssistantMessage({
|
|
67
|
-
event: props.event,
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
else if (props.event.type === "userMessage") {
|
|
71
|
-
return transformUserMessage({
|
|
72
|
-
event: props.event,
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
return transformValidateEvent({
|
|
76
|
-
operations: props.operations,
|
|
77
|
-
event: props.event,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* @internal
|
|
83
|
-
*/
|
|
84
|
-
export function transformCall<Model extends ILlmSchema.Model>(props: {
|
|
85
|
-
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
86
|
-
event: IAgenticaEventJson.ICall;
|
|
87
|
-
}): AgenticaCallEvent<Model> {
|
|
88
|
-
return createCallEvent({
|
|
89
|
-
id: props.event.id,
|
|
90
|
-
operation: findOperation({
|
|
91
|
-
operations: props.operations,
|
|
92
|
-
input: props.event.operation,
|
|
93
|
-
}),
|
|
94
|
-
arguments: props.event.arguments,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* @internal
|
|
100
|
-
*/
|
|
101
|
-
function transformCancel<Model extends ILlmSchema.Model>(props: {
|
|
102
|
-
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
103
|
-
event: IAgenticaEventJson.ICancel;
|
|
104
|
-
}): AgenticaCancelEvent<Model> {
|
|
105
|
-
return createCancelEvent({
|
|
106
|
-
selection: createOperationSelection({
|
|
107
|
-
operation: findOperation({
|
|
108
|
-
operations: props.operations,
|
|
109
|
-
input: props.event.selection.operation,
|
|
110
|
-
}),
|
|
111
|
-
reason: props.event.selection.reason,
|
|
112
|
-
}),
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* @internal
|
|
118
|
-
*/
|
|
119
|
-
function transformDescribe<Model extends ILlmSchema.Model>(props: {
|
|
120
|
-
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
121
|
-
event: IAgenticaEventJson.IDescribe;
|
|
122
|
-
}): AgenticaDescribeEvent<Model> {
|
|
123
|
-
return createDescribeEvent({
|
|
124
|
-
executes: props.event.executes.map(next =>
|
|
125
|
-
transformExecute({
|
|
126
|
-
operations: props.operations,
|
|
127
|
-
event: next,
|
|
128
|
-
}),
|
|
129
|
-
),
|
|
130
|
-
stream: toAsyncGenerator(props.event.text),
|
|
131
|
-
done: () => true,
|
|
132
|
-
get: () => props.event.text,
|
|
133
|
-
join: async () => props.event.text,
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* @internal
|
|
139
|
-
*/
|
|
140
|
-
function transformExecute<Model extends ILlmSchema.Model>(props: {
|
|
141
|
-
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
142
|
-
event: IAgenticaEventJson.IExecute;
|
|
143
|
-
}): AgenticaExecuteEvent<Model> {
|
|
144
|
-
return createExecuteEvent({
|
|
145
|
-
id: props.event.id,
|
|
146
|
-
operation: findOperation({
|
|
147
|
-
operations: props.operations,
|
|
148
|
-
input: props.event.operation,
|
|
149
|
-
}),
|
|
150
|
-
arguments: props.event.arguments,
|
|
151
|
-
value: props.event.value,
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* @internal
|
|
157
|
-
*/
|
|
158
|
-
function transformInitialize(): AgenticaInitializeEvent {
|
|
159
|
-
return createInitializeEvent();
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* @internal
|
|
164
|
-
*/
|
|
165
|
-
function transformRequest(props: {
|
|
166
|
-
event: IAgenticaEventJson.IRequest;
|
|
167
|
-
}): AgenticaRequestEvent {
|
|
168
|
-
return createRequestEvent(props.event);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* @internal
|
|
173
|
-
*/
|
|
174
|
-
function transformSelect<Model extends ILlmSchema.Model>(props: {
|
|
175
|
-
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
176
|
-
event: IAgenticaEventJson.ISelect;
|
|
177
|
-
}): AgenticaSelectEvent<Model> {
|
|
178
|
-
return createSelectEvent({
|
|
179
|
-
selection: createOperationSelection({
|
|
180
|
-
operation: findOperation({
|
|
181
|
-
operations: props.operations,
|
|
182
|
-
input: props.event.selection.operation,
|
|
183
|
-
}),
|
|
184
|
-
reason: props.event.selection.reason,
|
|
185
|
-
}),
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* @internal
|
|
191
|
-
*/
|
|
192
|
-
function transformAssistantMessage(props: {
|
|
193
|
-
event: IAgenticaEventJson.IAssistantMessage;
|
|
194
|
-
}): AgenticaAssistantMessageEvent {
|
|
195
|
-
return creatAssistantEvent({
|
|
196
|
-
stream: toAsyncGenerator(props.event.text),
|
|
197
|
-
done: () => true,
|
|
198
|
-
get: () => props.event.text,
|
|
199
|
-
join: async () => props.event.text,
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* @internal
|
|
205
|
-
*/
|
|
206
|
-
function transformUserMessage(props: {
|
|
207
|
-
event: IAgenticaEventJson.IUserMessage;
|
|
208
|
-
}): AgenticaUserMessageEvent {
|
|
209
|
-
return createUserMessageEvent(props.event);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* @internal
|
|
214
|
-
*/
|
|
215
|
-
function transformValidateEvent<Model extends ILlmSchema.Model>(props: {
|
|
216
|
-
event: IAgenticaEventJson.IValidate;
|
|
217
|
-
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
218
|
-
}): AgenticaValidateEvent<Model> {
|
|
219
|
-
return createValidateEvent({
|
|
220
|
-
id: props.event.id,
|
|
221
|
-
operation: findOperation({
|
|
222
|
-
operations: props.operations,
|
|
223
|
-
input: props.event.operation,
|
|
224
|
-
}),
|
|
225
|
-
result: props.event.result,
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* @internal
|
|
231
|
-
*/
|
|
232
|
-
function findOperation<Model extends ILlmSchema.Model>(props: {
|
|
233
|
-
operations: Map<string, Map<string, AgenticaOperation<Model>>>;
|
|
234
|
-
input: {
|
|
235
|
-
controller: string;
|
|
236
|
-
function: string;
|
|
237
|
-
};
|
|
238
|
-
}): AgenticaOperation<Model> {
|
|
239
|
-
const found: AgenticaOperation<Model> | undefined = props.operations
|
|
240
|
-
.get(props.input.controller)
|
|
241
|
-
?.get(props.input.function);
|
|
242
|
-
if (found === undefined) {
|
|
243
|
-
throw new Error(
|
|
244
|
-
`No operation found: (controller: ${props.input.controller}, function: ${props.input.function})`,
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
return found;
|
|
248
|
-
}
|
|
File without changes
|