@agentica/core 0.25.0 → 0.26.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.
Files changed (61) hide show
  1. package/README.md +56 -17
  2. package/lib/Agentica.js +5 -1
  3. package/lib/Agentica.js.map +1 -1
  4. package/lib/MicroAgentica.d.ts +1 -1
  5. package/lib/MicroAgentica.js +5 -1
  6. package/lib/MicroAgentica.js.map +1 -1
  7. package/lib/context/AgenticaTokenUsage.d.ts +2 -0
  8. package/lib/context/AgenticaTokenUsage.js +8 -0
  9. package/lib/context/AgenticaTokenUsage.js.map +1 -1
  10. package/lib/context/internal/AgenticaOperationComposer.spec.js +13 -5
  11. package/lib/context/internal/AgenticaOperationComposer.spec.js.map +1 -1
  12. package/lib/events/AgenticaEvent.type.js +8 -0
  13. package/lib/events/AgenticaEvent.type.js.map +1 -0
  14. package/lib/factory/histories.js +38 -10
  15. package/lib/factory/histories.js.map +1 -1
  16. package/lib/histories/AgenticaHistory.d.ts +5 -3
  17. package/lib/histories/AgenticaSystemMessageHistory.d.ts +5 -0
  18. package/lib/histories/AgenticaSystemMessageHistory.js +3 -0
  19. package/lib/histories/AgenticaSystemMessageHistory.js.map +1 -0
  20. package/lib/histories/index.d.ts +1 -0
  21. package/lib/histories/index.js +1 -0
  22. package/lib/histories/index.js.map +1 -1
  23. package/lib/index.mjs +78 -35
  24. package/lib/index.mjs.map +1 -1
  25. package/lib/json/IAgenticaEventJson.d.ts +20 -1
  26. package/lib/json/IAgenticaEventJson.type.d.ts +1 -0
  27. package/lib/json/IAgenticaEventJson.type.js +8 -0
  28. package/lib/json/IAgenticaEventJson.type.js.map +1 -0
  29. package/lib/json/IAgenticaHistoryJson.d.ts +16 -6
  30. package/lib/json/IAgenticaHistoryJson.type.d.ts +1 -0
  31. package/lib/json/IAgenticaHistoryJson.type.js +8 -0
  32. package/lib/json/IAgenticaHistoryJson.type.js.map +1 -0
  33. package/lib/structures/IAgenticaProps.d.ts +13 -0
  34. package/lib/structures/IMicroAgenticaProps.d.ts +13 -0
  35. package/lib/transformers/transformHistory.js +9 -0
  36. package/lib/transformers/transformHistory.js.map +1 -1
  37. package/lib/utils/types.d.ts +33 -0
  38. package/lib/utils/types.js +29 -0
  39. package/lib/utils/types.js.map +1 -0
  40. package/package.json +3 -2
  41. package/src/Agentica.ts +5 -1
  42. package/src/MicroAgentica.ts +9 -2
  43. package/src/context/AgenticaTokenUsage.ts +15 -0
  44. package/src/context/internal/AgenticaOperationComposer.spec.ts +15 -5
  45. package/src/events/AgenticaEvent.type.ts +19 -0
  46. package/src/factory/histories.ts +52 -10
  47. package/src/histories/AgenticaHistory.ts +6 -3
  48. package/src/histories/AgenticaSystemMessageHistory.ts +10 -0
  49. package/src/histories/index.ts +1 -0
  50. package/src/json/IAgenticaEventJson.ts +24 -0
  51. package/src/json/IAgenticaEventJson.type.ts +19 -0
  52. package/src/json/IAgenticaHistoryJson.ts +20 -8
  53. package/src/json/IAgenticaHistoryJson.type.ts +19 -0
  54. package/src/structures/IAgenticaProps.ts +14 -0
  55. package/src/structures/IMicroAgenticaProps.ts +14 -0
  56. package/src/transformers/transformHistory.ts +14 -1
  57. package/src/utils/types.ts +50 -0
  58. package/lib/transformers/transformEvent.js +0 -198
  59. package/lib/transformers/transformEvent.js.map +0 -1
  60. package/src/transformers/transformEvent.ts +0 -248
  61. /package/lib/{transformers/transformEvent.d.ts → events/AgenticaEvent.type.d.ts} +0 -0
@@ -0,0 +1,19 @@
1
+ import type { AgenticaHistory } from "../histories";
2
+ import type { Pass } from "../utils/types";
3
+
4
+ import { check, checks } from "../utils/types";
5
+
6
+ import type { IAgenticaHistoryJson } from "./IAgenticaHistoryJson";
7
+
8
+ checks([
9
+ check<
10
+ AgenticaHistory.Type,
11
+ IAgenticaHistoryJson.Type,
12
+ Pass
13
+ >(),
14
+ check<
15
+ AgenticaHistory.Type,
16
+ keyof IAgenticaHistoryJson.Mapper,
17
+ Pass
18
+ >(),
19
+ ]);
@@ -1,6 +1,8 @@
1
1
  import type { ILlmSchema } from "@samchon/openapi";
2
2
 
3
+ import type { AgenticaTokenUsage } from "../context/AgenticaTokenUsage";
3
4
  import type { IAgenticaHistoryJson } from "../json/IAgenticaHistoryJson";
5
+ import type { IAgenticaTokenUsageJson } from "../json/IAgenticaTokenUsageJson";
4
6
 
5
7
  import type { IAgenticaConfig } from "./IAgenticaConfig";
6
8
  import type { IAgenticaController } from "./IAgenticaController";
@@ -67,4 +69,16 @@ export interface IAgenticaProps<Model extends ILlmSchema.Model> {
67
69
  * assign the previouis prompt histories to this property.
68
70
  */
69
71
  histories?: IAgenticaHistoryJson[];
72
+
73
+ /**
74
+ * Token usage information.
75
+ *
76
+ * You can start token usage tracing by assigning this property.
77
+ *
78
+ * If you assign {@link IAgenticaTokenUsageJson} value, the
79
+ * token usage tracing would be from the value. Otherwise you
80
+ * assign the {@link AgenticaTokenUsage} typed instance, the
81
+ * tracing would be binded to the instance.
82
+ */
83
+ tokenUsage?: IAgenticaTokenUsageJson | AgenticaTokenUsage | undefined;
70
84
  }
@@ -1,5 +1,7 @@
1
1
  import type { ILlmSchema } from "@samchon/openapi";
2
2
 
3
+ import type { AgenticaTokenUsage } from "../context/AgenticaTokenUsage";
4
+ import type { IAgenticaTokenUsageJson } from "../json/IAgenticaTokenUsageJson";
3
5
  import type { IMicroAgenticaHistoryJson } from "../json/IMicroAgenticaHistoryJson";
4
6
 
5
7
  import type { IAgenticaController } from "./IAgenticaController";
@@ -67,4 +69,16 @@ export interface IMicroAgenticaProps<Model extends ILlmSchema.Model> {
67
69
  * assign the previouis prompt histories to this property.
68
70
  */
69
71
  histories?: IMicroAgenticaHistoryJson[];
72
+
73
+ /**
74
+ * Token usage information.
75
+ *
76
+ * You can start token usage tracing by assigning this property.
77
+ *
78
+ * If you assign {@link IAgenticaTokenUsageJson} value, the
79
+ * token usage tracing would be from the value. Otherwise you
80
+ * assign the {@link AgenticaTokenUsage} typed instance, the
81
+ * tracing would be binded to the instance.
82
+ */
83
+ tokenUsage?: IAgenticaTokenUsageJson | AgenticaTokenUsage | undefined;
70
84
  }
@@ -8,9 +8,10 @@ import type { AgenticaDescribeHistory } from "../histories/AgenticaDescribeHisto
8
8
  import type { AgenticaExecuteHistory } from "../histories/AgenticaExecuteHistory";
9
9
  import type { AgenticaHistory } from "../histories/AgenticaHistory";
10
10
  import type { AgenticaSelectHistory } from "../histories/AgenticaSelectHistory";
11
+ import type { AgenticaSystemMessageHistory } from "../histories/AgenticaSystemMessageHistory";
11
12
  import type { IAgenticaHistoryJson } from "../json/IAgenticaHistoryJson";
12
13
 
13
- import { createAssistantMessageHistory, createCancelHistory, createDescribeHistory, createExecuteHistory, createSelectHistory, createUserMessageHistory } from "../factory/histories";
14
+ import { createAssistantMessageHistory, createCancelHistory, createDescribeHistory, createExecuteHistory, createSelectHistory, createSystemMessageHistory, createUserMessageHistory } from "../factory/histories";
14
15
  import { createOperationSelection } from "../factory/operations";
15
16
 
16
17
  /**
@@ -32,6 +33,12 @@ export function transformHistory<Model extends ILlmSchema.Model>(props: {
32
33
  history: props.history,
33
34
  });
34
35
  }
36
+ // SYSTEM
37
+ else if (props.history.type === "systemMessage") {
38
+ return transformSystemMessage({
39
+ history: props.history,
40
+ });
41
+ }
35
42
  // SELECT & CANCEL
36
43
  else if (props.history.type === "select") {
37
44
  return transformSelect({
@@ -64,6 +71,12 @@ function transformAssistantMessage(props: {
64
71
  return createAssistantMessageHistory(props.history);
65
72
  }
66
73
 
74
+ function transformSystemMessage(props: {
75
+ history: IAgenticaHistoryJson.ISystemMessage;
76
+ }): AgenticaSystemMessageHistory {
77
+ return createSystemMessageHistory(props.history);
78
+ }
79
+
67
80
  function transformUserMessage(props: {
68
81
  history: IAgenticaHistoryJson.IUserMessage;
69
82
  }): AgenticaUserMessageHistory {
@@ -0,0 +1,50 @@
1
+ /**
2
+ * from ts-toolbelt repository
3
+ * https://github.com/millsp/ts-toolbelt/blob/master/sources/Test.ts
4
+ */
5
+
6
+ type Equals<A1, A2> = (<A>() => A extends A2 ? 1 : 0) extends <
7
+ A,
8
+ >() => A extends A1 ? 1 : 0
9
+ ? 1
10
+ : 0;
11
+
12
+ type Boolean = 0 | 1;
13
+ /**
14
+ * Test should pass
15
+ */
16
+ export type Pass = 1;
17
+
18
+ /**
19
+ * Test should fail
20
+ */
21
+ export type Fail = 0;
22
+
23
+ /**
24
+ * Check or test the validity of a type
25
+ * @param debug to debug with parameter hints (`ctrl+p`, `ctrl+shift+space`)
26
+ * @example
27
+ * ```ts
28
+ * // see in `tst` folder
29
+ * ```
30
+ */
31
+ export function check<Type, Expect, Outcome extends Boolean>(
32
+ debug?: Type,
33
+ ): Equals<Equals<Type, Expect>, Outcome> {
34
+ if (debug !== undefined) {
35
+ // eslint-disable-next-line no-console
36
+ console.log(debug);
37
+ }
38
+
39
+ return 1 as Equals<Equals<Type, Expect>, Outcome>;
40
+ }
41
+
42
+ /**
43
+ * Validates a batch of [[check]]
44
+ * @param _checks a batch of [[check]]
45
+ * @example
46
+ * ```ts
47
+ * // see in `tst` folder
48
+ * ```
49
+ */
50
+ export function checks(_checks: 1[]): void { }
@@ -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,SAAS,EAAE,CAAC;QACxC,OAAO,gBAAgB,CAAC;YACtB,KAAK,EAAE,KAAK,CAAC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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
- }