@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.
- package/README.md +56 -17
- package/lib/Agentica.js +5 -1
- package/lib/Agentica.js.map +1 -1
- package/lib/MicroAgentica.d.ts +1 -1
- package/lib/MicroAgentica.js +5 -1
- package/lib/MicroAgentica.js.map +1 -1
- package/lib/context/AgenticaTokenUsage.d.ts +2 -0
- package/lib/context/AgenticaTokenUsage.js +8 -0
- package/lib/context/AgenticaTokenUsage.js.map +1 -1
- 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 +78 -35
- 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/structures/IAgenticaProps.d.ts +13 -0
- package/lib/structures/IMicroAgenticaProps.d.ts +13 -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/Agentica.ts +5 -1
- package/src/MicroAgentica.ts +9 -2
- package/src/context/AgenticaTokenUsage.ts +15 -0
- 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/structures/IAgenticaProps.ts +14 -0
- package/src/structures/IMicroAgenticaProps.ts +14 -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
package/lib/index.mjs
CHANGED
|
@@ -10,6 +10,31 @@ import * as __typia_transform__assertGuard from "typia/lib/internal/_assertGuard
|
|
|
10
10
|
|
|
11
11
|
import * as __typia_transform__accessExpressionAsString from "typia/lib/internal/_accessExpressionAsString.js";
|
|
12
12
|
|
|
13
|
+
function aggregate(props) {
|
|
14
|
+
const component = props.usage[props.kind];
|
|
15
|
+
component.total += props.completionUsage.total_tokens;
|
|
16
|
+
component.input.total += props.completionUsage.prompt_tokens;
|
|
17
|
+
component.input.total += props.completionUsage.prompt_tokens_details?.audio_tokens ?? 0;
|
|
18
|
+
component.input.cached += props.completionUsage.prompt_tokens_details?.cached_tokens ?? 0;
|
|
19
|
+
component.output.total += props.completionUsage.completion_tokens;
|
|
20
|
+
component.output.accepted_prediction += props.completionUsage.completion_tokens_details?.accepted_prediction_tokens ?? 0;
|
|
21
|
+
component.output.reasoning += props.completionUsage.completion_tokens_details?.reasoning_tokens ?? 0;
|
|
22
|
+
component.output.rejected_prediction += props.completionUsage.completion_tokens_details?.rejected_prediction_tokens ?? 0;
|
|
23
|
+
const sum = getter => Object.entries(props.usage).filter((([key]) => key !== "aggregate")).map((([, comp]) => getter(comp))).reduce(((a, b) => a + b), 0);
|
|
24
|
+
const aggregate = props.usage.aggregate;
|
|
25
|
+
aggregate.total = sum((comp => comp.total));
|
|
26
|
+
aggregate.input.total = sum((comp => comp.input.total));
|
|
27
|
+
aggregate.input.cached = sum((comp => comp.input.cached));
|
|
28
|
+
aggregate.output.total = sum((comp => comp.output.total));
|
|
29
|
+
aggregate.output.reasoning = sum((comp => comp.output.reasoning));
|
|
30
|
+
aggregate.output.accepted_prediction = sum((comp => comp.output.accepted_prediction));
|
|
31
|
+
aggregate.output.rejected_prediction = sum((comp => comp.output.rejected_prediction));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const AgenticaTokenUsageAggregator = {
|
|
35
|
+
aggregate
|
|
36
|
+
};
|
|
37
|
+
|
|
13
38
|
class AgenticaTokenUsage {
|
|
14
39
|
constructor(props) {
|
|
15
40
|
if (props === undefined) {
|
|
@@ -46,6 +71,13 @@ class AgenticaTokenUsage {
|
|
|
46
71
|
increment(this.call, y.call);
|
|
47
72
|
increment(this.describe, y.describe);
|
|
48
73
|
}
|
|
74
|
+
use(kind, completionUsage) {
|
|
75
|
+
AgenticaTokenUsageAggregator.aggregate({
|
|
76
|
+
kind,
|
|
77
|
+
completionUsage,
|
|
78
|
+
usage: this
|
|
79
|
+
});
|
|
80
|
+
}
|
|
49
81
|
toJSON() {
|
|
50
82
|
return (() => {
|
|
51
83
|
const _co0 = input => ({
|
|
@@ -245,31 +277,6 @@ const AgenticaOperationComposer = {
|
|
|
245
277
|
compose
|
|
246
278
|
};
|
|
247
279
|
|
|
248
|
-
function aggregate(props) {
|
|
249
|
-
const component = props.usage[props.kind];
|
|
250
|
-
component.total += props.completionUsage.total_tokens;
|
|
251
|
-
component.input.total += props.completionUsage.prompt_tokens;
|
|
252
|
-
component.input.total += props.completionUsage.prompt_tokens_details?.audio_tokens ?? 0;
|
|
253
|
-
component.input.cached += props.completionUsage.prompt_tokens_details?.cached_tokens ?? 0;
|
|
254
|
-
component.output.total += props.completionUsage.completion_tokens;
|
|
255
|
-
component.output.accepted_prediction += props.completionUsage.completion_tokens_details?.accepted_prediction_tokens ?? 0;
|
|
256
|
-
component.output.reasoning += props.completionUsage.completion_tokens_details?.reasoning_tokens ?? 0;
|
|
257
|
-
component.output.rejected_prediction += props.completionUsage.completion_tokens_details?.rejected_prediction_tokens ?? 0;
|
|
258
|
-
const sum = getter => Object.entries(props.usage).filter((([key]) => key !== "aggregate")).map((([, comp]) => getter(comp))).reduce(((a, b) => a + b), 0);
|
|
259
|
-
const aggregate = props.usage.aggregate;
|
|
260
|
-
aggregate.total = sum((comp => comp.total));
|
|
261
|
-
aggregate.input.total = sum((comp => comp.input.total));
|
|
262
|
-
aggregate.input.cached = sum((comp => comp.input.cached));
|
|
263
|
-
aggregate.output.total = sum((comp => comp.output.total));
|
|
264
|
-
aggregate.output.reasoning = sum((comp => comp.output.reasoning));
|
|
265
|
-
aggregate.output.accepted_prediction = sum((comp => comp.output.accepted_prediction));
|
|
266
|
-
aggregate.output.rejected_prediction = sum((comp => comp.output.rejected_prediction));
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
const AgenticaTokenUsageAggregator = {
|
|
270
|
-
aggregate
|
|
271
|
-
};
|
|
272
|
-
|
|
273
280
|
function decodeHistory(history) {
|
|
274
281
|
if (history.type === "describe") {
|
|
275
282
|
return [];
|
|
@@ -327,19 +334,33 @@ function decodeHistory(history) {
|
|
|
327
334
|
}
|
|
328
335
|
})
|
|
329
336
|
} ];
|
|
330
|
-
}
|
|
337
|
+
}
|
|
338
|
+
if (history.type === "assistantMessage") {
|
|
331
339
|
return [ {
|
|
332
340
|
role: "assistant",
|
|
333
341
|
content: history.text
|
|
334
342
|
} ];
|
|
335
343
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
344
|
+
if (history.type === "systemMessage") {
|
|
345
|
+
return [ {
|
|
346
|
+
role: "system",
|
|
347
|
+
content: history.text
|
|
348
|
+
} ];
|
|
349
|
+
}
|
|
350
|
+
if (history.type === "userMessage") {
|
|
351
|
+
const contents = history.contents;
|
|
352
|
+
return [ {
|
|
353
|
+
role: "user",
|
|
354
|
+
content: contents.map(decodeUserMessageContent)
|
|
355
|
+
} ];
|
|
356
|
+
}
|
|
357
|
+
throw new Error(`Unsupported history type, value: ${JSON.stringify(history)}`);
|
|
340
358
|
}
|
|
341
359
|
|
|
342
360
|
function decodeUserMessageContent(content) {
|
|
361
|
+
if (content.type === "text") {
|
|
362
|
+
return content;
|
|
363
|
+
}
|
|
343
364
|
if (content.type === "audio") {
|
|
344
365
|
return {
|
|
345
366
|
type: "input_audio",
|
|
@@ -348,7 +369,8 @@ function decodeUserMessageContent(content) {
|
|
|
348
369
|
format: content.format
|
|
349
370
|
}
|
|
350
371
|
};
|
|
351
|
-
}
|
|
372
|
+
}
|
|
373
|
+
if (content.type === "file") {
|
|
352
374
|
return {
|
|
353
375
|
type: "file",
|
|
354
376
|
file: content.file.type === "data" ? {
|
|
@@ -358,7 +380,8 @@ function decodeUserMessageContent(content) {
|
|
|
358
380
|
file_id: content.file.id
|
|
359
381
|
}
|
|
360
382
|
};
|
|
361
|
-
}
|
|
383
|
+
}
|
|
384
|
+
if (content.type === "image") {
|
|
362
385
|
return {
|
|
363
386
|
type: "image_url",
|
|
364
387
|
image_url: {
|
|
@@ -367,7 +390,7 @@ function decodeUserMessageContent(content) {
|
|
|
367
390
|
}
|
|
368
391
|
};
|
|
369
392
|
}
|
|
370
|
-
|
|
393
|
+
throw new Error(`Unsupported user message content type, value: ${JSON.stringify(content)}`);
|
|
371
394
|
}
|
|
372
395
|
|
|
373
396
|
function createUserMessageHistory(props) {
|
|
@@ -392,6 +415,17 @@ function createAssistantMessageHistory(props) {
|
|
|
392
415
|
};
|
|
393
416
|
}
|
|
394
417
|
|
|
418
|
+
function createSystemMessageHistory(props) {
|
|
419
|
+
const prompt = {
|
|
420
|
+
type: "systemMessage",
|
|
421
|
+
text: props.text
|
|
422
|
+
};
|
|
423
|
+
return {
|
|
424
|
+
...prompt,
|
|
425
|
+
toJSON: () => prompt
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
|
|
395
429
|
function createDescribeHistory(props) {
|
|
396
430
|
return {
|
|
397
431
|
type: "describe",
|
|
@@ -644,6 +678,7 @@ var index$2 = Object.freeze({
|
|
|
644
678
|
createResponseEvent,
|
|
645
679
|
createSelectEvent,
|
|
646
680
|
createSelectHistory,
|
|
681
|
+
createSystemMessageHistory,
|
|
647
682
|
createUserMessageEvent,
|
|
648
683
|
createUserMessageHistory,
|
|
649
684
|
createValidateEvent,
|
|
@@ -4308,6 +4343,10 @@ function transformHistory(props) {
|
|
|
4308
4343
|
return transformAssistantMessage({
|
|
4309
4344
|
history: props.history
|
|
4310
4345
|
});
|
|
4346
|
+
} else if (props.history.type === "systemMessage") {
|
|
4347
|
+
return transformSystemMessage({
|
|
4348
|
+
history: props.history
|
|
4349
|
+
});
|
|
4311
4350
|
} else if (props.history.type === "select") {
|
|
4312
4351
|
return transformSelect({
|
|
4313
4352
|
operations: props.operations,
|
|
@@ -4334,6 +4373,10 @@ function transformAssistantMessage(props) {
|
|
|
4334
4373
|
return createAssistantMessageHistory(props.history);
|
|
4335
4374
|
}
|
|
4336
4375
|
|
|
4376
|
+
function transformSystemMessage(props) {
|
|
4377
|
+
return createSystemMessageHistory(props.history);
|
|
4378
|
+
}
|
|
4379
|
+
|
|
4337
4380
|
function transformUserMessage(props) {
|
|
4338
4381
|
return createUserMessageHistory(props.history);
|
|
4339
4382
|
}
|
|
@@ -4407,7 +4450,7 @@ class Agentica {
|
|
|
4407
4450
|
operations: this.operations_.group,
|
|
4408
4451
|
history: input
|
|
4409
4452
|
})));
|
|
4410
|
-
this.token_usage_ = AgenticaTokenUsage.zero();
|
|
4453
|
+
this.token_usage_ = this.props.tokenUsage !== undefined ? this.props.tokenUsage instanceof AgenticaTokenUsage ? this.props.tokenUsage : new AgenticaTokenUsage(this.props.tokenUsage) : AgenticaTokenUsage.zero();
|
|
4411
4454
|
this.ready_ = false;
|
|
4412
4455
|
this.executor_ = typeof props.config?.executor === "function" ? props.config.executor : execute(props.config?.executor ?? null);
|
|
4413
4456
|
}
|
|
@@ -43220,8 +43263,8 @@ class MicroAgentica {
|
|
|
43220
43263
|
operations: this.operations_.group,
|
|
43221
43264
|
history: input
|
|
43222
43265
|
})));
|
|
43266
|
+
this.token_usage_ = this.props.tokenUsage !== undefined ? this.props.tokenUsage instanceof AgenticaTokenUsage ? this.props.tokenUsage : new AgenticaTokenUsage(this.props.tokenUsage) : AgenticaTokenUsage.zero();
|
|
43223
43267
|
this.listeners_ = new Map;
|
|
43224
|
-
this.token_usage_ = AgenticaTokenUsage.zero();
|
|
43225
43268
|
}
|
|
43226
43269
|
clone() {
|
|
43227
43270
|
return new MicroAgentica({
|