@agentica/core 0.32.3 → 0.32.5
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/context/MicroAgenticaContext.d.ts +4 -0
- package/lib/events/AgenticaJsonParseErrorEvent.d.ts +1 -0
- package/lib/events/AgenticaValidateEvent.d.ts +1 -0
- package/lib/factory/events.d.ts +2 -0
- package/lib/factory/events.js +3 -0
- package/lib/factory/events.js.map +1 -1
- package/lib/index.mjs +44 -28
- package/lib/index.mjs.map +1 -1
- package/lib/json/IAgenticaEventJson.d.ts +2 -0
- package/lib/orchestrate/call.js +8 -6
- 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/select.js +5 -5
- package/lib/orchestrate/select.js.map +1 -1
- package/lib/utils/AssistantMessageEmptyError.js +9 -0
- package/lib/utils/AssistantMessageEmptyError.js.map +1 -1
- package/lib/utils/ChatGptCompletionStreamingUtil.d.ts +1 -1
- package/lib/utils/ChatGptCompletionStreamingUtil.js +2 -2
- package/lib/utils/ChatGptCompletionStreamingUtil.js.map +1 -1
- package/lib/utils/StreamUtil.d.ts +7 -4
- package/lib/utils/StreamUtil.js +17 -14
- package/lib/utils/StreamUtil.js.map +1 -1
- package/lib/utils/StreamUtil.spec.js +12 -12
- package/lib/utils/StreamUtil.spec.js.map +1 -1
- package/lib/utils/request.js +5 -4
- package/lib/utils/request.js.map +1 -1
- package/package.json +1 -1
- package/src/context/MicroAgenticaContext.ts +4 -0
- package/src/events/AgenticaJsonParseErrorEvent.ts +1 -0
- package/src/events/AgenticaValidateEvent.ts +2 -0
- package/src/factory/events.ts +5 -0
- package/src/json/IAgenticaEventJson.ts +4 -0
- package/src/orchestrate/call.ts +5 -1
- package/src/orchestrate/cancel.ts +1 -1
- package/src/orchestrate/describe.ts +1 -1
- package/src/orchestrate/initialize.ts +1 -1
- package/src/orchestrate/select.ts +2 -2
- package/src/utils/AssistantMessageEmptyError.ts +8 -1
- package/src/utils/ChatGptCompletionStreamingUtil.ts +2 -2
- package/src/utils/StreamUtil.spec.ts +12 -9
- package/src/utils/StreamUtil.ts +15 -11
- package/src/utils/request.ts +4 -3
package/lib/factory/events.d.ts
CHANGED
|
@@ -34,11 +34,13 @@ export declare function createJsonParseErrorEvent<Model extends ILlmSchema.Model
|
|
|
34
34
|
operation: AgenticaOperation<Model>;
|
|
35
35
|
arguments: string;
|
|
36
36
|
errorMessage: string;
|
|
37
|
+
life: number;
|
|
37
38
|
}): AgenticaJsonParseErrorEvent<Model>;
|
|
38
39
|
export declare function createValidateEvent<Model extends ILlmSchema.Model>(props: {
|
|
39
40
|
id: string;
|
|
40
41
|
operation: AgenticaOperation<Model>;
|
|
41
42
|
result: IValidation.IFailure;
|
|
43
|
+
life: number;
|
|
42
44
|
}): AgenticaValidateEvent<Model>;
|
|
43
45
|
export declare function createExecuteEvent<Model extends ILlmSchema.Model>(props: {
|
|
44
46
|
operation: AgenticaOperation<Model>;
|
package/lib/factory/events.js
CHANGED
|
@@ -96,6 +96,7 @@ function createJsonParseErrorEvent(props) {
|
|
|
96
96
|
operation: props.operation,
|
|
97
97
|
arguments: props.arguments,
|
|
98
98
|
errorMessage: props.errorMessage,
|
|
99
|
+
life: props.life,
|
|
99
100
|
};
|
|
100
101
|
}
|
|
101
102
|
function createValidateEvent(props) {
|
|
@@ -106,12 +107,14 @@ function createValidateEvent(props) {
|
|
|
106
107
|
created_at,
|
|
107
108
|
operation: props.operation,
|
|
108
109
|
result: props.result,
|
|
110
|
+
life: props.life,
|
|
109
111
|
toJSON: () => ({
|
|
110
112
|
type: "validate",
|
|
111
113
|
id: props.id,
|
|
112
114
|
created_at,
|
|
113
115
|
operation: props.operation.toJSON(),
|
|
114
116
|
result: props.result,
|
|
117
|
+
life: props.life,
|
|
115
118
|
}),
|
|
116
119
|
};
|
|
117
120
|
}
|
|
@@ -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;AAED,8DAiBC;AAED,kDAuBC;AAED,gDAkCC;AAKD,wDAsBC;AAED,kEAkCC;AAED,kDAuCC;AAKD,gDAeC;AAED,kDAmBC;AA/UD,+BAA0B;AAqB1B,2CAIqB;AAErB;;8DAE8D;AAC9D,SAAgB,qBAAqB;IACnC,MAAM,KAAK,GAAmC;QAC5C,EAAE,EAAE,IAAA,SAAE,GAAE;QACR,IAAI,EAAE,YAAY;QAClB,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACrC,CAAC;IACF,OAAO;QACL,EAAE,EAAE,KAAK,CAAC,EAAE;QACZ,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,MAAM,EAAE,GAAG,EAAE,CAAC,KAAK;KACpB,CAAC;AACJ,CAAC;AAED,SAAgB,iBAAiB,CAAiC,KAEjE;IACC,MAAM,EAAE,GAAW,IAAA,SAAE,GAAE,CAAC;IACxB,MAAM,UAAU,GAAW,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACpD,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,EAAE;QACF,UAAU;QACV,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;YACb,IAAI,EAAE,QAAQ;YACd,EAAE;YACF,UAAU;YACV,SAAS,EAAE,KAAK,CAA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AAI,EAAE,KAAK,CAAC,GAAG,EAAE;YACjB,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;gBACb,IAAI,EAAE,UAAU;gBAChB,EAAE;gBACF,UAAU;gBACV,QAAQ,EAAE,KAAK,CAAC,QAAQ,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,KAMnC;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;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
|
@@ -585,7 +585,8 @@ function createJsonParseErrorEvent(props) {
|
|
|
585
585
|
created_at,
|
|
586
586
|
operation: props.operation,
|
|
587
587
|
arguments: props.arguments,
|
|
588
|
-
errorMessage: props.errorMessage
|
|
588
|
+
errorMessage: props.errorMessage,
|
|
589
|
+
life: props.life
|
|
589
590
|
};
|
|
590
591
|
}
|
|
591
592
|
|
|
@@ -597,12 +598,14 @@ function createValidateEvent(props) {
|
|
|
597
598
|
created_at,
|
|
598
599
|
operation: props.operation,
|
|
599
600
|
result: props.result,
|
|
601
|
+
life: props.life,
|
|
600
602
|
toJSON: () => ({
|
|
601
603
|
type: "validate",
|
|
602
604
|
id: props.id,
|
|
603
605
|
created_at,
|
|
604
606
|
operation: props.operation.toJSON(),
|
|
605
|
-
result: props.result
|
|
607
|
+
result: props.result,
|
|
608
|
+
life: props.life
|
|
606
609
|
})
|
|
607
610
|
};
|
|
608
611
|
}
|
|
@@ -825,6 +828,12 @@ function __get_retry(limit) {
|
|
|
825
828
|
class AssistantMessageEmptyError extends Error {
|
|
826
829
|
constructor() {
|
|
827
830
|
super();
|
|
831
|
+
const proto = new.target.prototype;
|
|
832
|
+
if (Object.setPrototypeOf) {
|
|
833
|
+
Object.setPrototypeOf(this, proto);
|
|
834
|
+
} else {
|
|
835
|
+
this.__proto__ = proto;
|
|
836
|
+
}
|
|
828
837
|
}
|
|
829
838
|
}
|
|
830
839
|
|
|
@@ -1160,12 +1169,12 @@ class MPSC {
|
|
|
1160
1169
|
}
|
|
1161
1170
|
}
|
|
1162
1171
|
|
|
1163
|
-
async function readAll(stream) {
|
|
1172
|
+
async function readAll(stream, abortSignal) {
|
|
1164
1173
|
const reader = stream.getReader();
|
|
1165
1174
|
const result = [];
|
|
1166
1175
|
while (true) {
|
|
1167
1176
|
const {done, value} = await reader.read();
|
|
1168
|
-
if (done) {
|
|
1177
|
+
if (done || abortSignal?.aborted === true) {
|
|
1169
1178
|
break;
|
|
1170
1179
|
}
|
|
1171
1180
|
result.push(value);
|
|
@@ -1173,11 +1182,14 @@ async function readAll(stream) {
|
|
|
1173
1182
|
return result;
|
|
1174
1183
|
}
|
|
1175
1184
|
|
|
1176
|
-
async function reduce(stream, reducer,
|
|
1185
|
+
async function reduce(stream, reducer, options) {
|
|
1177
1186
|
const reader = stream.getReader();
|
|
1178
1187
|
const iterator = streamDefaultReaderToAsyncGenerator(reader);
|
|
1179
|
-
let acc = initial ?? null;
|
|
1188
|
+
let acc = options.initial ?? null;
|
|
1180
1189
|
for await (const value of iterator) {
|
|
1190
|
+
if (options.abortSignal?.aborted === true) {
|
|
1191
|
+
break;
|
|
1192
|
+
}
|
|
1181
1193
|
if (acc === null) {
|
|
1182
1194
|
acc = value;
|
|
1183
1195
|
continue;
|
|
@@ -1201,26 +1213,26 @@ async function* toAsyncGenerator(value) {
|
|
|
1201
1213
|
yield value;
|
|
1202
1214
|
}
|
|
1203
1215
|
|
|
1204
|
-
async function* streamDefaultReaderToAsyncGenerator(reader) {
|
|
1216
|
+
async function* streamDefaultReaderToAsyncGenerator(reader, abortSignal) {
|
|
1205
1217
|
while (true) {
|
|
1206
1218
|
const {done, value} = await reader.read();
|
|
1207
|
-
if (done) {
|
|
1219
|
+
if (done || abortSignal?.aborted === true) {
|
|
1208
1220
|
break;
|
|
1209
1221
|
}
|
|
1210
1222
|
yield value;
|
|
1211
1223
|
}
|
|
1212
1224
|
}
|
|
1213
1225
|
|
|
1214
|
-
function transform(stream, transformer) {
|
|
1226
|
+
function transform(stream, transformer, abortSignal) {
|
|
1215
1227
|
const reader = stream.getReader();
|
|
1216
1228
|
return new ReadableStream({
|
|
1217
1229
|
pull: async controller => {
|
|
1218
1230
|
const {done, value} = await reader.read();
|
|
1219
|
-
if (
|
|
1220
|
-
controller.enqueue(transformer(value));
|
|
1221
|
-
} else {
|
|
1231
|
+
if (done === true || abortSignal?.aborted === true) {
|
|
1222
1232
|
controller.close();
|
|
1233
|
+
return;
|
|
1223
1234
|
}
|
|
1235
|
+
controller.enqueue(transformer(value));
|
|
1224
1236
|
}
|
|
1225
1237
|
});
|
|
1226
1238
|
}
|
|
@@ -1243,7 +1255,7 @@ var index$2 = Object.freeze({
|
|
|
1243
1255
|
toAsyncGenerator
|
|
1244
1256
|
});
|
|
1245
1257
|
|
|
1246
|
-
async function reduceStreamingWithDispatch(stream, eventProcessor) {
|
|
1258
|
+
async function reduceStreamingWithDispatch(stream, eventProcessor, abortSignal) {
|
|
1247
1259
|
const streamContext = new Map;
|
|
1248
1260
|
const nullableCompletion = await StreamUtil.reduce(stream, (async (accPromise, chunk) => {
|
|
1249
1261
|
const acc = await accPromise;
|
|
@@ -1286,7 +1298,9 @@ async function reduceStreamingWithDispatch(stream, eventProcessor) {
|
|
|
1286
1298
|
}
|
|
1287
1299
|
registerContext(chunk.choices);
|
|
1288
1300
|
return ChatGptCompletionMessageUtil.accumulate(acc, chunk);
|
|
1289
|
-
})
|
|
1301
|
+
}), {
|
|
1302
|
+
abortSignal
|
|
1303
|
+
});
|
|
1290
1304
|
if (nullableCompletion == null) {
|
|
1291
1305
|
throw new Error("StreamUtil.reduce did not produce a ChatCompletion. Possible causes: the input stream was empty, invalid, or closed prematurely. " + "To debug: check that the stream is properly initialized and contains valid ChatCompletionChunk data. " + "You may also enable verbose logging upstream to inspect the stream contents. " + `Stream locked: ${stream.locked}.`);
|
|
1292
1306
|
}
|
|
@@ -1335,7 +1349,7 @@ function cancelFunctionFromContext(ctx, reference) {
|
|
|
1335
1349
|
}
|
|
1336
1350
|
|
|
1337
1351
|
async function call(ctx, operations) {
|
|
1338
|
-
const _retryFn = __get_retry(
|
|
1352
|
+
const _retryFn = __get_retry(1);
|
|
1339
1353
|
const retryFn = async fn => _retryFn(fn).catch((e => {
|
|
1340
1354
|
if (e instanceof AssistantMessageEmptyError) {
|
|
1341
1355
|
return Symbol("emptyAssistantMessage");
|
|
@@ -1422,7 +1436,7 @@ async function call(ctx, operations) {
|
|
|
1422
1436
|
}
|
|
1423
1437
|
|
|
1424
1438
|
async function predicate(ctx, operation, toolCall, previousValidationErrors, life) {
|
|
1425
|
-
const call = parseArguments(operation, toolCall);
|
|
1439
|
+
const call = parseArguments(operation, toolCall, life);
|
|
1426
1440
|
await ctx.dispatch(call);
|
|
1427
1441
|
if (call.type === "jsonParseError") {
|
|
1428
1442
|
return correctJsonError(ctx, call, previousValidationErrors, life - 1);
|
|
@@ -1432,7 +1446,8 @@ async function predicate(ctx, operation, toolCall, previousValidationErrors, lif
|
|
|
1432
1446
|
const event = createValidateEvent({
|
|
1433
1447
|
id: toolCall.id,
|
|
1434
1448
|
operation,
|
|
1435
|
-
result: check
|
|
1449
|
+
result: check,
|
|
1450
|
+
life
|
|
1436
1451
|
});
|
|
1437
1452
|
await ctx.dispatch(event);
|
|
1438
1453
|
return correctTypeError(ctx, call, event, [ ...previousValidationErrors, event ], life - 1);
|
|
@@ -1489,7 +1504,7 @@ async function correctJsonError(ctx, parseErrorEvent, previousValidationErrors,
|
|
|
1489
1504
|
});
|
|
1490
1505
|
}
|
|
1491
1506
|
|
|
1492
|
-
function parseArguments(operation, toolCall) {
|
|
1507
|
+
function parseArguments(operation, toolCall, life) {
|
|
1493
1508
|
try {
|
|
1494
1509
|
const data = JSON.parse(toolCall.function.arguments);
|
|
1495
1510
|
return createCallEvent({
|
|
@@ -1502,7 +1517,8 @@ function parseArguments(operation, toolCall) {
|
|
|
1502
1517
|
id: toolCall.id,
|
|
1503
1518
|
operation,
|
|
1504
1519
|
arguments: toolCall.function.arguments,
|
|
1505
|
-
errorMessage: error instanceof Error ? error.message : String(error)
|
|
1520
|
+
errorMessage: error instanceof Error ? error.message : String(error),
|
|
1521
|
+
life
|
|
1506
1522
|
});
|
|
1507
1523
|
}
|
|
1508
1524
|
}
|
|
@@ -1799,7 +1815,7 @@ async function step$1(ctx, operations, retry, failures) {
|
|
|
1799
1815
|
} ],
|
|
1800
1816
|
tool_choice: retry === 0 ? "auto" : "required"
|
|
1801
1817
|
});
|
|
1802
|
-
const chunks = await StreamUtil.readAll(completionStream);
|
|
1818
|
+
const chunks = await StreamUtil.readAll(completionStream, ctx.abortSignal);
|
|
1803
1819
|
const completion = ChatGptCompletionMessageUtil.merge(chunks);
|
|
1804
1820
|
if (retry++ < (ctx.config?.retry ?? AgenticaConstant.RETRY)) {
|
|
1805
1821
|
const failures = [];
|
|
@@ -1951,7 +1967,7 @@ async function describe(ctx, histories) {
|
|
|
1951
1967
|
...props
|
|
1952
1968
|
});
|
|
1953
1969
|
ctx.dispatch(event);
|
|
1954
|
-
}));
|
|
1970
|
+
}), ctx.abortSignal);
|
|
1955
1971
|
}
|
|
1956
1972
|
|
|
1957
1973
|
const ChatGptDescribeFunctionAgent = {
|
|
@@ -2618,7 +2634,7 @@ async function initialize(ctx) {
|
|
|
2618
2634
|
const completion = await reduceStreamingWithDispatch(completionStream, (props => {
|
|
2619
2635
|
const event = createAssistantMessageEvent(props);
|
|
2620
2636
|
ctx.dispatch(event);
|
|
2621
|
-
}));
|
|
2637
|
+
}), ctx.abortSignal);
|
|
2622
2638
|
if (completion === null) {
|
|
2623
2639
|
throw new Error("No completion received");
|
|
2624
2640
|
}
|
|
@@ -2766,7 +2782,7 @@ async function select(ctx) {
|
|
|
2766
2782
|
}
|
|
2767
2783
|
|
|
2768
2784
|
async function step(ctx, operations, retry, failures) {
|
|
2769
|
-
const _retryFn = __get_retry(
|
|
2785
|
+
const _retryFn = __get_retry(1);
|
|
2770
2786
|
const retryFn = async fn => _retryFn(fn).catch((e => {
|
|
2771
2787
|
if (e instanceof AssistantMessageEmptyError) {
|
|
2772
2788
|
return Symbol("emptyAssistantMessage");
|
|
@@ -2823,7 +2839,7 @@ async function step(ctx, operations, retry, failures) {
|
|
|
2823
2839
|
const completion = await reduceStreamingWithDispatch(stream, (props => {
|
|
2824
2840
|
const event = createAssistantMessageEvent(props);
|
|
2825
2841
|
void ctx.dispatch(event).catch((() => {}));
|
|
2826
|
-
}));
|
|
2842
|
+
}), ctx.abortSignal);
|
|
2827
2843
|
const allAssistantMessagesEmpty = completion.choices.every((v => v.message.tool_calls == null && v.message.content === ""));
|
|
2828
2844
|
if (allAssistantMessagesEmpty) {
|
|
2829
2845
|
const firstChoice = completion.choices.at(0);
|
|
@@ -3176,13 +3192,13 @@ const getChatCompletionWithStreamingFunction = props => async (source, body) =>
|
|
|
3176
3192
|
}
|
|
3177
3193
|
}
|
|
3178
3194
|
})();
|
|
3179
|
-
const [streamForEvent, temporaryStream] = StreamUtil.transform(completion.toReadableStream(), (value => ChatGptCompletionMessageUtil.transformCompletionChunk(value))).tee();
|
|
3195
|
+
const [streamForEvent, temporaryStream] = StreamUtil.transform(completion.toReadableStream(), (value => ChatGptCompletionMessageUtil.transformCompletionChunk(value)), props.abortSignal).tee();
|
|
3180
3196
|
const [streamForAggregate, streamForReturn] = temporaryStream.tee();
|
|
3181
3197
|
(async () => {
|
|
3182
3198
|
const reader = streamForAggregate.getReader();
|
|
3183
3199
|
while (true) {
|
|
3184
3200
|
const chunk = await reader.read();
|
|
3185
|
-
if (chunk.done) {
|
|
3201
|
+
if (chunk.done || props.abortSignal?.aborted === true) {
|
|
3186
3202
|
break;
|
|
3187
3203
|
}
|
|
3188
3204
|
if (chunk.value.usage != null) {
|
|
@@ -3199,11 +3215,11 @@ const getChatCompletionWithStreamingFunction = props => async (source, body) =>
|
|
|
3199
3215
|
id: v4(),
|
|
3200
3216
|
type: "response",
|
|
3201
3217
|
source,
|
|
3202
|
-
stream: streamDefaultReaderToAsyncGenerator(streamForStream.getReader()),
|
|
3218
|
+
stream: streamDefaultReaderToAsyncGenerator(streamForStream.getReader(), props.abortSignal),
|
|
3203
3219
|
body: event.body,
|
|
3204
3220
|
options: event.options,
|
|
3205
3221
|
join: async () => {
|
|
3206
|
-
const chunks = await StreamUtil.readAll(streamForJoin);
|
|
3222
|
+
const chunks = await StreamUtil.readAll(streamForJoin, props.abortSignal);
|
|
3207
3223
|
return ChatGptCompletionMessageUtil.merge(chunks);
|
|
3208
3224
|
},
|
|
3209
3225
|
created_at: (new Date).toISOString()
|