@agentica/core 0.32.8 → 0.33.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/lib/events/AgenticaCallEvent.d.ts +0 -4
- package/lib/events/AgenticaExecuteEvent.d.ts +1 -1
- package/lib/events/AgenticaJsonParseErrorEvent.d.ts +4 -0
- package/lib/events/AgenticaResponseEvent.d.ts +1 -0
- package/lib/events/AgenticaValidateEvent.d.ts +1 -1
- package/lib/factory/events.d.ts +4 -2
- package/lib/factory/events.js +11 -3
- package/lib/factory/events.js.map +1 -1
- package/lib/index.mjs +100 -86
- package/lib/index.mjs.map +1 -1
- package/lib/json/IAgenticaEventJson.d.ts +9 -5
- package/lib/orchestrate/call.js +9 -5
- 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/describe.js +1 -1
- package/lib/orchestrate/describe.js.map +1 -1
- package/lib/orchestrate/initialize.js +1 -1
- package/lib/orchestrate/initialize.js.map +1 -1
- package/lib/orchestrate/internal/cancelFunctionFromContext.js +1 -1
- package/lib/orchestrate/internal/cancelFunctionFromContext.js.map +1 -1
- package/lib/orchestrate/internal/selectFunctionFromContext.js +1 -1
- package/lib/orchestrate/internal/selectFunctionFromContext.js.map +1 -1
- package/lib/orchestrate/select.js +1 -1
- package/lib/orchestrate/select.js.map +1 -1
- package/lib/utils/ChatGptCompletionMessageUtil.d.ts +2 -2
- package/lib/utils/ChatGptCompletionMessageUtil.js +3 -3
- package/lib/utils/ChatGptCompletionMessageUtil.js.map +1 -1
- package/lib/utils/ChatGptCompletionMessageUtil.spec.js +4 -4
- package/lib/utils/ChatGptCompletionMessageUtil.spec.js.map +1 -1
- package/lib/utils/ChatGptCompletionStreamingUtil.js.map +1 -1
- package/lib/utils/ChatGptCompletionStreamingUtil.spec.js +2 -1
- package/lib/utils/ChatGptCompletionStreamingUtil.spec.js.map +1 -1
- package/lib/utils/JsonUtil.js +1 -2
- package/lib/utils/JsonUtil.js.map +1 -1
- package/lib/utils/JsonUtil.spec.js +38 -38
- package/lib/utils/JsonUtil.spec.js.map +1 -1
- package/lib/utils/StreamUtil.spec.js.map +1 -1
- package/lib/utils/request.d.ts +7 -7
- package/lib/utils/request.js +67 -65
- package/lib/utils/request.js.map +1 -1
- package/package.json +7 -7
- package/src/events/AgenticaCallEvent.ts +0 -5
- package/src/events/AgenticaExecuteEvent.ts +1 -1
- package/src/events/AgenticaJsonParseErrorEvent.ts +4 -0
- package/src/events/AgenticaResponseEvent.ts +2 -0
- package/src/events/AgenticaValidateEvent.ts +1 -1
- package/src/factory/events.ts +15 -5
- package/src/json/IAgenticaEventJson.ts +11 -6
- package/src/orchestrate/call.ts +14 -7
- package/src/orchestrate/cancel.ts +1 -1
- package/src/orchestrate/describe.ts +1 -1
- package/src/orchestrate/initialize.ts +1 -1
- package/src/orchestrate/internal/cancelFunctionFromContext.ts +1 -1
- package/src/orchestrate/internal/selectFunctionFromContext.ts +1 -1
- package/src/orchestrate/select.ts +1 -1
- package/src/utils/ChatGptCompletionMessageUtil.spec.ts +4 -4
- package/src/utils/ChatGptCompletionMessageUtil.ts +5 -4
- package/src/utils/ChatGptCompletionStreamingUtil.spec.ts +437 -435
- package/src/utils/ChatGptCompletionStreamingUtil.ts +5 -4
- package/src/utils/JsonUtil.spec.ts +58 -60
- package/src/utils/JsonUtil.ts +1 -4
- package/src/utils/StreamUtil.spec.ts +1 -1
- package/src/utils/StreamUtil.ts +2 -2
- package/src/utils/request.ts +92 -85
|
@@ -8,10 +8,6 @@ import type { AgenticaEventBase } from "./AgenticaEventBase";
|
|
|
8
8
|
* @author Samchon
|
|
9
9
|
*/
|
|
10
10
|
export interface AgenticaCallEvent<Model extends ILlmSchema.Model> extends AgenticaEventBase<"call"> {
|
|
11
|
-
/**
|
|
12
|
-
* ID of the tool calling.
|
|
13
|
-
*/
|
|
14
|
-
id: string;
|
|
15
11
|
/**
|
|
16
12
|
* Target operation to call.
|
|
17
13
|
*/
|
|
@@ -11,7 +11,7 @@ export declare namespace AgenticaExecuteEvent {
|
|
|
11
11
|
}
|
|
12
12
|
interface Base<Protocol extends "http" | "class", Operation extends AgenticaOperation<any>, History extends AgenticaExecuteHistory<any>, Value> extends AgenticaEventBase<"execute"> {
|
|
13
13
|
protocol: Protocol;
|
|
14
|
-
|
|
14
|
+
call_id: string;
|
|
15
15
|
operation: Operation;
|
|
16
16
|
arguments: Record<string, unknown>;
|
|
17
17
|
value: Value;
|
|
@@ -2,6 +2,10 @@ import type { ILlmSchema } from "@samchon/openapi";
|
|
|
2
2
|
import type { AgenticaOperation } from "../context/AgenticaOperation";
|
|
3
3
|
import type { AgenticaEventBase } from "./AgenticaEventBase";
|
|
4
4
|
export interface AgenticaJsonParseErrorEvent<Model extends ILlmSchema.Model> extends AgenticaEventBase<"jsonParseError"> {
|
|
5
|
+
/**
|
|
6
|
+
* ID of the tool calling.
|
|
7
|
+
*/
|
|
8
|
+
call_id: string;
|
|
5
9
|
operation: AgenticaOperation<Model>;
|
|
6
10
|
arguments: string;
|
|
7
11
|
errorMessage: string;
|
|
@@ -2,6 +2,7 @@ import type OpenAI from "openai";
|
|
|
2
2
|
import type { AgenticaEventBase } from "./AgenticaEventBase";
|
|
3
3
|
import type { AgenticaEventSource } from "./AgenticaEventSource";
|
|
4
4
|
export interface AgenticaResponseEvent extends AgenticaEventBase<"response"> {
|
|
5
|
+
request_id: string;
|
|
5
6
|
/**
|
|
6
7
|
* The source agent of the response.
|
|
7
8
|
*/
|
package/lib/factory/events.d.ts
CHANGED
|
@@ -30,19 +30,20 @@ export declare function createCallEvent<Model extends ILlmSchema.Model>(props: {
|
|
|
30
30
|
arguments: Record<string, any>;
|
|
31
31
|
}): AgenticaCallEvent<Model>;
|
|
32
32
|
export declare function createJsonParseErrorEvent<Model extends ILlmSchema.Model>(props: {
|
|
33
|
-
|
|
33
|
+
call_id: string;
|
|
34
34
|
operation: AgenticaOperation<Model>;
|
|
35
35
|
arguments: string;
|
|
36
36
|
errorMessage: string;
|
|
37
37
|
life: number;
|
|
38
38
|
}): AgenticaJsonParseErrorEvent<Model>;
|
|
39
39
|
export declare function createValidateEvent<Model extends ILlmSchema.Model>(props: {
|
|
40
|
-
|
|
40
|
+
call_id: string;
|
|
41
41
|
operation: AgenticaOperation<Model>;
|
|
42
42
|
result: IValidation.IFailure;
|
|
43
43
|
life: number;
|
|
44
44
|
}): AgenticaValidateEvent<Model>;
|
|
45
45
|
export declare function createExecuteEvent<Model extends ILlmSchema.Model>(props: {
|
|
46
|
+
call_id: string;
|
|
46
47
|
operation: AgenticaOperation<Model>;
|
|
47
48
|
arguments: Record<string, unknown>;
|
|
48
49
|
value: unknown;
|
|
@@ -70,6 +71,7 @@ export declare function createRequestEvent(props: {
|
|
|
70
71
|
options?: OpenAI.RequestOptions | undefined;
|
|
71
72
|
}): AgenticaRequestEvent;
|
|
72
73
|
export declare function createResponseEvent(props: {
|
|
74
|
+
request_id: string;
|
|
73
75
|
source: AgenticaEventSource;
|
|
74
76
|
body: OpenAI.ChatCompletionCreateParamsStreaming;
|
|
75
77
|
options?: OpenAI.RequestOptions | undefined;
|
package/lib/factory/events.js
CHANGED
|
@@ -88,10 +88,12 @@ function createCallEvent(props) {
|
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
90
|
function createJsonParseErrorEvent(props) {
|
|
91
|
+
const id = (0, uuid_1.v4)();
|
|
91
92
|
const created_at = new Date().toISOString();
|
|
92
93
|
return {
|
|
93
94
|
type: "jsonParseError",
|
|
94
|
-
id
|
|
95
|
+
id,
|
|
96
|
+
call_id: props.call_id,
|
|
95
97
|
created_at,
|
|
96
98
|
operation: props.operation,
|
|
97
99
|
arguments: props.arguments,
|
|
@@ -100,17 +102,20 @@ function createJsonParseErrorEvent(props) {
|
|
|
100
102
|
};
|
|
101
103
|
}
|
|
102
104
|
function createValidateEvent(props) {
|
|
105
|
+
const id = (0, uuid_1.v4)();
|
|
103
106
|
const created_at = new Date().toISOString();
|
|
104
107
|
return {
|
|
105
108
|
type: "validate",
|
|
106
|
-
id
|
|
109
|
+
id,
|
|
110
|
+
call_id: props.call_id,
|
|
107
111
|
created_at,
|
|
108
112
|
operation: props.operation,
|
|
109
113
|
result: props.result,
|
|
110
114
|
life: props.life,
|
|
111
115
|
toJSON: () => ({
|
|
112
116
|
type: "validate",
|
|
113
|
-
id
|
|
117
|
+
id,
|
|
118
|
+
call_id: props.call_id,
|
|
114
119
|
created_at,
|
|
115
120
|
operation: props.operation.toJSON(),
|
|
116
121
|
result: props.result,
|
|
@@ -125,6 +130,7 @@ function createExecuteEvent(props) {
|
|
|
125
130
|
type: "execute",
|
|
126
131
|
id,
|
|
127
132
|
created_at,
|
|
133
|
+
call_id: props.call_id,
|
|
128
134
|
protocol: props.operation.protocol,
|
|
129
135
|
operation: props.operation,
|
|
130
136
|
arguments: props.arguments,
|
|
@@ -134,6 +140,7 @@ function createExecuteEvent(props) {
|
|
|
134
140
|
type: "execute",
|
|
135
141
|
id,
|
|
136
142
|
created_at,
|
|
143
|
+
call_id: props.call_id,
|
|
137
144
|
protocol: props.operation.protocol,
|
|
138
145
|
operation: props.operation.toJSON(),
|
|
139
146
|
arguments: props.arguments,
|
|
@@ -253,6 +260,7 @@ function createResponseEvent(props) {
|
|
|
253
260
|
return {
|
|
254
261
|
type: "response",
|
|
255
262
|
id,
|
|
263
|
+
request_id: props.request_id,
|
|
256
264
|
created_at,
|
|
257
265
|
source: props.source,
|
|
258
266
|
body: props.body,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/factory/events.ts"],"names":[],"mappings":";;AAiCA,sDAYC;AAED,8CAsBC;AAED,8CAiBC;AAKD,0CAoBC;AAED,
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/factory/events.ts"],"names":[],"mappings":";;AAiCA,sDAYC;AAED,8CAsBC;AAED,8CAiBC;AAKD,0CAoBC;AA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,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;gBACzD,IAAI,EAAE,KAAK,CAAC,GAAG,EAAE;aAClB,CAAC;SACH,CAAC;KACH,CAAC;AACJ,CAAC;AAED;;8DAE8D;AAC9D,SAAgB,kBAAkB,CAAC,KAIlC;IACC,MAAM,EAAE,GAAW,IAAA,SAAE,GAAE,CAAC;IACxB,MAAM,UAAU,GAAW,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACpD,OAAO;QACL,IAAI,EAAE,SAAS;QACf,EAAE;QACF,UAAU;QACV,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,OAAO,EAAE,KAAK,CAAC,OAAO;KACvB,CAAC;AACJ,CAAC;AAED,SAAgB,mBAAmB,CAAC,KAOnC;IACC,MAAM,EAAE,GAAW,IAAA,SAAE,GAAE,CAAC;IACxB,MAAM,UAAU,GAAW,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACpD,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,EAAE;QACF,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,UAAU;QACV,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,IAAI,EAAE,KAAK,CAAC,IAAI;KACjB,CAAC;AACJ,CAAC"}
|
package/lib/index.mjs
CHANGED
|
@@ -580,10 +580,12 @@ function createCallEvent(props) {
|
|
|
580
580
|
}
|
|
581
581
|
|
|
582
582
|
function createJsonParseErrorEvent(props) {
|
|
583
|
+
const id = v4();
|
|
583
584
|
const created_at = (new Date).toISOString();
|
|
584
585
|
return {
|
|
585
586
|
type: "jsonParseError",
|
|
586
|
-
id
|
|
587
|
+
id,
|
|
588
|
+
call_id: props.call_id,
|
|
587
589
|
created_at,
|
|
588
590
|
operation: props.operation,
|
|
589
591
|
arguments: props.arguments,
|
|
@@ -593,17 +595,20 @@ function createJsonParseErrorEvent(props) {
|
|
|
593
595
|
}
|
|
594
596
|
|
|
595
597
|
function createValidateEvent(props) {
|
|
598
|
+
const id = v4();
|
|
596
599
|
const created_at = (new Date).toISOString();
|
|
597
600
|
return {
|
|
598
601
|
type: "validate",
|
|
599
|
-
id
|
|
602
|
+
id,
|
|
603
|
+
call_id: props.call_id,
|
|
600
604
|
created_at,
|
|
601
605
|
operation: props.operation,
|
|
602
606
|
result: props.result,
|
|
603
607
|
life: props.life,
|
|
604
608
|
toJSON: () => ({
|
|
605
609
|
type: "validate",
|
|
606
|
-
id
|
|
610
|
+
id,
|
|
611
|
+
call_id: props.call_id,
|
|
607
612
|
created_at,
|
|
608
613
|
operation: props.operation.toJSON(),
|
|
609
614
|
result: props.result,
|
|
@@ -619,6 +624,7 @@ function createExecuteEvent(props) {
|
|
|
619
624
|
type: "execute",
|
|
620
625
|
id,
|
|
621
626
|
created_at,
|
|
627
|
+
call_id: props.call_id,
|
|
622
628
|
protocol: props.operation.protocol,
|
|
623
629
|
operation: props.operation,
|
|
624
630
|
arguments: props.arguments,
|
|
@@ -628,6 +634,7 @@ function createExecuteEvent(props) {
|
|
|
628
634
|
type: "execute",
|
|
629
635
|
id,
|
|
630
636
|
created_at,
|
|
637
|
+
call_id: props.call_id,
|
|
631
638
|
protocol: props.operation.protocol,
|
|
632
639
|
operation: props.operation.toJSON(),
|
|
633
640
|
arguments: props.arguments,
|
|
@@ -749,6 +756,7 @@ function createResponseEvent(props) {
|
|
|
749
756
|
return {
|
|
750
757
|
type: "response",
|
|
751
758
|
id,
|
|
759
|
+
request_id: props.request_id,
|
|
752
760
|
created_at,
|
|
753
761
|
source: props.source,
|
|
754
762
|
body: props.body,
|
|
@@ -904,14 +912,13 @@ const JsonUtil = {
|
|
|
904
912
|
parse
|
|
905
913
|
};
|
|
906
914
|
|
|
915
|
+
const pipe = (...fns) => str => fns.reduce(((acc, fn) => fn(acc)), str);
|
|
916
|
+
|
|
907
917
|
function parse(str) {
|
|
908
918
|
const corrected = pipe(removeEmptyObjectPrefix, addMissingBraces, removeTrailingCommas)(str);
|
|
909
|
-
console.log(corrected);
|
|
910
919
|
return JSON.parse(corrected);
|
|
911
920
|
}
|
|
912
921
|
|
|
913
|
-
const pipe = (...fns) => str => fns.reduce(((acc, fn) => fn(acc)), str);
|
|
914
|
-
|
|
915
922
|
function transformCompletionChunk(source) {
|
|
916
923
|
const str = source instanceof Uint8Array ? ByteArrayUtil.toUtf8(source) : source;
|
|
917
924
|
const result = JsonUtil.parse(str);
|
|
@@ -983,7 +990,7 @@ function merge(chunks) {
|
|
|
983
990
|
system_fingerprint: firstChunk.system_fingerprint
|
|
984
991
|
});
|
|
985
992
|
result.choices.forEach((choice => {
|
|
986
|
-
choice.message.tool_calls?.forEach((toolCall => {
|
|
993
|
+
choice.message.tool_calls?.filter((tc => tc.type === "function")).forEach((toolCall => {
|
|
987
994
|
if (toolCall.function.arguments === "") {
|
|
988
995
|
toolCall.function.arguments = "{}";
|
|
989
996
|
}
|
|
@@ -1026,7 +1033,7 @@ function mergeChoice(acc, cur) {
|
|
|
1026
1033
|
const toolCalls = acc.message.tool_calls;
|
|
1027
1034
|
cur.delta.tool_calls.forEach((toolCall => {
|
|
1028
1035
|
const existingToolCall = toolCalls[toolCall.index];
|
|
1029
|
-
if (existingToolCall != null) {
|
|
1036
|
+
if (existingToolCall != null && existingToolCall.type === "function") {
|
|
1030
1037
|
toolCalls[toolCall.index] = mergeToolCalls(existingToolCall, toolCall);
|
|
1031
1038
|
return;
|
|
1032
1039
|
}
|
|
@@ -1044,7 +1051,7 @@ function mergeChoice(acc, cur) {
|
|
|
1044
1051
|
}
|
|
1045
1052
|
|
|
1046
1053
|
function mergeToolCalls(acc, cur) {
|
|
1047
|
-
if (cur.function != null) {
|
|
1054
|
+
if (cur.function != null && cur.type === "function") {
|
|
1048
1055
|
acc.function.arguments += cur.function.arguments ?? "";
|
|
1049
1056
|
acc.function.name += cur.function.name ?? "";
|
|
1050
1057
|
}
|
|
@@ -1359,7 +1366,7 @@ function cancelFunctionFromContext(ctx, reference) {
|
|
|
1359
1366
|
reason: reference.reason
|
|
1360
1367
|
})
|
|
1361
1368
|
});
|
|
1362
|
-
ctx.dispatch(event);
|
|
1369
|
+
void ctx.dispatch(event).catch((() => {}));
|
|
1363
1370
|
}
|
|
1364
1371
|
|
|
1365
1372
|
async function call(ctx, operations) {
|
|
@@ -1453,12 +1460,12 @@ async function predicate(ctx, operation, toolCall, previousValidationErrors, lif
|
|
|
1453
1460
|
const call = parseArguments(operation, toolCall, life);
|
|
1454
1461
|
await ctx.dispatch(call);
|
|
1455
1462
|
if (call.type === "jsonParseError") {
|
|
1456
|
-
return correctJsonError(ctx, call, previousValidationErrors, life - 1);
|
|
1463
|
+
return correctJsonError(ctx, toolCall, call, previousValidationErrors, life - 1);
|
|
1457
1464
|
}
|
|
1458
1465
|
const check = operation.function.validate(call.arguments);
|
|
1459
1466
|
if (check.success === false) {
|
|
1460
1467
|
const event = createValidateEvent({
|
|
1461
|
-
|
|
1468
|
+
call_id: toolCall.id,
|
|
1462
1469
|
operation,
|
|
1463
1470
|
result: check,
|
|
1464
1471
|
life
|
|
@@ -1472,6 +1479,7 @@ async function predicate(ctx, operation, toolCall, previousValidationErrors, lif
|
|
|
1472
1479
|
async function correctTypeError(ctx, callEvent, validateEvent, previousValidationErrors, life) {
|
|
1473
1480
|
return correctError(ctx, {
|
|
1474
1481
|
giveUp: () => createExecuteEvent({
|
|
1482
|
+
call_id: callEvent.id,
|
|
1475
1483
|
operation: callEvent.operation,
|
|
1476
1484
|
arguments: callEvent.arguments,
|
|
1477
1485
|
value: {
|
|
@@ -1493,9 +1501,10 @@ async function correctTypeError(ctx, callEvent, validateEvent, previousValidatio
|
|
|
1493
1501
|
});
|
|
1494
1502
|
}
|
|
1495
1503
|
|
|
1496
|
-
async function correctJsonError(ctx, parseErrorEvent, previousValidationErrors, life) {
|
|
1504
|
+
async function correctJsonError(ctx, toolCall, parseErrorEvent, previousValidationErrors, life) {
|
|
1497
1505
|
return correctError(ctx, {
|
|
1498
1506
|
giveUp: () => createExecuteEvent({
|
|
1507
|
+
call_id: toolCall.id,
|
|
1499
1508
|
operation: parseErrorEvent.operation,
|
|
1500
1509
|
arguments: {},
|
|
1501
1510
|
value: {
|
|
@@ -1528,7 +1537,7 @@ function parseArguments(operation, toolCall, life) {
|
|
|
1528
1537
|
});
|
|
1529
1538
|
} catch (error) {
|
|
1530
1539
|
return createJsonParseErrorEvent({
|
|
1531
|
-
|
|
1540
|
+
call_id: toolCall.id,
|
|
1532
1541
|
operation,
|
|
1533
1542
|
arguments: toolCall.function.arguments,
|
|
1534
1543
|
errorMessage: error instanceof Error ? error.message : String(error),
|
|
@@ -1587,7 +1596,7 @@ async function correctError(ctx, props) {
|
|
|
1587
1596
|
});
|
|
1588
1597
|
const chunks = await StreamUtil.readAll(stream);
|
|
1589
1598
|
const completion = ChatGptCompletionMessageUtil.merge(chunks);
|
|
1590
|
-
const toolCall = completion.choices[0]?.message.tool_calls?.find((s => s.function.name === props.operation.name));
|
|
1599
|
+
const toolCall = completion.choices[0]?.message.tool_calls?.filter((tc => tc.type === "function")).find((s => s.function.name === props.operation.name));
|
|
1591
1600
|
return toolCall === undefined ? props.giveUp() : predicate(ctx, props.operation, toolCall, props.previousValidationErrors, props.life);
|
|
1592
1601
|
}
|
|
1593
1602
|
|
|
@@ -1610,6 +1619,7 @@ async function executeFunction(call, operation) {
|
|
|
1610
1619
|
}
|
|
1611
1620
|
})();
|
|
1612
1621
|
return createExecuteEvent({
|
|
1622
|
+
call_id: call.id,
|
|
1613
1623
|
operation: call.operation,
|
|
1614
1624
|
arguments: call.arguments,
|
|
1615
1625
|
value,
|
|
@@ -1617,6 +1627,7 @@ async function executeFunction(call, operation) {
|
|
|
1617
1627
|
});
|
|
1618
1628
|
} catch (error) {
|
|
1619
1629
|
return createExecuteEvent({
|
|
1630
|
+
call_id: call.id,
|
|
1620
1631
|
operation: call.operation,
|
|
1621
1632
|
arguments: call.arguments,
|
|
1622
1633
|
value: error instanceof Error ? {
|
|
@@ -1835,7 +1846,7 @@ async function step$1(ctx, operations, retry, failures) {
|
|
|
1835
1846
|
const failures = [];
|
|
1836
1847
|
for (const choice of completion.choices) {
|
|
1837
1848
|
for (const tc of choice.message.tool_calls ?? []) {
|
|
1838
|
-
if (tc.function.name !== "cancelFunctions") {
|
|
1849
|
+
if (tc.type !== "function" || tc.function.name !== "cancelFunctions") {
|
|
1839
1850
|
continue;
|
|
1840
1851
|
}
|
|
1841
1852
|
const input = JsonUtil.parse(tc.function.arguments);
|
|
@@ -1980,7 +1991,7 @@ async function describe(ctx, histories) {
|
|
|
1980
1991
|
executes: histories,
|
|
1981
1992
|
...props
|
|
1982
1993
|
});
|
|
1983
|
-
ctx.dispatch(event);
|
|
1994
|
+
void ctx.dispatch(event).catch((() => {}));
|
|
1984
1995
|
}), ctx.abortSignal);
|
|
1985
1996
|
}
|
|
1986
1997
|
|
|
@@ -2647,7 +2658,7 @@ async function initialize(ctx) {
|
|
|
2647
2658
|
});
|
|
2648
2659
|
const completion = await reduceStreamingWithDispatch(completionStream, (props => {
|
|
2649
2660
|
const event = createAssistantMessageEvent(props);
|
|
2650
|
-
ctx.dispatch(event);
|
|
2661
|
+
void ctx.dispatch(event).catch((() => {}));
|
|
2651
2662
|
}), ctx.abortSignal);
|
|
2652
2663
|
if (completion === null) {
|
|
2653
2664
|
throw new Error("No completion received");
|
|
@@ -2670,7 +2681,7 @@ function selectFunctionFromContext(ctx, reference) {
|
|
|
2670
2681
|
const event = createSelectEvent({
|
|
2671
2682
|
selection
|
|
2672
2683
|
});
|
|
2673
|
-
ctx.dispatch(event);
|
|
2684
|
+
void ctx.dispatch(event).catch((() => {}));
|
|
2674
2685
|
}
|
|
2675
2686
|
|
|
2676
2687
|
const CONTAINER = {
|
|
@@ -2878,7 +2889,7 @@ async function step(ctx, operations, retry, failures) {
|
|
|
2878
2889
|
const failures = [];
|
|
2879
2890
|
for (const choice of completion.choices) {
|
|
2880
2891
|
for (const tc of choice.message.tool_calls ?? []) {
|
|
2881
|
-
if (tc.function.name !== "selectFunctions") {
|
|
2892
|
+
if (tc.type !== "function" || tc.function.name !== "selectFunctions") {
|
|
2882
2893
|
continue;
|
|
2883
2894
|
}
|
|
2884
2895
|
const input = JsonUtil.parse(tc.function.arguments);
|
|
@@ -3171,75 +3182,78 @@ var index$1 = Object.freeze({
|
|
|
3171
3182
|
decodeUserMessageContent
|
|
3172
3183
|
});
|
|
3173
3184
|
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
});
|
|
3190
|
-
await props.dispatch(event);
|
|
3191
|
-
const backoffStrategy = props.config?.backoffStrategy ?? (props => {
|
|
3192
|
-
throw props.error;
|
|
3193
|
-
});
|
|
3194
|
-
const completion = await (async () => {
|
|
3195
|
-
let count = 0;
|
|
3196
|
-
while (true) {
|
|
3197
|
-
try {
|
|
3198
|
-
return await props.vendor.api.chat.completions.create(event.body, event.options);
|
|
3199
|
-
} catch (error) {
|
|
3200
|
-
const waiting = backoffStrategy({
|
|
3201
|
-
count,
|
|
3202
|
-
error
|
|
3203
|
-
});
|
|
3204
|
-
await new Promise((resolve => setTimeout(resolve, waiting)));
|
|
3205
|
-
count++;
|
|
3185
|
+
function getChatCompletionWithStreamingFunction(props) {
|
|
3186
|
+
return async (source, body) => {
|
|
3187
|
+
const event = createRequestEvent({
|
|
3188
|
+
source,
|
|
3189
|
+
body: {
|
|
3190
|
+
...body,
|
|
3191
|
+
model: props.vendor.model,
|
|
3192
|
+
stream: true,
|
|
3193
|
+
stream_options: {
|
|
3194
|
+
include_usage: true
|
|
3195
|
+
}
|
|
3196
|
+
},
|
|
3197
|
+
options: {
|
|
3198
|
+
...props.vendor.options,
|
|
3199
|
+
signal: props.abortSignal
|
|
3206
3200
|
}
|
|
3207
|
-
}
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
const
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3201
|
+
});
|
|
3202
|
+
await props.dispatch(event);
|
|
3203
|
+
const backoffStrategy = props.config?.backoffStrategy ?? (props => {
|
|
3204
|
+
throw props.error;
|
|
3205
|
+
});
|
|
3206
|
+
const completion = await (async () => {
|
|
3207
|
+
let count = 0;
|
|
3208
|
+
while (true) {
|
|
3209
|
+
try {
|
|
3210
|
+
return await props.vendor.api.chat.completions.create(event.body, event.options);
|
|
3211
|
+
} catch (error) {
|
|
3212
|
+
const waiting = backoffStrategy({
|
|
3213
|
+
count,
|
|
3214
|
+
error
|
|
3215
|
+
});
|
|
3216
|
+
await new Promise((resolve => setTimeout(resolve, waiting)));
|
|
3217
|
+
count++;
|
|
3218
|
+
}
|
|
3217
3219
|
}
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3220
|
+
})();
|
|
3221
|
+
const [streamForEvent, temporaryStream] = StreamUtil.transform(completion.toReadableStream(), (value => ChatGptCompletionMessageUtil.transformCompletionChunk(value)), props.abortSignal).tee();
|
|
3222
|
+
const [streamForAggregate, streamForReturn] = temporaryStream.tee();
|
|
3223
|
+
(async () => {
|
|
3224
|
+
const reader = streamForAggregate.getReader();
|
|
3225
|
+
while (true) {
|
|
3226
|
+
const chunk = await reader.read();
|
|
3227
|
+
if (chunk.done || props.abortSignal?.aborted === true) {
|
|
3228
|
+
break;
|
|
3229
|
+
}
|
|
3230
|
+
if (chunk.value.usage != null) {
|
|
3231
|
+
AgenticaTokenUsageAggregator.aggregate({
|
|
3232
|
+
kind: source,
|
|
3233
|
+
completionUsage: chunk.value.usage,
|
|
3234
|
+
usage: props.usage
|
|
3235
|
+
});
|
|
3236
|
+
}
|
|
3224
3237
|
}
|
|
3225
|
-
}
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
};
|
|
3238
|
+
})().catch((() => {}));
|
|
3239
|
+
const [streamForStream, streamForJoin] = streamForEvent.tee();
|
|
3240
|
+
void props.dispatch({
|
|
3241
|
+
id: v4(),
|
|
3242
|
+
type: "response",
|
|
3243
|
+
request_id: event.id,
|
|
3244
|
+
source,
|
|
3245
|
+
stream: streamDefaultReaderToAsyncGenerator(streamForStream.getReader(), props.abortSignal),
|
|
3246
|
+
body: event.body,
|
|
3247
|
+
options: event.options,
|
|
3248
|
+
join: async () => {
|
|
3249
|
+
const chunks = await StreamUtil.readAll(streamForJoin, props.abortSignal);
|
|
3250
|
+
return ChatGptCompletionMessageUtil.merge(chunks);
|
|
3251
|
+
},
|
|
3252
|
+
created_at: (new Date).toISOString()
|
|
3253
|
+
}).catch((() => {}));
|
|
3254
|
+
return streamForReturn;
|
|
3255
|
+
};
|
|
3256
|
+
}
|
|
3243
3257
|
|
|
3244
3258
|
class Agentica {
|
|
3245
3259
|
constructor(props) {
|