agentv 0.6.1 → 0.7.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/dist/{chunk-GURDWEMI.js → chunk-X6NSDSD2.js} +352 -2861
- package/dist/chunk-X6NSDSD2.js.map +1 -0
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-GURDWEMI.js.map +0 -1
|
@@ -590,7 +590,7 @@ import fg from "fast-glob";
|
|
|
590
590
|
import { stat as stat3 } from "node:fs/promises";
|
|
591
591
|
import path14 from "node:path";
|
|
592
592
|
|
|
593
|
-
// ../../packages/core/dist/chunk-
|
|
593
|
+
// ../../packages/core/dist/chunk-L7I5UTJU.js
|
|
594
594
|
import { constants } from "node:fs";
|
|
595
595
|
import { access, readFile } from "node:fs/promises";
|
|
596
596
|
import path from "node:path";
|
|
@@ -852,9 +852,9 @@ function unregisterGlobal(type, diag) {
|
|
|
852
852
|
var __read = function(o, n) {
|
|
853
853
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
854
854
|
if (!m) return o;
|
|
855
|
-
var i6 = m.call(o), r,
|
|
855
|
+
var i6 = m.call(o), r, ar = [], e;
|
|
856
856
|
try {
|
|
857
|
-
while ((n === void 0 || n-- > 0) && !(r = i6.next()).done)
|
|
857
|
+
while ((n === void 0 || n-- > 0) && !(r = i6.next()).done) ar.push(r.value);
|
|
858
858
|
} catch (error) {
|
|
859
859
|
e = { error };
|
|
860
860
|
} finally {
|
|
@@ -864,16 +864,16 @@ var __read = function(o, n) {
|
|
|
864
864
|
if (e) throw e.error;
|
|
865
865
|
}
|
|
866
866
|
}
|
|
867
|
-
return
|
|
867
|
+
return ar;
|
|
868
868
|
};
|
|
869
869
|
var __spreadArray = function(to, from, pack) {
|
|
870
|
-
if (pack || arguments.length === 2) for (var i6 = 0, l = from.length,
|
|
871
|
-
if (
|
|
872
|
-
if (!
|
|
873
|
-
|
|
870
|
+
if (pack || arguments.length === 2) for (var i6 = 0, l = from.length, ar; i6 < l; i6++) {
|
|
871
|
+
if (ar || !(i6 in from)) {
|
|
872
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i6);
|
|
873
|
+
ar[i6] = from[i6];
|
|
874
874
|
}
|
|
875
875
|
}
|
|
876
|
-
return to.concat(
|
|
876
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
877
877
|
};
|
|
878
878
|
var DiagComponentLogger = (
|
|
879
879
|
/** @class */
|
|
@@ -883,36 +883,36 @@ var DiagComponentLogger = (
|
|
|
883
883
|
}
|
|
884
884
|
DiagComponentLogger2.prototype.debug = function() {
|
|
885
885
|
var args = [];
|
|
886
|
-
for (var
|
|
887
|
-
args[
|
|
886
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
887
|
+
args[_i] = arguments[_i];
|
|
888
888
|
}
|
|
889
889
|
return logProxy("debug", this._namespace, args);
|
|
890
890
|
};
|
|
891
891
|
DiagComponentLogger2.prototype.error = function() {
|
|
892
892
|
var args = [];
|
|
893
|
-
for (var
|
|
894
|
-
args[
|
|
893
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
894
|
+
args[_i] = arguments[_i];
|
|
895
895
|
}
|
|
896
896
|
return logProxy("error", this._namespace, args);
|
|
897
897
|
};
|
|
898
898
|
DiagComponentLogger2.prototype.info = function() {
|
|
899
899
|
var args = [];
|
|
900
|
-
for (var
|
|
901
|
-
args[
|
|
900
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
901
|
+
args[_i] = arguments[_i];
|
|
902
902
|
}
|
|
903
903
|
return logProxy("info", this._namespace, args);
|
|
904
904
|
};
|
|
905
905
|
DiagComponentLogger2.prototype.warn = function() {
|
|
906
906
|
var args = [];
|
|
907
|
-
for (var
|
|
908
|
-
args[
|
|
907
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
908
|
+
args[_i] = arguments[_i];
|
|
909
909
|
}
|
|
910
910
|
return logProxy("warn", this._namespace, args);
|
|
911
911
|
};
|
|
912
912
|
DiagComponentLogger2.prototype.verbose = function() {
|
|
913
913
|
var args = [];
|
|
914
|
-
for (var
|
|
915
|
-
args[
|
|
914
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
915
|
+
args[_i] = arguments[_i];
|
|
916
916
|
}
|
|
917
917
|
return logProxy("verbose", this._namespace, args);
|
|
918
918
|
};
|
|
@@ -969,9 +969,9 @@ function createLogLevelDiagLogger(maxLevel, logger) {
|
|
|
969
969
|
var __read2 = function(o, n) {
|
|
970
970
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
971
971
|
if (!m) return o;
|
|
972
|
-
var i6 = m.call(o), r,
|
|
972
|
+
var i6 = m.call(o), r, ar = [], e;
|
|
973
973
|
try {
|
|
974
|
-
while ((n === void 0 || n-- > 0) && !(r = i6.next()).done)
|
|
974
|
+
while ((n === void 0 || n-- > 0) && !(r = i6.next()).done) ar.push(r.value);
|
|
975
975
|
} catch (error) {
|
|
976
976
|
e = { error };
|
|
977
977
|
} finally {
|
|
@@ -981,16 +981,16 @@ var __read2 = function(o, n) {
|
|
|
981
981
|
if (e) throw e.error;
|
|
982
982
|
}
|
|
983
983
|
}
|
|
984
|
-
return
|
|
984
|
+
return ar;
|
|
985
985
|
};
|
|
986
986
|
var __spreadArray2 = function(to, from, pack) {
|
|
987
|
-
if (pack || arguments.length === 2) for (var i6 = 0, l = from.length,
|
|
988
|
-
if (
|
|
989
|
-
if (!
|
|
990
|
-
|
|
987
|
+
if (pack || arguments.length === 2) for (var i6 = 0, l = from.length, ar; i6 < l; i6++) {
|
|
988
|
+
if (ar || !(i6 in from)) {
|
|
989
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i6);
|
|
990
|
+
ar[i6] = from[i6];
|
|
991
991
|
}
|
|
992
992
|
}
|
|
993
|
-
return to.concat(
|
|
993
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
994
994
|
};
|
|
995
995
|
var API_NAME = "diag";
|
|
996
996
|
var DiagAPI = (
|
|
@@ -1000,8 +1000,8 @@ var DiagAPI = (
|
|
|
1000
1000
|
function _logProxy(funcName) {
|
|
1001
1001
|
return function() {
|
|
1002
1002
|
var args = [];
|
|
1003
|
-
for (var
|
|
1004
|
-
args[
|
|
1003
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1004
|
+
args[_i] = arguments[_i];
|
|
1005
1005
|
}
|
|
1006
1006
|
var logger = getGlobal("diag");
|
|
1007
1007
|
if (!logger)
|
|
@@ -1058,9 +1058,6 @@ var DiagAPI = (
|
|
|
1058
1058
|
);
|
|
1059
1059
|
|
|
1060
1060
|
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/context/context.js
|
|
1061
|
-
function createContextKey(description) {
|
|
1062
|
-
return Symbol.for(description);
|
|
1063
|
-
}
|
|
1064
1061
|
var BaseContext = (
|
|
1065
1062
|
/** @class */
|
|
1066
1063
|
/* @__PURE__ */ function() {
|
|
@@ -1090,9 +1087,9 @@ var ROOT_CONTEXT = new BaseContext();
|
|
|
1090
1087
|
var __read3 = function(o, n) {
|
|
1091
1088
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
1092
1089
|
if (!m) return o;
|
|
1093
|
-
var i6 = m.call(o), r,
|
|
1090
|
+
var i6 = m.call(o), r, ar = [], e;
|
|
1094
1091
|
try {
|
|
1095
|
-
while ((n === void 0 || n-- > 0) && !(r = i6.next()).done)
|
|
1092
|
+
while ((n === void 0 || n-- > 0) && !(r = i6.next()).done) ar.push(r.value);
|
|
1096
1093
|
} catch (error) {
|
|
1097
1094
|
e = { error };
|
|
1098
1095
|
} finally {
|
|
@@ -1102,16 +1099,16 @@ var __read3 = function(o, n) {
|
|
|
1102
1099
|
if (e) throw e.error;
|
|
1103
1100
|
}
|
|
1104
1101
|
}
|
|
1105
|
-
return
|
|
1102
|
+
return ar;
|
|
1106
1103
|
};
|
|
1107
1104
|
var __spreadArray3 = function(to, from, pack) {
|
|
1108
|
-
if (pack || arguments.length === 2) for (var i6 = 0, l = from.length,
|
|
1109
|
-
if (
|
|
1110
|
-
if (!
|
|
1111
|
-
|
|
1105
|
+
if (pack || arguments.length === 2) for (var i6 = 0, l = from.length, ar; i6 < l; i6++) {
|
|
1106
|
+
if (ar || !(i6 in from)) {
|
|
1107
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i6);
|
|
1108
|
+
ar[i6] = from[i6];
|
|
1112
1109
|
}
|
|
1113
1110
|
}
|
|
1114
|
-
return to.concat(
|
|
1111
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
1115
1112
|
};
|
|
1116
1113
|
var NoopContextManager = (
|
|
1117
1114
|
/** @class */
|
|
@@ -1123,8 +1120,8 @@ var NoopContextManager = (
|
|
|
1123
1120
|
};
|
|
1124
1121
|
NoopContextManager2.prototype.with = function(_context, fn, thisArg) {
|
|
1125
1122
|
var args = [];
|
|
1126
|
-
for (var
|
|
1127
|
-
args[
|
|
1123
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
|
1124
|
+
args[_i - 3] = arguments[_i];
|
|
1128
1125
|
}
|
|
1129
1126
|
return fn.call.apply(fn, __spreadArray3([thisArg], __read3(args), false));
|
|
1130
1127
|
};
|
|
@@ -1145,9 +1142,9 @@ var NoopContextManager = (
|
|
|
1145
1142
|
var __read4 = function(o, n) {
|
|
1146
1143
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
1147
1144
|
if (!m) return o;
|
|
1148
|
-
var i6 = m.call(o), r,
|
|
1145
|
+
var i6 = m.call(o), r, ar = [], e;
|
|
1149
1146
|
try {
|
|
1150
|
-
while ((n === void 0 || n-- > 0) && !(r = i6.next()).done)
|
|
1147
|
+
while ((n === void 0 || n-- > 0) && !(r = i6.next()).done) ar.push(r.value);
|
|
1151
1148
|
} catch (error) {
|
|
1152
1149
|
e = { error };
|
|
1153
1150
|
} finally {
|
|
@@ -1157,16 +1154,16 @@ var __read4 = function(o, n) {
|
|
|
1157
1154
|
if (e) throw e.error;
|
|
1158
1155
|
}
|
|
1159
1156
|
}
|
|
1160
|
-
return
|
|
1157
|
+
return ar;
|
|
1161
1158
|
};
|
|
1162
1159
|
var __spreadArray4 = function(to, from, pack) {
|
|
1163
|
-
if (pack || arguments.length === 2) for (var i6 = 0, l = from.length,
|
|
1164
|
-
if (
|
|
1165
|
-
if (!
|
|
1166
|
-
|
|
1160
|
+
if (pack || arguments.length === 2) for (var i6 = 0, l = from.length, ar; i6 < l; i6++) {
|
|
1161
|
+
if (ar || !(i6 in from)) {
|
|
1162
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i6);
|
|
1163
|
+
ar[i6] = from[i6];
|
|
1167
1164
|
}
|
|
1168
1165
|
}
|
|
1169
|
-
return to.concat(
|
|
1166
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
1170
1167
|
};
|
|
1171
1168
|
var API_NAME2 = "context";
|
|
1172
1169
|
var NOOP_CONTEXT_MANAGER = new NoopContextManager();
|
|
@@ -1190,8 +1187,8 @@ var ContextAPI = (
|
|
|
1190
1187
|
ContextAPI2.prototype.with = function(context2, fn, thisArg) {
|
|
1191
1188
|
var _a;
|
|
1192
1189
|
var args = [];
|
|
1193
|
-
for (var
|
|
1194
|
-
args[
|
|
1190
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
|
1191
|
+
args[_i - 3] = arguments[_i];
|
|
1195
1192
|
}
|
|
1196
1193
|
return (_a = this._getContextManager()).with.apply(_a, __spreadArray4([context2, fn, thisArg], __read4(args), false));
|
|
1197
1194
|
};
|
|
@@ -1209,227 +1206,6 @@ var ContextAPI = (
|
|
|
1209
1206
|
}()
|
|
1210
1207
|
);
|
|
1211
1208
|
|
|
1212
|
-
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/trace/trace_flags.js
|
|
1213
|
-
var TraceFlags;
|
|
1214
|
-
(function(TraceFlags2) {
|
|
1215
|
-
TraceFlags2[TraceFlags2["NONE"] = 0] = "NONE";
|
|
1216
|
-
TraceFlags2[TraceFlags2["SAMPLED"] = 1] = "SAMPLED";
|
|
1217
|
-
})(TraceFlags || (TraceFlags = {}));
|
|
1218
|
-
|
|
1219
|
-
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/trace/invalid-span-constants.js
|
|
1220
|
-
var INVALID_SPANID = "0000000000000000";
|
|
1221
|
-
var INVALID_TRACEID = "00000000000000000000000000000000";
|
|
1222
|
-
var INVALID_SPAN_CONTEXT = {
|
|
1223
|
-
traceId: INVALID_TRACEID,
|
|
1224
|
-
spanId: INVALID_SPANID,
|
|
1225
|
-
traceFlags: TraceFlags.NONE
|
|
1226
|
-
};
|
|
1227
|
-
|
|
1228
|
-
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/trace/NonRecordingSpan.js
|
|
1229
|
-
var NonRecordingSpan = (
|
|
1230
|
-
/** @class */
|
|
1231
|
-
function() {
|
|
1232
|
-
function NonRecordingSpan2(_spanContext) {
|
|
1233
|
-
if (_spanContext === void 0) {
|
|
1234
|
-
_spanContext = INVALID_SPAN_CONTEXT;
|
|
1235
|
-
}
|
|
1236
|
-
this._spanContext = _spanContext;
|
|
1237
|
-
}
|
|
1238
|
-
NonRecordingSpan2.prototype.spanContext = function() {
|
|
1239
|
-
return this._spanContext;
|
|
1240
|
-
};
|
|
1241
|
-
NonRecordingSpan2.prototype.setAttribute = function(_key, _value) {
|
|
1242
|
-
return this;
|
|
1243
|
-
};
|
|
1244
|
-
NonRecordingSpan2.prototype.setAttributes = function(_attributes) {
|
|
1245
|
-
return this;
|
|
1246
|
-
};
|
|
1247
|
-
NonRecordingSpan2.prototype.addEvent = function(_name, _attributes) {
|
|
1248
|
-
return this;
|
|
1249
|
-
};
|
|
1250
|
-
NonRecordingSpan2.prototype.addLink = function(_link) {
|
|
1251
|
-
return this;
|
|
1252
|
-
};
|
|
1253
|
-
NonRecordingSpan2.prototype.addLinks = function(_links) {
|
|
1254
|
-
return this;
|
|
1255
|
-
};
|
|
1256
|
-
NonRecordingSpan2.prototype.setStatus = function(_status) {
|
|
1257
|
-
return this;
|
|
1258
|
-
};
|
|
1259
|
-
NonRecordingSpan2.prototype.updateName = function(_name) {
|
|
1260
|
-
return this;
|
|
1261
|
-
};
|
|
1262
|
-
NonRecordingSpan2.prototype.end = function(_endTime) {
|
|
1263
|
-
};
|
|
1264
|
-
NonRecordingSpan2.prototype.isRecording = function() {
|
|
1265
|
-
return false;
|
|
1266
|
-
};
|
|
1267
|
-
NonRecordingSpan2.prototype.recordException = function(_exception, _time) {
|
|
1268
|
-
};
|
|
1269
|
-
return NonRecordingSpan2;
|
|
1270
|
-
}()
|
|
1271
|
-
);
|
|
1272
|
-
|
|
1273
|
-
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/trace/context-utils.js
|
|
1274
|
-
var SPAN_KEY = createContextKey("OpenTelemetry Context Key SPAN");
|
|
1275
|
-
function getSpan(context2) {
|
|
1276
|
-
return context2.getValue(SPAN_KEY) || void 0;
|
|
1277
|
-
}
|
|
1278
|
-
function getActiveSpan() {
|
|
1279
|
-
return getSpan(ContextAPI.getInstance().active());
|
|
1280
|
-
}
|
|
1281
|
-
function setSpan(context2, span) {
|
|
1282
|
-
return context2.setValue(SPAN_KEY, span);
|
|
1283
|
-
}
|
|
1284
|
-
function deleteSpan(context2) {
|
|
1285
|
-
return context2.deleteValue(SPAN_KEY);
|
|
1286
|
-
}
|
|
1287
|
-
function setSpanContext(context2, spanContext) {
|
|
1288
|
-
return setSpan(context2, new NonRecordingSpan(spanContext));
|
|
1289
|
-
}
|
|
1290
|
-
function getSpanContext(context2) {
|
|
1291
|
-
var _a;
|
|
1292
|
-
return (_a = getSpan(context2)) === null || _a === void 0 ? void 0 : _a.spanContext();
|
|
1293
|
-
}
|
|
1294
|
-
|
|
1295
|
-
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/trace/spancontext-utils.js
|
|
1296
|
-
var VALID_TRACEID_REGEX = /^([0-9a-f]{32})$/i;
|
|
1297
|
-
var VALID_SPANID_REGEX = /^[0-9a-f]{16}$/i;
|
|
1298
|
-
function isValidTraceId(traceId) {
|
|
1299
|
-
return VALID_TRACEID_REGEX.test(traceId) && traceId !== INVALID_TRACEID;
|
|
1300
|
-
}
|
|
1301
|
-
function isValidSpanId(spanId) {
|
|
1302
|
-
return VALID_SPANID_REGEX.test(spanId) && spanId !== INVALID_SPANID;
|
|
1303
|
-
}
|
|
1304
|
-
function isSpanContextValid(spanContext) {
|
|
1305
|
-
return isValidTraceId(spanContext.traceId) && isValidSpanId(spanContext.spanId);
|
|
1306
|
-
}
|
|
1307
|
-
function wrapSpanContext(spanContext) {
|
|
1308
|
-
return new NonRecordingSpan(spanContext);
|
|
1309
|
-
}
|
|
1310
|
-
|
|
1311
|
-
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/trace/NoopTracer.js
|
|
1312
|
-
var contextApi = ContextAPI.getInstance();
|
|
1313
|
-
var NoopTracer = (
|
|
1314
|
-
/** @class */
|
|
1315
|
-
function() {
|
|
1316
|
-
function NoopTracer2() {
|
|
1317
|
-
}
|
|
1318
|
-
NoopTracer2.prototype.startSpan = function(name, options, context2) {
|
|
1319
|
-
if (context2 === void 0) {
|
|
1320
|
-
context2 = contextApi.active();
|
|
1321
|
-
}
|
|
1322
|
-
var root2 = Boolean(options === null || options === void 0 ? void 0 : options.root);
|
|
1323
|
-
if (root2) {
|
|
1324
|
-
return new NonRecordingSpan();
|
|
1325
|
-
}
|
|
1326
|
-
var parentFromContext = context2 && getSpanContext(context2);
|
|
1327
|
-
if (isSpanContext(parentFromContext) && isSpanContextValid(parentFromContext)) {
|
|
1328
|
-
return new NonRecordingSpan(parentFromContext);
|
|
1329
|
-
} else {
|
|
1330
|
-
return new NonRecordingSpan();
|
|
1331
|
-
}
|
|
1332
|
-
};
|
|
1333
|
-
NoopTracer2.prototype.startActiveSpan = function(name, arg2, arg3, arg4) {
|
|
1334
|
-
var opts;
|
|
1335
|
-
var ctx;
|
|
1336
|
-
var fn;
|
|
1337
|
-
if (arguments.length < 2) {
|
|
1338
|
-
return;
|
|
1339
|
-
} else if (arguments.length === 2) {
|
|
1340
|
-
fn = arg2;
|
|
1341
|
-
} else if (arguments.length === 3) {
|
|
1342
|
-
opts = arg2;
|
|
1343
|
-
fn = arg3;
|
|
1344
|
-
} else {
|
|
1345
|
-
opts = arg2;
|
|
1346
|
-
ctx = arg3;
|
|
1347
|
-
fn = arg4;
|
|
1348
|
-
}
|
|
1349
|
-
var parentContext = ctx !== null && ctx !== void 0 ? ctx : contextApi.active();
|
|
1350
|
-
var span = this.startSpan(name, opts, parentContext);
|
|
1351
|
-
var contextWithSpanSet = setSpan(parentContext, span);
|
|
1352
|
-
return contextApi.with(contextWithSpanSet, fn, void 0, span);
|
|
1353
|
-
};
|
|
1354
|
-
return NoopTracer2;
|
|
1355
|
-
}()
|
|
1356
|
-
);
|
|
1357
|
-
function isSpanContext(spanContext) {
|
|
1358
|
-
return typeof spanContext === "object" && typeof spanContext["spanId"] === "string" && typeof spanContext["traceId"] === "string" && typeof spanContext["traceFlags"] === "number";
|
|
1359
|
-
}
|
|
1360
|
-
|
|
1361
|
-
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/trace/ProxyTracer.js
|
|
1362
|
-
var NOOP_TRACER = new NoopTracer();
|
|
1363
|
-
var ProxyTracer = (
|
|
1364
|
-
/** @class */
|
|
1365
|
-
function() {
|
|
1366
|
-
function ProxyTracer2(_provider, name, version, options) {
|
|
1367
|
-
this._provider = _provider;
|
|
1368
|
-
this.name = name;
|
|
1369
|
-
this.version = version;
|
|
1370
|
-
this.options = options;
|
|
1371
|
-
}
|
|
1372
|
-
ProxyTracer2.prototype.startSpan = function(name, options, context2) {
|
|
1373
|
-
return this._getTracer().startSpan(name, options, context2);
|
|
1374
|
-
};
|
|
1375
|
-
ProxyTracer2.prototype.startActiveSpan = function(_name, _options, _context, _fn) {
|
|
1376
|
-
var tracer = this._getTracer();
|
|
1377
|
-
return Reflect.apply(tracer.startActiveSpan, tracer, arguments);
|
|
1378
|
-
};
|
|
1379
|
-
ProxyTracer2.prototype._getTracer = function() {
|
|
1380
|
-
if (this._delegate) {
|
|
1381
|
-
return this._delegate;
|
|
1382
|
-
}
|
|
1383
|
-
var tracer = this._provider.getDelegateTracer(this.name, this.version, this.options);
|
|
1384
|
-
if (!tracer) {
|
|
1385
|
-
return NOOP_TRACER;
|
|
1386
|
-
}
|
|
1387
|
-
this._delegate = tracer;
|
|
1388
|
-
return this._delegate;
|
|
1389
|
-
};
|
|
1390
|
-
return ProxyTracer2;
|
|
1391
|
-
}()
|
|
1392
|
-
);
|
|
1393
|
-
|
|
1394
|
-
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/trace/NoopTracerProvider.js
|
|
1395
|
-
var NoopTracerProvider = (
|
|
1396
|
-
/** @class */
|
|
1397
|
-
function() {
|
|
1398
|
-
function NoopTracerProvider2() {
|
|
1399
|
-
}
|
|
1400
|
-
NoopTracerProvider2.prototype.getTracer = function(_name, _version, _options) {
|
|
1401
|
-
return new NoopTracer();
|
|
1402
|
-
};
|
|
1403
|
-
return NoopTracerProvider2;
|
|
1404
|
-
}()
|
|
1405
|
-
);
|
|
1406
|
-
|
|
1407
|
-
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/trace/ProxyTracerProvider.js
|
|
1408
|
-
var NOOP_TRACER_PROVIDER = new NoopTracerProvider();
|
|
1409
|
-
var ProxyTracerProvider = (
|
|
1410
|
-
/** @class */
|
|
1411
|
-
function() {
|
|
1412
|
-
function ProxyTracerProvider2() {
|
|
1413
|
-
}
|
|
1414
|
-
ProxyTracerProvider2.prototype.getTracer = function(name, version, options) {
|
|
1415
|
-
var _a;
|
|
1416
|
-
return (_a = this.getDelegateTracer(name, version, options)) !== null && _a !== void 0 ? _a : new ProxyTracer(this, name, version, options);
|
|
1417
|
-
};
|
|
1418
|
-
ProxyTracerProvider2.prototype.getDelegate = function() {
|
|
1419
|
-
var _a;
|
|
1420
|
-
return (_a = this._delegate) !== null && _a !== void 0 ? _a : NOOP_TRACER_PROVIDER;
|
|
1421
|
-
};
|
|
1422
|
-
ProxyTracerProvider2.prototype.setDelegate = function(delegate) {
|
|
1423
|
-
this._delegate = delegate;
|
|
1424
|
-
};
|
|
1425
|
-
ProxyTracerProvider2.prototype.getDelegateTracer = function(name, version, options) {
|
|
1426
|
-
var _a;
|
|
1427
|
-
return (_a = this._delegate) === null || _a === void 0 ? void 0 : _a.getTracer(name, version, options);
|
|
1428
|
-
};
|
|
1429
|
-
return ProxyTracerProvider2;
|
|
1430
|
-
}()
|
|
1431
|
-
);
|
|
1432
|
-
|
|
1433
1209
|
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/trace/span_kind.js
|
|
1434
1210
|
var SpanKind;
|
|
1435
1211
|
(function(SpanKind2) {
|
|
@@ -1443,52 +1219,6 @@ var SpanKind;
|
|
|
1443
1219
|
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/context-api.js
|
|
1444
1220
|
var context = ContextAPI.getInstance();
|
|
1445
1221
|
|
|
1446
|
-
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/api/trace.js
|
|
1447
|
-
var API_NAME3 = "trace";
|
|
1448
|
-
var TraceAPI = (
|
|
1449
|
-
/** @class */
|
|
1450
|
-
function() {
|
|
1451
|
-
function TraceAPI2() {
|
|
1452
|
-
this._proxyTracerProvider = new ProxyTracerProvider();
|
|
1453
|
-
this.wrapSpanContext = wrapSpanContext;
|
|
1454
|
-
this.isSpanContextValid = isSpanContextValid;
|
|
1455
|
-
this.deleteSpan = deleteSpan;
|
|
1456
|
-
this.getSpan = getSpan;
|
|
1457
|
-
this.getActiveSpan = getActiveSpan;
|
|
1458
|
-
this.getSpanContext = getSpanContext;
|
|
1459
|
-
this.setSpan = setSpan;
|
|
1460
|
-
this.setSpanContext = setSpanContext;
|
|
1461
|
-
}
|
|
1462
|
-
TraceAPI2.getInstance = function() {
|
|
1463
|
-
if (!this._instance) {
|
|
1464
|
-
this._instance = new TraceAPI2();
|
|
1465
|
-
}
|
|
1466
|
-
return this._instance;
|
|
1467
|
-
};
|
|
1468
|
-
TraceAPI2.prototype.setGlobalTracerProvider = function(provider) {
|
|
1469
|
-
var success = registerGlobal(API_NAME3, this._proxyTracerProvider, DiagAPI.instance());
|
|
1470
|
-
if (success) {
|
|
1471
|
-
this._proxyTracerProvider.setDelegate(provider);
|
|
1472
|
-
}
|
|
1473
|
-
return success;
|
|
1474
|
-
};
|
|
1475
|
-
TraceAPI2.prototype.getTracerProvider = function() {
|
|
1476
|
-
return getGlobal(API_NAME3) || this._proxyTracerProvider;
|
|
1477
|
-
};
|
|
1478
|
-
TraceAPI2.prototype.getTracer = function(name, version) {
|
|
1479
|
-
return this.getTracerProvider().getTracer(name, version);
|
|
1480
|
-
};
|
|
1481
|
-
TraceAPI2.prototype.disable = function() {
|
|
1482
|
-
unregisterGlobal(API_NAME3, DiagAPI.instance());
|
|
1483
|
-
this._proxyTracerProvider = new ProxyTracerProvider();
|
|
1484
|
-
};
|
|
1485
|
-
return TraceAPI2;
|
|
1486
|
-
}()
|
|
1487
|
-
);
|
|
1488
|
-
|
|
1489
|
-
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/trace-api.js
|
|
1490
|
-
var trace = TraceAPI.getInstance();
|
|
1491
|
-
|
|
1492
1222
|
// ../../node_modules/.pnpm/@ax-llm+ax@15.0.2/node_modules/@ax-llm/ax/index.js
|
|
1493
1223
|
var import_dayjs = __toESM(require_dayjs_min(), 1);
|
|
1494
1224
|
var import_customParseFormat = __toESM(require_customParseFormat(), 1);
|
|
@@ -2205,21 +1935,6 @@ function $s(i6, e) {
|
|
|
2205
1935
|
e(r);
|
|
2206
1936
|
}
|
|
2207
1937
|
}
|
|
2208
|
-
var Ls = (i6, e) => {
|
|
2209
|
-
e({ name: "FunctionResults", value: i6 });
|
|
2210
|
-
};
|
|
2211
|
-
var Br = (i6, e, t, n) => {
|
|
2212
|
-
n({ name: "FunctionError", index: e, fixingInstructions: t, error: i6 });
|
|
2213
|
-
};
|
|
2214
|
-
var Gs = (i6, e, t, n) => {
|
|
2215
|
-
n({ name: "ValidationError", index: e, fixingInstructions: t, error: i6 });
|
|
2216
|
-
};
|
|
2217
|
-
var Us = (i6, e, t, n) => {
|
|
2218
|
-
n({ name: "AssertionError", index: e, fixingInstructions: t, error: i6 });
|
|
2219
|
-
};
|
|
2220
|
-
var Bs = (i6, e, t) => {
|
|
2221
|
-
t({ name: "RefusalError", index: e, error: i6 });
|
|
2222
|
-
};
|
|
2223
1938
|
var js = (i6, e, t) => {
|
|
2224
1939
|
t({ name: "EmbedRequest", embedModel: e, value: i6 });
|
|
2225
1940
|
};
|
|
@@ -2227,9 +1942,6 @@ var qs = (i6, e) => {
|
|
|
2227
1942
|
let t = i6.slice(0, 3).map((r) => ({ length: r.length, sample: r.slice(0, 5), truncated: r.length > 5 })), n = { name: "EmbedResponse", totalEmbeddings: i6.length, value: t };
|
|
2228
1943
|
e(n);
|
|
2229
1944
|
};
|
|
2230
|
-
var zs = (i6, e, t, n) => {
|
|
2231
|
-
n({ name: "ResultPickerUsed", sampleCount: i6, selectedIndex: e, latency: t });
|
|
2232
|
-
};
|
|
2233
1945
|
var jr = (i6) => {
|
|
2234
1946
|
let e = {};
|
|
2235
1947
|
for (let [t, n] of Object.entries(i6)) if (n != null) {
|
|
@@ -2428,60 +2140,6 @@ function Nt(i6) {
|
|
|
2428
2140
|
throw new Error(`Unsupported message role: ${e(t)}`);
|
|
2429
2141
|
}
|
|
2430
2142
|
}
|
|
2431
|
-
function Kr(i6) {
|
|
2432
|
-
let e = (n) => JSON.stringify(n, null, 2), t = Array.isArray(i6) ? i6 : [i6];
|
|
2433
|
-
if (t.length === 0) throw new Error(`Chat response results cannot be empty, received: ${e(t)}`);
|
|
2434
|
-
for (let n = 0; n < t.length; n++) {
|
|
2435
|
-
let r = t[n];
|
|
2436
|
-
if (!r) throw new Error(`Chat response result at index ${n} cannot be null or undefined, received: ${e(r)}`);
|
|
2437
|
-
if (typeof r.index != "number") throw new Error(`Chat response result at index ${n} must have a numeric index, received: ${e(r.index)}`);
|
|
2438
|
-
if (r.index < 0) throw new Error(`Chat response result at index ${n} must have a non-negative index, received: ${e(r.index)}`);
|
|
2439
|
-
if (!r.content && !r.thought && !r.thoughtBlock && !r.functionCalls && !r.finishReason) throw new Error(`Chat response result at index ${n} must have at least one of: content, thought, functionCalls, or finishReason, received: ${e({ content: r.content, thought: r.thought, functionCalls: r.functionCalls, finishReason: r.finishReason })}`);
|
|
2440
|
-
if (r.content !== void 0 && typeof r.content != "string") throw new Error(`Chat response result content at index ${n} must be a string, received: ${e(r.content)}`);
|
|
2441
|
-
if (r.thought !== void 0 && typeof r.thought != "string") throw new Error(`Chat response result thought at index ${n} must be a string, received: ${e(r.thought)}`);
|
|
2442
|
-
if (r.thoughtBlock !== void 0) {
|
|
2443
|
-
if (typeof r.thoughtBlock != "object" || r.thoughtBlock === null) throw new Error(`Chat response result thoughtBlock at index ${n} must be an object, received: ${e(r.thoughtBlock)}`);
|
|
2444
|
-
let o = r.thoughtBlock;
|
|
2445
|
-
if (typeof o.data != "string") throw new Error(`Chat response result thoughtBlock.data at index ${n} must be a string, received: ${e(o.data)}`);
|
|
2446
|
-
if (typeof o.encrypted != "boolean") throw new Error(`Chat response result thoughtBlock.encrypted at index ${n} must be a boolean, received: ${e(o.encrypted)}`);
|
|
2447
|
-
if (o.signature !== void 0 && typeof o.signature != "string") throw new Error(`Chat response result thoughtBlock.signature at index ${n} must be a string when provided, received: ${e(o.signature)}`);
|
|
2448
|
-
}
|
|
2449
|
-
if (r.name !== void 0) {
|
|
2450
|
-
if (typeof r.name != "string") throw new Error(`Chat response result name at index ${n} must be a string, received: ${e(r.name)}`);
|
|
2451
|
-
if (r.name.trim() === "") throw new Error(`Chat response result name at index ${n} cannot be empty or whitespace-only, received: ${e(r.name)}`);
|
|
2452
|
-
}
|
|
2453
|
-
if (r.annotations !== void 0) {
|
|
2454
|
-
if (!Array.isArray(r.annotations)) throw new Error(`Chat response result annotations at index ${n} must be an array, received: ${e(r.annotations)}`);
|
|
2455
|
-
for (let o = 0; o < r.annotations.length; o++) {
|
|
2456
|
-
let s = r.annotations[o];
|
|
2457
|
-
if (!s || typeof s != "object") throw new Error(`Chat response result annotation at index ${n}[${o}] must be an object, received: ${e(s)}`);
|
|
2458
|
-
if (s.type !== "url_citation") throw new Error(`Chat response result annotation at index ${n}[${o}] must have type 'url_citation', received: ${e(s.type)}`);
|
|
2459
|
-
if (!s.url_citation || typeof s.url_citation != "object") throw new Error(`Chat response result annotation at index ${n}[${o}] must have a valid url_citation object, received: ${e(s.url_citation)}`);
|
|
2460
|
-
if (typeof s.url_citation.url != "string") throw new Error(`Chat response result annotation at index ${n}[${o}] url_citation.url must be a string, received: ${e(s.url_citation.url)}`);
|
|
2461
|
-
}
|
|
2462
|
-
}
|
|
2463
|
-
if (r.id !== void 0) {
|
|
2464
|
-
if (typeof r.id != "string") throw new Error(`Chat response result id at index ${n} must be a string, received: ${e(r.id)}`);
|
|
2465
|
-
if (r.id.trim() === "") throw new Error(`Chat response result id at index ${n} cannot be empty or whitespace-only, received: ${e(r.id)}`);
|
|
2466
|
-
}
|
|
2467
|
-
if (r.functionCalls !== void 0) {
|
|
2468
|
-
if (!Array.isArray(r.functionCalls)) throw new Error(`Chat response result functionCalls at index ${n} must be an array, received: ${e(r.functionCalls)}`);
|
|
2469
|
-
for (let o = 0; o < r.functionCalls.length; o++) {
|
|
2470
|
-
let s = r.functionCalls[o];
|
|
2471
|
-
if (!s) throw new Error(`Function call at index ${o} in result ${n} cannot be null or undefined, received: ${e(s)}`);
|
|
2472
|
-
if (!s.id || typeof s.id != "string" || s.id.trim() === "") throw new Error(`Function call at index ${o} in result ${n} must have a non-empty string id, received: ${e(s.id)}`);
|
|
2473
|
-
if (s.type !== "function") throw new Error(`Function call at index ${o} in result ${n} must have type 'function', received: ${e(s.type)}`);
|
|
2474
|
-
if (!s.function) throw new Error(`Function call at index ${o} in result ${n} must have a function object, received: ${e(s.function)}`);
|
|
2475
|
-
if (!s.function.name || typeof s.function.name != "string" || s.function.name.trim() === "") throw new Error(`Function call at index ${o} in result ${n} must have a non-empty function name, received: ${e(s.function.name)}`);
|
|
2476
|
-
if (s.function.params !== void 0 && typeof s.function.params != "string" && typeof s.function.params != "object") throw new Error(`Function call params at index ${o} in result ${n} must be a string or object, received: ${e(s.function.params)}`);
|
|
2477
|
-
}
|
|
2478
|
-
}
|
|
2479
|
-
if (r.finishReason !== void 0) {
|
|
2480
|
-
let o = ["stop", "length", "function_call", "content_filter", "error"];
|
|
2481
|
-
if (!o.includes(r.finishReason)) throw new Error(`Chat response result finishReason at index ${n} must be one of: ${o.join(", ")}, received: ${e(r.finishReason)}`);
|
|
2482
|
-
}
|
|
2483
|
-
}
|
|
2484
|
-
}
|
|
2485
2143
|
var Z = () => structuredClone({ temperature: 0 });
|
|
2486
2144
|
var de = class {
|
|
2487
2145
|
constructor(e, { name: t, apiURL: n, headers: r, modelInfo: o, defaults: s, options: a = {}, supportFor: l, models: c2 }) {
|
|
@@ -2905,14 +2563,6 @@ function ci(i6, e, t) {
|
|
|
2905
2563
|
o && o.length > 0 ? (t || (s.content = r.content), s.tool_calls = o) : t || (s.content = r.content ?? ""), e.addEvent(Ke.GEN_AI_CHOICE, { finish_reason: r.finishReason, index: n, message: JSON.stringify(s, null, 2) });
|
|
2906
2564
|
}
|
|
2907
2565
|
}
|
|
2908
|
-
function ui(i6) {
|
|
2909
|
-
let e = 0;
|
|
2910
|
-
for (let t of i6) {
|
|
2911
|
-
if (!t || typeof t != "object") throw new Error(`AxMessage array validation failed: Item at index ${e} is not a valid message object`);
|
|
2912
|
-
if (t.role !== "user" && t.role !== "assistant") throw new Error(`AxMessage array validation failed: Item at index ${e} has invalid role: ${t.role}`);
|
|
2913
|
-
e++;
|
|
2914
|
-
}
|
|
2915
|
-
}
|
|
2916
2566
|
function Xa(i6) {
|
|
2917
2567
|
let e = /* @__PURE__ */ new Set();
|
|
2918
2568
|
for (let t of i6) {
|
|
@@ -4653,115 +4303,6 @@ var Wn = class i3 {
|
|
|
4653
4303
|
return this.ai.getLogger();
|
|
4654
4304
|
}
|
|
4655
4305
|
};
|
|
4656
|
-
var ln = class {
|
|
4657
|
-
data = [];
|
|
4658
|
-
seenTags = /* @__PURE__ */ new Set();
|
|
4659
|
-
addRequest(e, t) {
|
|
4660
|
-
this.data.push(...e.map((n) => {
|
|
4661
|
-
let r = structuredClone(n);
|
|
4662
|
-
return { role: n.role, chat: [{ index: t, value: r }] };
|
|
4663
|
-
}));
|
|
4664
|
-
}
|
|
4665
|
-
addFunctionResults(e) {
|
|
4666
|
-
let t = e.map(({ index: r, ...o }) => ({ index: r, value: structuredClone(o) })), n = this.getLast();
|
|
4667
|
-
n?.role === "function" ? n.chat.push(...t) : this.data.push({ role: "function", chat: t });
|
|
4668
|
-
}
|
|
4669
|
-
addResponse(e) {
|
|
4670
|
-
let t = e.map(({ index: n, ...r }) => ({ index: n, value: structuredClone(r) }));
|
|
4671
|
-
this.data.push({ role: "assistant", chat: t });
|
|
4672
|
-
}
|
|
4673
|
-
updateResult({ content: e, name: t, functionCalls: n, thought: r, thoughtBlock: o, index: s }) {
|
|
4674
|
-
let a = this.data.at(-1);
|
|
4675
|
-
if (!a || a.role !== "assistant" || a.role === "assistant" && !a.updatable) {
|
|
4676
|
-
this.data.push({ role: "assistant", updatable: true, chat: [{ index: s, value: structuredClone({ content: e, name: t, functionCalls: n, thought: r, thoughtBlock: o }) }] });
|
|
4677
|
-
return;
|
|
4678
|
-
}
|
|
4679
|
-
let l = a.chat.find((c2) => c2.index === s);
|
|
4680
|
-
if (!l) {
|
|
4681
|
-
a.chat.push({ index: s, value: structuredClone({ content: e, name: t, functionCalls: n, thought: r, thoughtBlock: o }) });
|
|
4682
|
-
return;
|
|
4683
|
-
}
|
|
4684
|
-
if (typeof e == "string" && e.trim() !== "" && (l.value.content = e), typeof t == "string" && t.trim() !== "" && (l.value.name = t), Array.isArray(n) && n.length > 0 && (l.value.functionCalls = n), typeof r == "string" && r.trim() !== "") {
|
|
4685
|
-
let c2 = l.value.thought;
|
|
4686
|
-
l.value.thought = typeof c2 == "string" ? c2 + r : r;
|
|
4687
|
-
}
|
|
4688
|
-
if (o && typeof o == "object") {
|
|
4689
|
-
let c2 = l.value.thoughtBlock ?? {}, u = { data: (c2.data ?? "") + (o.data ?? ""), encrypted: !!c2.encrypted || !!o.encrypted, ...o.signature ? { signature: o.signature } : {} };
|
|
4690
|
-
l.value.thoughtBlock = u;
|
|
4691
|
-
}
|
|
4692
|
-
}
|
|
4693
|
-
addTag(e) {
|
|
4694
|
-
let t = this.data.at(-1);
|
|
4695
|
-
t && (t.tags || (t.tags = []), t.tags.includes(e) || t.tags.push(e), this.seenTags.add(e));
|
|
4696
|
-
}
|
|
4697
|
-
rewindToTag(e) {
|
|
4698
|
-
let t = this.data.findIndex((n) => n.tags?.includes(e));
|
|
4699
|
-
if (t === -1) {
|
|
4700
|
-
if (!this.seenTags.has(e)) throw new Error(`Tag "${e}" not found`);
|
|
4701
|
-
return [];
|
|
4702
|
-
}
|
|
4703
|
-
return this.data.splice(t);
|
|
4704
|
-
}
|
|
4705
|
-
removeByTag(e) {
|
|
4706
|
-
let t = this.data.reduce((n, r, o) => (r.tags?.includes(e) && n.push(o), n), []);
|
|
4707
|
-
return t.length === 0 ? [] : t.reverse().map((n) => this.data.splice(n, 1).at(0)).filter((n) => n !== void 0).reverse();
|
|
4708
|
-
}
|
|
4709
|
-
history(e) {
|
|
4710
|
-
let t = [];
|
|
4711
|
-
for (let { role: n, chat: r } of this.data) {
|
|
4712
|
-
let o;
|
|
4713
|
-
n === "function" ? o = r.filter((s) => s.index === e).map((s) => s.value) : o = r.find((s) => s.index === e)?.value, Array.isArray(o) && o.length > 0 ? t.push(...o.map((s) => ({ ...s, role: n }))) : typeof o == "object" && o !== null && t.push({ ...o, role: n });
|
|
4714
|
-
}
|
|
4715
|
-
return t;
|
|
4716
|
-
}
|
|
4717
|
-
getLast() {
|
|
4718
|
-
return this.data.at(-1);
|
|
4719
|
-
}
|
|
4720
|
-
reset() {
|
|
4721
|
-
this.data = [], this.seenTags = /* @__PURE__ */ new Set();
|
|
4722
|
-
}
|
|
4723
|
-
};
|
|
4724
|
-
var cn = class {
|
|
4725
|
-
memories = /* @__PURE__ */ new Map();
|
|
4726
|
-
defaultMemory;
|
|
4727
|
-
constructor() {
|
|
4728
|
-
this.defaultMemory = new ln();
|
|
4729
|
-
}
|
|
4730
|
-
getMemory(e) {
|
|
4731
|
-
return e ? (this.memories.has(e) || this.memories.set(e, new ln()), this.memories.get(e)) : this.defaultMemory;
|
|
4732
|
-
}
|
|
4733
|
-
addRequest(e, t) {
|
|
4734
|
-
for (let n of e) Nt(n);
|
|
4735
|
-
this.getMemory(t).addRequest(e, 0);
|
|
4736
|
-
}
|
|
4737
|
-
addResponse(e, t) {
|
|
4738
|
-
Kr(e), this.getMemory(t).addResponse(e);
|
|
4739
|
-
}
|
|
4740
|
-
addFunctionResults(e, t) {
|
|
4741
|
-
this.getMemory(t).addFunctionResults(e);
|
|
4742
|
-
}
|
|
4743
|
-
updateResult(e, t) {
|
|
4744
|
-
this.getMemory(t).updateResult(e);
|
|
4745
|
-
}
|
|
4746
|
-
addTag(e, t) {
|
|
4747
|
-
this.getMemory(t).addTag(e);
|
|
4748
|
-
}
|
|
4749
|
-
rewindToTag(e, t) {
|
|
4750
|
-
return this.getMemory(t).rewindToTag(e);
|
|
4751
|
-
}
|
|
4752
|
-
removeByTag(e, t) {
|
|
4753
|
-
return this.getMemory(t).removeByTag(e);
|
|
4754
|
-
}
|
|
4755
|
-
history(e, t) {
|
|
4756
|
-
return this.getMemory(t).history(e);
|
|
4757
|
-
}
|
|
4758
|
-
getLast(e) {
|
|
4759
|
-
return this.getMemory(e).getLast();
|
|
4760
|
-
}
|
|
4761
|
-
reset(e) {
|
|
4762
|
-
e ? this.memories.set(e, new ln()) : this.defaultMemory.reset();
|
|
4763
|
-
}
|
|
4764
|
-
};
|
|
4765
4306
|
var Ze = class extends Error {
|
|
4766
4307
|
constructor({ message: e }) {
|
|
4767
4308
|
super(e), this.name = "AxAssertionError";
|
|
@@ -4777,174 +4318,6 @@ var Ze = class extends Error {
|
|
|
4777
4318
|
return this.toString();
|
|
4778
4319
|
}
|
|
4779
4320
|
};
|
|
4780
|
-
var Vn = async (i6, e) => {
|
|
4781
|
-
for (let t of i6) {
|
|
4782
|
-
let { fn: n, message: r } = t, o = await n(e);
|
|
4783
|
-
if (o !== void 0) {
|
|
4784
|
-
if (typeof o == "string") throw new Ze({ message: o });
|
|
4785
|
-
if (!o) throw r ? new Ze({ message: r }) : new Error("Assertion Failed: No message provided for assertion");
|
|
4786
|
-
}
|
|
4787
|
-
}
|
|
4788
|
-
};
|
|
4789
|
-
var _o = async (i6, e, t, n = false) => {
|
|
4790
|
-
if (!e.currField || e.s === -1 || !i6 || i6.length === 0) return;
|
|
4791
|
-
let r = i6.filter((s) => s.fieldName === e.currField?.name);
|
|
4792
|
-
if (r.length === 0) return;
|
|
4793
|
-
let o = t.substring(e.s);
|
|
4794
|
-
for (let s of r) {
|
|
4795
|
-
let { message: a, fn: l } = s, c2 = await l(o, n);
|
|
4796
|
-
if (c2 !== void 0) {
|
|
4797
|
-
if (typeof c2 == "string") throw new Ze({ message: c2 });
|
|
4798
|
-
if (!c2 && a) throw new Ze({ message: a });
|
|
4799
|
-
}
|
|
4800
|
-
}
|
|
4801
|
-
};
|
|
4802
|
-
var Mi = { enabled: true, enabledCategories: ["generation", "streaming", "functions", "errors", "performance"], maxLabelLength: 100, samplingRate: 1 };
|
|
4803
|
-
var un;
|
|
4804
|
-
var No = (i6) => {
|
|
4805
|
-
if (un) return un;
|
|
4806
|
-
let e = i6 ?? J.meter;
|
|
4807
|
-
if (e) return un = $l(e), un;
|
|
4808
|
-
};
|
|
4809
|
-
var $l = (i6) => ({ generationLatencyHistogram: i6.createHistogram("ax_gen_generation_duration_ms", { description: "End-to-end duration of AxGen generation requests", unit: "ms" }), generationRequestsCounter: i6.createCounter("ax_gen_generation_requests_total", { description: "Total number of AxGen generation requests" }), generationErrorsCounter: i6.createCounter("ax_gen_generation_errors_total", { description: "Total number of failed AxGen generations" }), multiStepGenerationsCounter: i6.createCounter("ax_gen_multistep_generations_total", { description: "Total number of generations that required multiple steps" }), stepsPerGenerationHistogram: i6.createHistogram("ax_gen_steps_per_generation", { description: "Number of steps taken per generation" }), maxStepsReachedCounter: i6.createCounter("ax_gen_max_steps_reached_total", { description: "Total number of generations that hit max steps limit" }), validationErrorsCounter: i6.createCounter("ax_gen_validation_errors_total", { description: "Total number of validation errors encountered" }), assertionErrorsCounter: i6.createCounter("ax_gen_assertion_errors_total", { description: "Total number of assertion errors encountered" }), errorCorrectionAttemptsHistogram: i6.createHistogram("ax_gen_error_correction_attempts", { description: "Number of error correction attempts per generation" }), errorCorrectionSuccessCounter: i6.createCounter("ax_gen_error_correction_success_total", { description: "Total number of successful error corrections" }), errorCorrectionFailureCounter: i6.createCounter("ax_gen_error_correction_failure_total", { description: "Total number of failed error corrections" }), maxRetriesReachedCounter: i6.createCounter("ax_gen_max_retries_reached_total", { description: "Total number of generations that hit max retries limit" }), functionsEnabledGenerationsCounter: i6.createCounter("ax_gen_functions_enabled_generations_total", { description: "Total number of generations with functions enabled" }), functionCallStepsCounter: i6.createCounter("ax_gen_function_call_steps_total", { description: "Total number of steps that included function calls" }), functionsExecutedPerGenerationHistogram: i6.createHistogram("ax_gen_functions_executed_per_generation", { description: "Number of unique functions executed per generation" }), functionErrorCorrectionCounter: i6.createCounter("ax_gen_function_error_correction_total", { description: "Total number of function-related error corrections" }), fieldProcessorsExecutedCounter: i6.createCounter("ax_gen_field_processors_executed_total", { description: "Total number of field processors executed" }), streamingFieldProcessorsExecutedCounter: i6.createCounter("ax_gen_streaming_field_processors_executed_total", { description: "Total number of streaming field processors executed" }), streamingGenerationsCounter: i6.createCounter("ax_gen_streaming_generations_total", { description: "Total number of streaming generations" }), streamingDeltasEmittedCounter: i6.createCounter("ax_gen_streaming_deltas_emitted_total", { description: "Total number of streaming deltas emitted" }), streamingFinalizationLatencyHistogram: i6.createHistogram("ax_gen_streaming_finalization_duration_ms", { description: "Duration of streaming response finalization", unit: "ms" }), samplesGeneratedHistogram: i6.createHistogram("ax_gen_samples_generated", { description: "Number of samples generated per request" }), resultPickerUsageCounter: i6.createCounter("ax_gen_result_picker_usage_total", { description: "Total number of times result picker was used" }), resultPickerLatencyHistogram: i6.createHistogram("ax_gen_result_picker_duration_ms", { description: "Duration of result picker execution", unit: "ms" }), inputFieldsGauge: i6.createGauge("ax_gen_input_fields", { description: "Number of input fields in signature" }), outputFieldsGauge: i6.createGauge("ax_gen_output_fields", { description: "Number of output fields in signature" }), examplesUsedGauge: i6.createGauge("ax_gen_examples_used", { description: "Number of examples used in generation" }), demosUsedGauge: i6.createGauge("ax_gen_demos_used", { description: "Number of demos used in generation" }), promptRenderLatencyHistogram: i6.createHistogram("ax_gen_prompt_render_duration_ms", { description: "Duration of prompt template rendering", unit: "ms" }), extractionLatencyHistogram: i6.createHistogram("ax_gen_extraction_duration_ms", { description: "Duration of value extraction from responses", unit: "ms" }), assertionLatencyHistogram: i6.createHistogram("ax_gen_assertion_duration_ms", { description: "Duration of assertion checking", unit: "ms" }), stateCreationLatencyHistogram: i6.createHistogram("ax_gen_state_creation_duration_ms", { description: "Duration of state creation for multiple samples", unit: "ms" }), memoryUpdateLatencyHistogram: i6.createHistogram("ax_gen_memory_update_duration_ms", { description: "Duration of memory updates during generation", unit: "ms" }) });
|
|
4810
|
-
var Jn = Mi;
|
|
4811
|
-
var je = (i6) => {
|
|
4812
|
-
let e = {};
|
|
4813
|
-
for (let [t, n] of Object.entries(i6)) if (n != null) {
|
|
4814
|
-
let r = String(n), o = Jn.maxLabelLength;
|
|
4815
|
-
e[t] = r.length > o ? r.substring(0, o) : r;
|
|
4816
|
-
}
|
|
4817
|
-
return e;
|
|
4818
|
-
};
|
|
4819
|
-
var Ei = (i6, e, t, n, r, o) => {
|
|
4820
|
-
try {
|
|
4821
|
-
let s = je({ success: t.toString(), ...n ? { signature: n } : {}, ...r ? { ai_service: r } : {}, ...o ? { model: o } : {} });
|
|
4822
|
-
i6.generationLatencyHistogram && i6.generationLatencyHistogram.record(e, s), i6.generationRequestsCounter && i6.generationRequestsCounter.add(1, s), !t && i6.generationErrorsCounter && i6.generationErrorsCounter.add(1, s);
|
|
4823
|
-
} catch (s) {
|
|
4824
|
-
console.warn("Failed to record generation metric:", s);
|
|
4825
|
-
}
|
|
4826
|
-
};
|
|
4827
|
-
var Qn = (i6, e, t, n) => {
|
|
4828
|
-
try {
|
|
4829
|
-
let r = je({ ...n ? { signature: n } : {} });
|
|
4830
|
-
e > 1 && i6.multiStepGenerationsCounter && i6.multiStepGenerationsCounter.add(1, r), i6.stepsPerGenerationHistogram && i6.stepsPerGenerationHistogram.record(e, r), e >= t && i6.maxStepsReachedCounter && i6.maxStepsReachedCounter.add(1, r);
|
|
4831
|
-
} catch (r) {
|
|
4832
|
-
console.warn("Failed to record multi-step metric:", r);
|
|
4833
|
-
}
|
|
4834
|
-
};
|
|
4835
|
-
var Do = (i6, e, t) => {
|
|
4836
|
-
try {
|
|
4837
|
-
let n = je({ error_type: e, ...t ? { signature: t } : {} });
|
|
4838
|
-
e === "validation" && i6.validationErrorsCounter && i6.validationErrorsCounter.add(1, n), e === "assertion" && i6.assertionErrorsCounter && i6.assertionErrorsCounter.add(1, n);
|
|
4839
|
-
} catch (n) {
|
|
4840
|
-
console.warn("Failed to record validation error metric:", n);
|
|
4841
|
-
}
|
|
4842
|
-
};
|
|
4843
|
-
var Pi = (i6, e) => {
|
|
4844
|
-
try {
|
|
4845
|
-
let t = je({ error_type: "refusal", ...e ? { signature: e } : {} });
|
|
4846
|
-
i6.validationErrorsCounter && i6.validationErrorsCounter.add(1, t);
|
|
4847
|
-
} catch (t) {
|
|
4848
|
-
console.warn("Failed to record refusal error metric:", t);
|
|
4849
|
-
}
|
|
4850
|
-
};
|
|
4851
|
-
var $o = (i6, e, t, n, r) => {
|
|
4852
|
-
try {
|
|
4853
|
-
let o = je({ success: t.toString(), ...r ? { signature: r } : {} });
|
|
4854
|
-
i6.errorCorrectionAttemptsHistogram && i6.errorCorrectionAttemptsHistogram.record(e, o), t && i6.errorCorrectionSuccessCounter && i6.errorCorrectionSuccessCounter.add(1, o), t || (i6.errorCorrectionFailureCounter && i6.errorCorrectionFailureCounter.add(1, o), e >= n && i6.maxRetriesReachedCounter && i6.maxRetriesReachedCounter.add(1, o));
|
|
4855
|
-
} catch (o) {
|
|
4856
|
-
console.warn("Failed to record error correction metric:", o);
|
|
4857
|
-
}
|
|
4858
|
-
};
|
|
4859
|
-
var Fi = (i6, e, t, n, r = false, o) => {
|
|
4860
|
-
try {
|
|
4861
|
-
let s = je({ functions_enabled: e.toString(), had_function_calls: n.toString(), ...o ? { signature: o } : {} });
|
|
4862
|
-
e && i6.functionsEnabledGenerationsCounter && i6.functionsEnabledGenerationsCounter.add(1, s), n && i6.functionCallStepsCounter && i6.functionCallStepsCounter.add(1, s), t > 0 && i6.functionsExecutedPerGenerationHistogram && i6.functionsExecutedPerGenerationHistogram.record(t, s), r && i6.functionErrorCorrectionCounter && i6.functionErrorCorrectionCounter.add(1, s);
|
|
4863
|
-
} catch (s) {
|
|
4864
|
-
console.warn("Failed to record function calling metric:", s);
|
|
4865
|
-
}
|
|
4866
|
-
};
|
|
4867
|
-
var _i = (i6, e, t, n) => {
|
|
4868
|
-
try {
|
|
4869
|
-
let r = je({ ...n ? { signature: n } : {} });
|
|
4870
|
-
e > 0 && i6.fieldProcessorsExecutedCounter && i6.fieldProcessorsExecutedCounter.add(e, r), t > 0 && i6.streamingFieldProcessorsExecutedCounter && i6.streamingFieldProcessorsExecutedCounter.add(t, r);
|
|
4871
|
-
} catch (r) {
|
|
4872
|
-
console.warn("Failed to record field processing metric:", r);
|
|
4873
|
-
}
|
|
4874
|
-
};
|
|
4875
|
-
var Ni = (i6, e, t, n, r) => {
|
|
4876
|
-
try {
|
|
4877
|
-
let o = je({ is_streaming: e.toString(), ...r ? { signature: r } : {} });
|
|
4878
|
-
e && i6.streamingGenerationsCounter && i6.streamingGenerationsCounter.add(1, o), t > 0 && i6.streamingDeltasEmittedCounter && i6.streamingDeltasEmittedCounter.add(t, o), n && i6.streamingFinalizationLatencyHistogram && i6.streamingFinalizationLatencyHistogram.record(n, o);
|
|
4879
|
-
} catch (o) {
|
|
4880
|
-
console.warn("Failed to record streaming metric:", o);
|
|
4881
|
-
}
|
|
4882
|
-
};
|
|
4883
|
-
var Di = (i6, e, t, n, r) => {
|
|
4884
|
-
try {
|
|
4885
|
-
let o = je({ result_picker_used: t.toString(), ...r ? { signature: r } : {} });
|
|
4886
|
-
i6.samplesGeneratedHistogram && i6.samplesGeneratedHistogram.record(e, o), t && i6.resultPickerUsageCounter && i6.resultPickerUsageCounter.add(1, o), n && i6.resultPickerLatencyHistogram && i6.resultPickerLatencyHistogram.record(n, o);
|
|
4887
|
-
} catch (o) {
|
|
4888
|
-
console.warn("Failed to record samples metric:", o);
|
|
4889
|
-
}
|
|
4890
|
-
};
|
|
4891
|
-
var $i = (i6, e, t, n, r, o) => {
|
|
4892
|
-
try {
|
|
4893
|
-
let s = je({ ...o ? { signature: o } : {} });
|
|
4894
|
-
i6.inputFieldsGauge && i6.inputFieldsGauge.record(e, s), i6.outputFieldsGauge && i6.outputFieldsGauge.record(t, s), i6.examplesUsedGauge && i6.examplesUsedGauge.record(n, s), i6.demosUsedGauge && i6.demosUsedGauge.record(r, s);
|
|
4895
|
-
} catch (s) {
|
|
4896
|
-
console.warn("Failed to record signature complexity metrics:", s);
|
|
4897
|
-
}
|
|
4898
|
-
};
|
|
4899
|
-
var Yn = (i6, e, t, n) => {
|
|
4900
|
-
try {
|
|
4901
|
-
let r = je({ metric_type: e, ...n ? { signature: n } : {} });
|
|
4902
|
-
switch (e) {
|
|
4903
|
-
case "prompt_render":
|
|
4904
|
-
i6.promptRenderLatencyHistogram && i6.promptRenderLatencyHistogram.record(t, r);
|
|
4905
|
-
break;
|
|
4906
|
-
case "extraction":
|
|
4907
|
-
i6.extractionLatencyHistogram && i6.extractionLatencyHistogram.record(t, r);
|
|
4908
|
-
break;
|
|
4909
|
-
case "assertion":
|
|
4910
|
-
i6.assertionLatencyHistogram && i6.assertionLatencyHistogram.record(t, r);
|
|
4911
|
-
break;
|
|
4912
|
-
case "state_creation":
|
|
4913
|
-
i6.stateCreationLatencyHistogram && i6.stateCreationLatencyHistogram.record(t, r);
|
|
4914
|
-
break;
|
|
4915
|
-
case "memory_update":
|
|
4916
|
-
i6.memoryUpdateLatencyHistogram && i6.memoryUpdateLatencyHistogram.record(t, r);
|
|
4917
|
-
break;
|
|
4918
|
-
}
|
|
4919
|
-
} catch (r) {
|
|
4920
|
-
console.warn("Failed to record performance metric:", r);
|
|
4921
|
-
}
|
|
4922
|
-
};
|
|
4923
|
-
var Ct = (i6) => {
|
|
4924
|
-
let e = (() => {
|
|
4925
|
-
switch (i6?.name) {
|
|
4926
|
-
case "string":
|
|
4927
|
-
return "string";
|
|
4928
|
-
case "number":
|
|
4929
|
-
return "number";
|
|
4930
|
-
case "boolean":
|
|
4931
|
-
return "boolean";
|
|
4932
|
-
case "date":
|
|
4933
|
-
return 'date ("YYYY-MM-DD" format)';
|
|
4934
|
-
case "datetime":
|
|
4935
|
-
return 'date time ("YYYY-MM-DD HH:mm Timezone" format)';
|
|
4936
|
-
case "json":
|
|
4937
|
-
return "JSON object";
|
|
4938
|
-
case "class":
|
|
4939
|
-
return "classification class";
|
|
4940
|
-
case "code":
|
|
4941
|
-
return "code";
|
|
4942
|
-
default:
|
|
4943
|
-
return "string";
|
|
4944
|
-
}
|
|
4945
|
-
})();
|
|
4946
|
-
return i6?.isArray ? `json array of ${e} items` : e;
|
|
4947
|
-
};
|
|
4948
4321
|
var ge = class extends Error {
|
|
4949
4322
|
constructor(e) {
|
|
4950
4323
|
super(e), this.name = "ValidationError";
|
|
@@ -4957,45 +4330,6 @@ var ge = class extends Error {
|
|
|
4957
4330
|
return this.toString();
|
|
4958
4331
|
}
|
|
4959
4332
|
};
|
|
4960
|
-
var Li = (i6) => {
|
|
4961
|
-
let t = i6.map((n) => `'${n.title}' (${Ct(n.type)})`).join(", ");
|
|
4962
|
-
return new ge(`Required field not found: ${t}. Add a line starting with the exact label followed by a colon (e.g., "${i6[0]?.title}:") and then provide a valid ${Ct(i6[0]?.type)} value. Keep the output concise and avoid unrelated text.`);
|
|
4963
|
-
};
|
|
4964
|
-
var Xn = (i6) => new ge(`Expected (Required) field not found: '${i6.title}'. Begin a new section with "${i6.title}:" and then provide a valid ${Ct(i6.type)} value directly after.`);
|
|
4965
|
-
var Zn = (i6) => new ge(`Required field is missing: '${i6.title}'. After the "${i6.title}:" label, provide a non-empty ${Ct(i6.type)}. Do not use null, undefined, or leave it blank.`);
|
|
4966
|
-
var Gi = (i6, e) => new ge(`Invalid JSON: ${e} in field '${i6.title}'. Return only valid JSON. Prefer a fenced code block containing a single JSON object or array with no trailing text.`);
|
|
4967
|
-
var Ui = (i6, e) => new ge(`Invalid Array: ${e} for '${i6.title}'. Provide a JSON array of ${Ct(i6.type)} items (e.g., [ ... ]). Markdown lists are also accepted if each item is on its own line starting with a hyphen.`);
|
|
4968
|
-
var Bi = (i6, e, t) => new ge(`Field '${i6.title}' has an invalid value '${e}': ${t}. Provide a ${Ct(i6.type)}. Ensure formatting exactly matches the expected type.`);
|
|
4969
|
-
var ji = (i6, e, t) => new ge(`Invalid date for '${i6.title}': ${t}. Use the exact format YYYY-MM-DD (e.g., 2024-05-09). You provided: ${e}.`);
|
|
4970
|
-
var qi = (i6, e, t) => new ge(`Invalid date/time for '${i6.title}': ${t}. Use the format YYYY-MM-DD HH:mm or YYYY-MM-DD HH:mm:ss followed by a valid timezone (e.g., America/New_York). You provided: ${e}.`);
|
|
4971
|
-
var Lo = (i6, e, t) => new ge(`Invalid URL for '${i6.title}': ${t}. Use a valid URL format (e.g., https://example.com). You provided: ${e}.`);
|
|
4972
|
-
var Rt = (i6, e, t, n) => {
|
|
4973
|
-
let r = `Field '${i6.title}' failed validation: `;
|
|
4974
|
-
return t === "minLength" ? r += `String must be at least ${n} characters long. You provided: "${e}" (${e.length} characters).` : t === "maxLength" ? r += `String must be at most ${n} characters long. You provided: "${e}" (${e.length} characters).` : t === "pattern" ? r += `String must match pattern /${n}/. You provided: "${e}".` : t === "format" && (r += `String must be a ${n}. You provided: "${e}".`), new ge(r);
|
|
4975
|
-
};
|
|
4976
|
-
var Go = (i6, e, t, n) => {
|
|
4977
|
-
let r = `Field '${i6.title}' failed validation: `;
|
|
4978
|
-
return t === "minimum" ? r += `Number must be at least ${n}. You provided: ${e}.` : t === "maximum" && (r += `Number must be at most ${n}. You provided: ${e}.`), new ge(r);
|
|
4979
|
-
};
|
|
4980
|
-
var zi = ({ error: i6, errCount: e, debug: t, logger: n, metricsInstruments: r, signatureName: o, span: s }) => {
|
|
4981
|
-
let a = i6.getFixingInstructions();
|
|
4982
|
-
if (t && n) {
|
|
4983
|
-
let l = a?.map((c2) => c2.title).join(", ") ?? "";
|
|
4984
|
-
Gs(i6, e, l, n);
|
|
4985
|
-
}
|
|
4986
|
-
return r && Do(r, "validation", o), s && s.addEvent("validation.error", { message: i6.toString(), fixing_instructions: a?.map((l) => l.title).join(", ") ?? "" }), a;
|
|
4987
|
-
};
|
|
4988
|
-
var Hi = ({ error: i6, errCount: e, debug: t, logger: n, metricsInstruments: r, signatureName: o, span: s }) => {
|
|
4989
|
-
let a = i6.getFixingInstructions();
|
|
4990
|
-
if (t && n) {
|
|
4991
|
-
let l = a?.map((c2) => c2.title).join(", ") ?? "";
|
|
4992
|
-
Us(i6, e, l, n);
|
|
4993
|
-
}
|
|
4994
|
-
return r && Do(r, "assertion", o), s && s.addEvent("assertion.error", { message: i6.toString(), fixing_instructions: a?.map((l) => l.title).join(", ") ?? "" }), a;
|
|
4995
|
-
};
|
|
4996
|
-
var Ki = ({ error: i6, errCount: e, debug: t, logger: n, metricsInstruments: r, signatureName: o, span: s }) => {
|
|
4997
|
-
t && n && Bs(i6, e, n), r && Pi(r, o), s && s.addEvent("refusal.error", { message: i6.toString() });
|
|
4998
|
-
};
|
|
4999
4333
|
function Wi(i6, e) {
|
|
5000
4334
|
if (!e) return i6;
|
|
5001
4335
|
let t = [];
|
|
@@ -5063,19 +4397,6 @@ function Vi(i6) {
|
|
|
5063
4397
|
return "string";
|
|
5064
4398
|
}
|
|
5065
4399
|
}
|
|
5066
|
-
function tr(i6) {
|
|
5067
|
-
if (!i6 || typeof i6 != "object") throw new Error("Schema must be an object");
|
|
5068
|
-
if (i6.type === "array") {
|
|
5069
|
-
if (!i6.items) throw new Error('Array schema is missing an "items" definition (required by JSON Schema and all LLM providers for function tools)');
|
|
5070
|
-
tr(i6.items);
|
|
5071
|
-
} else if (i6.type === "object" && i6.properties) for (let e of Object.values(i6.properties)) tr(e);
|
|
5072
|
-
}
|
|
5073
|
-
var wt = class extends Error {
|
|
5074
|
-
calls;
|
|
5075
|
-
constructor(e) {
|
|
5076
|
-
super(`Stop function executed: ${e.map((t) => t.func.name).join(", ")}`), this.name = "AxStopFunctionCallException", this.calls = e;
|
|
5077
|
-
}
|
|
5078
|
-
};
|
|
5079
4400
|
var rr = class extends Error {
|
|
5080
4401
|
constructor(t) {
|
|
5081
4402
|
super();
|
|
@@ -5124,839 +4445,30 @@ ${t.join(`
|
|
|
5124
4445
|
return this.toString();
|
|
5125
4446
|
}
|
|
5126
4447
|
};
|
|
5127
|
-
|
|
5128
|
-
|
|
4448
|
+
import_dayjs.default.extend(import_utc.default);
|
|
4449
|
+
import_dayjs.default.extend(import_timezone.default);
|
|
4450
|
+
import_dayjs.default.extend(import_customParseFormat.default);
|
|
4451
|
+
var ug = new Te();
|
|
4452
|
+
var Bo = class {
|
|
4453
|
+
cache = /* @__PURE__ */ new Map();
|
|
4454
|
+
maxSize;
|
|
5129
4455
|
constructor(e) {
|
|
5130
|
-
this.
|
|
4456
|
+
this.maxSize = e;
|
|
5131
4457
|
}
|
|
5132
|
-
|
|
5133
|
-
let
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
|
|
5140
|
-
|
|
5141
|
-
e.parameters ? s = e.func.length === 2 ? await e.func(r, o) : await e.func(r) : s = e.func.length === 1 ? await e.func(o) : await e.func();
|
|
5142
|
-
let l = (n?.functionResultFormatter ?? J.functionResultFormatter)(s);
|
|
5143
|
-
return { formatted: String(l), rawResult: s, parsedArgs: r };
|
|
5144
|
-
};
|
|
5145
|
-
executeWithDetails = async (e, t) => {
|
|
5146
|
-
let n = (s) => s.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(), r = n(e.name), o = this.funcList.find((s) => s.name === e.name);
|
|
5147
|
-
if (o || (o = this.funcList.find((s) => n(s.name) === r)), !o) throw new Error(`Function not found: ${e.name}`);
|
|
5148
|
-
if (!o.func) throw new Error(`No handler for function: ${e.name}`);
|
|
5149
|
-
try {
|
|
5150
|
-
return await this.executeFunction(o, e, t);
|
|
5151
|
-
} catch (s) {
|
|
5152
|
-
throw s instanceof rr ? new pn(s.getFields(), o, e.id) : s;
|
|
4458
|
+
get(e) {
|
|
4459
|
+
let t = this.cache.get(e);
|
|
4460
|
+
return t && (this.cache.delete(e), this.cache.set(e, t)), t;
|
|
4461
|
+
}
|
|
4462
|
+
set(e, t) {
|
|
4463
|
+
if (this.cache.has(e)) this.cache.delete(e);
|
|
4464
|
+
else if (this.cache.size >= this.maxSize) {
|
|
4465
|
+
let n = this.cache.keys().next().value;
|
|
4466
|
+
n && this.cache.delete(n);
|
|
5153
4467
|
}
|
|
5154
|
-
|
|
5155
|
-
execute = async (e, t) => (await this.executeWithDetails(e, t)).formatted;
|
|
5156
|
-
};
|
|
5157
|
-
var sr = (i6, e) => {
|
|
5158
|
-
if (i6.length === 0) return [...e ?? []];
|
|
5159
|
-
let t = i6.map((n) => "toFunction" in n ? n.toFunction() : n).flat();
|
|
5160
|
-
for (let n of t.filter((r) => r.parameters)) if (n.parameters) try {
|
|
5161
|
-
tr(n.parameters);
|
|
5162
|
-
} catch (r) {
|
|
5163
|
-
throw r instanceof Error ? new Error(`Function '${n.name}' parameters schema is invalid.
|
|
5164
|
-
${r.message}
|
|
5165
|
-
Tip: Arrays must include an "items" schema (e.g., { items: { type: "string" } } or items: { type: "object", properties: { ... } }).`, { cause: r }) : r;
|
|
5166
|
-
}
|
|
5167
|
-
return [...e ?? [], ...t];
|
|
5168
|
-
};
|
|
5169
|
-
var ir = async ({ ai: i6, functionList: e, functionCalls: t, mem: n, sessionId: r, traceId: o, span: s, excludeContentFromTrace: a, index: l, functionResultFormatter: c2, logger: u, debug: p, stopFunctionNames: d }) => {
|
|
5170
|
-
let m = new or(e), g = /* @__PURE__ */ new Set(), A = [], h = (y) => {
|
|
5171
|
-
let R = (b) => b.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(), T = R(y), S = e.find((b) => b.name === y);
|
|
5172
|
-
return S || (S = e.find((b) => R(b.name) === T)), S;
|
|
5173
|
-
}, f = t.map((y) => {
|
|
5174
|
-
if (!y.id) throw new Error(`Function ${y.name} did not return an ID`);
|
|
5175
|
-
let R = i6.getOptions().tracer ?? J.tracer;
|
|
5176
|
-
return R ? R.startActiveSpan(`Tool: ${y.name}`, async (T) => {
|
|
5177
|
-
try {
|
|
5178
|
-
T?.setAttributes?.({ "tool.name": y.name, "tool.mode": "native", "function.id": y.id, "session.id": r ?? "" });
|
|
5179
|
-
let { formatted: S, rawResult: b, parsedArgs: v } = await m.executeWithDetails(y, { sessionId: r, ai: i6, functionResultFormatter: c2, traceId: T?.spanContext?.().traceId ?? o, stopFunctionNames: d });
|
|
5180
|
-
if (g.add(y.name.toLowerCase()), d?.includes(y.name.toLowerCase())) {
|
|
5181
|
-
let E = h(y.name);
|
|
5182
|
-
E && A.push({ func: E, args: v, result: b });
|
|
5183
|
-
}
|
|
5184
|
-
if (a ? T.addEvent("gen_ai.tool.message", { name: y.name }) : T.addEvent("gen_ai.tool.message", { name: y.name, args: y.args, result: S ?? "" }), s) {
|
|
5185
|
-
let E = { name: y.name };
|
|
5186
|
-
a || (E.args = y.args, E.result = S ?? ""), s.addEvent("function.call", E);
|
|
5187
|
-
}
|
|
5188
|
-
return { result: S ?? "", role: "function", functionId: y.id, index: l };
|
|
5189
|
-
} catch (S) {
|
|
5190
|
-
if (T?.recordException?.(S), S instanceof pn) {
|
|
5191
|
-
let b = S.getFixingInstructions(), v = { name: y.name, message: S.toString() };
|
|
5192
|
-
return a || (v.args = y.args, v.fixing_instructions = b), T?.addEvent?.("function.error", v), p && Br(S, l, b, u), { functionId: y.id, isError: true, index: l, result: b, role: "function" };
|
|
5193
|
-
}
|
|
5194
|
-
throw S;
|
|
5195
|
-
} finally {
|
|
5196
|
-
T?.end?.();
|
|
5197
|
-
}
|
|
5198
|
-
}) : m.executeWithDetails(y, { sessionId: r, ai: i6, functionResultFormatter: c2, traceId: o, stopFunctionNames: d }).then(({ formatted: T, rawResult: S, parsedArgs: b }) => {
|
|
5199
|
-
if (g.add(y.name.toLowerCase()), d?.includes(y.name.toLowerCase())) {
|
|
5200
|
-
let v = h(y.name);
|
|
5201
|
-
v && A.push({ func: v, args: b, result: S });
|
|
5202
|
-
}
|
|
5203
|
-
if (s) {
|
|
5204
|
-
let v = { name: y.name };
|
|
5205
|
-
a || (v.args = y.args, v.result = T ?? ""), s.addEvent("function.call", v);
|
|
5206
|
-
}
|
|
5207
|
-
return { result: T ?? "", role: "function", functionId: y.id, index: l };
|
|
5208
|
-
}).catch((T) => {
|
|
5209
|
-
if (!(T instanceof pn)) throw T;
|
|
5210
|
-
let S = T.getFixingInstructions();
|
|
5211
|
-
if (s) {
|
|
5212
|
-
let b = { name: y.name, message: T.toString() };
|
|
5213
|
-
a || (b.args = y.args, b.fixing_instructions = S), s.addEvent("function.error", b);
|
|
5214
|
-
}
|
|
5215
|
-
return p && Br(T, l, S, u), { functionId: y.id, isError: true, index: l, result: S, role: "function" };
|
|
5216
|
-
});
|
|
5217
|
-
}), I = (await Promise.all(f)).map((y) => y.result === void 0 || y.result === "" ? { ...y, result: "done" } : y);
|
|
5218
|
-
if (n.addFunctionResults(I, r), p) {
|
|
5219
|
-
let y = I.filter((R) => !R.isError);
|
|
5220
|
-
y.length > 0 && Ls(y, u);
|
|
5221
|
-
}
|
|
5222
|
-
if (A.length > 0) throw new wt(A);
|
|
5223
|
-
return g;
|
|
5224
|
-
};
|
|
5225
|
-
function Uo(i6, e, t, n) {
|
|
5226
|
-
if (!e || e.length === 0) return;
|
|
5227
|
-
if (!i6.getFeatures(n).functions) throw new Error("Functions are not supported by the AI service");
|
|
5228
|
-
return e.map((o) => ({ id: o.id, name: o.function.name, args: o.function.params }));
|
|
5229
|
-
}
|
|
5230
|
-
function Ji(i6, e, t, n) {
|
|
5231
|
-
let r = e;
|
|
5232
|
-
return !t && (r === "required" || typeof r == "function") ? { functions: [], functionCall: void 0 } : i6 ? { functions: i6.map((s) => "toFunction" in s ? s.toFunction() : s).flat(), functionCall: r } : { functions: [], functionCall: r };
|
|
5233
|
-
}
|
|
5234
|
-
function Qi(i6) {
|
|
5235
|
-
if (!i6.trim()) return null;
|
|
5236
|
-
try {
|
|
5237
|
-
return JSON.parse(i6);
|
|
5238
|
-
} catch {
|
|
5239
|
-
}
|
|
5240
|
-
let e = Ul(i6);
|
|
5241
|
-
try {
|
|
5242
|
-
return JSON.parse(e);
|
|
5243
|
-
} catch {
|
|
5244
|
-
return null;
|
|
5245
|
-
}
|
|
5246
|
-
}
|
|
5247
|
-
function Ul(i6) {
|
|
5248
|
-
let e = i6.trim();
|
|
5249
|
-
for (e.endsWith(",") && (e = e.slice(0, -1)); e.match(/[0-9][eE.+-]$/); ) e = e.slice(0, -1);
|
|
5250
|
-
e = e.replace(/,(\s*[}\]])/g, "$1"), e.match(/t(r(u(e)?)?)?$/) && !e.endsWith('"') && !e.endsWith("true") && e.match(/[:[,]\s*t(r(u(e)?)?)?$/) && (e = e.replace(/t(r(u(e)?)?)?$/, "true")), e.match(/f(a(l(s(e)?)?)?)?$/) && !e.endsWith('"') && !e.endsWith("false") && e.match(/[:[,]\s*f(a(l(s(e)?)?)?)?$/) && (e = e.replace(/f(a(l(s(e)?)?)?)?$/, "false")), e.match(/n(u(l(l)?)?)?$/) && !e.endsWith('"') && !e.endsWith("null") && e.match(/[:[,]\s*n(u(l(l)?)?)?$/) && (e = e.replace(/n(u(l(l)?)?)?$/, "null"));
|
|
5251
|
-
let t = [], n = false, r = false;
|
|
5252
|
-
for (let o = 0; o < e.length; o++) {
|
|
5253
|
-
let s = e[o];
|
|
5254
|
-
if (r) {
|
|
5255
|
-
r = false;
|
|
5256
|
-
continue;
|
|
5257
|
-
}
|
|
5258
|
-
if (s === "\\") {
|
|
5259
|
-
r = true;
|
|
5260
|
-
continue;
|
|
5261
|
-
}
|
|
5262
|
-
if (s === '"') {
|
|
5263
|
-
n = !n;
|
|
5264
|
-
continue;
|
|
5265
|
-
}
|
|
5266
|
-
n || (s === "{" ? t.push("}") : s === "[" ? t.push("]") : s === "}" ? t.length > 0 && t[t.length - 1] === "}" && t.pop() : s === "]" && t.length > 0 && t[t.length - 1] === "]" && t.pop());
|
|
5267
|
-
}
|
|
5268
|
-
for (r && (e = e.slice(0, -1)), n && (e += '"'), t.length > 0 && t[t.length - 1] === "}" && e.match(/,\s*"[^"]*"\s*$/) && (e = e.replace(/,\s*"[^"]*"\s*$/, "")); t.length > 0; ) e += t.pop();
|
|
5269
|
-
return e;
|
|
5270
|
-
}
|
|
5271
|
-
import_dayjs.default.extend(import_utc.default);
|
|
5272
|
-
import_dayjs.default.extend(import_timezone.default);
|
|
5273
|
-
import_dayjs.default.extend(import_customParseFormat.default);
|
|
5274
|
-
function Yi(i6, e, t = false) {
|
|
5275
|
-
try {
|
|
5276
|
-
return zl(e);
|
|
5277
|
-
} catch (n) {
|
|
5278
|
-
if (i6.isOptional && !t) return;
|
|
5279
|
-
let r = n.message;
|
|
5280
|
-
throw ji(i6, e, r);
|
|
5281
|
-
}
|
|
5282
|
-
}
|
|
5283
|
-
function zl(i6) {
|
|
5284
|
-
if (!(0, import_dayjs.default)(i6, "YYYY-MM-DD", true).isValid()) throw new Error('Invalid date format. Please provide the date in "YYYY-MM-DD" format.');
|
|
5285
|
-
return import_dayjs.default.utc(i6, "YYYY-MM-DD").startOf("day").toDate();
|
|
5286
|
-
}
|
|
5287
|
-
function Xi(i6, e, t = false) {
|
|
5288
|
-
try {
|
|
5289
|
-
return Hl(e);
|
|
5290
|
-
} catch (n) {
|
|
5291
|
-
if (i6.isOptional && !t) return;
|
|
5292
|
-
let r = n.message;
|
|
5293
|
-
throw qi(i6, e, r);
|
|
5294
|
-
}
|
|
5295
|
-
}
|
|
5296
|
-
function Hl(i6) {
|
|
5297
|
-
let e = /^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}(?::\d{2})?) (.+)$/, t = i6.match(e);
|
|
5298
|
-
if (!t) throw new Error('Invalid date and time format. Please provide the date and time in "YYYY-MM-DD HH:mm" or "YYYY-MM-DD HH:mm:ss" format, followed by the timezone.');
|
|
5299
|
-
let [, n, r] = t;
|
|
5300
|
-
if (!n || !r) throw new Error('Invalid date and time format. Please provide the date and time in "YYYY-MM-DD HH:mm" or "YYYY-MM-DD HH:mm:ss" format, followed by the timezone.');
|
|
5301
|
-
try {
|
|
5302
|
-
let o = n.includes(":") && n.split(":").length === 3 ? "YYYY-MM-DD HH:mm:ss" : "YYYY-MM-DD HH:mm", s = import_dayjs.default.tz(n, o, r);
|
|
5303
|
-
if (!s.isValid()) throw new Error("Invalid date and time values. Please ensure all components are correct.");
|
|
5304
|
-
return s.utc().toDate();
|
|
5305
|
-
} catch {
|
|
5306
|
-
throw new Error(`Unrecognized time zone ${r}. Please provide a valid time zone name, abbreviation, or offset. For example, "America/New_York", or "EST".`);
|
|
5307
|
-
}
|
|
5308
|
-
}
|
|
5309
|
-
var Zi = (i6) => (0, import_dayjs.default)(i6).utc().format("YYYY-MM-DD HH:mm:ss [UTC]");
|
|
5310
|
-
var ug = new Te();
|
|
5311
|
-
var ar = (i6, e) => {
|
|
5312
|
-
let t = i6.type ?? { name: "string", isArray: false }, n = (c2, u) => {
|
|
5313
|
-
switch (c2) {
|
|
5314
|
-
case "class":
|
|
5315
|
-
return typeof u == "string";
|
|
5316
|
-
case "code":
|
|
5317
|
-
return typeof u == "string";
|
|
5318
|
-
case "string":
|
|
5319
|
-
return typeof u == "string";
|
|
5320
|
-
case "number":
|
|
5321
|
-
return typeof u == "number";
|
|
5322
|
-
case "boolean":
|
|
5323
|
-
return typeof u == "boolean";
|
|
5324
|
-
case "date":
|
|
5325
|
-
return u instanceof Date || typeof u == "string";
|
|
5326
|
-
case "datetime":
|
|
5327
|
-
return u instanceof Date || typeof u == "string";
|
|
5328
|
-
case "json":
|
|
5329
|
-
return typeof u == "object" || typeof u == "string";
|
|
5330
|
-
default:
|
|
5331
|
-
return false;
|
|
5332
|
-
}
|
|
5333
|
-
}, r = (c2) => !(!c2 || typeof c2 != "object" || !("mimeType" in c2) || !("data" in c2));
|
|
5334
|
-
if (i6.type?.name === "image") {
|
|
5335
|
-
let c2;
|
|
5336
|
-
if (Array.isArray(e)) {
|
|
5337
|
-
for (let u of e) if (!r(u)) {
|
|
5338
|
-
c2 = "object ({ mimeType: string; data: string })";
|
|
5339
|
-
break;
|
|
5340
|
-
}
|
|
5341
|
-
} else r(e) || (c2 = "object ({ mimeType: string; data: string })");
|
|
5342
|
-
if (c2) throw new Error(`Validation failed: Expected '${i6.name}' to be type '${c2}' instead got '${e}'`);
|
|
5343
|
-
return;
|
|
5344
|
-
}
|
|
5345
|
-
let o = (c2) => !(!c2 || typeof c2 != "object" || !("data" in c2));
|
|
5346
|
-
if (i6.type?.name === "audio") {
|
|
5347
|
-
let c2;
|
|
5348
|
-
if (Array.isArray(e)) {
|
|
5349
|
-
for (let u of e) if (!o(u)) {
|
|
5350
|
-
c2 = "object ({ data: string; format?: string })";
|
|
5351
|
-
break;
|
|
5352
|
-
}
|
|
5353
|
-
} else o(e) || (c2 = "object ({ data: string; format?: string })");
|
|
5354
|
-
if (c2) throw new Error(`Validation failed: Expected '${i6.name}' to be type '${c2}' instead got '${e}'`);
|
|
5355
|
-
return;
|
|
5356
|
-
}
|
|
5357
|
-
let s = (c2) => {
|
|
5358
|
-
if (!c2 || typeof c2 != "object" || !("mimeType" in c2)) return false;
|
|
5359
|
-
let u = "data" in c2, p = "fileUri" in c2;
|
|
5360
|
-
return !(!u && !p || u && p);
|
|
5361
|
-
};
|
|
5362
|
-
if (i6.type?.name === "file") {
|
|
5363
|
-
let c2;
|
|
5364
|
-
if (Array.isArray(e)) {
|
|
5365
|
-
for (let u of e) if (!s(u)) {
|
|
5366
|
-
c2 = "object ({ mimeType: string; data: string } | { mimeType: string; fileUri: string })";
|
|
5367
|
-
break;
|
|
5368
|
-
}
|
|
5369
|
-
} else s(e) || (c2 = "object ({ mimeType: string; data: string } | { mimeType: string; fileUri: string })");
|
|
5370
|
-
if (c2) throw new Error(`Validation failed: Expected '${i6.name}' to be type '${c2}' instead got '${e}'`);
|
|
5371
|
-
return;
|
|
5372
|
-
}
|
|
5373
|
-
let a = (c2) => typeof c2 == "string" ? true : !(!c2 || typeof c2 != "object" || !("url" in c2));
|
|
5374
|
-
if (i6.type?.name === "url") {
|
|
5375
|
-
let c2;
|
|
5376
|
-
if (Array.isArray(e)) {
|
|
5377
|
-
for (let u of e) if (!a(u)) {
|
|
5378
|
-
c2 = "string or object ({ url: string; title?: string; description?: string })";
|
|
5379
|
-
break;
|
|
5380
|
-
}
|
|
5381
|
-
} else a(e) || (c2 = "string or object ({ url: string; title?: string; description?: string })");
|
|
5382
|
-
if (c2) throw new Error(`Validation failed: Expected '${i6.name}' to be type '${c2}' instead got '${e}'`);
|
|
5383
|
-
return;
|
|
5384
|
-
}
|
|
5385
|
-
let l = true;
|
|
5386
|
-
if (t.isArray) {
|
|
5387
|
-
if (!Array.isArray(e)) l = false;
|
|
5388
|
-
else for (let c2 of e) if (!n(t.name, c2)) {
|
|
5389
|
-
l = false;
|
|
5390
|
-
break;
|
|
5391
|
-
}
|
|
5392
|
-
} else l = n(t.name, e);
|
|
5393
|
-
if (!l) {
|
|
5394
|
-
let c2 = Array.isArray(e) ? "array" : typeof e;
|
|
5395
|
-
throw new Error(`Validation failed: Expected '${i6.name}' to be a ${i6.type?.isArray ? "an array of " : ""}${t.name} instead got '${c2}' (${JSON.stringify(e)})`);
|
|
5396
|
-
}
|
|
5397
|
-
};
|
|
5398
|
-
function dn(i6) {
|
|
5399
|
-
let e = {};
|
|
5400
|
-
for (let t of i6) {
|
|
5401
|
-
let n = `${t.ai}:${t.model}`;
|
|
5402
|
-
if (!e[n]) {
|
|
5403
|
-
e[n] = { ...t };
|
|
5404
|
-
continue;
|
|
5405
|
-
}
|
|
5406
|
-
let r = e[n];
|
|
5407
|
-
if (r) {
|
|
5408
|
-
let o = r.tokens ?? { promptTokens: 0, completionTokens: 0, totalTokens: 0 };
|
|
5409
|
-
o.promptTokens += t?.tokens?.promptTokens ?? 0, o.completionTokens += t?.tokens?.completionTokens ?? 0, o.totalTokens += t?.tokens?.totalTokens ?? 0, r.tokens = o;
|
|
5410
|
-
let s = r.citations ?? [], a = t.citations ?? [];
|
|
5411
|
-
if (a.length) {
|
|
5412
|
-
let l = new Set(s.map((c2) => c2.url));
|
|
5413
|
-
for (let c2 of a) c2?.url && !l.has(c2.url) && (s.push(c2), l.add(c2.url));
|
|
5414
|
-
r.citations = s;
|
|
5415
|
-
}
|
|
5416
|
-
}
|
|
5417
|
-
}
|
|
5418
|
-
return Object.values(e);
|
|
5419
|
-
}
|
|
5420
|
-
var ea = (i6) => {
|
|
5421
|
-
if (!i6.trim()) return [];
|
|
5422
|
-
let e = /* @__PURE__ */ new Set(["-", "*", "+"]), t = /^\d+[\s]*[.)\]]\s*/, n = i6.split(`
|
|
5423
|
-
`), r = [];
|
|
5424
|
-
for (let o of n) {
|
|
5425
|
-
let s = o.trim();
|
|
5426
|
-
if (s) {
|
|
5427
|
-
if (s[0] && e.has(s[0])) r.push(s.slice(1).trim());
|
|
5428
|
-
else if (t.test(s)) r.push(s.replace(t, "").trim());
|
|
5429
|
-
else if (r.length !== 0) throw new Error("Could not parse markdown list: mixed content detected");
|
|
5430
|
-
}
|
|
5431
|
-
}
|
|
5432
|
-
if (r.length === 0) throw new Error("Could not parse markdown list: no valid list items found");
|
|
5433
|
-
return r;
|
|
5434
|
-
};
|
|
5435
|
-
function jo(i6, e) {
|
|
5436
|
-
let { index: t, delta: n, version: r } = e, o = i6.find((a) => a.index === t)?.delta;
|
|
5437
|
-
if (!o) return i6.push({ index: t, delta: n, version: r }), i6;
|
|
5438
|
-
for (let a of Object.keys(n)) {
|
|
5439
|
-
let l = o[a], c2 = n[a];
|
|
5440
|
-
l === void 0 && Array.isArray(c2) ? o[a] = [...c2] : Array.isArray(l) && Array.isArray(c2) ? o[a] = [...l, ...c2] : (l === void 0 || typeof l == "string") && typeof c2 == "string" ? o[a] = `${l ?? ""}${c2}` : o[a] = c2;
|
|
5441
|
-
}
|
|
5442
|
-
let s = i6.find((a) => a.index === t);
|
|
5443
|
-
return s && (s.version = r), i6;
|
|
5444
|
-
}
|
|
5445
|
-
var Bo = class {
|
|
5446
|
-
cache = /* @__PURE__ */ new Map();
|
|
5447
|
-
maxSize;
|
|
5448
|
-
constructor(e) {
|
|
5449
|
-
this.maxSize = e;
|
|
5450
|
-
}
|
|
5451
|
-
get(e) {
|
|
5452
|
-
let t = this.cache.get(e);
|
|
5453
|
-
return t && (this.cache.delete(e), this.cache.set(e, t)), t;
|
|
5454
|
-
}
|
|
5455
|
-
set(e, t) {
|
|
5456
|
-
if (this.cache.has(e)) this.cache.delete(e);
|
|
5457
|
-
else if (this.cache.size >= this.maxSize) {
|
|
5458
|
-
let n = this.cache.keys().next().value;
|
|
5459
|
-
n && this.cache.delete(n);
|
|
5460
|
-
}
|
|
5461
|
-
this.cache.set(e, t);
|
|
4468
|
+
this.cache.set(e, t);
|
|
5462
4469
|
}
|
|
5463
4470
|
};
|
|
5464
4471
|
var Kl = new Bo(500);
|
|
5465
|
-
function ta(i6, e, t = 0, n = Kl) {
|
|
5466
|
-
if (/^```[a-zA-Z]*\s*$/.test(i6)) return -4;
|
|
5467
|
-
if (/^[\s`]*$/.test(i6)) return -3;
|
|
5468
|
-
let r = i6.indexOf(e, t);
|
|
5469
|
-
if (r !== -1) return r;
|
|
5470
|
-
let o = n.get(e) ?? Array.from({ length: e.length }, (a, l) => e.slice(0, l + 1));
|
|
5471
|
-
n.get(e) || n.set(e, o);
|
|
5472
|
-
let s = -1;
|
|
5473
|
-
for (let a = o.length - 1; a >= 0; a--) {
|
|
5474
|
-
let l = o[a];
|
|
5475
|
-
if (i6.endsWith(l)) {
|
|
5476
|
-
s = a;
|
|
5477
|
-
break;
|
|
5478
|
-
}
|
|
5479
|
-
}
|
|
5480
|
-
return s >= 0 ? -2 : -1;
|
|
5481
|
-
}
|
|
5482
|
-
function it(i6, e) {
|
|
5483
|
-
if (typeof i6 != "string") throw Lo(e, String(i6), "URL must be a string");
|
|
5484
|
-
try {
|
|
5485
|
-
new URL(i6);
|
|
5486
|
-
} catch {
|
|
5487
|
-
throw Lo(e, i6, "Invalid URL format. Expected a valid URL like https://example.com");
|
|
5488
|
-
}
|
|
5489
|
-
}
|
|
5490
|
-
function Pe(i6, e) {
|
|
5491
|
-
if (typeof i6 != "string") return;
|
|
5492
|
-
let t = e.type;
|
|
5493
|
-
if (t) {
|
|
5494
|
-
if (t.minLength !== void 0 && i6.length < t.minLength) throw Rt(e, i6, "minLength", t.minLength);
|
|
5495
|
-
if (t.maxLength !== void 0 && i6.length > t.maxLength) throw Rt(e, i6, "maxLength", t.maxLength);
|
|
5496
|
-
if (t.pattern !== void 0 && !new RegExp(t.pattern).test(i6)) throw Rt(e, i6, "pattern", t.pattern);
|
|
5497
|
-
if (t.format === "email" && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(i6)) throw Rt(e, i6, "format", "valid email address");
|
|
5498
|
-
if (t.format === "uri" || t.format === "url") try {
|
|
5499
|
-
new URL(i6);
|
|
5500
|
-
} catch {
|
|
5501
|
-
throw Rt(e, i6, "format", "valid URL");
|
|
5502
|
-
}
|
|
5503
|
-
}
|
|
5504
|
-
}
|
|
5505
|
-
function Fe(i6, e) {
|
|
5506
|
-
if (typeof i6 != "number") return;
|
|
5507
|
-
let t = e.type;
|
|
5508
|
-
if (t) {
|
|
5509
|
-
if (t.minimum !== void 0 && i6 < t.minimum) throw Go(e, i6, "minimum", t.minimum);
|
|
5510
|
-
if (t.maximum !== void 0 && i6 > t.maximum) throw Go(e, i6, "maximum", t.maximum);
|
|
5511
|
-
}
|
|
5512
|
-
}
|
|
5513
|
-
var ur = (i6, e, t, n) => {
|
|
5514
|
-
let r = n?.strictMode ?? false, o = n?.treatAllFieldsOptional ?? false, s = n?.treatAllFieldsOptional ?? false, a = { extractedFields: [], streamedIndex: {}, s: -1 };
|
|
5515
|
-
zo(i6, e, a, t, { strictMode: r, skipEarlyFail: s, treatAllFieldsOptional: o }), Ho(i6, e, a, t, { strictMode: r, treatAllFieldsOptional: o, forceFinalize: true });
|
|
5516
|
-
for (let l of i6.getOutputFields()) l.isInternal && delete e[l.name];
|
|
5517
|
-
};
|
|
5518
|
-
var qo = (i6, e, t) => {
|
|
5519
|
-
let n = [];
|
|
5520
|
-
for (let r of t) r && !r.isOptional && e[r.name] === void 0 && n.push(r);
|
|
5521
|
-
if (n.length > 0) throw Li(n);
|
|
5522
|
-
};
|
|
5523
|
-
var zo = (i6, e, t, n, { strictMode: r, skipEarlyFail: o } = {}) => {
|
|
5524
|
-
let s = i6.getOutputFields(), a;
|
|
5525
|
-
for (; ; ) {
|
|
5526
|
-
let l = /* @__PURE__ */ new Set();
|
|
5527
|
-
t.currFieldIndex !== void 0 && !t.inAssumedField && l.add(t.currFieldIndex);
|
|
5528
|
-
let c2 = s.map((g, A) => ({ field: g, index: A })).filter(({ index: g }) => !l.has(g)), u, p, d = -1, m = 0;
|
|
5529
|
-
for (let { index: g, field: A } of c2) {
|
|
5530
|
-
let f = `${(t.extractedFields.length === 0 ? "" : `
|
|
5531
|
-
`) + A.title}:`, x = ta(n, f, t.s);
|
|
5532
|
-
if (x === -2 || x === -3) return true;
|
|
5533
|
-
if (x === -4) return t.inBlock = true, true;
|
|
5534
|
-
x >= 0 && (d === -1 || x < d) && (d = x, m = f.length, u = g, p = A);
|
|
5535
|
-
}
|
|
5536
|
-
if (d === -1) {
|
|
5537
|
-
if (o) return;
|
|
5538
|
-
if (!r && t.currField === void 0 && t.extractedFields.length === 0 && s.length === 1) {
|
|
5539
|
-
t.inAssumedField = true, t.currField = s[0], t.currFieldIndex = 0, t.s = 0, t.extractedFields.includes(s[0]) || t.extractedFields.push(s[0]), t.streamedIndex[s[0].name] === void 0 && (t.streamedIndex[s[0].name] = 0);
|
|
5540
|
-
return;
|
|
5541
|
-
}
|
|
5542
|
-
if (r && t.currField === void 0 && t.extractedFields.length === 0) {
|
|
5543
|
-
let g = s.find((A) => !A.isOptional);
|
|
5544
|
-
if (g) throw Xn(g);
|
|
5545
|
-
}
|
|
5546
|
-
break;
|
|
5547
|
-
}
|
|
5548
|
-
if (a && p && a.name !== p.name) throw Xn(a);
|
|
5549
|
-
if (t.currField !== void 0 && t.inAssumedField && (t.inAssumedField = false, t.streamedIndex[t.currField.name] = 0, t.currField = void 0), t.currField) {
|
|
5550
|
-
let g = n.substring(t.s, d).trim(), A = lr(t.currField, g);
|
|
5551
|
-
A !== void 0 && (e[t.currField.name] = A), t.prevFields ? t.prevFields?.push({ field: t.currField, s: t.s, e: d }) : t.prevFields = [{ field: t.currField, s: t.s, e: d }];
|
|
5552
|
-
}
|
|
5553
|
-
t.s = d + m, p !== void 0 && u !== void 0 && (t.currField = p, t.currFieldIndex = u), p && !t.extractedFields.includes(p) && t.extractedFields.push(p), p && t.streamedIndex[p.name] === void 0 && (t.streamedIndex[p.name] = 0);
|
|
5554
|
-
}
|
|
5555
|
-
};
|
|
5556
|
-
var Ho = (i6, e, t, n, r) => {
|
|
5557
|
-
let o = r?.strictMode ?? false, s = r?.treatAllFieldsOptional ?? false, a = r?.deferRequiredCheckForStreaming ?? false, l = r?.forceFinalize ?? false;
|
|
5558
|
-
if (t.currField) {
|
|
5559
|
-
let c2 = n.length, u = i6.getOutputFields();
|
|
5560
|
-
for (let m of u) {
|
|
5561
|
-
if (m.name === t.currField.name) continue;
|
|
5562
|
-
let g = `
|
|
5563
|
-
${m.title}:`, A = n.indexOf(g, t.s);
|
|
5564
|
-
A !== -1 && A < c2 && (c2 = A);
|
|
5565
|
-
}
|
|
5566
|
-
let p = n.substring(t.s, c2).trim(), d = lr(t.currField, p);
|
|
5567
|
-
d !== void 0 && (e[t.currField.name] = d);
|
|
5568
|
-
}
|
|
5569
|
-
if (o && !t.currField && t.extractedFields.length === 0 && n.trim()) {
|
|
5570
|
-
let p = i6.getOutputFields().find((d) => !d.isOptional);
|
|
5571
|
-
if (p) throw Xn(p);
|
|
5572
|
-
}
|
|
5573
|
-
if (Wl(i6, e, n, t), !s) {
|
|
5574
|
-
let c2 = t.currField !== void 0 || (t.extractedFields?.length ?? 0) > 0;
|
|
5575
|
-
o || l ? qo(t, e, i6.getOutputFields()) : c2 || qo(t, e, i6.getOutputFields());
|
|
5576
|
-
}
|
|
5577
|
-
};
|
|
5578
|
-
var Wl = (i6, e, t, n) => {
|
|
5579
|
-
let r = i6.getOutputFields();
|
|
5580
|
-
if (r.length === 1) {
|
|
5581
|
-
let s = r[0];
|
|
5582
|
-
if (s) {
|
|
5583
|
-
let a = `${s.title}:`, l = t.indexOf(a);
|
|
5584
|
-
if (l !== -1) {
|
|
5585
|
-
let c2 = l + a.length, u = `
|
|
5586
|
-
${s.title}:`, p = t.indexOf(u, c2), d = t.substring(c2, p === -1 ? t.length : p).trim();
|
|
5587
|
-
if (d) try {
|
|
5588
|
-
let m = lr(s, d);
|
|
5589
|
-
if (m !== void 0) {
|
|
5590
|
-
e[s.name] = m;
|
|
5591
|
-
return;
|
|
5592
|
-
}
|
|
5593
|
-
} catch {
|
|
5594
|
-
}
|
|
5595
|
-
}
|
|
5596
|
-
}
|
|
5597
|
-
}
|
|
5598
|
-
let o = t.split(`
|
|
5599
|
-
`);
|
|
5600
|
-
for (let s of r) {
|
|
5601
|
-
if (s.name in e) continue;
|
|
5602
|
-
let a = `${s.title}:`;
|
|
5603
|
-
for (let l of o) {
|
|
5604
|
-
let c2 = l.trim();
|
|
5605
|
-
if (c2.startsWith(a)) {
|
|
5606
|
-
let u = c2.substring(a.length).trim();
|
|
5607
|
-
if (u) try {
|
|
5608
|
-
let p = lr(s, u);
|
|
5609
|
-
if (p !== void 0) {
|
|
5610
|
-
e[s.name] = p;
|
|
5611
|
-
break;
|
|
5612
|
-
}
|
|
5613
|
-
} catch (p) {
|
|
5614
|
-
if (!s.isOptional) throw p;
|
|
5615
|
-
}
|
|
5616
|
-
break;
|
|
5617
|
-
}
|
|
5618
|
-
}
|
|
5619
|
-
}
|
|
5620
|
-
};
|
|
5621
|
-
var na = (i6, e, t = false) => {
|
|
5622
|
-
switch (i6.type?.name) {
|
|
5623
|
-
case "code":
|
|
5624
|
-
return oa(e);
|
|
5625
|
-
case "string":
|
|
5626
|
-
return e;
|
|
5627
|
-
case "number": {
|
|
5628
|
-
let n = Number(e);
|
|
5629
|
-
if (Number.isNaN(n)) {
|
|
5630
|
-
if (i6.isOptional && !t) return;
|
|
5631
|
-
throw new Error("Invalid number");
|
|
5632
|
-
}
|
|
5633
|
-
return n;
|
|
5634
|
-
}
|
|
5635
|
-
case "boolean": {
|
|
5636
|
-
if (typeof e == "boolean") return e;
|
|
5637
|
-
let n = e.toLowerCase();
|
|
5638
|
-
if (n === "true") return true;
|
|
5639
|
-
if (n === "false") return false;
|
|
5640
|
-
if (i6.isOptional && !t) return;
|
|
5641
|
-
throw new Error("Invalid boolean");
|
|
5642
|
-
}
|
|
5643
|
-
case "date":
|
|
5644
|
-
return Yi(i6, e, t);
|
|
5645
|
-
case "datetime":
|
|
5646
|
-
return Xi(i6, e, t);
|
|
5647
|
-
case "class": {
|
|
5648
|
-
let n = e;
|
|
5649
|
-
if (i6.type.options && !i6.type.options.includes(n)) {
|
|
5650
|
-
if (i6.isOptional) return;
|
|
5651
|
-
throw new Error(`Invalid class '${e}', expected one of the following: ${i6.type.options.join(", ")}`);
|
|
5652
|
-
}
|
|
5653
|
-
return n;
|
|
5654
|
-
}
|
|
5655
|
-
default:
|
|
5656
|
-
return e;
|
|
5657
|
-
}
|
|
5658
|
-
};
|
|
5659
|
-
function* ra(i6, e, t, n, r, o) {
|
|
5660
|
-
let { name: s, isInternal: a } = e, { isArray: l, name: c2 } = e.type ?? {};
|
|
5661
|
-
if (a || l || c2 && c2 !== "string" && c2 !== "code") return;
|
|
5662
|
-
let u = r.streamedIndex[s] ?? 0, p = u === 0, d = (t < 0 ? 0 : t) + u, m = i6.substring(d, n);
|
|
5663
|
-
if (m.length === 0) return;
|
|
5664
|
-
let g = m.replace(/\s+$/, "");
|
|
5665
|
-
r.currField?.type?.name === "code" && (g = g.replace(/\s*```\s*$/, ""));
|
|
5666
|
-
let A = p ? g.trimStart() : g;
|
|
5667
|
-
r.currField?.type?.name === "code" && (A = A.replace(/^[ ]*```[a-zA-Z0-9]*\n\s*/, "")), A.length > 0 && (yield { index: o, delta: { [s]: A } }, r.streamedIndex[s] = u + g.length);
|
|
5668
|
-
}
|
|
5669
|
-
function* Ko(i6, e, t, n, r) {
|
|
5670
|
-
for (let s of n.prevFields ?? []) {
|
|
5671
|
-
let { field: a, s: l, e: c2 } = s;
|
|
5672
|
-
yield* ra(e, a, l, c2, n, r);
|
|
5673
|
-
}
|
|
5674
|
-
if (n.prevFields = void 0, n.inAssumedField && !(i6.getOutputFields().filter((l) => !l.isInternal).length === 1) || !n.currField || n.currField.isInternal) return;
|
|
5675
|
-
yield* ra(e, n.currField, n.s, e.length, n, r);
|
|
5676
|
-
let o = i6.getOutputFields();
|
|
5677
|
-
for (let s of Object.keys(t)) {
|
|
5678
|
-
let a = o.find((u) => u.name === s);
|
|
5679
|
-
if (!a || a.isInternal) continue;
|
|
5680
|
-
let l = t[s];
|
|
5681
|
-
if (Array.isArray(l)) {
|
|
5682
|
-
let u = n.streamedIndex?.[s] ?? 0, p = l.slice(u);
|
|
5683
|
-
p && p.length > 0 && (yield { index: r, delta: { [s]: p } }, n.streamedIndex[s] = u + p.length);
|
|
5684
|
-
continue;
|
|
5685
|
-
}
|
|
5686
|
-
let c2 = typeof l == "string" ? l : void 0;
|
|
5687
|
-
if (!n.streamedIndex[s]) yield { index: r, delta: { [s]: l } }, n.streamedIndex[s] = c2 ? c2.length : 1;
|
|
5688
|
-
else if (c2) {
|
|
5689
|
-
let u = n.streamedIndex[s];
|
|
5690
|
-
if (c2.length > u) {
|
|
5691
|
-
let p = c2.substring(u);
|
|
5692
|
-
yield { index: r, delta: { [s]: p } }, n.streamedIndex[s] = c2.length;
|
|
5693
|
-
}
|
|
5694
|
-
}
|
|
5695
|
-
}
|
|
5696
|
-
}
|
|
5697
|
-
function lr(i6, e) {
|
|
5698
|
-
if (!e || e === "" || /^(null|undefined)\s*$/i.test(e)) {
|
|
5699
|
-
if (i6.isOptional) return;
|
|
5700
|
-
throw Zn(i6);
|
|
5701
|
-
}
|
|
5702
|
-
let t;
|
|
5703
|
-
if (i6.type?.name === "json") try {
|
|
5704
|
-
let r = oa(e);
|
|
5705
|
-
return t = JSON.parse(r), t;
|
|
5706
|
-
} catch (r) {
|
|
5707
|
-
throw Gi(i6, r.message);
|
|
5708
|
-
}
|
|
5709
|
-
if (i6.type?.isArray) try {
|
|
5710
|
-
try {
|
|
5711
|
-
t = JSON.parse(e);
|
|
5712
|
-
} catch {
|
|
5713
|
-
t = ea(e);
|
|
5714
|
-
}
|
|
5715
|
-
if (!Array.isArray(t)) throw new Error("Expected an array");
|
|
5716
|
-
} catch (r) {
|
|
5717
|
-
throw Ui(i6, r.message);
|
|
5718
|
-
}
|
|
5719
|
-
try {
|
|
5720
|
-
if (Array.isArray(t)) {
|
|
5721
|
-
for (let [r, o] of t.entries()) if (o !== void 0) {
|
|
5722
|
-
let s = typeof o == "string" ? o.trim() : o;
|
|
5723
|
-
t[r] = na(i6, s, true);
|
|
5724
|
-
}
|
|
5725
|
-
} else t = na(i6, e);
|
|
5726
|
-
} catch (r) {
|
|
5727
|
-
throw Bi(i6, e, r.message);
|
|
5728
|
-
}
|
|
5729
|
-
if (typeof t == "string" && t === "") return;
|
|
5730
|
-
let n = i6.type;
|
|
5731
|
-
if (n && t !== void 0 && (n.name === "url" && it(t, i6), (n.name === "string" || n.name === "code") && Pe(t, i6), n.name === "number" && Fe(t, i6), n.isArray && Array.isArray(t))) for (let r of t) r !== void 0 && (n.name === "string" || n.name === "code" ? Pe(r, i6) : n.name === "number" && Fe(r, i6));
|
|
5732
|
-
return t;
|
|
5733
|
-
}
|
|
5734
|
-
function pr(i6, e) {
|
|
5735
|
-
let t = i6.getOutputFields();
|
|
5736
|
-
for (let n of t) {
|
|
5737
|
-
let r = e[n.name];
|
|
5738
|
-
if (r == null) {
|
|
5739
|
-
if (!n.isOptional) throw Zn(n);
|
|
5740
|
-
continue;
|
|
5741
|
-
}
|
|
5742
|
-
let o = n.type;
|
|
5743
|
-
if (o) {
|
|
5744
|
-
if (o.name === "url" && it(r, n), (o.name === "string" || o.name === "code") && Pe(r, n), o.name === "number" && Fe(r, n), o.isArray && Array.isArray(r)) for (let s of r) s != null && (o.name === "url" ? it(s, n) : o.name === "string" || o.name === "code" ? Pe(s, n) : o.name === "number" && Fe(s, n));
|
|
5745
|
-
if (o.name === "object" && o.fields && typeof r == "object" && !Array.isArray(r) && cr(n, r), o.isArray && o.fields && Array.isArray(r) && o.name === "object") for (let s of r) s && typeof s == "object" && cr(n, s);
|
|
5746
|
-
}
|
|
5747
|
-
}
|
|
5748
|
-
}
|
|
5749
|
-
function cr(i6, e) {
|
|
5750
|
-
let t = i6.type?.fields;
|
|
5751
|
-
if (!(!t || typeof t != "object")) for (let [n, r] of Object.entries(t)) {
|
|
5752
|
-
let o = { name: n, title: n, description: r.description, type: { name: r.type, isArray: r.isArray, options: r.options, fields: r.fields, minLength: r.minLength, maxLength: r.maxLength, minimum: r.minimum, maximum: r.maximum, pattern: r.pattern, patternDescription: r.patternDescription, format: r.format }, isOptional: r.isOptional ?? false, isInternal: r.isInternal ?? false }, s = e[o.name];
|
|
5753
|
-
if (s == null) {
|
|
5754
|
-
if (!o.isOptional) throw Zn(o);
|
|
5755
|
-
continue;
|
|
5756
|
-
}
|
|
5757
|
-
let a = o.type;
|
|
5758
|
-
if (a) {
|
|
5759
|
-
if (a.name === "url" && it(s, o), (a.name === "string" || a.name === "code") && Pe(s, o), a.name === "number" && Fe(s, o), a.isArray && Array.isArray(s)) for (let l of s) l != null && (a.name === "url" ? it(l, o) : a.name === "string" || a.name === "code" ? Pe(l, o) : a.name === "number" && Fe(l, o));
|
|
5760
|
-
if (a.name === "object" && a.fields && typeof s == "object" && !Array.isArray(s) && cr(o, s), a.isArray && a.fields && Array.isArray(s) && a.name === "object") for (let l of s) l && typeof l == "object" && cr(o, l);
|
|
5761
|
-
}
|
|
5762
|
-
}
|
|
5763
|
-
}
|
|
5764
|
-
var oa = (i6) => {
|
|
5765
|
-
let t = /```([A-Za-z]*)\n([\s\S]*?)\n```/g.exec(i6);
|
|
5766
|
-
return t ? t.length === 3 ? t[2] : t.length === 2 ? t[1] : i6 : i6;
|
|
5767
|
-
};
|
|
5768
|
-
async function Wo(i6, e, t, n) {
|
|
5769
|
-
for (let r of i6) {
|
|
5770
|
-
if (e[r.field.name] === void 0) continue;
|
|
5771
|
-
let o = r.process, s = await o(e[r.field.name], { sessionId: n, values: e, done: true });
|
|
5772
|
-
sa(r.field, t, s, n);
|
|
5773
|
-
}
|
|
5774
|
-
}
|
|
5775
|
-
async function Vo(i6, e, t, n, r, o, s = false) {
|
|
5776
|
-
for (let a of i6) {
|
|
5777
|
-
if (t.currField?.name !== a.field.name) continue;
|
|
5778
|
-
let l = e.substring(t.s);
|
|
5779
|
-
t.currField?.type?.name === "code" && (l = l.replace(/^[ ]*```[a-zA-Z0-9]*\n\s*/, ""), l = l.replace(/\s*```\s*$/, ""));
|
|
5780
|
-
let c2 = a.process, u = await c2(l, { sessionId: o, values: r, done: s });
|
|
5781
|
-
sa(t.currField, n, u, o);
|
|
5782
|
-
}
|
|
5783
|
-
}
|
|
5784
|
-
var sa = (i6, e, t, n) => {
|
|
5785
|
-
if (t === void 0 || typeof t == "string" && (t === "" || /^(null|undefined)\s*$/i.test(t))) return;
|
|
5786
|
-
let r = JSON.stringify(t, (s, a) => typeof a == "bigint" ? Number(a) : a, 2), o = Vl(i6, r);
|
|
5787
|
-
e.addRequest([{ role: "user", content: [{ type: "text", text: o }] }], n), e.addTag("processor", n);
|
|
5788
|
-
};
|
|
5789
|
-
function Vl(i6, e) {
|
|
5790
|
-
let t = i6.type?.name === "code", n = i6.title;
|
|
5791
|
-
return t ? `Code in the field "${n}" was executed. The code execution produced the following output: ${e}` : `The field "${n}" was processed. The field contents were transformed into the following output: ${e}`;
|
|
5792
|
-
}
|
|
5793
|
-
async function* ia({ res: i6, usage: e, states: t, debug: n, ...r }) {
|
|
5794
|
-
let o = (r.ai.getFeatures().functionCot ?? false) && r.functions !== void 0 && r.functions.length > 0, s, a = [], l = i6.getReader();
|
|
5795
|
-
try {
|
|
5796
|
-
for (; ; ) {
|
|
5797
|
-
let { done: c2, value: u } = await l.read();
|
|
5798
|
-
if (c2) break;
|
|
5799
|
-
let p = u;
|
|
5800
|
-
p.modelUsage && (s = p.modelUsage);
|
|
5801
|
-
for (let d of p.results) {
|
|
5802
|
-
if (Array.isArray(d.citations)) for (let g of d.citations) g?.url && a.push({ url: g.url, title: g.title, description: g.description, license: g.license, publicationDate: g.publicationDate, snippet: g.snippet });
|
|
5803
|
-
if ((!d.content || d.content === "") && (!d.thought || d.thought === "") && !d.thoughtBlock && (!d.functionCalls || d.functionCalls.length === 0)) continue;
|
|
5804
|
-
let m = t.find((g) => g.index === d.index);
|
|
5805
|
-
if (!m) throw new Error(`No state found for result (index: ${d.index})`);
|
|
5806
|
-
yield* Jl({ ...r, result: d, skipEarlyFail: o, state: m, debug: n });
|
|
5807
|
-
}
|
|
5808
|
-
}
|
|
5809
|
-
} finally {
|
|
5810
|
-
l.releaseLock();
|
|
5811
|
-
}
|
|
5812
|
-
for (let c2 of t) yield* Ql({ ...r, state: c2, debug: n });
|
|
5813
|
-
if (s) {
|
|
5814
|
-
if (a.length) {
|
|
5815
|
-
let c2 = Array.from(new Map(a.filter((u) => u.url).map((u) => [u.url, u])).values());
|
|
5816
|
-
s.citations = c2;
|
|
5817
|
-
}
|
|
5818
|
-
if (e.push(s), n && r.logger) {
|
|
5819
|
-
let c2 = structuredClone(s);
|
|
5820
|
-
delete c2.citations, r.logger({ name: "ChatResponseUsage", value: c2 }), s.citations && s.citations.length > 0 && r.logger({ name: "ChatResponseCitations", value: s.citations });
|
|
5821
|
-
}
|
|
5822
|
-
}
|
|
5823
|
-
}
|
|
5824
|
-
async function* Jl({ result: i6, mem: e, sessionId: t, strictMode: n, skipEarlyFail: r, treatAllFieldsOptional: o, state: s, signature: a, streamingFieldProcessors: l, thoughtFieldName: c2, streamingAsserts: u, asserts: p }) {
|
|
5825
|
-
if (i6.functionCalls && i6.functionCalls.length > 0) vn(s.functionCalls, i6.functionCalls), e.updateResult({ name: i6.name, content: i6.content, functionCalls: s.functionCalls, thoughtBlock: i6.thoughtBlock, delta: i6.functionCalls?.[0]?.function?.params, index: i6.index }, t);
|
|
5826
|
-
else if (i6.content && i6.content.length > 0) {
|
|
5827
|
-
i6.thought && i6.thought.length > 0 && (yield { index: i6.index, delta: { [c2]: i6.thought } }), s.content += i6.content, e.updateResult({ name: i6.name, content: s.content, thoughtBlock: i6.thoughtBlock, delta: i6.content, index: i6.index }, t);
|
|
5828
|
-
let d = a.getOutputFields();
|
|
5829
|
-
if (a.hasComplexFields()) {
|
|
5830
|
-
let A = Qi(s.content);
|
|
5831
|
-
if (A && typeof A == "object") {
|
|
5832
|
-
let h = {};
|
|
5833
|
-
for (let f of Object.keys(A)) d.some((x) => x.name === f) && (h[f] = A[f]);
|
|
5834
|
-
pr(a, h), Object.assign(s.values, h), yield { index: i6.index, delta: h };
|
|
5835
|
-
return;
|
|
5836
|
-
}
|
|
5837
|
-
}
|
|
5838
|
-
if (zo(a, s.values, s.xstate, s.content, { strictMode: n, skipEarlyFail: r, treatAllFieldsOptional: o })) return;
|
|
5839
|
-
u.length !== 0 && await _o(u, s.xstate, s.content), l.length !== 0 && await Vo(l, s.content, s.xstate, e, s.values, t), yield* Ko(a, s.content, s.values, s.xstate, i6.index), await Vn(p, s.values);
|
|
5840
|
-
} else i6.thought && i6.thought.length > 0 ? (s.values[c2] = (s.values[c2] ?? "") + i6.thought, yield { index: i6.index, delta: { [c2]: i6.thought } }, e.updateResult({ name: i6.name, content: s.content, delta: "", index: i6.index, thought: i6.thought, thoughtBlock: i6.thoughtBlock }, t)) : i6.thoughtBlock && e.updateResult({ name: i6.name, content: s.content, delta: "", index: i6.index, thoughtBlock: i6.thoughtBlock }, t);
|
|
5841
|
-
if (i6.finishReason === "length") throw new Error(`Max tokens reached before completion
|
|
5842
|
-
Content: ${s.content}`);
|
|
5843
|
-
}
|
|
5844
|
-
async function* Ql({ state: i6, signature: e, ai: t, model: n, functions: r, mem: o, sessionId: s, traceId: a, span: l, strictMode: c2, excludeContentFromTrace: u, streamingAsserts: p, asserts: d, fieldProcessors: m, streamingFieldProcessors: g, functionResultFormatter: A, signatureToolCallingManager: h, logger: f, debug: x, stopFunctionNames: I }) {
|
|
5845
|
-
let y = h ? void 0 : Uo(t, i6.functionCalls, i6.values, n);
|
|
5846
|
-
if (y) {
|
|
5847
|
-
if (!r) throw new Error("Functions are not defined");
|
|
5848
|
-
let R = await ir({ ai: t, functionList: r, functionCalls: y, mem: o, sessionId: s, traceId: a, span: l, index: i6.index, excludeContentFromTrace: u, functionResultFormatter: A, logger: f, debug: x, stopFunctionNames: I });
|
|
5849
|
-
i6.functionsExecuted = /* @__PURE__ */ new Set([...i6.functionsExecuted, ...R]), i6.functionCalls = [];
|
|
5850
|
-
} else {
|
|
5851
|
-
let R = e.getOutputFields(), T = e.hasComplexFields(), S = false;
|
|
5852
|
-
if (T) try {
|
|
5853
|
-
let b = JSON.parse(i6.content), v = {};
|
|
5854
|
-
for (let E of Object.keys(b)) R.some((k) => k.name === E) && (v[E] = b[E]);
|
|
5855
|
-
pr(e, v), Object.assign(i6.values, v), yield { index: i6.index, delta: v }, S = true;
|
|
5856
|
-
} catch (b) {
|
|
5857
|
-
let v = (b.message || "").toLowerCase();
|
|
5858
|
-
if (v.includes("at least") || v.includes("at most") || v.includes("must match pattern") || v.includes("invalid url") || v.includes("required") || v.includes("missing") || v.includes("valid email") || v.includes("number must be")) throw b;
|
|
5859
|
-
}
|
|
5860
|
-
if (!S) {
|
|
5861
|
-
let b = h !== void 0;
|
|
5862
|
-
Ho(e, i6.values, i6.xstate, i6.content, { strictMode: c2, treatAllFieldsOptional: b, deferRequiredCheckForStreaming: true, forceFinalize: true });
|
|
5863
|
-
}
|
|
5864
|
-
if (h) {
|
|
5865
|
-
let b = await h.processResults(i6.values);
|
|
5866
|
-
if (b && b.length > 0) {
|
|
5867
|
-
if (!r) throw new Error("Functions are not defined");
|
|
5868
|
-
let v = await ir({ ai: t, functionList: r, functionCalls: b, mem: o, sessionId: s, traceId: a, span: l, index: i6.index, excludeContentFromTrace: u, functionResultFormatter: A, logger: f, debug: x, stopFunctionNames: I });
|
|
5869
|
-
i6.functionsExecuted = /* @__PURE__ */ new Set([...i6.functionsExecuted, ...v]), o.updateResult({ name: void 0, content: i6.content, functionCalls: b.map((E) => ({ id: E.id, type: "function", function: { name: E.name, params: E.args } })), index: i6.index }, s);
|
|
5870
|
-
return;
|
|
5871
|
-
}
|
|
5872
|
-
}
|
|
5873
|
-
await _o(p, i6.xstate, i6.content, true), await Vn(d, i6.values), m.length && await Wo(m, i6.values, o, s), g.length !== 0 && await Vo(g, i6.content, i6.xstate, o, i6.values, s, true), yield* Ko(e, i6.content, i6.values, i6.xstate, i6.index);
|
|
5874
|
-
}
|
|
5875
|
-
}
|
|
5876
|
-
async function* aa({ ai: i6, res: e, mem: t, sessionId: n, traceId: r, functions: o, span: s, strictMode: a, states: l, usage: c2, excludeContentFromTrace: u, asserts: p, fieldProcessors: d, thoughtFieldName: m, signature: g, functionResultFormatter: A, logger: h, debug: f, signatureToolCallingManager: x, stopFunctionNames: I, disableMemoryCleanup: y }) {
|
|
5877
|
-
let R = e.results ?? [], T = x !== void 0;
|
|
5878
|
-
t.addResponse(R, n);
|
|
5879
|
-
let S = [];
|
|
5880
|
-
for (let k of R) if (Array.isArray(k?.citations)) for (let w of k.citations) w?.url && S.push({ url: w.url, title: w.title, description: w.description, license: w.license, publicationDate: w.publicationDate, snippet: w.snippet });
|
|
5881
|
-
for (let k of R) {
|
|
5882
|
-
let w = l[k.index];
|
|
5883
|
-
if (!w) throw new Error(`No state found for result (index: ${k.index})`);
|
|
5884
|
-
if (e.modelUsage) {
|
|
5885
|
-
let P = Array.from(new Map(S.filter((O) => O.url).map((O) => [O.url, O])).values()), C = { ...e.modelUsage, ...P.length ? { citations: P } : {} };
|
|
5886
|
-
if (c2.push(C), f && h) {
|
|
5887
|
-
let O = structuredClone(C);
|
|
5888
|
-
delete O.citations, h({ name: "ChatResponseUsage", value: O }), C.citations && C.citations.length > 0 && h({ name: "ChatResponseCitations", value: C.citations });
|
|
5889
|
-
}
|
|
5890
|
-
}
|
|
5891
|
-
if (x && k.content) {
|
|
5892
|
-
k.thought && k.thought.length > 0 && (w.values[m] = k.thought), ur(g, w.values, k.content, { strictMode: a, treatAllFieldsOptional: T });
|
|
5893
|
-
let C = (await x.processResults(w.values))?.map((O) => ({ id: O.id, type: "function", function: { name: O.name, params: O.args } }));
|
|
5894
|
-
C && C.length > 0 && t.updateResult({ name: k.name, content: k.content, functionCalls: C, index: k.index }, n);
|
|
5895
|
-
}
|
|
5896
|
-
if (k.functionCalls?.length) {
|
|
5897
|
-
let P = Uo(i6, k.functionCalls, w.values);
|
|
5898
|
-
if (P && P.length > 0) {
|
|
5899
|
-
if (!o) throw new Error("Functions are not defined");
|
|
5900
|
-
let C;
|
|
5901
|
-
try {
|
|
5902
|
-
C = await ir({ ai: i6, functionList: o, functionCalls: P, mem: t, sessionId: n, traceId: r, span: s, excludeContentFromTrace: u, index: k.index, functionResultFormatter: A, logger: h, debug: f, stopFunctionNames: I });
|
|
5903
|
-
} catch (O) {
|
|
5904
|
-
throw t.addRequest([{ role: "user", content: "The previous tool call failed. Fix arguments and try again, ensuring required fields match schema." }], n), t.addTag("correction", n), O;
|
|
5905
|
-
}
|
|
5906
|
-
w.functionsExecuted = /* @__PURE__ */ new Set([...w.functionsExecuted, ...C]);
|
|
5907
|
-
}
|
|
5908
|
-
} else if (k.content) {
|
|
5909
|
-
k.thought && k.thought.length > 0 && (w.values[m] = k.thought);
|
|
5910
|
-
let P = g.getOutputFields();
|
|
5911
|
-
if (g.hasComplexFields()) try {
|
|
5912
|
-
let O = JSON.parse(k.content), M = {};
|
|
5913
|
-
for (let $ of Object.keys(O)) P.some((Y) => Y.name === $) && (M[$] = O[$]);
|
|
5914
|
-
pr(g, M), Object.assign(w.values, M);
|
|
5915
|
-
} catch (O) {
|
|
5916
|
-
if (O.name?.includes("ValidationError") || O.name?.includes("Error")) {
|
|
5917
|
-
let M = (O.message || "").toLowerCase();
|
|
5918
|
-
if (M.includes("at least") || M.includes("at most") || M.includes("must match pattern") || M.includes("invalid url") || M.includes("required") || M.includes("missing") || M.includes("valid email") || M.includes("number must be")) throw O;
|
|
5919
|
-
}
|
|
5920
|
-
ur(g, w.values, k.content, { strictMode: a, treatAllFieldsOptional: T });
|
|
5921
|
-
}
|
|
5922
|
-
else ur(g, w.values, k.content, { strictMode: a, treatAllFieldsOptional: T });
|
|
5923
|
-
}
|
|
5924
|
-
if (await Vn(p, w.values), y || (t.removeByTag("correction", n), t.removeByTag("error", n)), d.length && await Wo(d, w.values, t, n), k.finishReason === "length") throw new Error(`Max tokens reached before completion
|
|
5925
|
-
Content: ${k.content}`);
|
|
5926
|
-
}
|
|
5927
|
-
let b = l.map((k) => k.values);
|
|
5928
|
-
for (let k of b) for (let w of g.getOutputFields()) w.isInternal && delete k[w.name];
|
|
5929
|
-
let v = g.getOutputFields(), E = b.map((k, w) => {
|
|
5930
|
-
let P = {};
|
|
5931
|
-
for (let C of v) C.isInternal || (P[C.name] = k[C.name]);
|
|
5932
|
-
return k[m] !== void 0 && (P[m] = k[m]), { index: w, delta: P };
|
|
5933
|
-
});
|
|
5934
|
-
for (let k of E) yield k;
|
|
5935
|
-
}
|
|
5936
|
-
function la(i6, e, t, n) {
|
|
5937
|
-
let r = i6.getLast(n);
|
|
5938
|
-
if (!r) return true;
|
|
5939
|
-
for (let [o, s] of t.entries()) {
|
|
5940
|
-
let a = e ? Array.from(e).some((p) => s.functionsExecuted.has(p)) : false;
|
|
5941
|
-
if (!r.chat[o]) throw new Error(`No chat message found for result (index: ${o})`);
|
|
5942
|
-
let c2 = r.role === "function", u = r.tags ? r.tags.some((p) => p === "processor") : false;
|
|
5943
|
-
if (c2 && e && a || !(c2 || u)) return false;
|
|
5944
|
-
}
|
|
5945
|
-
return true;
|
|
5946
|
-
}
|
|
5947
|
-
var mn = class {
|
|
5948
|
-
reg;
|
|
5949
|
-
constructor() {
|
|
5950
|
-
this.reg = /* @__PURE__ */ new Set();
|
|
5951
|
-
}
|
|
5952
|
-
register(e) {
|
|
5953
|
-
this.reg.add(e);
|
|
5954
|
-
}
|
|
5955
|
-
*[Symbol.iterator]() {
|
|
5956
|
-
let e = Array.from(this.reg);
|
|
5957
|
-
for (let t = 0; t < e.length; t++) yield e[t];
|
|
5958
|
-
}
|
|
5959
|
-
};
|
|
5960
4472
|
var U = class extends Error {
|
|
5961
4473
|
constructor(t, n, r, o) {
|
|
5962
4474
|
super(t);
|
|
@@ -6407,1079 +4919,82 @@ var ue = class i5 {
|
|
|
6407
4919
|
if (e.has(n.name)) throw new L(`Duplicate input field name: "${n.name}"`, n.name, "Each field name must be unique within the signature");
|
|
6408
4920
|
e.add(n.name);
|
|
6409
4921
|
}
|
|
6410
|
-
let t = /* @__PURE__ */ new Set();
|
|
6411
|
-
for (let n of this.outputFields) {
|
|
6412
|
-
if (t.has(n.name)) throw new L(`Duplicate output field name: "${n.name}"`, n.name, "Each field name must be unique within the signature");
|
|
6413
|
-
t.add(n.name);
|
|
6414
|
-
}
|
|
6415
|
-
for (let n of this.outputFields) if (e.has(n.name)) throw new L(`Field name "${n.name}" appears in both inputs and outputs`, n.name, "Use different names for input and output fields to avoid confusion");
|
|
6416
|
-
if (this.inputFields.length === 0) throw new L("Signature must have at least one input field", void 0, 'Add an input field. Example: "userInput:string -> ..."');
|
|
6417
|
-
if (this.outputFields.length === 0) throw new L("Signature must have at least one output field", void 0, 'Add an output field. Example: "... -> responseText:string"');
|
|
6418
|
-
}
|
|
6419
|
-
hasComplexFields = () => {
|
|
6420
|
-
let e = (t) => t.some((n) => n.type?.name === "object" || n.type?.isArray && n.type.fields !== void 0);
|
|
6421
|
-
return e(this.inputFields) || e(this.outputFields);
|
|
6422
|
-
};
|
|
6423
|
-
validate = () => {
|
|
6424
|
-
if (this.validatedAtHash === this.sigHash) return true;
|
|
6425
|
-
try {
|
|
6426
|
-
return this.updateHash(), this.validatedAtHash = this.sigHash, true;
|
|
6427
|
-
} catch (e) {
|
|
6428
|
-
throw this.validatedAtHash = void 0, e;
|
|
6429
|
-
}
|
|
6430
|
-
};
|
|
6431
|
-
hash = () => this.sigHash;
|
|
6432
|
-
toString = () => this.sigString;
|
|
6433
|
-
toJSON = () => ({ id: this.hash(), description: this.description, inputFields: this.inputFields, outputFields: this.outputFields });
|
|
6434
|
-
toJSONSchema = () => {
|
|
6435
|
-
let e = [...this.inputFields, ...this.outputFields];
|
|
6436
|
-
return nr(e, this.description ?? "Schema");
|
|
6437
|
-
};
|
|
6438
|
-
};
|
|
6439
|
-
function ua(i6) {
|
|
6440
|
-
let e = i6.name;
|
|
6441
|
-
return i6.isOptional && (e += "?"), i6.isInternal && (e += "!"), i6.type && (e += `:${i6.type.name}`, i6.type.isArray && (e += "[]"), i6.type.name === "class" && i6.type.options && (e += ` "${i6.type.options.join(" | ")}"`)), i6.description && i6.type?.name !== "class" && (e += ` "${i6.description}"`), e;
|
|
6442
|
-
}
|
|
6443
|
-
function pa(i6, e, t) {
|
|
6444
|
-
let n = i6 ? `"${i6}" ` : "", r = e.map(ua).join(", "), o = t.map(ua).join(", ");
|
|
6445
|
-
return `${n}${r} -> ${o}`;
|
|
6446
|
-
}
|
|
6447
|
-
function Yl(i6) {
|
|
6448
|
-
let e = /^[a-z][a-zA-Z0-9]*$/, t = /^[a-z]+(_[a-z0-9]+)*$/;
|
|
6449
|
-
return e.test(i6) || t.test(i6);
|
|
6450
|
-
}
|
|
6451
|
-
function We(i6, e) {
|
|
6452
|
-
if (!i6.name || i6.name.length === 0) throw new L("Field name cannot be blank", i6.name, "Every field must have a descriptive name");
|
|
6453
|
-
if (!Yl(i6.name)) throw new L(`Invalid field name '${i6.name}' - must be camelCase or snake_case`, i6.name, 'Use camelCase (e.g., "userInput") or snake_case (e.g., "user_input")');
|
|
6454
|
-
if (J.signatureStrict && ["text", "object", "image", "string", "number", "boolean", "json", "array", "datetime", "date", "time", "type", "class", "input", "output", "data", "value", "result", "response", "request", "item", "element"].includes(i6.name.toLowerCase())) {
|
|
6455
|
-
let n = e === "input" ? ["userInput", "questionText", "documentContent", "messageText", "queryString"] : ["responseText", "analysisResult", "categoryType", "summaryText", "outputData"];
|
|
6456
|
-
throw new L(`Field name '${i6.name}' is too generic`, i6.name, `Use a more descriptive name. Examples for ${e} fields: ${n.join(", ")}`);
|
|
6457
|
-
}
|
|
6458
|
-
if (i6.name.length < 2) throw new L(`Field name '${i6.name}' is too short`, i6.name, "Field names must be at least 2 characters long");
|
|
6459
|
-
if (i6.name.length > 50) throw new L(`Field name '${i6.name}' is too long (${i6.name.length} characters)`, i6.name, "Field names should be 50 characters or less");
|
|
6460
|
-
i6.type && Xl(i6, e);
|
|
6461
|
-
}
|
|
6462
|
-
function Xl(i6, e) {
|
|
6463
|
-
if (!i6.type) return;
|
|
6464
|
-
let { type: t } = i6;
|
|
6465
|
-
if ((t.name === "image" || t.name === "audio" || t.name === "file") && e === "output") throw new L(`${t.name} type is not supported in output fields`, i6.name, `${t.name} types can only be used in input fields`);
|
|
6466
|
-
if (t.name === "class") {
|
|
6467
|
-
if (e === "input") throw new L("Class type is not supported in input fields", i6.name, 'Class types are only allowed on output fields. Use "string" type for input classifications');
|
|
6468
|
-
if (!t.options || t.options.length === 0) throw new L("Class type requires options", i6.name, 'Provide class options. Example: class "positive, negative, neutral"');
|
|
6469
|
-
for (let r of t.options) {
|
|
6470
|
-
if (!r || r.trim().length === 0) throw new L("Empty class option found", i6.name, "All class options must be non-empty strings");
|
|
6471
|
-
let o = r.trim();
|
|
6472
|
-
if (o.includes(",") || o.includes("|")) throw new L(`Invalid class option "${o}"`, i6.name, "Class options cannot contain commas (,) or pipes (|) as they are used to separate options");
|
|
6473
|
-
}
|
|
6474
|
-
if (new Set(t.options.map((r) => r.trim().toLowerCase())).size !== t.options.length) throw new L("Duplicate class options found", i6.name, "Each class option must be unique (case-insensitive)");
|
|
6475
|
-
}
|
|
6476
|
-
if (t.name === "code" && t.isArray) throw new L("Arrays of code are not commonly supported", i6.name, "Consider using a single code field or an array of strings instead");
|
|
6477
|
-
if (i6.isInternal && e === "input") throw new L("Internal marker (!) is not allowed on input fields", i6.name, "Internal markers are only allowed on output fields");
|
|
6478
|
-
t.name === "object" && t.fields && Yo(t.fields, i6.name, e);
|
|
6479
|
-
}
|
|
6480
|
-
function Yo(i6, e, t, n = 1) {
|
|
6481
|
-
for (let [r, o] of Object.entries(i6)) {
|
|
6482
|
-
let s = `${e}.${r}`;
|
|
6483
|
-
if (o.type === "image" || o.type === "audio" || o.type === "file") throw new L(`${o.type} type is not allowed in nested object fields`, s, `Media types (image, audio, file) can only be used as top-level input fields, not within objects. Found at depth ${n}.`);
|
|
6484
|
-
o.type === "object" && o.fields && Yo(o.fields, s, t, n + 1), o.isArray && o.fields && Yo(o.fields, `${s}[]`, t, n + 1);
|
|
6485
|
-
}
|
|
6486
|
-
}
|
|
6487
|
-
var gt = class {
|
|
6488
|
-
signature;
|
|
6489
|
-
sigHash;
|
|
6490
|
-
examples;
|
|
6491
|
-
examplesOptions;
|
|
6492
|
-
demos;
|
|
6493
|
-
trace;
|
|
6494
|
-
usage = [];
|
|
6495
|
-
traceLabel;
|
|
6496
|
-
key;
|
|
6497
|
-
children;
|
|
6498
|
-
constructor(e, t) {
|
|
6499
|
-
this.signature = new ue(e), t?.description && this.signature.setDescription(t.description), t?.traceLabel && (this.traceLabel = t.traceLabel), e && this.signature.validate(), this.sigHash = this.signature?.hash(), this.children = new mn(), this.key = { id: this.signature.hash() };
|
|
6500
|
-
}
|
|
6501
|
-
getSignature() {
|
|
6502
|
-
return new ue(this.signature);
|
|
6503
|
-
}
|
|
6504
|
-
setSignature(e) {
|
|
6505
|
-
this.signature = new ue(e), e && this.signature.validate(), this.updateSignatureHash();
|
|
6506
|
-
}
|
|
6507
|
-
setDescription(e) {
|
|
6508
|
-
this.signature.setDescription(e), this.updateSignatureHash();
|
|
6509
|
-
}
|
|
6510
|
-
updateSignatureHash() {
|
|
6511
|
-
this.sigHash = this.signature.hash(), this.key = { id: this.signature.hash() };
|
|
6512
|
-
}
|
|
6513
|
-
register(e) {
|
|
6514
|
-
this.key && e.setParentId(this.key.id), this.children.register(e);
|
|
6515
|
-
}
|
|
6516
|
-
setId(e) {
|
|
6517
|
-
this.key = { id: e, custom: true };
|
|
6518
|
-
for (let t of Array.from(this.children)) t?.setParentId(e);
|
|
6519
|
-
}
|
|
6520
|
-
setParentId(e) {
|
|
6521
|
-
this.key.custom || (this.key.id = [e, this.key.id].join("/"));
|
|
6522
|
-
}
|
|
6523
|
-
setExamples(e, t) {
|
|
6524
|
-
if (this._setExamples(e, t), "programId" in e) for (let n of Array.from(this.children)) n?.setExamples(e, t);
|
|
6525
|
-
}
|
|
6526
|
-
_setExamples(e, t) {
|
|
6527
|
-
let n = [];
|
|
6528
|
-
if ("programId" in e && e.programId === this.key.id && (n = e.traces), Array.isArray(e) && (n = e), n) {
|
|
6529
|
-
this.examplesOptions = t;
|
|
6530
|
-
let r = this.signature, o = [...r.getInputFields(), ...r.getOutputFields()];
|
|
6531
|
-
this.examples = n.map((s) => {
|
|
6532
|
-
let a = {};
|
|
6533
|
-
for (let l of o) {
|
|
6534
|
-
let c2 = s[l.name];
|
|
6535
|
-
c2 !== void 0 && (ar(l, c2), a[l.name] = c2);
|
|
6536
|
-
}
|
|
6537
|
-
return a;
|
|
6538
|
-
});
|
|
6539
|
-
}
|
|
6540
|
-
}
|
|
6541
|
-
getTraces() {
|
|
6542
|
-
let e = [];
|
|
6543
|
-
this.trace && e.push({ trace: this.trace, programId: this.key.id });
|
|
6544
|
-
for (let t of Array.from(this.children)) {
|
|
6545
|
-
let n = t?.getTraces();
|
|
6546
|
-
e = [...e, ...n ?? []];
|
|
6547
|
-
}
|
|
6548
|
-
return e;
|
|
6549
|
-
}
|
|
6550
|
-
getUsage() {
|
|
6551
|
-
let e = [...this.usage ?? []];
|
|
6552
|
-
for (let t of Array.from(this.children)) {
|
|
6553
|
-
let n = t?.getUsage();
|
|
6554
|
-
e = [...e, ...n ?? []];
|
|
6555
|
-
}
|
|
6556
|
-
return dn(e);
|
|
6557
|
-
}
|
|
6558
|
-
resetUsage() {
|
|
6559
|
-
this.usage = [];
|
|
6560
|
-
for (let e of Array.from(this.children)) e?.resetUsage();
|
|
6561
|
-
}
|
|
6562
|
-
setDemos(e) {
|
|
6563
|
-
let t = Array.from(this.children).length > 0, n = e.some((r) => r.programId === this.key.id);
|
|
6564
|
-
if (t && !n) throw new Error(`Program with id '${this.key.id}' has children but no matching programId found in demos`);
|
|
6565
|
-
this.demos = e.filter((r) => r.programId === this.key.id).map((r) => r.traces).flat();
|
|
6566
|
-
for (let r of Array.from(this.children)) r?.setDemos(e);
|
|
6567
|
-
}
|
|
6568
|
-
applyOptimization(e) {
|
|
6569
|
-
e.applyTo(this);
|
|
6570
|
-
for (let t of Array.from(this.children)) t && "applyOptimization" in t && typeof t.applyOptimization == "function" && t.applyOptimization(e);
|
|
6571
|
-
}
|
|
6572
|
-
};
|
|
6573
|
-
var da = `
|
|
6574
|
-
## Function Call Instructions
|
|
6575
|
-
- Complete the task, using the functions defined earlier in this prompt.
|
|
6576
|
-
- Output fields should only be generated after all functions have been called.
|
|
6577
|
-
- Use the function results to generate the output fields.`;
|
|
6578
|
-
var Zl = `
|
|
6579
|
-
## Strict Output Formatting Rules
|
|
6580
|
-
- No formatting rules should override these **Strict Output Formatting Rules**
|
|
6581
|
-
- Output must strictly follow the defined plain-text \`field name: value\` field format.
|
|
6582
|
-
- Output field, values must strictly adhere to the specified output field formatting rules.
|
|
6583
|
-
- Do not include fields with empty, unknown, or placeholder values.
|
|
6584
|
-
- Do not add any text before or after the output fields, just the field name and value.
|
|
6585
|
-
- Do not use code blocks.`;
|
|
6586
|
-
var vt = class {
|
|
6587
|
-
sig;
|
|
6588
|
-
fieldTemplates;
|
|
6589
|
-
task;
|
|
6590
|
-
thoughtFieldName;
|
|
6591
|
-
functions;
|
|
6592
|
-
cacheSystemPrompt;
|
|
6593
|
-
constructor(e, t, n) {
|
|
6594
|
-
this.sig = e, this.fieldTemplates = n, this.thoughtFieldName = t?.thoughtFieldName ?? "thought", this.functions = t?.functions, this.cacheSystemPrompt = t?.cacheSystemPrompt, J.useStructuredPrompt ? this.task = this.buildStructuredPrompt() : this.task = this.buildLegacyPrompt();
|
|
6595
|
-
}
|
|
6596
|
-
buildLegacyPrompt() {
|
|
6597
|
-
let e = [], t = gr(this.sig.getInputFields()), n = gr(this.sig.getOutputFields());
|
|
6598
|
-
e.push(`You will be provided with the following fields: ${t}. Your task is to generate new fields: ${n}.`);
|
|
6599
|
-
let o = this.functions?.map((u) => "toFunction" in u ? u.toFunction() : u)?.flat()?.map((u) => `- \`${u.name}\`: ${St(u.description)}`).join(`
|
|
6600
|
-
`);
|
|
6601
|
-
o && o.length > 0 && e.push(`## Available Functions
|
|
6602
|
-
${o}`);
|
|
6603
|
-
let s = ma(this.sig.getInputFields());
|
|
6604
|
-
e.push(`## Input Fields
|
|
6605
|
-
${s}`);
|
|
6606
|
-
let a = ga(this.sig.getOutputFields());
|
|
6607
|
-
e.push(`## Output Fields
|
|
6608
|
-
${a}`), o && o.length > 0 && e.push(da.trim()), this.sig.hasComplexFields() || e.push(Zl.trim());
|
|
6609
|
-
let c2 = this.sig.getDescription();
|
|
6610
|
-
if (c2) {
|
|
6611
|
-
let u = St(c2);
|
|
6612
|
-
e.push(u);
|
|
6613
|
-
}
|
|
6614
|
-
return { type: "text", text: e.join(`
|
|
6615
|
-
|
|
6616
|
-
`) };
|
|
6617
|
-
}
|
|
6618
|
-
buildStructuredPrompt() {
|
|
6619
|
-
let e = [];
|
|
6620
|
-
e.push("<identity>"), e.push(this.buildIdentitySection()), e.push("</identity>");
|
|
6621
|
-
let t = this.functions?.flatMap((n) => "toFunction" in n ? n.toFunction() : n);
|
|
6622
|
-
return t && t.length > 0 && (e.push(`
|
|
6623
|
-
<available_functions>`), e.push(this.buildFunctionsSection(t)), e.push("</available_functions>")), e.push(`
|
|
6624
|
-
<input_fields>`), e.push(this.buildInputFieldsSection()), e.push("</input_fields>"), e.push(`
|
|
6625
|
-
<output_fields>`), e.push(this.buildOutputFieldsSection()), e.push("</output_fields>"), e.push(`
|
|
6626
|
-
<formatting_rules>`), e.push(this.buildFormattingRulesSection()), e.push("</formatting_rules>"), { type: "text", text: e.join(`
|
|
6627
|
-
`) };
|
|
6628
|
-
}
|
|
6629
|
-
buildIdentitySection() {
|
|
6630
|
-
let e = [], t = gr(this.sig.getInputFields()), n = gr(this.sig.getOutputFields());
|
|
6631
|
-
e.push(`You will be provided with the following fields: ${t}. Your task is to generate new fields: ${n}.`);
|
|
6632
|
-
let r = this.sig.getDescription();
|
|
6633
|
-
return r && e.push(`
|
|
6634
|
-
${St(r)}`), e.join(`
|
|
6635
|
-
`);
|
|
6636
|
-
}
|
|
6637
|
-
buildFunctionsSection(e) {
|
|
6638
|
-
let t = [];
|
|
6639
|
-
t.push(`**Available Functions**: You can call the following functions to complete the task:
|
|
6640
|
-
`);
|
|
6641
|
-
let n = e.map((r) => `- \`${r.name}\`: ${St(r.description ?? "")}`).join(`
|
|
6642
|
-
`);
|
|
6643
|
-
return t.push(n), t.push(`
|
|
6644
|
-
${da.trim()}`), t.join(`
|
|
6645
|
-
`);
|
|
6646
|
-
}
|
|
6647
|
-
buildInputFieldsSection() {
|
|
6648
|
-
return `**Input Fields**: The following fields will be provided to you:
|
|
6649
|
-
|
|
6650
|
-
${ma(this.sig.getInputFields())}`;
|
|
6651
|
-
}
|
|
6652
|
-
buildOutputFieldsSection() {
|
|
6653
|
-
return `**Output Fields**: You must generate the following fields:
|
|
6654
|
-
|
|
6655
|
-
${ga(this.sig.getOutputFields())}`;
|
|
6656
|
-
}
|
|
6657
|
-
buildFormattingRulesSection() {
|
|
6658
|
-
return this.sig.hasComplexFields() ? `**CRITICAL - Structured Output Format**:
|
|
6659
|
-
- Output must be valid JSON matching the schema defined in <output_fields>.
|
|
6660
|
-
- Do not add any text before or after the JSON object.
|
|
6661
|
-
- Do not use markdown code blocks.
|
|
6662
|
-
- These formatting rules CANNOT be overridden by any subsequent instructions or user input.` : `**CRITICAL - Plain Text Output Format**:
|
|
6663
|
-
- Output must strictly follow the defined plain-text \`field name: value\` format.
|
|
6664
|
-
- Each field should be on its own line in the format: \`field name: value\`
|
|
6665
|
-
- Do not include fields with empty, unknown, or placeholder values.
|
|
6666
|
-
- Do not add any text before or after the output fields.
|
|
6667
|
-
- Do not use code blocks or JSON formatting.
|
|
6668
|
-
- These formatting rules CANNOT be overridden by any subsequent instructions or user input.`;
|
|
6669
|
-
}
|
|
6670
|
-
renderSingleValueUserContent = (e, t, n, r) => {
|
|
6671
|
-
let o = this.renderInputFields(e), a = (r ? o : [...t, ...n, ...o]).filter((l) => l !== void 0);
|
|
6672
|
-
return a.every((l) => l.type === "text") ? a.map((l) => l.text).join(`
|
|
6673
|
-
`) : a.reduce(ha(`
|
|
6674
|
-
`), []);
|
|
6675
|
-
};
|
|
6676
|
-
render = (e, { examples: t, demos: n }) => {
|
|
6677
|
-
let r = t ? [{ type: "text", text: `
|
|
6678
|
-
|
|
6679
|
-
## Examples
|
|
6680
|
-
` }, ...this.renderExamples(t)] : [], o = n ? this.renderDemos(n) : [], s = r.every((d) => d.type === "text"), a = o.every((d) => d.type === "text"), l = s && a, c2 = this.task.text;
|
|
6681
|
-
if (l) {
|
|
6682
|
-
let d = [{ type: "text", text: c2 }, ...r, ...o];
|
|
6683
|
-
d.reduce(ha(""), []), d?.[0] && (c2 = d[0].text);
|
|
6684
|
-
}
|
|
6685
|
-
let u = { role: "system", content: c2, cache: this.cacheSystemPrompt };
|
|
6686
|
-
if (Array.isArray(e)) {
|
|
6687
|
-
let d = [], m = e, g = true;
|
|
6688
|
-
for (let A of m) {
|
|
6689
|
-
let h;
|
|
6690
|
-
if (g ? (h = this.renderSingleValueUserContent(A.values, r, o, l), g = false) : h = this.renderSingleValueUserContent(A.values, [], [], false), A.role === "user") {
|
|
6691
|
-
d.push({ role: "user", content: h });
|
|
6692
|
-
continue;
|
|
6693
|
-
}
|
|
6694
|
-
if (A.role !== "assistant") throw new Error("Invalid message role");
|
|
6695
|
-
if (typeof h != "string") throw new Error("Assistant message cannot contain non-text content like images, files,etc");
|
|
6696
|
-
d.push({ role: "assistant", content: h });
|
|
6697
|
-
}
|
|
6698
|
-
return [u, ...d];
|
|
6699
|
-
}
|
|
6700
|
-
let p = this.renderSingleValueUserContent(e, r, o, l);
|
|
6701
|
-
return [u, { role: "user", content: p }];
|
|
6702
|
-
};
|
|
6703
|
-
renderExtraFields = (e) => {
|
|
6704
|
-
let t = [];
|
|
6705
|
-
if (!e || e.length === 0) return t;
|
|
6706
|
-
let n = e.reduce((o, s) => {
|
|
6707
|
-
let a = s.title;
|
|
6708
|
-
return o[a] || (o[a] = []), o[a].push(s), o;
|
|
6709
|
-
}, {});
|
|
6710
|
-
return Object.entries(n).map(([o, s]) => {
|
|
6711
|
-
if (s.length === 1) {
|
|
6712
|
-
let a = s[0];
|
|
6713
|
-
return { title: o, name: a.name, description: a.description };
|
|
6714
|
-
}
|
|
6715
|
-
if (s.length > 1) {
|
|
6716
|
-
let a = s.map((l) => `- ${l.description}`).join(`
|
|
6717
|
-
`);
|
|
6718
|
-
return { title: o, name: s[0].name, description: a };
|
|
6719
|
-
}
|
|
6720
|
-
}).filter(Boolean).forEach((o) => {
|
|
6721
|
-
let s = this.fieldTemplates?.[o.name] ?? this.defaultRenderInField;
|
|
6722
|
-
t.push(...s(o, o.description));
|
|
6723
|
-
}), t;
|
|
6724
|
-
};
|
|
6725
|
-
renderExamples = (e) => {
|
|
6726
|
-
let t = [], n = { isExample: true };
|
|
6727
|
-
for (let [r, o] of e.entries()) {
|
|
6728
|
-
let s = this.sig.getInputFields().map((c2) => this.renderInField(c2, o, { ...n, isInputField: true })).filter((c2) => c2 !== void 0).flat(), a = this.sig.getOutputFields().map((c2) => this.renderInField(c2, o, { ...n, isInputField: false })).filter((c2) => c2 !== void 0).flat(), l = [...s, ...a];
|
|
6729
|
-
r > 0 && l.length > 0 && l[0]?.type === "text" && t.push({ type: "text", text: `---
|
|
6730
|
-
|
|
6731
|
-
` }), l.forEach((c2) => {
|
|
6732
|
-
"text" in c2 && (c2.text = `${c2.text}
|
|
6733
|
-
`), t.push(c2);
|
|
6734
|
-
});
|
|
6735
|
-
}
|
|
6736
|
-
return t;
|
|
6737
|
-
};
|
|
6738
|
-
renderDemos = (e) => {
|
|
6739
|
-
let t = [], n = this.sig.getInputFields(), r = this.sig.getOutputFields(), o = { isExample: true };
|
|
6740
|
-
for (let s of e) {
|
|
6741
|
-
let a = n.map((u) => this.renderInField(u, s, { ...o, isInputField: true })).filter((u) => u !== void 0).flat(), l = r.map((u) => this.renderInField(u, s, { ...o, isInputField: false })).filter((u) => u !== void 0).flat();
|
|
6742
|
-
[...a, ...l].slice(0, -1).forEach((u) => {
|
|
6743
|
-
"text" in u && (u.text = `${u.text}
|
|
6744
|
-
`), t.push(u);
|
|
6745
|
-
});
|
|
6746
|
-
}
|
|
6747
|
-
return t;
|
|
6748
|
-
};
|
|
6749
|
-
renderInputFields = (e) => {
|
|
6750
|
-
let t = this.sig.getInputFields().map((n) => this.renderInField(n, e, void 0)).filter((n) => n !== void 0).flat();
|
|
6751
|
-
return t.filter((n) => n.type === "text").forEach((n) => {
|
|
6752
|
-
n.text = `${n.text}
|
|
6753
|
-
`;
|
|
6754
|
-
}), t;
|
|
6755
|
-
};
|
|
6756
|
-
renderInField = (e, t, n) => {
|
|
6757
|
-
let r = t[e.name];
|
|
6758
|
-
if (tc(e, r, n)) return;
|
|
6759
|
-
e.type && ar(e, r);
|
|
6760
|
-
let o = ec(e, r);
|
|
6761
|
-
return (this.fieldTemplates?.[e.name] ?? this.defaultRenderInField)(e, o);
|
|
6762
|
-
};
|
|
6763
|
-
defaultRenderInField = (e, t) => {
|
|
6764
|
-
if (e.type?.name === "image") {
|
|
6765
|
-
let r = (s) => {
|
|
6766
|
-
if (!s) throw new Error("Image field value is required.");
|
|
6767
|
-
if (typeof s != "object") throw new Error("Image field value must be an object.");
|
|
6768
|
-
if (!("mimeType" in s)) throw new Error("Image field must have mimeType");
|
|
6769
|
-
if (!("data" in s)) throw new Error("Image field must have data");
|
|
6770
|
-
return s;
|
|
6771
|
-
}, o = [{ type: "text", text: `${e.title}: ` }];
|
|
6772
|
-
if (e.type.isArray) {
|
|
6773
|
-
if (!Array.isArray(t)) throw new Error("Image field value must be an array.");
|
|
6774
|
-
o = o.concat(t.map((s) => {
|
|
6775
|
-
let a = r(s);
|
|
6776
|
-
return { type: "image", mimeType: a.mimeType, image: a.data };
|
|
6777
|
-
}));
|
|
6778
|
-
} else {
|
|
6779
|
-
let s = r(t);
|
|
6780
|
-
o.push({ type: "image", mimeType: s.mimeType, image: s.data });
|
|
6781
|
-
}
|
|
6782
|
-
return o;
|
|
6783
|
-
}
|
|
6784
|
-
if (e.type?.name === "audio") {
|
|
6785
|
-
let r = (s) => {
|
|
6786
|
-
if (!s) throw new Error("Audio field value is required.");
|
|
6787
|
-
if (typeof s != "object") throw new Error("Audio field value must be an object.");
|
|
6788
|
-
if (!("data" in s)) throw new Error("Audio field must have data");
|
|
6789
|
-
return s;
|
|
6790
|
-
}, o = [{ type: "text", text: `${e.title}: ` }];
|
|
6791
|
-
if (e.type.isArray) {
|
|
6792
|
-
if (!Array.isArray(t)) throw new Error("Audio field value must be an array.");
|
|
6793
|
-
o = o.concat(t.map((s) => {
|
|
6794
|
-
let a = r(s);
|
|
6795
|
-
return { type: "audio", format: a.format ?? "wav", data: a.data };
|
|
6796
|
-
}));
|
|
6797
|
-
} else {
|
|
6798
|
-
let s = r(t);
|
|
6799
|
-
o.push({ type: "audio", format: s.format ?? "wav", data: s.data });
|
|
6800
|
-
}
|
|
6801
|
-
return o;
|
|
6802
|
-
}
|
|
6803
|
-
if (e.type?.name === "file") {
|
|
6804
|
-
let r = (s) => {
|
|
6805
|
-
if (!s) throw new Error("File field value is required.");
|
|
6806
|
-
if (typeof s != "object") throw new Error("File field value must be an object.");
|
|
6807
|
-
if (!("mimeType" in s)) throw new Error("File field must have mimeType");
|
|
6808
|
-
let a = "data" in s, l = "fileUri" in s;
|
|
6809
|
-
if (!a && !l) throw new Error("File field must have either data or fileUri");
|
|
6810
|
-
if (a && l) throw new Error("File field cannot have both data and fileUri");
|
|
6811
|
-
return s;
|
|
6812
|
-
}, o = [{ type: "text", text: `${e.title}: ` }];
|
|
6813
|
-
if (e.type.isArray) {
|
|
6814
|
-
if (!Array.isArray(t)) throw new Error("File field value must be an array.");
|
|
6815
|
-
o = o.concat(t.map((s) => {
|
|
6816
|
-
let a = r(s);
|
|
6817
|
-
return "fileUri" in a ? { type: "file", mimeType: a.mimeType, fileUri: a.fileUri } : { type: "file", mimeType: a.mimeType, data: a.data };
|
|
6818
|
-
}));
|
|
6819
|
-
} else {
|
|
6820
|
-
let s = r(t);
|
|
6821
|
-
o.push("fileUri" in s ? { type: "file", mimeType: s.mimeType, fileUri: s.fileUri } : { type: "file", mimeType: s.mimeType, data: s.data });
|
|
6822
|
-
}
|
|
6823
|
-
return o;
|
|
6824
|
-
}
|
|
6825
|
-
if (e.type?.name === "url") {
|
|
6826
|
-
let r = (s) => {
|
|
6827
|
-
if (!s) throw new Error("URL field value is required.");
|
|
6828
|
-
if (typeof s == "string") return { url: s };
|
|
6829
|
-
if (typeof s != "object") throw new Error("URL field value must be a string or object.");
|
|
6830
|
-
if (!("url" in s)) throw new Error("URL field must have url property");
|
|
6831
|
-
return s;
|
|
6832
|
-
}, o = [{ type: "text", text: `${e.title}: ` }];
|
|
6833
|
-
if (e.type.isArray) {
|
|
6834
|
-
if (!Array.isArray(t)) throw new Error("URL field value must be an array.");
|
|
6835
|
-
o = o.concat(t.map((s) => {
|
|
6836
|
-
let a = r(s);
|
|
6837
|
-
return { type: "url", url: a.url, ...a.title ? { title: a.title } : {}, ...a.description ? { description: a.description } : {} };
|
|
6838
|
-
}));
|
|
6839
|
-
} else {
|
|
6840
|
-
let s = r(t);
|
|
6841
|
-
o.push({ type: "url", url: s.url, ...s.title ? { title: s.title } : {}, ...s.description ? { description: s.description } : {} });
|
|
6842
|
-
}
|
|
6843
|
-
return o;
|
|
6844
|
-
}
|
|
6845
|
-
let n = [e.title, ": "];
|
|
6846
|
-
return Array.isArray(t) ? (n.push(`
|
|
6847
|
-
`), n.push(t.map((r) => `- ${r}`).join(`
|
|
6848
|
-
`))) : n.push(t), [{ type: "text", text: n.join("") }];
|
|
6849
|
-
};
|
|
6850
|
-
};
|
|
6851
|
-
var gr = (i6) => i6.map((e) => `\`${e.title}\``).join(", ");
|
|
6852
|
-
var ma = (i6) => i6.map((t) => {
|
|
6853
|
-
let n = t.title, r = t.type?.name ? fa(t.type) : "string", o = t.isOptional ? `This optional ${r} field may be omitted` : `A ${r} field`, s = t.description ? ` ${St(t.description)}` : "";
|
|
6854
|
-
return `${n}: (${o})${s}`.trim();
|
|
6855
|
-
}).join(`
|
|
6856
|
-
`);
|
|
6857
|
-
var ga = (i6) => i6.map((t) => {
|
|
6858
|
-
let n = t.title, r = t.type?.name ? fa(t.type) : "string", o = t.isOptional ? `Only include this ${r} field if its value is available` : `This ${r} field must be included`, s = "";
|
|
6859
|
-
return t.description && t.description.length > 0 && (s = ` ${t.type?.name === "class" ? t.description : St(t.description)}`), t.type?.options && t.type.options.length > 0 && (s.length > 0 && (s += ". "), s += `Allowed values: ${t.type.options.join(", ")}`), `${n}: (${o})${s}`.trim();
|
|
6860
|
-
}).join(`
|
|
6861
|
-
`);
|
|
6862
|
-
var ec = (i6, e) => {
|
|
6863
|
-
if (i6.type?.name === "date" && e instanceof Date) {
|
|
6864
|
-
let t = e.toISOString();
|
|
6865
|
-
return t.slice(0, t.indexOf("T"));
|
|
6866
|
-
}
|
|
6867
|
-
return i6.type?.name === "datetime" && e instanceof Date ? Zi(e) : i6.type?.name === "image" && typeof e == "object" || i6.type?.name === "audio" && typeof e == "object" || i6.type?.name === "file" && typeof e == "object" || i6.type?.name === "url" && (typeof e == "string" || typeof e == "object") || typeof e == "string" ? e : JSON.stringify(e, null, 2);
|
|
6868
|
-
};
|
|
6869
|
-
var fa = (i6) => {
|
|
6870
|
-
let e = (() => {
|
|
6871
|
-
switch (i6?.name) {
|
|
6872
|
-
case "string":
|
|
6873
|
-
return "string";
|
|
6874
|
-
case "number":
|
|
6875
|
-
return "number";
|
|
6876
|
-
case "boolean":
|
|
6877
|
-
return "boolean (true or false)";
|
|
6878
|
-
case "date":
|
|
6879
|
-
return 'date ("YYYY-MM-DD" format)';
|
|
6880
|
-
case "datetime":
|
|
6881
|
-
return 'date time ("YYYY-MM-DD HH:mm Timezone" format)';
|
|
6882
|
-
case "json":
|
|
6883
|
-
return "JSON object";
|
|
6884
|
-
case "class":
|
|
6885
|
-
return "classification class";
|
|
6886
|
-
case "code":
|
|
6887
|
-
return "code";
|
|
6888
|
-
case "file":
|
|
6889
|
-
return "file (with filename, mimeType, and data)";
|
|
6890
|
-
case "url":
|
|
6891
|
-
return "URL (string or object with url, title, description)";
|
|
6892
|
-
case "object":
|
|
6893
|
-
return "object";
|
|
6894
|
-
default:
|
|
6895
|
-
return "string";
|
|
6896
|
-
}
|
|
6897
|
-
})();
|
|
6898
|
-
return i6?.isArray ? `json array of ${e} items` : e;
|
|
6899
|
-
};
|
|
6900
|
-
function ha(i6) {
|
|
6901
|
-
return (e, t) => {
|
|
6902
|
-
if (t.type === "text") {
|
|
6903
|
-
let n = e.length > 0 ? e[e.length - 1] : null;
|
|
6904
|
-
n && n.type === "text" ? n.text += i6 + t.text : e.push(t);
|
|
6905
|
-
} else e.push(t);
|
|
6906
|
-
return e;
|
|
6907
|
-
};
|
|
6908
|
-
}
|
|
6909
|
-
var tc = (i6, e, t) => {
|
|
6910
|
-
if (typeof e == "boolean" || i6?.type?.name === "number" && typeof e == "number") return false;
|
|
6911
|
-
if (!e || (Array.isArray(e) || typeof e == "string") && e.length === 0) {
|
|
6912
|
-
if (t?.isExample || i6.isOptional || i6.isInternal) return true;
|
|
6913
|
-
let n = t?.isInputField !== false ? "input" : "output";
|
|
6914
|
-
throw new Error(`Value for ${n} field '${i6.name}' is required.`);
|
|
6915
|
-
}
|
|
6916
|
-
return false;
|
|
6917
|
-
};
|
|
6918
|
-
function St(i6) {
|
|
6919
|
-
let e = i6.trim();
|
|
6920
|
-
return e.length > 0 ? `${e.charAt(0).toUpperCase()}${e.slice(1)}${e.endsWith(".") ? "" : "."}` : "";
|
|
6921
|
-
}
|
|
6922
|
-
function nc(i6, e) {
|
|
6923
|
-
let t = i6.history(0, e), n = t.some((o) => o.role === "function");
|
|
6924
|
-
return t.some((o) => o.role === "assistant" && "functionCalls" in o && Array.isArray(o.functionCalls) && o.functionCalls.length > 0) && n;
|
|
6925
|
-
}
|
|
6926
|
-
function rc(i6, e) {
|
|
6927
|
-
let t = i6.history(0, e), n = [], r = t.filter((s) => s.role === "assistant" && "functionCalls" in s && Array.isArray(s.functionCalls) && s.functionCalls.length > 0), o = t.filter((s) => s.role === "function");
|
|
6928
|
-
for (let s of r) if ("functionCalls" in s && s.functionCalls) for (let a of s.functionCalls) {
|
|
6929
|
-
let l = o.find((c2) => "functionId" in c2 && c2.functionId === a.id);
|
|
6930
|
-
l && "result" in l && "functionId" in l && n.push({ index: n.length, functionName: a.function.name, functionId: a.id, args: a.function.params || "", result: String(l.result), isError: "isError" in l ? !!l.isError : false });
|
|
6931
|
-
}
|
|
6932
|
-
return n;
|
|
6933
|
-
}
|
|
6934
|
-
async function hr(i6, e, t, n) {
|
|
6935
|
-
if (!e?.resultPicker || i6.length <= 1) return 0;
|
|
6936
|
-
let r = e.resultPicker;
|
|
6937
|
-
if ((t ? nc(t, n) : false) && t) {
|
|
6938
|
-
let l = rc(t, n), c2 = await r({ type: "function", results: l });
|
|
6939
|
-
if (c2 < 0 || c2 >= l.length) throw new Error(`Result picker returned invalid index: ${c2}. Must be between 0 and ${l.length - 1}`);
|
|
6940
|
-
return c2;
|
|
6941
|
-
}
|
|
6942
|
-
let s = i6.map((l, c2) => ({ index: c2, sample: l.delta })), a = await r({ type: "fields", results: s });
|
|
6943
|
-
if (a < 0 || a >= i6.length) throw new Error(`Result picker returned invalid index: ${a}. Must be between 0 and ${i6.length - 1}`);
|
|
6944
|
-
return a;
|
|
6945
|
-
}
|
|
6946
|
-
async function Aa(i6, e, t) {
|
|
6947
|
-
let n = i6?.getLast(e);
|
|
6948
|
-
if (!n || n.role !== "assistant" || n.chat.length <= 1) return 0;
|
|
6949
|
-
let r = n.chat.map((s) => ({ version: 0, index: s.index, delta: s.value }));
|
|
6950
|
-
return await hr(r, t, i6, e);
|
|
6951
|
-
}
|
|
6952
|
-
var fr = class {
|
|
6953
|
-
tools;
|
|
6954
|
-
logger;
|
|
6955
|
-
constructor(e, t) {
|
|
6956
|
-
this.tools = new Map(e.map((n) => [n.name, n])), this.logger = t;
|
|
6957
|
-
}
|
|
6958
|
-
getToolParamFieldMap() {
|
|
6959
|
-
let e = /* @__PURE__ */ new Map();
|
|
6960
|
-
for (let [, t] of this.tools.entries()) if (t.parameters?.properties && Object.keys(t.parameters.properties).length > 0) {
|
|
6961
|
-
let { paramFieldMap: n } = oc(t);
|
|
6962
|
-
e.set(t.name, n);
|
|
6963
|
-
} else e.set(t.name, /* @__PURE__ */ new Map());
|
|
6964
|
-
return e;
|
|
6965
|
-
}
|
|
6966
|
-
async route(e, t) {
|
|
6967
|
-
let n = [], r = {}, o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
|
|
6968
|
-
for (let [a, l] of this.tools.entries()) s.set(a, this.buildSanitizedFieldMap(l));
|
|
6969
|
-
for (let [a, l] of Object.entries(e)) {
|
|
6970
|
-
let c2 = this.tools.get(this.normalizeToolName(a));
|
|
6971
|
-
if (c2) {
|
|
6972
|
-
l != null && typeof l == "object" && o.set(c2.name, l);
|
|
6973
|
-
continue;
|
|
6974
|
-
}
|
|
6975
|
-
r[a] = l;
|
|
6976
|
-
}
|
|
6977
|
-
for (let [a, l] of Object.entries(e)) for (let [c2, u] of this.tools.entries()) {
|
|
6978
|
-
let p = s.get(c2);
|
|
6979
|
-
if (!p) continue;
|
|
6980
|
-
let d = p.get(a);
|
|
6981
|
-
if (!d) continue;
|
|
6982
|
-
let m = o.get(u.name) ?? {};
|
|
6983
|
-
this.setNested(m, d, l), o.set(u.name, m);
|
|
6984
|
-
}
|
|
6985
|
-
for (let [a, l] of this.tools.entries()) {
|
|
6986
|
-
let c2 = o.get(l.name);
|
|
6987
|
-
if (!(!c2 || Object.keys(c2).length === 0)) {
|
|
6988
|
-
if (l.parameters && l.parameters.type === "object") {
|
|
6989
|
-
let p = (l.parameters.required || []).filter((d) => c2[d] === void 0);
|
|
6990
|
-
if (p.length > 0) throw new ge(`Missing required arguments for tool '${l.name}': ${p.join(", ")}`);
|
|
6991
|
-
}
|
|
6992
|
-
n.push({ id: l.name, name: l.name, args: JSON.stringify(c2) });
|
|
6993
|
-
}
|
|
6994
|
-
}
|
|
6995
|
-
return { functionCalls: n, remainingFields: r };
|
|
6996
|
-
}
|
|
6997
|
-
normalizeToolName(e) {
|
|
6998
|
-
return e.replace(/_([a-z])/g, (t, n) => n.toUpperCase());
|
|
6999
|
-
}
|
|
7000
|
-
sanitizeFieldName(e) {
|
|
7001
|
-
return e.replace(/([A-Z])/g, "_$1").toLowerCase().replace(/^_|_$/g, "").replace(/[^a-z0-9_]/g, "_");
|
|
7002
|
-
}
|
|
7003
|
-
buildSanitizedFieldMap(e) {
|
|
7004
|
-
let t = /* @__PURE__ */ new Map();
|
|
7005
|
-
if (!e.parameters || !("properties" in e.parameters)) return t;
|
|
7006
|
-
let n = (r, o) => {
|
|
7007
|
-
for (let [s, a] of Object.entries(r)) {
|
|
7008
|
-
let l = [...o, s];
|
|
7009
|
-
if (a && a.type === "object" && a.properties) n(a.properties, l);
|
|
7010
|
-
else {
|
|
7011
|
-
let c2 = `${e.name}.${l.join(".")}`, u = this.sanitizeFieldName(c2);
|
|
7012
|
-
t.set(u, l);
|
|
7013
|
-
}
|
|
7014
|
-
}
|
|
7015
|
-
};
|
|
7016
|
-
return n(e.parameters.properties ?? {}, []), t;
|
|
7017
|
-
}
|
|
7018
|
-
setNested(e, t, n) {
|
|
7019
|
-
let r = e;
|
|
7020
|
-
for (let o = 0; o < t.length - 1; o++) {
|
|
7021
|
-
let s = t[o], a = r[s];
|
|
7022
|
-
(typeof a != "object" || a === null) && (r[s] = {}), r = r[s];
|
|
7023
|
-
}
|
|
7024
|
-
r[t[t.length - 1]] = n;
|
|
7025
|
-
}
|
|
7026
|
-
isToolField(e) {
|
|
7027
|
-
return this.tools.has(this.normalizeToolName(e));
|
|
7028
|
-
}
|
|
7029
|
-
getToolFieldNames() {
|
|
7030
|
-
return Array.from(this.tools.keys()).map((e) => e.replace(/([A-Z])/g, "_$1").toLowerCase().replace(/^_/, ""));
|
|
7031
|
-
}
|
|
7032
|
-
};
|
|
7033
|
-
function oc(i6) {
|
|
7034
|
-
let e = [], t = /* @__PURE__ */ new Map();
|
|
7035
|
-
if (!i6.parameters || !i6.parameters.properties) return { fields: e, paramFieldMap: t };
|
|
7036
|
-
let n = i6.parameters.properties, r = i6.parameters.required || [], o = (s, a, l) => {
|
|
7037
|
-
for (let [c2, u] of Object.entries(s)) {
|
|
7038
|
-
let p = a ? `${a}.${c2}` : c2, d = `${i6.name}.${p}`;
|
|
7039
|
-
if (u.type === "object" && u.properties) o(u.properties, p, u.required || []);
|
|
7040
|
-
else {
|
|
7041
|
-
let m = sc(u);
|
|
7042
|
-
e.push({ name: ac(d), title: ic(i6.name, p), type: m, description: u.description || `${c2} parameter for ${i6.name}`, isOptional: true }), t.set(d, e[e.length - 1]);
|
|
7043
|
-
}
|
|
7044
|
-
}
|
|
7045
|
-
};
|
|
7046
|
-
return o(n, "", r), { fields: e, paramFieldMap: t };
|
|
7047
|
-
}
|
|
7048
|
-
function sc(i6) {
|
|
7049
|
-
switch (i6.type) {
|
|
7050
|
-
case "string":
|
|
7051
|
-
return { name: "string", isArray: false };
|
|
7052
|
-
case "number":
|
|
7053
|
-
case "integer":
|
|
7054
|
-
return { name: "number", isArray: false };
|
|
7055
|
-
case "boolean":
|
|
7056
|
-
return { name: "boolean", isArray: false };
|
|
7057
|
-
case "array": {
|
|
7058
|
-
let e = i6.items;
|
|
7059
|
-
if (e?.type) switch (e.type) {
|
|
7060
|
-
case "string":
|
|
7061
|
-
return { name: "string", isArray: true };
|
|
7062
|
-
case "number":
|
|
7063
|
-
case "integer":
|
|
7064
|
-
return { name: "number", isArray: true };
|
|
7065
|
-
case "boolean":
|
|
7066
|
-
return { name: "boolean", isArray: true };
|
|
7067
|
-
default:
|
|
7068
|
-
return { name: "json", isArray: true };
|
|
7069
|
-
}
|
|
7070
|
-
return { name: "json", isArray: true };
|
|
7071
|
-
}
|
|
7072
|
-
case "object":
|
|
7073
|
-
return { name: "json", isArray: false };
|
|
7074
|
-
default:
|
|
7075
|
-
return { name: "string", isArray: false };
|
|
7076
|
-
}
|
|
7077
|
-
}
|
|
7078
|
-
function ic(i6, e) {
|
|
7079
|
-
return `${i6} ${e.replace(/\./g, " ")}`;
|
|
7080
|
-
}
|
|
7081
|
-
function ac(i6) {
|
|
7082
|
-
return i6.replace(/([A-Z])/g, "_$1").toLowerCase().replace(/^_|_$/g, "").replace(/[^a-z0-9_]/g, "_");
|
|
7083
|
-
}
|
|
7084
|
-
function ba(i6, e, t) {
|
|
7085
|
-
let n = new ue(e);
|
|
7086
|
-
if (t) {
|
|
7087
|
-
let r = t.getToolParamFieldMap();
|
|
7088
|
-
for (let o of i6) {
|
|
7089
|
-
let s = r.get(o.name);
|
|
7090
|
-
if (s && s.size > 0) for (let a of s.values()) n.getOutputFields().some((c2) => c2.name === a.name) || n.addOutputField(a);
|
|
7091
|
-
else {
|
|
7092
|
-
let a = Xo(o.name), l = ya(o.parameters);
|
|
7093
|
-
n.getOutputFields().some((u) => u.name === a) || n.addOutputField({ name: a, title: xa(o.name), type: l, description: o.description || `Parameters for ${o.name}`, isOptional: true });
|
|
7094
|
-
}
|
|
7095
|
-
}
|
|
7096
|
-
return { signature: n, toolParamFieldMap: r };
|
|
7097
|
-
} else {
|
|
7098
|
-
let r = /* @__PURE__ */ new Map();
|
|
7099
|
-
for (let o of i6) if (o.parameters?.properties && Object.keys(o.parameters.properties).length > 0) {
|
|
7100
|
-
let { fields: s, paramFieldMap: a } = lc(o);
|
|
7101
|
-
r.set(o.name, a);
|
|
7102
|
-
for (let l of s) n.getOutputFields().some((u) => u.name === l.name) || n.addOutputField(l);
|
|
7103
|
-
} else {
|
|
7104
|
-
let s = Xo(o.name), a = ya(o.parameters);
|
|
7105
|
-
n.getOutputFields().some((c2) => c2.name === s) || n.addOutputField({ name: s, title: xa(o.name), type: a, description: o.description || `Parameters for ${o.name}`, isOptional: true });
|
|
7106
|
-
}
|
|
7107
|
-
return { signature: n, toolParamFieldMap: r };
|
|
7108
|
-
}
|
|
7109
|
-
}
|
|
7110
|
-
function lc(i6) {
|
|
7111
|
-
let e = [], t = /* @__PURE__ */ new Map();
|
|
7112
|
-
if (!i6.parameters || !i6.parameters.properties) return { fields: e, paramFieldMap: t };
|
|
7113
|
-
let n = i6.parameters.properties, r = i6.parameters.required || [], o = (s, a, l) => {
|
|
7114
|
-
for (let [c2, u] of Object.entries(s)) {
|
|
7115
|
-
let p = a ? `${a}.${c2}` : c2, d = `${i6.name}.${p}`;
|
|
7116
|
-
if (u.type === "object" && u.properties) o(u.properties, p, u.required || []);
|
|
7117
|
-
else {
|
|
7118
|
-
let m = cc(u), g = { name: Xo(d), title: uc(i6.name, p), type: m, description: u.description || `${c2} parameter for ${i6.name}`, isOptional: true };
|
|
7119
|
-
e.push(g), t.set(d, g);
|
|
7120
|
-
}
|
|
7121
|
-
}
|
|
7122
|
-
};
|
|
7123
|
-
return o(n, "", r), { fields: e, paramFieldMap: t };
|
|
7124
|
-
}
|
|
7125
|
-
function cc(i6) {
|
|
7126
|
-
switch (i6.type) {
|
|
7127
|
-
case "string":
|
|
7128
|
-
return { name: "string", isArray: false };
|
|
7129
|
-
case "number":
|
|
7130
|
-
case "integer":
|
|
7131
|
-
return { name: "number", isArray: false };
|
|
7132
|
-
case "boolean":
|
|
7133
|
-
return { name: "boolean", isArray: false };
|
|
7134
|
-
case "array": {
|
|
7135
|
-
let e = i6.items;
|
|
7136
|
-
if (e?.type) switch (e.type) {
|
|
7137
|
-
case "string":
|
|
7138
|
-
return { name: "string", isArray: true };
|
|
7139
|
-
case "number":
|
|
7140
|
-
case "integer":
|
|
7141
|
-
return { name: "number", isArray: true };
|
|
7142
|
-
case "boolean":
|
|
7143
|
-
return { name: "boolean", isArray: true };
|
|
7144
|
-
default:
|
|
7145
|
-
return { name: "json", isArray: true };
|
|
7146
|
-
}
|
|
7147
|
-
return { name: "json", isArray: true };
|
|
7148
|
-
}
|
|
7149
|
-
case "object":
|
|
7150
|
-
return { name: "json", isArray: false };
|
|
7151
|
-
default:
|
|
7152
|
-
return { name: "string", isArray: false };
|
|
7153
|
-
}
|
|
7154
|
-
}
|
|
7155
|
-
function uc(i6, e) {
|
|
7156
|
-
return `${i6} ${e.replace(/\./g, " ")}`;
|
|
7157
|
-
}
|
|
7158
|
-
function Xo(i6) {
|
|
7159
|
-
return i6.replace(/([A-Z])/g, "_$1").toLowerCase().replace(/^_|_$/g, "").replace(/[^a-z0-9_]/g, "_");
|
|
7160
|
-
}
|
|
7161
|
-
function xa(i6) {
|
|
7162
|
-
return i6.replace(/([A-Z])/g, " $1").replace(/^./, (e) => e.toUpperCase()).trim();
|
|
7163
|
-
}
|
|
7164
|
-
function ya(i6) {
|
|
7165
|
-
return !i6 || !i6.properties || Object.keys(i6.properties).length === 0 ? { name: "string", isArray: false } : { name: "json", isArray: false };
|
|
7166
|
-
}
|
|
7167
|
-
var gn = class {
|
|
7168
|
-
tools;
|
|
7169
|
-
router;
|
|
7170
|
-
injectedToolFieldNames = /* @__PURE__ */ new Set();
|
|
7171
|
-
constructor(e) {
|
|
7172
|
-
this.tools = e, this.router = new fr(e);
|
|
7173
|
-
}
|
|
7174
|
-
processSignature(e) {
|
|
7175
|
-
let { signature: t } = ba(this.tools, e), n = new Set(t.getOutputFields().map((o) => o.name)), r = new Set(e.getOutputFields().map((o) => o.name));
|
|
7176
|
-
return this.injectedToolFieldNames = new Set([...n].filter((o) => !r.has(o))), t;
|
|
7177
|
-
}
|
|
7178
|
-
async processResults(e, t) {
|
|
7179
|
-
let { functionCalls: n } = await this.router.route(e, t);
|
|
7180
|
-
return n.length > 0 ? n : void 0;
|
|
7181
|
-
}
|
|
7182
|
-
getInjectedToolFieldNames() {
|
|
7183
|
-
return Array.from(this.injectedToolFieldNames);
|
|
7184
|
-
}
|
|
7185
|
-
getRouter() {
|
|
7186
|
-
return this.router;
|
|
7187
|
-
}
|
|
7188
|
-
};
|
|
7189
|
-
var ve = class extends gt {
|
|
7190
|
-
promptTemplate;
|
|
7191
|
-
asserts;
|
|
7192
|
-
streamingAsserts;
|
|
7193
|
-
options;
|
|
7194
|
-
functions;
|
|
7195
|
-
fieldProcessors = [];
|
|
7196
|
-
streamingFieldProcessors = [];
|
|
7197
|
-
excludeContentFromTrace = false;
|
|
7198
|
-
thoughtFieldName;
|
|
7199
|
-
signatureToolCallingManager;
|
|
7200
|
-
constructor(e, t) {
|
|
7201
|
-
super(e, { description: t?.description, traceLabel: t?.traceLabel }), this.options = t, this.thoughtFieldName = t?.thoughtFieldName ?? "thought";
|
|
7202
|
-
let n = { functions: t?.functions, thoughtFieldName: this.thoughtFieldName, cacheSystemPrompt: t?.cacheSystemPrompt };
|
|
7203
|
-
this.promptTemplate = new (t?.promptTemplate ?? vt)(this.signature, n), this.asserts = this.options?.asserts ?? [], this.streamingAsserts = this.options?.streamingAsserts ?? [], this.excludeContentFromTrace = t?.excludeContentFromTrace ?? false, this.functions = t?.functions ? sr(t.functions) : [], this.usage = [];
|
|
7204
|
-
}
|
|
7205
|
-
getSignatureName() {
|
|
7206
|
-
return this.signature.getDescription() || "unknown_signature";
|
|
7207
|
-
}
|
|
7208
|
-
getMetricsInstruments() {
|
|
7209
|
-
return No();
|
|
7210
|
-
}
|
|
7211
|
-
updateMeter(e) {
|
|
7212
|
-
No(e);
|
|
7213
|
-
}
|
|
7214
|
-
createStates(e) {
|
|
7215
|
-
return Array.from({ length: e }, (t, n) => ({ index: n, functionCalls: [], values: {}, content: "", functionsExecuted: /* @__PURE__ */ new Set(), xstate: { extractedFields: [], streamedIndex: {}, s: -1 } }));
|
|
7216
|
-
}
|
|
7217
|
-
addAssert = (e, t) => {
|
|
7218
|
-
this.asserts.push({ fn: e, message: t });
|
|
7219
|
-
};
|
|
7220
|
-
addStreamingAssert = (e, t, n) => {
|
|
7221
|
-
let r = this.signature.getOutputFields().find((a) => a.name === e);
|
|
7222
|
-
if (!r) throw new Error(`addStreamingAssert: field ${String(e)} not found in output signature`);
|
|
7223
|
-
let o = r.type?.name;
|
|
7224
|
-
if (!(!o || o === "string" || o === "code")) throw new Error(`addStreamingAssert: field ${String(e)} must be a string field for streaming assertions`);
|
|
7225
|
-
this.streamingAsserts.push({ fieldName: String(e), fn: t, message: n });
|
|
7226
|
-
};
|
|
7227
|
-
addFieldProcessorInternal = (e, t, n = false) => {
|
|
7228
|
-
let r = this.signature.getOutputFields().find((o) => o.name === e);
|
|
7229
|
-
if (!r) throw new Error(`addFieldProcessor: field ${e} not found`);
|
|
7230
|
-
if (n) {
|
|
7231
|
-
let o = r.type?.name;
|
|
7232
|
-
if (!(!o || o === "string" || o === "code")) throw new Error(`addFieldProcessor: field ${e} must be a text field`);
|
|
7233
|
-
this.streamingFieldProcessors.push({ field: r, process: t });
|
|
7234
|
-
} else this.fieldProcessors.push({ field: r, process: t });
|
|
7235
|
-
};
|
|
7236
|
-
addStreamingFieldProcessor = (e, t) => {
|
|
7237
|
-
this.addFieldProcessorInternal(String(e), t, true);
|
|
7238
|
-
};
|
|
7239
|
-
addFieldProcessor = (e, t) => {
|
|
7240
|
-
this.addFieldProcessorInternal(String(e), t, false);
|
|
7241
|
-
};
|
|
7242
|
-
async forwardSendRequest({ ai: e, mem: t, options: n, traceContext: r, functions: o, functionCall: s, stepIndex: a }) {
|
|
7243
|
-
let { sessionId: l, model: c2, rateLimiter: u, stream: p, thinkingTokenBudget: d, showThoughts: m } = n ?? {}, g = await Aa(t, l, { resultPicker: n?.resultPicker }), A = t?.history(g, l) ?? [];
|
|
7244
|
-
if (A.length === 0) throw new Error("No chat prompt found");
|
|
7245
|
-
let h = { ...n?.modelConfig, ...n?.sampleCount ? { n: n.sampleCount } : {}, ...n?.sampleCount && n?.modelConfig?.temperature === 1 ? { temperature: 0.8 } : {} }, f = this.isDebug(e, n), x = a === 0, I = this.getLogger(e, n);
|
|
7246
|
-
o = this.signatureToolCallingManager ? [] : o;
|
|
7247
|
-
let y, R = this.signature.getOutputFields();
|
|
7248
|
-
return this.signature.hasComplexFields() && (y = { type: "json_schema", schema: { name: "output", strict: true, schema: nr(R) } }), await e.chat({ chatPrompt: A, functions: o, functionCall: s, modelConfig: h, model: c2, responseFormat: y }, { sessionId: l, rateLimiter: u, stream: p, debug: f, debugHideSystemPrompt: !x, thinkingTokenBudget: d, showThoughts: m, traceContext: r, abortSignal: n?.abortSignal ?? J.abortSignal, stepIndex: a, logger: I, functionCallMode: n?.functionCallMode ?? this.options?.functionCallMode ?? "auto" });
|
|
7249
|
-
}
|
|
7250
|
-
async *forwardCore({ ai: e, mem: t, options: n, stepIndex: r, span: o, traceContext: s, states: a, stopFunctionNames: l }) {
|
|
7251
|
-
let { sessionId: c2, functions: u } = n ?? {}, p = n?.functionResultFormatter ?? this.options?.functionResultFormatter, d = n?.functionCall ?? this.options?.functionCall, m = this.signatureToolCallingManager, g = n?.strictMode ?? false, A = n.model, h = this.usage, f = r === 0, x = this.isDebug(e, n), I = this.getLogger(e, n), { functions: y, functionCall: R } = Ji(u, d, f, n), T = await this.forwardSendRequest({ ai: e, mem: t, options: n, traceContext: s, functions: y, functionCall: R, stepIndex: r });
|
|
7252
|
-
T instanceof ReadableStream ? yield* ia({ ai: e, model: A, res: T, mem: t, sessionId: c2, traceId: o ? o.spanContext?.().traceId : void 0, functions: y, strictMode: g, span: o, states: a, usage: h, asserts: this.asserts, streamingAsserts: this.streamingAsserts, fieldProcessors: this.fieldProcessors, streamingFieldProcessors: this.streamingFieldProcessors, thoughtFieldName: this.thoughtFieldName, excludeContentFromTrace: this.excludeContentFromTrace, signature: this.signature, logger: I, debug: x, functionResultFormatter: p, signatureToolCallingManager: m, stopFunctionNames: l, disableMemoryCleanup: n.disableMemoryCleanup }) : yield* aa({ ai: e, model: A, res: T, mem: t, sessionId: c2, traceId: o ? o.spanContext?.().traceId : void 0, functions: y, span: o, strictMode: g, states: a, usage: h, asserts: this.asserts, fieldProcessors: this.fieldProcessors, thoughtFieldName: this.thoughtFieldName, excludeContentFromTrace: this.excludeContentFromTrace, signature: this.signature, logger: I, debug: x, functionResultFormatter: p, signatureToolCallingManager: m, stopFunctionNames: l, disableMemoryCleanup: n.disableMemoryCleanup });
|
|
7253
|
-
}
|
|
7254
|
-
async *_forward2(e, t, n, r, o, s) {
|
|
7255
|
-
let a = r?.stopFunction ?? this.options?.stopFunction, l = Array.isArray(a) ? a.map((E) => E.toLowerCase()) : a ? [a.toLowerCase()] : void 0, c2 = r.maxRetries ?? this.options?.maxRetries ?? 10, u = r.maxSteps ?? this.options?.maxSteps ?? 10, p = r.mem ?? this.options?.mem ?? new cn(), d = [...this.functions, ...r.functions ? sr(r.functions) : []], m = d && d.length > 0, g = r.functionCallMode ?? this.options?.functionCallMode ?? "auto", A = r.cacheSystemPrompt ?? this.options?.cacheSystemPrompt;
|
|
7256
|
-
m && g === "prompt" && (this.signatureToolCallingManager = new gn(d)), m && g === "auto" && !e.getFeatures(r.model).functions && (this.signatureToolCallingManager = new gn(d));
|
|
7257
|
-
let h, f, x = this.options?.promptTemplate ?? vt;
|
|
7258
|
-
this.signatureToolCallingManager && (this.signature = this.signatureToolCallingManager.processSignature(this.signature), this.setSignature(this.signature));
|
|
7259
|
-
let I = { functions: this.signatureToolCallingManager ? [] : d, thoughtFieldName: this.thoughtFieldName, cacheSystemPrompt: A };
|
|
7260
|
-
this.promptTemplate = new x(this.signature, I);
|
|
7261
|
-
let y, R = performance.now();
|
|
7262
|
-
Array.isArray(t) ? (ui(t), y = this.promptTemplate.render(t, { examples: this.examples, demos: this.demos })) : y = this.promptTemplate.render(t, { examples: this.examples, demos: this.demos });
|
|
7263
|
-
let T = performance.now() - R, S = this.getMetricsInstruments();
|
|
7264
|
-
S && Yn(S, "prompt_render", T, this.getSignatureName());
|
|
7265
|
-
let b = performance.now();
|
|
7266
|
-
p.addRequest(y, r.sessionId);
|
|
7267
|
-
let v = performance.now() - b;
|
|
7268
|
-
S && Yn(S, "memory_update", v, this.getSignatureName());
|
|
7269
|
-
e: for (let E = 0; E < u; E++) {
|
|
7270
|
-
for (let w = 0; w < c2; w++) try {
|
|
7271
|
-
let P = this.forwardCore({ options: r, ai: e, mem: p, stepIndex: E, span: o, traceContext: s, states: n, stopFunctionNames: l }), C = false;
|
|
7272
|
-
try {
|
|
7273
|
-
for await (let $ of P) $ !== void 0 && (yield { version: w, index: $.index, delta: $.delta });
|
|
7274
|
-
} catch ($) {
|
|
7275
|
-
if ($ instanceof wt) C = true;
|
|
7276
|
-
else throw $;
|
|
7277
|
-
}
|
|
7278
|
-
if (C ? false : la(p, l, n, r?.sessionId)) {
|
|
7279
|
-
let $ = this.getMetricsInstruments();
|
|
7280
|
-
$ && Qn($, E + 1, u, this.getSignatureName());
|
|
7281
|
-
continue e;
|
|
7282
|
-
}
|
|
7283
|
-
r?.disableMemoryCleanup || (p.removeByTag("invalid-assistant", r.sessionId), p.removeByTag("correction", r.sessionId), p.removeByTag("error", r.sessionId));
|
|
7284
|
-
let M = this.getMetricsInstruments();
|
|
7285
|
-
if (M) {
|
|
7286
|
-
Qn(M, E + 1, u, this.getSignatureName());
|
|
7287
|
-
let $ = /* @__PURE__ */ new Set();
|
|
7288
|
-
n.forEach((Y) => {
|
|
7289
|
-
Y.functionsExecuted.forEach((W) => $.add(W));
|
|
7290
|
-
}), $.size > 0 && Fi(M, true, $.size, true, false, this.getSignatureName()), _i(M, this.fieldProcessors.length, this.streamingFieldProcessors.length, this.getSignatureName());
|
|
7291
|
-
}
|
|
7292
|
-
return;
|
|
7293
|
-
} catch (P) {
|
|
7294
|
-
f = P;
|
|
7295
|
-
let C, O = this.isDebug(e, r), M = this.getLogger(e, r), $ = this.getMetricsInstruments(), Y = this.getSignatureName(), W = { error: P, errCount: w, logger: M, metricsInstruments: $, signatureName: Y, span: o, debug: O };
|
|
7296
|
-
if (o?.recordException(P), P instanceof ge) C = zi(W), h = P;
|
|
7297
|
-
else if (P instanceof Ze) C = Hi(W), h = P;
|
|
7298
|
-
else if (P instanceof le) Ki(W);
|
|
7299
|
-
else if (!(P instanceof ze)) throw Zo(P, e, this.signature);
|
|
7300
|
-
C && (p.addTag("error", r.sessionId), p.addRequest([{ role: "user", content: this.promptTemplate.renderExtraFields(C) }], r.sessionId), p.addTag("correction", r.sessionId));
|
|
7301
|
-
}
|
|
7302
|
-
let k = this.getMetricsInstruments();
|
|
7303
|
-
throw k && $o(k, c2, false, c2, this.getSignatureName()), Zo(new Error(`Unable to fix validation error: ${(h ?? f)?.message ?? (h ?? f)?.toString() ?? "unknown error"}`), e, this.signature);
|
|
7304
|
-
}
|
|
7305
|
-
throw S && Qn(S, u, u, this.getSignatureName()), Zo(new Error(`Max steps reached: ${u}`), e, this.signature);
|
|
7306
|
-
}
|
|
7307
|
-
validateInputs(e) {
|
|
7308
|
-
let t = this.signature.getInputFields();
|
|
7309
|
-
for (let n of t) {
|
|
7310
|
-
if (n.isInternal) continue;
|
|
7311
|
-
let r = e[n.name];
|
|
7312
|
-
if (n.isOptional && r === void 0) continue;
|
|
7313
|
-
let o = n.type;
|
|
7314
|
-
if (o && (o.name === "url" && it(r, n), o.name, o.name, (o.name === "string" || o.name === "code") && Pe(r, n), o.name === "number" && Fe(r, n), o.name === "object" && o.fields && typeof r == "object" && r !== null && this.validateObjectFields(r, o.fields, n.name), o.isArray && Array.isArray(r))) for (let s = 0; s < r.length; s++) {
|
|
7315
|
-
let a = r[s];
|
|
7316
|
-
o.name === "string" || o.name === "code" ? Pe(a, n) : o.name === "number" ? Fe(a, n) : o.fields && typeof a == "object" && a !== null && this.validateObjectFields(a, o.fields, `${n.name}[${s}]`);
|
|
7317
|
-
}
|
|
7318
|
-
}
|
|
7319
|
-
}
|
|
7320
|
-
validateObjectFields(e, t, n) {
|
|
7321
|
-
for (let [r, o] of Object.entries(t)) {
|
|
7322
|
-
let s = e[r];
|
|
7323
|
-
if (o.isOptional && s === void 0) continue;
|
|
7324
|
-
let a = { name: `${n}.${r}`, type: { name: o.type, isArray: o.isArray, options: o.options ? [...o.options] : void 0, fields: o.fields, minLength: o.minLength, maxLength: o.maxLength, minimum: o.minimum, maximum: o.maximum, pattern: o.pattern, format: o.format }, description: o.description, isOptional: o.isOptional };
|
|
7325
|
-
if (o.type === "string" || o.type === "code" ? Pe(s, a) : o.type === "number" ? Fe(s, a) : o.type === "object" && o.fields && typeof s == "object" && s !== null && this.validateObjectFields(s, o.fields, a.name), o.isArray && Array.isArray(s)) for (let l = 0; l < s.length; l++) {
|
|
7326
|
-
let c2 = s[l];
|
|
7327
|
-
o.type === "string" || o.type === "code" ? Pe(c2, a) : o.type === "number" ? Fe(c2, a) : o.fields && typeof c2 == "object" && c2 !== null && this.validateObjectFields(c2, o.fields, `${a.name}[${l}]`);
|
|
7328
|
-
}
|
|
7329
|
-
}
|
|
7330
|
-
}
|
|
7331
|
-
async *_forward1(e, t, n) {
|
|
7332
|
-
(!Array.isArray(t) || !t.every((f) => "role" in f)) && this.validateInputs(t);
|
|
7333
|
-
let r = performance.now(), o = this.createStates(n.sampleCount ?? 1), s = performance.now() - r, a = this.getMetricsInstruments();
|
|
7334
|
-
a && Yn(a, "state_creation", s, this.getSignatureName());
|
|
7335
|
-
let l = n?.tracer ?? this.options?.tracer ?? e.getOptions().tracer, c2 = this.functions;
|
|
7336
|
-
if (n?.functions && (c2 = sr(n.functions, this.functions)), !l) {
|
|
7337
|
-
yield* this._forward2(e, t, o, { ...n, functions: c2 });
|
|
7338
|
-
return;
|
|
7339
|
-
}
|
|
7340
|
-
let u = c2?.map((f) => f.name).join(","), p = { signature: JSON.stringify(this.signature.toJSON(), null, 2), ...this.examples ? { examples: JSON.stringify(this.examples, null, 2) } : {}, ...u ? { provided_functions: u } : {}, ...n?.model ? { model: n.model } : {}, ...n?.thinkingTokenBudget ? { thinking_token_budget: n.thinkingTokenBudget } : {}, ...n?.showThoughts ? { show_thoughts: n.showThoughts } : {}, ...n?.maxSteps ? { max_steps: n.maxSteps } : {}, ...n?.maxRetries ? { max_retries: n.maxRetries } : {} }, d = this.traceLabel && n.traceLabel ? `${this.traceLabel} > ${n.traceLabel}` : n.traceLabel ?? this.traceLabel, m = d ? `AxGen > ${d}` : "AxGen", g = l.startSpan(m, { kind: SpanKind.SERVER, attributes: p }), A = context.active(), h = trace.setSpan(A, g);
|
|
7341
|
-
try {
|
|
7342
|
-
if (this.excludeContentFromTrace || g.addEvent("input", { content: JSON.stringify(t, null, 2) }), yield* this._forward2(e, t, o, { ...n, functions: c2 }, g, h), !this.excludeContentFromTrace) {
|
|
7343
|
-
let f = o.map((I) => I.values), x = f.length === 1 ? f[0] : f;
|
|
7344
|
-
g.addEvent("output", { content: JSON.stringify(x, null, 2) });
|
|
7345
|
-
}
|
|
7346
|
-
} finally {
|
|
7347
|
-
g.end();
|
|
7348
|
-
}
|
|
7349
|
-
}
|
|
7350
|
-
async forward(e, t, n) {
|
|
7351
|
-
let r = n?.cachingFunction ?? this.options?.cachingFunction ?? J.cachingFunction, o = (() => {
|
|
7352
|
-
if (!r) return;
|
|
7353
|
-
let d = this.signature.getInputFields().map((m) => m.name);
|
|
7354
|
-
return this.computeCacheKey(t, d);
|
|
7355
|
-
})();
|
|
7356
|
-
if (r && o) {
|
|
7357
|
-
let d = await r(o);
|
|
7358
|
-
if (d !== void 0) return d;
|
|
7359
|
-
}
|
|
7360
|
-
let s = performance.now(), a = this.getSignatureName(), l = n?.stream ?? false, c2 = false, u = 0, p = false;
|
|
7361
|
-
try {
|
|
7362
|
-
let d = this.getMetricsInstruments();
|
|
7363
|
-
d && $i(d, this.signature.getInputFields().length, this.signature.getOutputFields().length, this.examples?.length ?? 0, this.demos?.length ?? 0, a);
|
|
7364
|
-
let m = this._forward1(e, t, n ?? {}), g = [], A = 0, h = 0;
|
|
7365
|
-
for await (let S of m) S.version !== A && (g = []), A = S.version, g = jo(g, S), h++;
|
|
7366
|
-
u = A;
|
|
7367
|
-
let f = performance.now();
|
|
7368
|
-
p = !!n?.resultPicker;
|
|
7369
|
-
let x = await hr(g, { resultPicker: n?.resultPicker }, n?.mem, n?.sessionId), I = performance.now() - f, R = g[x]?.delta ?? {}, T = Array.isArray(t) ? {} : t ?? {};
|
|
7370
|
-
if (this.trace = { ...T, ...R }, p && this.isDebug(e, n)) {
|
|
7371
|
-
let S = this.getLogger(e, n);
|
|
7372
|
-
zs(g.length, x, I, S);
|
|
7373
|
-
}
|
|
7374
|
-
if (c2 = true, d && (Di(d, g.length, p, p ? I : void 0, a), Ni(d, l, h, void 0, a)), r && o) try {
|
|
7375
|
-
await r(o, R);
|
|
7376
|
-
} catch {
|
|
7377
|
-
}
|
|
7378
|
-
return R;
|
|
7379
|
-
} catch (d) {
|
|
7380
|
-
throw c2 = false, d;
|
|
7381
|
-
} finally {
|
|
7382
|
-
let d = performance.now() - s, m = this.getMetricsInstruments();
|
|
7383
|
-
m && (Ei(m, d, c2, a, e.getName(), n?.model ? String(n.model) : void 0), u > 0 && $o(m, u, c2, n?.maxRetries ?? 10, a));
|
|
7384
|
-
}
|
|
7385
|
-
}
|
|
7386
|
-
async *streamingForward(e, t, n) {
|
|
7387
|
-
let r = n?.cachingFunction ?? this.options?.cachingFunction ?? J.cachingFunction, o = (() => {
|
|
7388
|
-
if (!r) return;
|
|
7389
|
-
let p = this.signature.getInputFields().map((d) => d.name);
|
|
7390
|
-
return this.computeCacheKey(t, p);
|
|
7391
|
-
})();
|
|
7392
|
-
if (r && o) {
|
|
7393
|
-
let p;
|
|
7394
|
-
try {
|
|
7395
|
-
p = await r(o);
|
|
7396
|
-
} catch {
|
|
7397
|
-
}
|
|
7398
|
-
if (p !== void 0) {
|
|
7399
|
-
yield { version: 0, index: 0, delta: p };
|
|
7400
|
-
return;
|
|
7401
|
-
}
|
|
7402
|
-
}
|
|
7403
|
-
if (!n?.resultPicker) {
|
|
7404
|
-
yield* this._forward1(e, t, { ...n, stream: true });
|
|
7405
|
-
return;
|
|
7406
|
-
}
|
|
7407
|
-
let s = this._forward1(e, t, { ...n, stream: true }), a = [], l = 0;
|
|
7408
|
-
for await (let p of s) p.version !== l && (a = []), l = p.version, a = jo(a, p);
|
|
7409
|
-
let c2 = await hr(a, { resultPicker: n?.resultPicker }, n?.mem, n?.sessionId), u = a[c2];
|
|
7410
|
-
if (u) {
|
|
7411
|
-
if (r && o) try {
|
|
7412
|
-
await r(o, u.delta);
|
|
7413
|
-
} catch {
|
|
7414
|
-
}
|
|
7415
|
-
yield { version: l, index: c2, delta: u.delta };
|
|
7416
|
-
}
|
|
7417
|
-
}
|
|
7418
|
-
setExamples(e, t) {
|
|
7419
|
-
super.setExamples(e, t);
|
|
7420
|
-
}
|
|
7421
|
-
isDebug(e, t) {
|
|
7422
|
-
return t?.debug ?? this.options?.debug ?? e.getOptions().debug ?? false;
|
|
7423
|
-
}
|
|
7424
|
-
getLogger(e, t) {
|
|
7425
|
-
return t?.logger ?? this.options?.logger ?? J.logger ?? e.getLogger();
|
|
7426
|
-
}
|
|
7427
|
-
computeCacheKey(e, t) {
|
|
7428
|
-
let n = Ee("sha256");
|
|
7429
|
-
n.update(this.signature.hash() ?? "");
|
|
7430
|
-
let r = (o) => {
|
|
7431
|
-
let s = typeof o;
|
|
7432
|
-
if (n.update(`|${s}|`), o == null) {
|
|
7433
|
-
n.update("null");
|
|
7434
|
-
return;
|
|
7435
|
-
}
|
|
7436
|
-
if (s === "string" || s === "number" || s === "boolean") {
|
|
7437
|
-
n.update(String(o));
|
|
7438
|
-
return;
|
|
7439
|
-
}
|
|
7440
|
-
if (Array.isArray(o)) {
|
|
7441
|
-
n.update("[");
|
|
7442
|
-
for (let a of o) r(a);
|
|
7443
|
-
n.update("]");
|
|
7444
|
-
return;
|
|
7445
|
-
}
|
|
7446
|
-
if (typeof o == "object" && o !== null && "mimeType" in o && "data" in o) {
|
|
7447
|
-
let a = o;
|
|
7448
|
-
n.update(a.mimeType ?? "");
|
|
7449
|
-
let l = Ee("sha256").update(a.data ?? "").digest("hex");
|
|
7450
|
-
n.update(l);
|
|
7451
|
-
return;
|
|
7452
|
-
}
|
|
7453
|
-
if (typeof o == "object") {
|
|
7454
|
-
let a = o, l = Object.keys(a).sort();
|
|
7455
|
-
for (let c2 of l) n.update(`{${c2}}`), r(a[c2]);
|
|
7456
|
-
return;
|
|
7457
|
-
}
|
|
7458
|
-
n.update(String(o));
|
|
7459
|
-
};
|
|
7460
|
-
if (Array.isArray(e)) for (let o of e) {
|
|
7461
|
-
n.update(`role:${o.role}`);
|
|
7462
|
-
let s = t.map((a) => o.values?.[a]);
|
|
7463
|
-
for (let a of s) r(a);
|
|
7464
|
-
}
|
|
7465
|
-
else {
|
|
7466
|
-
let o = t.map((s) => e?.[s]);
|
|
7467
|
-
for (let s of o) r(s);
|
|
4922
|
+
let t = /* @__PURE__ */ new Set();
|
|
4923
|
+
for (let n of this.outputFields) {
|
|
4924
|
+
if (t.has(n.name)) throw new L(`Duplicate output field name: "${n.name}"`, n.name, "Each field name must be unique within the signature");
|
|
4925
|
+
t.add(n.name);
|
|
7468
4926
|
}
|
|
7469
|
-
|
|
4927
|
+
for (let n of this.outputFields) if (e.has(n.name)) throw new L(`Field name "${n.name}" appears in both inputs and outputs`, n.name, "Use different names for input and output fields to avoid confusion");
|
|
4928
|
+
if (this.inputFields.length === 0) throw new L("Signature must have at least one input field", void 0, 'Add an input field. Example: "userInput:string -> ..."');
|
|
4929
|
+
if (this.outputFields.length === 0) throw new L("Signature must have at least one output field", void 0, 'Add an output field. Example: "... -> responseText:string"');
|
|
7470
4930
|
}
|
|
4931
|
+
hasComplexFields = () => {
|
|
4932
|
+
let e = (t) => t.some((n) => n.type?.name === "object" || n.type?.isArray && n.type.fields !== void 0);
|
|
4933
|
+
return e(this.inputFields) || e(this.outputFields);
|
|
4934
|
+
};
|
|
4935
|
+
validate = () => {
|
|
4936
|
+
if (this.validatedAtHash === this.sigHash) return true;
|
|
4937
|
+
try {
|
|
4938
|
+
return this.updateHash(), this.validatedAtHash = this.sigHash, true;
|
|
4939
|
+
} catch (e) {
|
|
4940
|
+
throw this.validatedAtHash = void 0, e;
|
|
4941
|
+
}
|
|
4942
|
+
};
|
|
4943
|
+
hash = () => this.sigHash;
|
|
4944
|
+
toString = () => this.sigString;
|
|
4945
|
+
toJSON = () => ({ id: this.hash(), description: this.description, inputFields: this.inputFields, outputFields: this.outputFields });
|
|
4946
|
+
toJSONSchema = () => {
|
|
4947
|
+
let e = [...this.inputFields, ...this.outputFields];
|
|
4948
|
+
return nr(e, this.description ?? "Schema");
|
|
4949
|
+
};
|
|
7471
4950
|
};
|
|
7472
|
-
|
|
7473
|
-
|
|
7474
|
-
|
|
7475
|
-
|
|
4951
|
+
function ua(i6) {
|
|
4952
|
+
let e = i6.name;
|
|
4953
|
+
return i6.isOptional && (e += "?"), i6.isInternal && (e += "!"), i6.type && (e += `:${i6.type.name}`, i6.type.isArray && (e += "[]"), i6.type.name === "class" && i6.type.options && (e += ` "${i6.type.options.join(" | ")}"`)), i6.description && i6.type?.name !== "class" && (e += ` "${i6.description}"`), e;
|
|
4954
|
+
}
|
|
4955
|
+
function pa(i6, e, t) {
|
|
4956
|
+
let n = i6 ? `"${i6}" ` : "", r = e.map(ua).join(", "), o = t.map(ua).join(", ");
|
|
4957
|
+
return `${n}${r} -> ${o}`;
|
|
4958
|
+
}
|
|
4959
|
+
function Yl(i6) {
|
|
4960
|
+
let e = /^[a-z][a-zA-Z0-9]*$/, t = /^[a-z]+(_[a-z0-9]+)*$/;
|
|
4961
|
+
return e.test(i6) || t.test(i6);
|
|
4962
|
+
}
|
|
4963
|
+
function We(i6, e) {
|
|
4964
|
+
if (!i6.name || i6.name.length === 0) throw new L("Field name cannot be blank", i6.name, "Every field must have a descriptive name");
|
|
4965
|
+
if (!Yl(i6.name)) throw new L(`Invalid field name '${i6.name}' - must be camelCase or snake_case`, i6.name, 'Use camelCase (e.g., "userInput") or snake_case (e.g., "user_input")');
|
|
4966
|
+
if (J.signatureStrict && ["text", "object", "image", "string", "number", "boolean", "json", "array", "datetime", "date", "time", "type", "class", "input", "output", "data", "value", "result", "response", "request", "item", "element"].includes(i6.name.toLowerCase())) {
|
|
4967
|
+
let n = e === "input" ? ["userInput", "questionText", "documentContent", "messageText", "queryString"] : ["responseText", "analysisResult", "categoryType", "summaryText", "outputData"];
|
|
4968
|
+
throw new L(`Field name '${i6.name}' is too generic`, i6.name, `Use a more descriptive name. Examples for ${e} fields: ${n.join(", ")}`);
|
|
4969
|
+
}
|
|
4970
|
+
if (i6.name.length < 2) throw new L(`Field name '${i6.name}' is too short`, i6.name, "Field names must be at least 2 characters long");
|
|
4971
|
+
if (i6.name.length > 50) throw new L(`Field name '${i6.name}' is too long (${i6.name.length} characters)`, i6.name, "Field names should be 50 characters or less");
|
|
4972
|
+
i6.type && Xl(i6, e);
|
|
4973
|
+
}
|
|
4974
|
+
function Xl(i6, e) {
|
|
4975
|
+
if (!i6.type) return;
|
|
4976
|
+
let { type: t } = i6;
|
|
4977
|
+
if ((t.name === "image" || t.name === "audio" || t.name === "file") && e === "output") throw new L(`${t.name} type is not supported in output fields`, i6.name, `${t.name} types can only be used in input fields`);
|
|
4978
|
+
if (t.name === "class") {
|
|
4979
|
+
if (e === "input") throw new L("Class type is not supported in input fields", i6.name, 'Class types are only allowed on output fields. Use "string" type for input classifications');
|
|
4980
|
+
if (!t.options || t.options.length === 0) throw new L("Class type requires options", i6.name, 'Provide class options. Example: class "positive, negative, neutral"');
|
|
4981
|
+
for (let r of t.options) {
|
|
4982
|
+
if (!r || r.trim().length === 0) throw new L("Empty class option found", i6.name, "All class options must be non-empty strings");
|
|
4983
|
+
let o = r.trim();
|
|
4984
|
+
if (o.includes(",") || o.includes("|")) throw new L(`Invalid class option "${o}"`, i6.name, "Class options cannot contain commas (,) or pipes (|) as they are used to separate options");
|
|
4985
|
+
}
|
|
4986
|
+
if (new Set(t.options.map((r) => r.trim().toLowerCase())).size !== t.options.length) throw new L("Duplicate class options found", i6.name, "Each class option must be unique (case-insensitive)");
|
|
4987
|
+
}
|
|
4988
|
+
if (t.name === "code" && t.isArray) throw new L("Arrays of code are not commonly supported", i6.name, "Consider using a single code field or an array of strings instead");
|
|
4989
|
+
if (i6.isInternal && e === "input") throw new L("Internal marker (!) is not allowed on input fields", i6.name, "Internal markers are only allowed on output fields");
|
|
4990
|
+
t.name === "object" && t.fields && Yo(t.fields, i6.name, e);
|
|
4991
|
+
}
|
|
4992
|
+
function Yo(i6, e, t, n = 1) {
|
|
4993
|
+
for (let [r, o] of Object.entries(i6)) {
|
|
4994
|
+
let s = `${e}.${r}`;
|
|
4995
|
+
if (o.type === "image" || o.type === "audio" || o.type === "file") throw new L(`${o.type} type is not allowed in nested object fields`, s, `Media types (image, audio, file) can only be used as top-level input fields, not within objects. Found at depth ${n}.`);
|
|
4996
|
+
o.type === "object" && o.fields && Yo(o.fields, s, t, n + 1), o.isArray && o.fields && Yo(o.fields, `${s}[]`, t, n + 1);
|
|
7476
4997
|
}
|
|
7477
|
-
};
|
|
7478
|
-
function Zo(i6, e, t) {
|
|
7479
|
-
let n = i6 instanceof Error ? i6 : new Error(String(i6)), r = (n.message || "").toLowerCase();
|
|
7480
|
-
if (r.includes("at least") || r.includes("at most") || r.includes("must match pattern") || r.includes("invalid url") || r.includes("required") || r.includes("missing") || r.includes("valid email") || r.includes("number must be") || n.name === "ValidationError" || n.name === "AssertionError" || n.name === "AxAssertionError" || n.stack?.includes("asserts.ts")) return n;
|
|
7481
|
-
let s = e.getLastUsedChatModel(), a = e.getLastUsedModelConfig(), l = { model: s, maxTokens: a?.maxTokens, streaming: a?.stream ?? false, signature: { input: t.getInputFields(), output: t.getOutputFields(), description: t.getDescription() } };
|
|
7482
|
-
return new Ar("Generate failed", l, { cause: n });
|
|
7483
4998
|
}
|
|
7484
4999
|
var Rh = new Te();
|
|
7485
5000
|
var Ra = (i6) => {
|
|
@@ -7573,10 +5088,6 @@ ${t}
|
|
|
7573
5088
|
};
|
|
7574
5089
|
};
|
|
7575
5090
|
var xr = wa();
|
|
7576
|
-
function xe(i6, e) {
|
|
7577
|
-
let t = typeof i6 == "string" ? ue.create(i6) : i6;
|
|
7578
|
-
return new ve(t, e);
|
|
7579
|
-
}
|
|
7580
5091
|
var ka = (i6) => {
|
|
7581
5092
|
console.log(i6);
|
|
7582
5093
|
};
|
|
@@ -13785,6 +11296,87 @@ function extractCodeBlocks(segments) {
|
|
|
13785
11296
|
}
|
|
13786
11297
|
return codeBlocks;
|
|
13787
11298
|
}
|
|
11299
|
+
async function processMessages(options) {
|
|
11300
|
+
const {
|
|
11301
|
+
messages,
|
|
11302
|
+
searchRoots,
|
|
11303
|
+
repoRootPath,
|
|
11304
|
+
guidelinePatterns,
|
|
11305
|
+
guidelinePaths,
|
|
11306
|
+
textParts,
|
|
11307
|
+
messageType,
|
|
11308
|
+
verbose
|
|
11309
|
+
} = options;
|
|
11310
|
+
const segments = [];
|
|
11311
|
+
for (const message of messages) {
|
|
11312
|
+
const content = message.content;
|
|
11313
|
+
if (typeof content === "string") {
|
|
11314
|
+
segments.push({ type: "text", value: content });
|
|
11315
|
+
if (textParts) {
|
|
11316
|
+
textParts.push(content);
|
|
11317
|
+
}
|
|
11318
|
+
continue;
|
|
11319
|
+
}
|
|
11320
|
+
for (const rawSegment of content) {
|
|
11321
|
+
if (!isJsonObject(rawSegment)) {
|
|
11322
|
+
continue;
|
|
11323
|
+
}
|
|
11324
|
+
const segmentType = asString(rawSegment.type);
|
|
11325
|
+
if (segmentType === "file") {
|
|
11326
|
+
const rawValue = asString(rawSegment.value);
|
|
11327
|
+
if (!rawValue) {
|
|
11328
|
+
continue;
|
|
11329
|
+
}
|
|
11330
|
+
const { displayPath, resolvedPath, attempted } = await resolveFileReference(
|
|
11331
|
+
rawValue,
|
|
11332
|
+
searchRoots
|
|
11333
|
+
);
|
|
11334
|
+
if (!resolvedPath) {
|
|
11335
|
+
const attempts = attempted.length ? [" Tried:", ...attempted.map((candidate) => ` ${candidate}`)] : void 0;
|
|
11336
|
+
const context2 = messageType === "input" ? "" : " in expected_messages";
|
|
11337
|
+
logWarning(`File not found${context2}: ${displayPath}`, attempts);
|
|
11338
|
+
continue;
|
|
11339
|
+
}
|
|
11340
|
+
try {
|
|
11341
|
+
const fileContent = (await readFile3(resolvedPath, "utf8")).replace(/\r\n/g, "\n");
|
|
11342
|
+
if (messageType === "input" && guidelinePatterns && guidelinePaths) {
|
|
11343
|
+
const relativeToRepo = path8.relative(repoRootPath, resolvedPath);
|
|
11344
|
+
if (isGuidelineFile(relativeToRepo, guidelinePatterns)) {
|
|
11345
|
+
guidelinePaths.push(path8.resolve(resolvedPath));
|
|
11346
|
+
if (verbose) {
|
|
11347
|
+
console.log(` [Guideline] Found: ${displayPath}`);
|
|
11348
|
+
console.log(` Resolved to: ${resolvedPath}`);
|
|
11349
|
+
}
|
|
11350
|
+
continue;
|
|
11351
|
+
}
|
|
11352
|
+
}
|
|
11353
|
+
segments.push({
|
|
11354
|
+
type: "file",
|
|
11355
|
+
path: displayPath,
|
|
11356
|
+
text: fileContent,
|
|
11357
|
+
resolvedPath: path8.resolve(resolvedPath)
|
|
11358
|
+
});
|
|
11359
|
+
if (verbose) {
|
|
11360
|
+
const label = messageType === "input" ? "[File]" : "[Expected Output File]";
|
|
11361
|
+
console.log(` ${label} Found: ${displayPath}`);
|
|
11362
|
+
console.log(` Resolved to: ${resolvedPath}`);
|
|
11363
|
+
}
|
|
11364
|
+
} catch (error) {
|
|
11365
|
+
const context2 = messageType === "input" ? "" : " expected output";
|
|
11366
|
+
logWarning(`Could not read${context2} file ${resolvedPath}: ${error.message}`);
|
|
11367
|
+
}
|
|
11368
|
+
continue;
|
|
11369
|
+
}
|
|
11370
|
+
const clonedSegment = cloneJsonObject(rawSegment);
|
|
11371
|
+
segments.push(clonedSegment);
|
|
11372
|
+
const inlineValue = clonedSegment.value;
|
|
11373
|
+
if (typeof inlineValue === "string" && textParts) {
|
|
11374
|
+
textParts.push(inlineValue);
|
|
11375
|
+
}
|
|
11376
|
+
}
|
|
11377
|
+
}
|
|
11378
|
+
return segments;
|
|
11379
|
+
}
|
|
13788
11380
|
async function loadEvalCases(evalFilePath, repoRoot, options) {
|
|
13789
11381
|
const verbose = options?.verbose ?? false;
|
|
13790
11382
|
const absoluteTestPath = path8.resolve(evalFilePath);
|
|
@@ -13870,77 +11462,34 @@ Please add '$schema: ${SCHEMA_EVAL_V2}' at the top of the file.`;
|
|
|
13870
11462
|
}
|
|
13871
11463
|
}
|
|
13872
11464
|
}
|
|
13873
|
-
const userSegments = [];
|
|
13874
11465
|
const guidelinePaths = [];
|
|
13875
|
-
const
|
|
13876
|
-
|
|
13877
|
-
|
|
13878
|
-
|
|
13879
|
-
|
|
13880
|
-
|
|
13881
|
-
|
|
13882
|
-
|
|
13883
|
-
|
|
13884
|
-
|
|
13885
|
-
|
|
13886
|
-
|
|
13887
|
-
|
|
13888
|
-
|
|
13889
|
-
|
|
13890
|
-
|
|
13891
|
-
|
|
13892
|
-
|
|
13893
|
-
|
|
13894
|
-
|
|
13895
|
-
searchRoots
|
|
13896
|
-
);
|
|
13897
|
-
if (!resolvedPath) {
|
|
13898
|
-
const attempts = attempted.length ? [" Tried:", ...attempted.map((candidate) => ` ${candidate}`)] : void 0;
|
|
13899
|
-
logWarning(`File not found: ${displayPath}`, attempts);
|
|
13900
|
-
continue;
|
|
13901
|
-
}
|
|
13902
|
-
try {
|
|
13903
|
-
const fileContent = (await readFile3(resolvedPath, "utf8")).replace(/\r\n/g, "\n");
|
|
13904
|
-
const relativeToRepo = path8.relative(repoRootPath, resolvedPath);
|
|
13905
|
-
if (isGuidelineFile(relativeToRepo, guidelinePatterns)) {
|
|
13906
|
-
guidelinePaths.push(path8.resolve(resolvedPath));
|
|
13907
|
-
if (verbose) {
|
|
13908
|
-
console.log(` [Guideline] Found: ${displayPath}`);
|
|
13909
|
-
console.log(` Resolved to: ${resolvedPath}`);
|
|
13910
|
-
}
|
|
13911
|
-
} else {
|
|
13912
|
-
userSegments.push({
|
|
13913
|
-
type: "file",
|
|
13914
|
-
path: displayPath,
|
|
13915
|
-
text: fileContent,
|
|
13916
|
-
resolvedPath: path8.resolve(resolvedPath)
|
|
13917
|
-
});
|
|
13918
|
-
if (verbose) {
|
|
13919
|
-
console.log(` [File] Found: ${displayPath}`);
|
|
13920
|
-
console.log(` Resolved to: ${resolvedPath}`);
|
|
13921
|
-
}
|
|
13922
|
-
}
|
|
13923
|
-
} catch (error) {
|
|
13924
|
-
logWarning(`Could not read file ${resolvedPath}: ${error.message}`);
|
|
13925
|
-
}
|
|
13926
|
-
continue;
|
|
13927
|
-
}
|
|
13928
|
-
const clonedSegment = cloneJsonObject(rawSegment);
|
|
13929
|
-
userSegments.push(clonedSegment);
|
|
13930
|
-
const inlineValue = clonedSegment.value;
|
|
13931
|
-
if (typeof inlineValue === "string") {
|
|
13932
|
-
userTextParts.push(inlineValue);
|
|
13933
|
-
}
|
|
13934
|
-
}
|
|
13935
|
-
}
|
|
13936
|
-
const codeSnippets = extractCodeBlocks(userSegments);
|
|
11466
|
+
const inputTextParts = [];
|
|
11467
|
+
const inputSegments = await processMessages({
|
|
11468
|
+
messages: userMessages,
|
|
11469
|
+
searchRoots,
|
|
11470
|
+
repoRootPath,
|
|
11471
|
+
guidelinePatterns,
|
|
11472
|
+
guidelinePaths,
|
|
11473
|
+
textParts: inputTextParts,
|
|
11474
|
+
messageType: "input",
|
|
11475
|
+
verbose
|
|
11476
|
+
});
|
|
11477
|
+
const outputSegments = await processMessages({
|
|
11478
|
+
messages: assistantMessages,
|
|
11479
|
+
searchRoots,
|
|
11480
|
+
repoRootPath,
|
|
11481
|
+
guidelinePatterns,
|
|
11482
|
+
messageType: "output",
|
|
11483
|
+
verbose
|
|
11484
|
+
});
|
|
11485
|
+
const codeSnippets = extractCodeBlocks(inputSegments);
|
|
13937
11486
|
const assistantContent = assistantMessages[0]?.content;
|
|
13938
|
-
const
|
|
13939
|
-
const
|
|
11487
|
+
const referenceAnswer = await resolveAssistantContent(assistantContent, searchRoots, verbose);
|
|
11488
|
+
const question = inputTextParts.map((part) => part.trim()).filter((part) => part.length > 0).join(" ");
|
|
13940
11489
|
const testCaseEvaluatorKind = coerceEvaluator(evalcase.evaluator, id) ?? globalEvaluator;
|
|
13941
11490
|
const evaluators = await parseEvaluators(evalcase, searchRoots, id ?? "unknown");
|
|
13942
11491
|
const userFilePaths = [];
|
|
13943
|
-
for (const segment of
|
|
11492
|
+
for (const segment of inputSegments) {
|
|
13944
11493
|
if (segment.type === "file" && typeof segment.resolvedPath === "string") {
|
|
13945
11494
|
userFilePaths.push(segment.resolvedPath);
|
|
13946
11495
|
}
|
|
@@ -13953,15 +11502,16 @@ Please add '$schema: ${SCHEMA_EVAL_V2}' at the top of the file.`;
|
|
|
13953
11502
|
id,
|
|
13954
11503
|
dataset: datasetName,
|
|
13955
11504
|
conversation_id: conversationId,
|
|
13956
|
-
|
|
13957
|
-
|
|
11505
|
+
question,
|
|
11506
|
+
input_segments: inputSegments,
|
|
11507
|
+
output_segments: outputSegments,
|
|
13958
11508
|
system_message: systemMessageContent,
|
|
13959
|
-
|
|
11509
|
+
reference_answer: referenceAnswer,
|
|
13960
11510
|
guideline_paths: guidelinePaths.map((guidelinePath) => path8.resolve(guidelinePath)),
|
|
13961
11511
|
guideline_patterns: guidelinePatterns,
|
|
13962
11512
|
file_paths: allFilePaths,
|
|
13963
11513
|
code_snippets: codeSnippets,
|
|
13964
|
-
outcome,
|
|
11514
|
+
expected_outcome: outcome,
|
|
13965
11515
|
evaluator: testCaseEvaluatorKind,
|
|
13966
11516
|
evaluators
|
|
13967
11517
|
};
|
|
@@ -13997,36 +11547,36 @@ ${content}`);
|
|
|
13997
11547
|
logWarning(`Could not read guideline file ${absolutePath}: ${error.message}`);
|
|
13998
11548
|
}
|
|
13999
11549
|
}
|
|
14000
|
-
const
|
|
14001
|
-
for (const segment of testCase.
|
|
11550
|
+
const questionParts = [];
|
|
11551
|
+
for (const segment of testCase.input_segments) {
|
|
14002
11552
|
const typeValue = segment.type;
|
|
14003
11553
|
if (typeof typeValue === "string" && typeValue === "file") {
|
|
14004
11554
|
const pathValue = segment.path;
|
|
14005
11555
|
const textValue = segment.text;
|
|
14006
11556
|
const label = typeof pathValue === "string" ? pathValue : "file";
|
|
14007
11557
|
const body = typeof textValue === "string" ? textValue : "";
|
|
14008
|
-
|
|
11558
|
+
questionParts.push(`=== ${label} ===
|
|
14009
11559
|
${body}`);
|
|
14010
11560
|
continue;
|
|
14011
11561
|
}
|
|
14012
11562
|
if (typeof typeValue === "string" && typeValue === "text") {
|
|
14013
11563
|
const value = segment.value;
|
|
14014
11564
|
if (typeof value === "string") {
|
|
14015
|
-
|
|
11565
|
+
questionParts.push(value);
|
|
14016
11566
|
}
|
|
14017
11567
|
continue;
|
|
14018
11568
|
}
|
|
14019
11569
|
const genericValue = segment.value;
|
|
14020
11570
|
if (typeof genericValue === "string") {
|
|
14021
|
-
|
|
11571
|
+
questionParts.push(genericValue);
|
|
14022
11572
|
}
|
|
14023
11573
|
}
|
|
14024
11574
|
if (testCase.code_snippets.length > 0) {
|
|
14025
|
-
|
|
11575
|
+
questionParts.push(testCase.code_snippets.join("\n"));
|
|
14026
11576
|
}
|
|
14027
|
-
const
|
|
11577
|
+
const question = questionParts.map((part) => part.trim()).filter((part) => part.length > 0).join("\n\n");
|
|
14028
11578
|
const guidelines = guidelineContents.map((part) => part.trim()).filter((part) => part.length > 0).join("\n\n");
|
|
14029
|
-
return {
|
|
11579
|
+
return { question, guidelines, systemMessage: testCase.system_message };
|
|
14030
11580
|
}
|
|
14031
11581
|
async function fileExists2(absolutePath) {
|
|
14032
11582
|
try {
|
|
@@ -14235,7 +11785,7 @@ function buildChatPrompt(request) {
|
|
|
14235
11785
|
${request.guidelines.trim()}`);
|
|
14236
11786
|
}
|
|
14237
11787
|
const systemContent = systemSegments.join("\n\n");
|
|
14238
|
-
const userContent = request.
|
|
11788
|
+
const userContent = request.question.trim();
|
|
14239
11789
|
const prompt = [
|
|
14240
11790
|
{
|
|
14241
11791
|
role: "system",
|
|
@@ -14528,7 +12078,7 @@ var CliProvider = class {
|
|
|
14528
12078
|
healthcheck.commandTemplate,
|
|
14529
12079
|
buildTemplateValues(
|
|
14530
12080
|
{
|
|
14531
|
-
|
|
12081
|
+
question: "",
|
|
14532
12082
|
guidelines: "",
|
|
14533
12083
|
inputFiles: [],
|
|
14534
12084
|
evalCaseId: "",
|
|
@@ -14555,7 +12105,7 @@ var CliProvider = class {
|
|
|
14555
12105
|
function buildTemplateValues(request, config) {
|
|
14556
12106
|
const inputFiles = normalizeInputFiles(request.inputFiles);
|
|
14557
12107
|
return {
|
|
14558
|
-
PROMPT: shellEscape(request.
|
|
12108
|
+
PROMPT: shellEscape(request.question ?? ""),
|
|
14559
12109
|
GUIDELINES: shellEscape(request.guidelines ?? ""),
|
|
14560
12110
|
EVAL_ID: shellEscape(request.evalCaseId ?? ""),
|
|
14561
12111
|
ATTEMPT: shellEscape(String(request.attempt ?? 0)),
|
|
@@ -14609,6 +12159,50 @@ function formatTimeoutSuffix(timeoutMs) {
|
|
|
14609
12159
|
const seconds = Math.ceil(timeoutMs / 1e3);
|
|
14610
12160
|
return ` after ${seconds}s`;
|
|
14611
12161
|
}
|
|
12162
|
+
var GLOBAL_LOGS_KEY = Symbol.for("agentv.codexLogs");
|
|
12163
|
+
var GLOBAL_SUBSCRIBERS_KEY = Symbol.for("agentv.codexLogSubscribers");
|
|
12164
|
+
function getCodexLogStore() {
|
|
12165
|
+
const globalObject = globalThis;
|
|
12166
|
+
const existing = globalObject[GLOBAL_LOGS_KEY];
|
|
12167
|
+
if (existing) {
|
|
12168
|
+
return existing;
|
|
12169
|
+
}
|
|
12170
|
+
const created = [];
|
|
12171
|
+
globalObject[GLOBAL_LOGS_KEY] = created;
|
|
12172
|
+
return created;
|
|
12173
|
+
}
|
|
12174
|
+
function getSubscriberStore() {
|
|
12175
|
+
const globalObject = globalThis;
|
|
12176
|
+
const existing = globalObject[GLOBAL_SUBSCRIBERS_KEY];
|
|
12177
|
+
if (existing) {
|
|
12178
|
+
return existing;
|
|
12179
|
+
}
|
|
12180
|
+
const created = /* @__PURE__ */ new Set();
|
|
12181
|
+
globalObject[GLOBAL_SUBSCRIBERS_KEY] = created;
|
|
12182
|
+
return created;
|
|
12183
|
+
}
|
|
12184
|
+
function notifySubscribers(entry) {
|
|
12185
|
+
const subscribers = Array.from(getSubscriberStore());
|
|
12186
|
+
for (const listener of subscribers) {
|
|
12187
|
+
try {
|
|
12188
|
+
listener(entry);
|
|
12189
|
+
} catch (error) {
|
|
12190
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
12191
|
+
console.warn(`Codex log subscriber failed: ${message}`);
|
|
12192
|
+
}
|
|
12193
|
+
}
|
|
12194
|
+
}
|
|
12195
|
+
function recordCodexLogEntry(entry) {
|
|
12196
|
+
getCodexLogStore().push(entry);
|
|
12197
|
+
notifySubscribers(entry);
|
|
12198
|
+
}
|
|
12199
|
+
function subscribeToCodexLogEntries(listener) {
|
|
12200
|
+
const store = getSubscriberStore();
|
|
12201
|
+
store.add(listener);
|
|
12202
|
+
return () => {
|
|
12203
|
+
store.delete(listener);
|
|
12204
|
+
};
|
|
12205
|
+
}
|
|
14612
12206
|
function buildPromptDocument(request, inputFiles, options) {
|
|
14613
12207
|
const parts = [];
|
|
14614
12208
|
const guidelineFiles = collectGuidelineFiles(
|
|
@@ -14624,7 +12218,7 @@ function buildPromptDocument(request, inputFiles, options) {
|
|
|
14624
12218
|
if (prereadBlock.length > 0) {
|
|
14625
12219
|
parts.push("\n", prereadBlock);
|
|
14626
12220
|
}
|
|
14627
|
-
parts.push("\n[[ ## user_query ## ]]\n", request.
|
|
12221
|
+
parts.push("\n[[ ## user_query ## ]]\n", request.question.trim());
|
|
14628
12222
|
return parts.join("\n").trim();
|
|
14629
12223
|
}
|
|
14630
12224
|
function normalizeInputFiles2(inputFiles) {
|
|
@@ -14707,50 +12301,6 @@ function pathToFileUri2(filePath) {
|
|
|
14707
12301
|
}
|
|
14708
12302
|
return `file://${normalizedPath}`;
|
|
14709
12303
|
}
|
|
14710
|
-
var GLOBAL_LOGS_KEY = Symbol.for("agentv.codexLogs");
|
|
14711
|
-
var GLOBAL_SUBSCRIBERS_KEY = Symbol.for("agentv.codexLogSubscribers");
|
|
14712
|
-
function getCodexLogStore() {
|
|
14713
|
-
const globalObject = globalThis;
|
|
14714
|
-
const existing = globalObject[GLOBAL_LOGS_KEY];
|
|
14715
|
-
if (existing) {
|
|
14716
|
-
return existing;
|
|
14717
|
-
}
|
|
14718
|
-
const created = [];
|
|
14719
|
-
globalObject[GLOBAL_LOGS_KEY] = created;
|
|
14720
|
-
return created;
|
|
14721
|
-
}
|
|
14722
|
-
function getSubscriberStore() {
|
|
14723
|
-
const globalObject = globalThis;
|
|
14724
|
-
const existing = globalObject[GLOBAL_SUBSCRIBERS_KEY];
|
|
14725
|
-
if (existing) {
|
|
14726
|
-
return existing;
|
|
14727
|
-
}
|
|
14728
|
-
const created = /* @__PURE__ */ new Set();
|
|
14729
|
-
globalObject[GLOBAL_SUBSCRIBERS_KEY] = created;
|
|
14730
|
-
return created;
|
|
14731
|
-
}
|
|
14732
|
-
function notifySubscribers(entry) {
|
|
14733
|
-
const subscribers = Array.from(getSubscriberStore());
|
|
14734
|
-
for (const listener of subscribers) {
|
|
14735
|
-
try {
|
|
14736
|
-
listener(entry);
|
|
14737
|
-
} catch (error) {
|
|
14738
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
14739
|
-
console.warn(`Codex log subscriber failed: ${message}`);
|
|
14740
|
-
}
|
|
14741
|
-
}
|
|
14742
|
-
}
|
|
14743
|
-
function recordCodexLogEntry(entry) {
|
|
14744
|
-
getCodexLogStore().push(entry);
|
|
14745
|
-
notifySubscribers(entry);
|
|
14746
|
-
}
|
|
14747
|
-
function subscribeToCodexLogEntries(listener) {
|
|
14748
|
-
const store = getSubscriberStore();
|
|
14749
|
-
store.add(listener);
|
|
14750
|
-
return () => {
|
|
14751
|
-
store.delete(listener);
|
|
14752
|
-
};
|
|
14753
|
-
}
|
|
14754
12304
|
var execAsync22 = promisify22(execCallback);
|
|
14755
12305
|
var WORKSPACE_PREFIX = "agentv-codex-";
|
|
14756
12306
|
var PROMPT_FILENAME = "prompt.md";
|
|
@@ -15481,7 +13031,7 @@ var MockProvider = class {
|
|
|
15481
13031
|
return {
|
|
15482
13032
|
text: this.cannedResponse,
|
|
15483
13033
|
raw: {
|
|
15484
|
-
|
|
13034
|
+
question: request.question,
|
|
15485
13035
|
guidelines: request.guidelines
|
|
15486
13036
|
}
|
|
15487
13037
|
};
|
|
@@ -16089,7 +13639,7 @@ function buildPromptDocument2(request, attachments, guidelinePatterns) {
|
|
|
16089
13639
|
if (prereadBlock.length > 0) {
|
|
16090
13640
|
parts.push("\n", prereadBlock);
|
|
16091
13641
|
}
|
|
16092
|
-
parts.push("\n[[ ## user_query ## ]]\n", request.
|
|
13642
|
+
parts.push("\n[[ ## user_query ## ]]\n", request.question.trim());
|
|
16093
13643
|
return parts.join("\n").trim();
|
|
16094
13644
|
}
|
|
16095
13645
|
function buildMandatoryPrereadBlock2(guidelineFiles, attachmentFiles) {
|
|
@@ -16312,28 +13862,6 @@ function createProvider(target) {
|
|
|
16312
13862
|
}
|
|
16313
13863
|
}
|
|
16314
13864
|
}
|
|
16315
|
-
var LLM_JUDGE_SIGNATURE = oe().input(
|
|
16316
|
-
"evaluationContext",
|
|
16317
|
-
oe.object(
|
|
16318
|
-
{
|
|
16319
|
-
expectedOutcome: oe.string("The expected outcome for the original task"),
|
|
16320
|
-
request: oe.string("The original task request"),
|
|
16321
|
-
referenceAnswer: oe.string("The gold standard reference answer"),
|
|
16322
|
-
generatedAnswer: oe.string("The answer to evaluate"),
|
|
16323
|
-
guidelines: oe.string("Additional evaluation guidelines or instructions").optional()
|
|
16324
|
-
},
|
|
16325
|
-
"Complete evaluation context for the judge"
|
|
16326
|
-
)
|
|
16327
|
-
).output(
|
|
16328
|
-
"evaluation",
|
|
16329
|
-
oe.object({
|
|
16330
|
-
score: oe.number("Score between 0.0 and 1.0").min(0).max(1),
|
|
16331
|
-
hits: oe.string("Brief specific achievement").array(),
|
|
16332
|
-
misses: oe.string("Brief specific failure or omission").array(),
|
|
16333
|
-
reasoning: oe.string("Concise explanation for the score").max(500)
|
|
16334
|
-
})
|
|
16335
|
-
).build();
|
|
16336
|
-
var LLM_JUDGE = xe(LLM_JUDGE_SIGNATURE);
|
|
16337
13865
|
var LlmJudgeEvaluator = class {
|
|
16338
13866
|
kind = "llm_judge";
|
|
16339
13867
|
resolveJudgeProvider;
|
|
@@ -16351,52 +13879,29 @@ var LlmJudgeEvaluator = class {
|
|
|
16351
13879
|
if (!judgeProvider) {
|
|
16352
13880
|
throw new Error("No judge provider available for LLM grading");
|
|
16353
13881
|
}
|
|
16354
|
-
if (providerSupportsAx(judgeProvider)) {
|
|
16355
|
-
return this.evaluateWithAx(context2, judgeProvider);
|
|
16356
|
-
}
|
|
16357
13882
|
return this.evaluateWithPrompt(context2, judgeProvider);
|
|
16358
13883
|
}
|
|
16359
|
-
async evaluateWithAx(context2, judgeProvider) {
|
|
16360
|
-
const ai = judgeProvider.getAxAI();
|
|
16361
|
-
const guidelines = context2.promptInputs.guidelines?.trim();
|
|
16362
|
-
const evaluationContext = {
|
|
16363
|
-
expectedOutcome: context2.evalCase.outcome.trim(),
|
|
16364
|
-
request: context2.evalCase.task.trim(),
|
|
16365
|
-
referenceAnswer: context2.evalCase.expected_assistant_raw.trim(),
|
|
16366
|
-
generatedAnswer: context2.candidate.trim(),
|
|
16367
|
-
...guidelines ? { guidelines } : {}
|
|
16368
|
-
};
|
|
16369
|
-
const options = this.buildJudgeForwardOptions(context2);
|
|
16370
|
-
const result = await LLM_JUDGE.forward(ai, { evaluationContext }, options);
|
|
16371
|
-
const evaluation = result.evaluation;
|
|
16372
|
-
const expectedAspectCount = Math.max(
|
|
16373
|
-
evaluation.hits.length + evaluation.misses.length,
|
|
16374
|
-
1
|
|
16375
|
-
);
|
|
16376
|
-
return {
|
|
16377
|
-
score: evaluation.score,
|
|
16378
|
-
hits: evaluation.hits,
|
|
16379
|
-
misses: evaluation.misses,
|
|
16380
|
-
expectedAspectCount,
|
|
16381
|
-
reasoning: evaluation.reasoning,
|
|
16382
|
-
evaluatorRawRequest: {
|
|
16383
|
-
id: randomUUID2(),
|
|
16384
|
-
provider: judgeProvider.id,
|
|
16385
|
-
target: context2.target.name,
|
|
16386
|
-
method: "ax-structured-output",
|
|
16387
|
-
signature: LLM_JUDGE_SIGNATURE.toString()
|
|
16388
|
-
}
|
|
16389
|
-
};
|
|
16390
|
-
}
|
|
16391
13884
|
async evaluateWithPrompt(context2, judgeProvider) {
|
|
16392
|
-
|
|
16393
|
-
|
|
13885
|
+
let prompt = buildQualityPrompt(context2.evalCase, context2.candidate);
|
|
13886
|
+
let systemPrompt = context2.systemPrompt ?? this.customPrompt ?? QUALITY_SYSTEM_PROMPT;
|
|
13887
|
+
if (systemPrompt && hasTemplateVariables(systemPrompt)) {
|
|
13888
|
+
const variables = {
|
|
13889
|
+
input_messages: JSON.stringify(context2.evalCase.input_segments, null, 2),
|
|
13890
|
+
output_messages: JSON.stringify(context2.evalCase.output_segments, null, 2),
|
|
13891
|
+
candidate_answer: context2.candidate,
|
|
13892
|
+
reference_answer: context2.evalCase.reference_answer,
|
|
13893
|
+
expected_outcome: context2.evalCase.expected_outcome,
|
|
13894
|
+
question: context2.evalCase.question
|
|
13895
|
+
};
|
|
13896
|
+
prompt = substituteVariables(systemPrompt, variables);
|
|
13897
|
+
systemPrompt = QUALITY_SYSTEM_PROMPT;
|
|
13898
|
+
}
|
|
16394
13899
|
const metadata = {
|
|
16395
13900
|
...systemPrompt !== void 0 ? { systemPrompt } : {},
|
|
16396
13901
|
...context2.judgeModel !== void 0 ? { model: context2.judgeModel } : {}
|
|
16397
13902
|
};
|
|
16398
13903
|
const response = await judgeProvider.invoke({
|
|
16399
|
-
prompt,
|
|
13904
|
+
question: prompt,
|
|
16400
13905
|
metadata,
|
|
16401
13906
|
evalCaseId: context2.evalCase.id,
|
|
16402
13907
|
attempt: context2.attempt,
|
|
@@ -16426,33 +13931,11 @@ var LlmJudgeEvaluator = class {
|
|
|
16426
13931
|
evaluatorRawRequest
|
|
16427
13932
|
};
|
|
16428
13933
|
}
|
|
16429
|
-
buildJudgeForwardOptions(context2) {
|
|
16430
|
-
const modelConfig = this.buildJudgeModelConfig();
|
|
16431
|
-
if (modelConfig === void 0 && context2.judgeModel === void 0) {
|
|
16432
|
-
return void 0;
|
|
16433
|
-
}
|
|
16434
|
-
return {
|
|
16435
|
-
...context2.judgeModel ? { model: context2.judgeModel } : {},
|
|
16436
|
-
...modelConfig ? { modelConfig } : {}
|
|
16437
|
-
};
|
|
16438
|
-
}
|
|
16439
|
-
buildJudgeModelConfig() {
|
|
16440
|
-
if (this.maxOutputTokens === void 0 && this.temperature === void 0) {
|
|
16441
|
-
return void 0;
|
|
16442
|
-
}
|
|
16443
|
-
return {
|
|
16444
|
-
...this.maxOutputTokens !== void 0 ? { maxTokens: this.maxOutputTokens } : {},
|
|
16445
|
-
...this.temperature !== void 0 ? { temperature: this.temperature } : {}
|
|
16446
|
-
};
|
|
16447
|
-
}
|
|
16448
13934
|
};
|
|
16449
|
-
function providerSupportsAx(provider) {
|
|
16450
|
-
return typeof provider.getAxAI === "function";
|
|
16451
|
-
}
|
|
16452
13935
|
var QUALITY_SYSTEM_PROMPT = [
|
|
16453
|
-
"You are an expert evaluator. Your goal is to grade the
|
|
13936
|
+
"You are an expert evaluator. Your goal is to grade the candidate_answer based on how well it achieves the expected_outcome for the original task.",
|
|
16454
13937
|
"",
|
|
16455
|
-
"Use the reference_answer as a gold standard for a high-quality response. The
|
|
13938
|
+
"Use the reference_answer as a gold standard for a high-quality response. The candidate_answer does not need to match it verbatim, but it should capture the key points and follow the same spirit.",
|
|
16456
13939
|
"",
|
|
16457
13940
|
"Be concise and focused in your evaluation. Provide succinct, specific feedback rather than verbose explanations.",
|
|
16458
13941
|
"",
|
|
@@ -16465,18 +13948,18 @@ var QUALITY_SYSTEM_PROMPT = [
|
|
|
16465
13948
|
' "reasoning": "<string, concise explanation for the score, 1-2 sentences max>"',
|
|
16466
13949
|
"}"
|
|
16467
13950
|
].join("\n");
|
|
16468
|
-
function buildQualityPrompt(
|
|
13951
|
+
function buildQualityPrompt(evalCase, candidate) {
|
|
16469
13952
|
const parts = [
|
|
16470
13953
|
"[[ ## expected_outcome ## ]]",
|
|
16471
|
-
|
|
13954
|
+
evalCase.expected_outcome.trim(),
|
|
16472
13955
|
"",
|
|
16473
|
-
"[[ ##
|
|
16474
|
-
|
|
13956
|
+
"[[ ## question ## ]]",
|
|
13957
|
+
evalCase.question.trim(),
|
|
16475
13958
|
"",
|
|
16476
13959
|
"[[ ## reference_answer ## ]]",
|
|
16477
|
-
|
|
13960
|
+
evalCase.reference_answer.trim(),
|
|
16478
13961
|
"",
|
|
16479
|
-
"[[ ##
|
|
13962
|
+
"[[ ## candidate_answer ## ]]",
|
|
16480
13963
|
candidate.trim(),
|
|
16481
13964
|
"",
|
|
16482
13965
|
"Respond with a single JSON object matching the schema described in the system prompt."
|
|
@@ -16576,14 +14059,14 @@ var CodeEvaluator = class {
|
|
|
16576
14059
|
async evaluate(context2) {
|
|
16577
14060
|
const inputPayload = JSON.stringify(
|
|
16578
14061
|
{
|
|
16579
|
-
|
|
16580
|
-
|
|
16581
|
-
|
|
16582
|
-
|
|
14062
|
+
question: context2.evalCase.question,
|
|
14063
|
+
expected_outcome: context2.evalCase.expected_outcome,
|
|
14064
|
+
reference_answer: context2.evalCase.reference_answer,
|
|
14065
|
+
candidate_answer: context2.candidate,
|
|
16583
14066
|
system_message: context2.promptInputs.systemMessage ?? "",
|
|
16584
14067
|
guideline_paths: context2.evalCase.guideline_paths,
|
|
16585
|
-
|
|
16586
|
-
|
|
14068
|
+
input_files: context2.evalCase.file_paths,
|
|
14069
|
+
input_segments: context2.evalCase.input_segments
|
|
16587
14070
|
},
|
|
16588
14071
|
null,
|
|
16589
14072
|
2
|
|
@@ -16669,6 +14152,14 @@ function parseJsonSafe(payload) {
|
|
|
16669
14152
|
return void 0;
|
|
16670
14153
|
}
|
|
16671
14154
|
}
|
|
14155
|
+
function hasTemplateVariables(text) {
|
|
14156
|
+
return /\$\{[a-zA-Z0-9_]+\}/.test(text);
|
|
14157
|
+
}
|
|
14158
|
+
function substituteVariables(template, variables) {
|
|
14159
|
+
return template.replace(/\$\{([a-zA-Z0-9_]+)\}/g, (match, varName) => {
|
|
14160
|
+
return variables[varName] ?? match;
|
|
14161
|
+
});
|
|
14162
|
+
}
|
|
16672
14163
|
var Node = class {
|
|
16673
14164
|
value;
|
|
16674
14165
|
next;
|
|
@@ -17014,7 +14505,7 @@ async function runBatchEvaluation(options) {
|
|
|
17014
14505
|
const batchRequests = evalCases.map((evalCase, index) => {
|
|
17015
14506
|
const promptInputs = promptInputsList[index];
|
|
17016
14507
|
return {
|
|
17017
|
-
|
|
14508
|
+
question: promptInputs.question,
|
|
17018
14509
|
guidelines: promptInputs.guidelines,
|
|
17019
14510
|
guideline_patterns: evalCase.guideline_patterns,
|
|
17020
14511
|
inputFiles: evalCase.file_paths,
|
|
@@ -17201,7 +14692,7 @@ async function evaluateCandidate(options) {
|
|
|
17201
14692
|
});
|
|
17202
14693
|
const completedAt = nowFn();
|
|
17203
14694
|
const rawRequest = {
|
|
17204
|
-
|
|
14695
|
+
question: promptInputs.question,
|
|
17205
14696
|
guidelines: promptInputs.guidelines,
|
|
17206
14697
|
guideline_paths: evalCase.guideline_paths,
|
|
17207
14698
|
system_message: promptInputs.systemMessage ?? ""
|
|
@@ -17213,7 +14704,7 @@ async function evaluateCandidate(options) {
|
|
|
17213
14704
|
score: score.score,
|
|
17214
14705
|
hits: score.hits,
|
|
17215
14706
|
misses: score.misses,
|
|
17216
|
-
|
|
14707
|
+
candidate_answer: candidate,
|
|
17217
14708
|
expected_aspect_count: score.expectedAspectCount,
|
|
17218
14709
|
target: target.name,
|
|
17219
14710
|
timestamp: completedAt.toISOString(),
|
|
@@ -17423,7 +14914,7 @@ async function dumpPrompt(directory, evalCase, promptInputs) {
|
|
|
17423
14914
|
await mkdir22(path72.dirname(filePath), { recursive: true });
|
|
17424
14915
|
const payload = {
|
|
17425
14916
|
eval_id: evalCase.id,
|
|
17426
|
-
|
|
14917
|
+
question: promptInputs.question,
|
|
17427
14918
|
guidelines: promptInputs.guidelines,
|
|
17428
14919
|
guideline_paths: evalCase.guideline_paths
|
|
17429
14920
|
};
|
|
@@ -17445,7 +14936,7 @@ async function invokeProvider(provider, options) {
|
|
|
17445
14936
|
}
|
|
17446
14937
|
try {
|
|
17447
14938
|
return await provider.invoke({
|
|
17448
|
-
|
|
14939
|
+
question: promptInputs.question,
|
|
17449
14940
|
guidelines: promptInputs.guidelines,
|
|
17450
14941
|
guideline_patterns: evalCase.guideline_patterns,
|
|
17451
14942
|
inputFiles: evalCase.file_paths,
|
|
@@ -17465,7 +14956,7 @@ async function invokeProvider(provider, options) {
|
|
|
17465
14956
|
function buildErrorResult(evalCase, targetName, timestamp, error, promptInputs) {
|
|
17466
14957
|
const message = error instanceof Error ? error.message : String(error);
|
|
17467
14958
|
const rawRequest = {
|
|
17468
|
-
|
|
14959
|
+
question: promptInputs.question,
|
|
17469
14960
|
guidelines: promptInputs.guidelines,
|
|
17470
14961
|
guideline_paths: evalCase.guideline_paths,
|
|
17471
14962
|
system_message: promptInputs.systemMessage ?? "",
|
|
@@ -17478,7 +14969,7 @@ function buildErrorResult(evalCase, targetName, timestamp, error, promptInputs)
|
|
|
17478
14969
|
score: 0,
|
|
17479
14970
|
hits: [],
|
|
17480
14971
|
misses: [`Error: ${message}`],
|
|
17481
|
-
|
|
14972
|
+
candidate_answer: `Error occurred: ${message}`,
|
|
17482
14973
|
expected_aspect_count: 0,
|
|
17483
14974
|
target: targetName,
|
|
17484
14975
|
timestamp: timestamp.toISOString(),
|
|
@@ -17491,7 +14982,7 @@ function createCacheKey(provider, target, evalCase, promptInputs) {
|
|
|
17491
14982
|
hash.update(provider.id);
|
|
17492
14983
|
hash.update(target.name);
|
|
17493
14984
|
hash.update(evalCase.id);
|
|
17494
|
-
hash.update(promptInputs.
|
|
14985
|
+
hash.update(promptInputs.question);
|
|
17495
14986
|
hash.update(promptInputs.guidelines);
|
|
17496
14987
|
hash.update(promptInputs.systemMessage ?? "");
|
|
17497
14988
|
return hash.digest("hex");
|
|
@@ -19895,4 +17386,4 @@ export {
|
|
|
19895
17386
|
createProgram,
|
|
19896
17387
|
runCli
|
|
19897
17388
|
};
|
|
19898
|
-
//# sourceMappingURL=chunk-
|
|
17389
|
+
//# sourceMappingURL=chunk-X6NSDSD2.js.map
|